Repository navigation
Commit c8cb510
<!-- claude-projects-attribution: {"github_login":"zhuangjianguo"} -->
_Requested by **Steedos** · [project
thread](https://claude.ai/code/project/chan_018ETKaNwMZCNRYD7D8Q9Ubb?thread=cmsg_018ETKaNwMZCNRYD7D8Q9Ubb7q6UepuLZRqHF7Q7j1iobb)_
Fixes #25866
Clause-②: yes (widening)
Metadata-protocol: added
Ruling-ref: 6408558941
## What lands
`FieldPermissionSchema` gains an optional `when`: a row condition in the
same canonical CEL as `rowLevelSecurity[].using`, on the **edit** vote
only (letter A of the ruling, comment 6408558941).
- **Spec** (`packages/spec/src/security/permission.zod.ts`). `when` is a
non-blank string; `readable: false` beside it is refused at parse with a
message that says the condition reaches the edit vote only; `condition`
/ `where` / `filter` are refused with a pointer to `when`. The describe
states the whole contract (absent votes on every row; present votes as
declared on matching rows and is **absent** elsewhere; stored row before
an update, incoming row on an insert; unjudgeable rows are the lock;
validated like an RLS predicate; row-blind readers report the lock).
Generated artefacts regenerated (`authorable-surface/security.json`,
`content/docs/references/{api/protocol,security/permission}.mdx`,
`liveness/state-counts/permission.md`);
`dropped-refinements.baseline.json` gains the `security/FieldPermission`
root site and the six `fields.valueType` sites the build printed;
`liveness/permission.json` classifies `fields.when` live with its
readers.
- **Core** (`effective-object-permissions.ts`).
`fieldPermissionVote(entry, verdict)` is the ONE reading of an entry
under a tri-state verdict (`matched` / `unmatched` / `unjudged`), and
`buildEffectiveFieldPermissions(sets)` is the row-blind most-permissive
merge the hono endpoint now calls. Bits are read `=== true`,
byte-identical to the previous merges for an entry without `when`.
- **RLS compiler** (`rls-compiler.ts`). The `current_user` builder is
extracted from `compileFilter` into one private `userContextOf`
(reserved-key refusal included), and `compileRowPredicate(expression,
executionContext, fieldGuard?)` compiles ONE predicate through the same
compile, field-existence judge and comparand faces a `check` clause
takes — no OR-combination, no deny sentinel. ⛔ Not the `ql.findOne`
query rewrite of the `using` gate: the row is judged in process.
- **Evaluator** (`permission-evaluator.ts`).
`getFieldPermissions(object, sets, judge?)` votes each entry through
`fieldPermissionVote`; without a judge a conditioned entry is `unjudged`
(its lock). `conditionedFieldEntries(object, sets)` lists them for
explain.
- **Write gate** (`security-plugin-object-inputs.ts` →
`computeForbiddenFieldWrites`, now async, with a `row` argument). Fast
path when no set carries a `when` for the object. Otherwise each
distinct `when` is compiled once (`compileRowPredicate` with the
object's field guard) and judged by the gate's own
`storedFormCheckJudge`: each incoming row of an insert on its own values
(the union is refused), the caller-read stored row of a by-id update
(`getCallerPreImage`, fetched lazily and only when a `when` exists). A
null pre-image, a predicate update, a reader that holds no row, or a
condition that yields no filter for this request applies the entry as
its lock and WARNs why. Wired at the middleware's field step (2.5) and
in `canWriteObject` (`security-plugin-object-admission.ts`: inserts
judged on the payload, updates applied as the lock since the method
holds no row).
- **Explain** (`explain-engine.ts`). The `fls` layer appends a sentence
naming each row-conditioned entry as such: `amount (locked when status
== 'approved', set "hr_user")` — judged per row by the write gate,
applied as the lock elsewhere.
- **Lint** (`validate-rls-predicate-enforceability.ts`). A new `when`
clause: `permissions[].fields["<object>.<field>"].when` is walked by the
passes `using` / `check` take, against the key's object (the head before
the first `.`), with the cost named: the entry cannot be judged and is
applied as its lock on every row. Ids: the existing `rls-predicate-*`
five.
- **Hono** (`current-user-endpoints.ts`). The inline `fields` merge of
`/auth/me/permissions` is `buildEffectiveFieldPermissions(resolved)`:
row-blind, so a conditioned entry is reported as its lock and no client
is told of an edit the gate refuses.
- **ADR-0066 ⑧** gains the dated note (2026-10-26): the row condition
narrows where an entry votes and does not change the union-without-deny
posture. The ADR anchor for `permission-evaluator.ts` already pins
ADR-0066, so no anchor file changes.
- **Changeset** `.changeset/25866-field-permission-row-condition.md`:
`minor` on spec, core, plugin-security, lint, plugin-hono-server.
## Readers of `getFieldPermissions` — each one's conclusion
| Reader | Conclusion |
| --- | --- |
| `security-plugin-explain-access.ts` (`getFieldMask`,
`getPartialMaskRules`) | Row-blind by design; no judge passed, so a
conditioned entry is its lock. The explain report additionally names
each such entry in the `fls` layer. No change to the mask derivation. |
| `security-plugin-field-readers.ts` (writable-field projection,
:188/:212) | Row-blind; lock. A form may show a field read-only on a row
the gate would admit — the honest direction (never wider than the gate).
Unchanged code. |
| `security-plugin-object-inputs.ts` `computeQueryGuardFieldPerms`
(:460/:466) and `maskOperationResult` | Row-blind; lock (read bits are
row-blind by contract, so the masker's answer is unchanged). Unchanged
code. |
| `packages/lint/src/validate-security-posture.ts` :755 / :814 | Reads
the entry's key qualification and field existence only; `when` changes
neither. The predicate itself is judged in
`validate-rls-predicate-enforceability.ts` (see deviations). Unchanged
code. |
| `packages/core/src/security/effective-object-permissions.ts` ~:546 |
The `objects` merge is untouched; the `fields` merge now lives beside it
(`buildEffectiveFieldPermissions`) and reads the lock. |
| `plugin-hono-server/src/current-user-endpoints.ts` ~:900 | Calls the
core merge; row-blind lock. |
## Landing-point deviations from the Claim (6410022810)
1. **Lint landed in `validate-rls-predicate-enforceability.ts`, not
`validate-security-posture.ts`.** The ruling says "validated like an RLS
predicate (field names exist, no cross-object)". That rule already owns
the compiler-backed passes (`isSupportedRlsExpression`, the reference
pass, the comparand faces) and the five `rls-predicate-*` ids; a second
spelling in `validate-security-posture.ts` would be the drift the rule
exists to avoid. `validate-security-posture.ts` is unchanged.
2. **`plugin-hono-server/src/current-user-endpoints.ts` is touched**
(outside the Claim's parenthetical list, inside its "other readers"
obligation): it carried an inline copy of the field merge, which would
otherwise have reported a conditioned entry as editable.
3. **Spec generated artefacts** beyond `json-schema`: the build also
rewrites `authorable-surface/security.json`, two reference `.mdx` pages,
the dropped-refinements ledger and the liveness ledger + state count.
All in the Claim's "+ generated spec artefacts".
4. **Three hand-written doc pages** are touched:
`content/docs/permissions/field-level-security.mdx` and
`content/docs/protocol/objectql/security.mdx` gain a `when` paragraph
(both stated that a field permission entry has exactly two keys), and
the validation matrix row in
`content/docs/deployment/validating-metadata.mdx` now names the field
permission `when` among what the RLS predicate rule judges. The Docs
Drift Check on this PR named all three; leaving the sentences false is
the drift the documentation guardrail exists to stop. Hand-written trees
are editable per AGENTS.md; no release-owned page is touched.
## Not measured here
- Studio form (`../objectui`) is not readable from this seat: the
generated JSON Schema / authorable surface carries `when`, so the form's
key offer is the schema's; the Studio reading itself is unmeasured.
- hotclm#126/#127 are not readable from this seat; the shape in the
tests is the card's (a lock on a stage field from `approved` onward).
## 维护者速读(草稿)
- 字段权限条目新增可选 `when`(与 RLS `using` 同一 CEL),只作用于 **editable**;`readable:
false` 与 `when` 同时出现在解析期拒绝。
- 条件**只收窄投票范围**:匹配行按声明投票,不匹配行视为未声明;不改变"并集不否决"的 ⑧ 姿态(ADR-0066 已加
2026-10-26 注)。
- 写门在 update 前判定**库中行**、insert 判定**入参行**,进程内判定(`compileRowPredicate` +
`storedFormCheckJudge`),不走查询改写;无法判定(谓词更新、读不到的行、本请求无法解析的条件)按**锁**处理并
WARN。
- 不持有行的读取方(`/auth/me/permissions`、字段投影、`os explain`)一律按锁上报,保证不比写门更宽。
- lint 复用 `validateRlsPredicateEnforceability` 的全部通道判定
`permissions[].fields[].when`。
- Tier H(ADR 改动),保持草稿,待维护者批准。
## Acceptance notes
- Spec: `permission.test.ts` — conditioned lock/grant accepted,
`readable:false`+`when` refused at `when` with the stated message,
blank/null refused, aliases pointed at `when`, rides on
`PermissionSetSchema`.
- Core: `fieldPermissionVote` under the three verdicts;
`buildEffectiveFieldPermissions` row-blind lock, union without deny,
fresh entries.
- Plugin-security (`security-plugin.test.ts`): insert draft admitted /
approved refused / bulk union; by-id update judged on the stored row
(approved pre-image refused even when the payload moves to draft; draft
pre-image admitted even when the payload approves) with ONE
caller-context by-id read; predicate update → lock + WARN; null
pre-image → 404 upstream at 2.7 and the gate's own derivation → lock +
WARN; `current_user.id` resolves against the caller; unresolvable
`current_user.nope` → lock + WARN; `canWriteObject` insert-on-payload /
update-as-lock. Evaluator: matched / unmatched / unjudged votes, union
with a sibling grant, `conditionedFieldEntries`. Explain: the `fls`
sentence.
- Lint: the four injections at the `when` site, path/where/message,
silent on a valid condition, key-object targeting, blank skipped.
## Verification
See the `os-dev-report` comment on #25866 for the gate run record (exit
codes captured before any pipe, reconciled with `dispatch-gates --ran`)
and the per-package typecheck/test results.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01N3GzdgZRZ3z4wYfkWX1RJd)_
🤖 Generated with [Claude Code](https://claude.com/claude-code)
https://claude.ai/code/session_01N3GzdgZRZ3z4wYfkWX1RJd
---------
Co-authored-by: zhuangjianguo <zhuangjianguo@steedos.com>
Co-authored-by: Claude <noreply@anthropic.com>
1 parent 6a6ebff commit c8cb510
28 files changed
Lines changed: 1132 additions & 96 deletions
File tree
- .changeset
- content/docs
- deployment
- permissions
- protocol/objectql
- references
- api
- security
- docs/adr
- packages
- core/src/security
- lint/src
- plugins
- plugin-hono-server/src
- plugin-security/src
- spec
- authorable-surface
- liveness
- state-counts
- src/security
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
488 | 488 | | |
489 | 489 | | |
490 | 490 | | |
491 | | - | |
| 491 | + | |
492 | 492 | | |
493 | 493 | | |
494 | 494 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
25 | 68 | | |
26 | 69 | | |
27 | 70 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
220 | | - | |
| 220 | + | |
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| |||
256 | 256 | | |
257 | 257 | | |
258 | 258 | | |
| 259 | + | |
259 | 260 | | |
260 | 261 | | |
261 | 262 | | |
262 | 263 | | |
| 264 | + | |
| 265 | + | |
263 | 266 | | |
264 | 267 | | |
265 | 268 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1633 | 1633 | | |
1634 | 1634 | | |
1635 | 1635 | | |
1636 | | - | |
| 1636 | + | |
1637 | 1637 | | |
1638 | 1638 | | |
1639 | 1639 | | |
| |||
1658 | 1658 | | |
1659 | 1659 | | |
1660 | 1660 | | |
| 1661 | + | |
1661 | 1662 | | |
1662 | 1663 | | |
1663 | 1664 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
69 | 69 | | |
70 | 70 | | |
71 | 71 | | |
| 72 | + | |
72 | 73 | | |
73 | 74 | | |
74 | 75 | | |
| |||
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
124 | | - | |
| 125 | + | |
125 | 126 | | |
126 | 127 | | |
127 | 128 | | |
| |||
158 | 159 | | |
159 | 160 | | |
160 | 161 | | |
| 162 | + | |
161 | 163 | | |
162 | 164 | | |
163 | 165 | | |
| |||
0 commit comments