Repository navigation
Commit 94e60c0
fix(plugin-security)!: collectRLSPolicies applies an object's declared default row scope when no held set carries a row policy for it (#24451)
Fixes #24340
Clause-②: no (narrowing) — the narrowing is real only for a principal
with no platform baseline whose permission sets carry no row policy for
an object that declares a default (0 measured producers: no object in
this tree declares `defaultRowScope`, ruling E′ item 7).
## What changed
`collectRLSPolicies`
(`packages/plugins/plugin-security/src/security-plugin.ts`), the one
collection every read, write and explain door composes from, now applies
an object's declared `ObjectSchema.defaultRowScope` (#24338) when the
held sets' collection for that object and operation comes out empty.
This is #24164 ruling E′ item 2, at the one collection point:
- **When no held set carries a row policy for the object**, the object's
default applies: one policy, `object` implied, built by
`objectDefaultRowScopePolicy` (new, `object-default-row-scope.ts`) and
marked by identity.
- **An authored set policy is used as authored**: the default is never
added to a non-empty collection.
- **Superuser-bypass principals are untouched**: the bypass is decided
by the callers before the collection, so they never reach it.
- **An object with no default keeps today's behaviour**: the branch
returns the held collection unchanged.
The shipped sets are not edited (`default-permission-sets.ts`
untouched), so their behaviour and explain output do not move; the
platform-objects declarations and the registry rule are #24341's.
### What "carries a row policy" means (measured, then pinned)
It is exactly what the collection already means by empty: the held sets'
policies after the ADR-0105 D3 admission, `enabled`, the `positions`
domain and `'*'` matching (`RLSCompiler.getApplicablePolicies`). So:
- a held `'*'` policy counts (the default is not applied);
- a held policy for another operation does not count (an object whose
held sets scope only `update` reads under its default);
- a held policy switched off or outside the caller's positions does not
count.
An object-level reading ("any held policy naming the object, any
operation") was measured and rejected: `member_default` ships the
wildcard ownership floor (`owner_only_writes` / `owner_only_deletes`,
object `'*'`), so that reading would switch the default off for every
baseline member on every object. The two readings agree on every
declaration in sight: the identity defaults #24341 is to declare mirror
the operations of the set literals they copy. The ADR-0095 D1 note words
it as Layer 1 silence, which is the collection's emptiness.
### The default takes the path a held policy takes
From the admission on, the default is a held policy: it passes the same
ADR-0105 D3 admission (`admitCollectedPolicy`, extracted from the loop
unchanged, so a default spelling a shipped tenant policy is stripped
exactly as its set copy is, by the `(object, name, using)` provenance
key), the same `getApplicablePolicies` filter (its own `operation`,
`positions`, `enabled`), and the same compiler (`using`, `check`).
### Call sites (every one reads the same collection)
| Call site (HEAD line) | What the collection is used for | What the
default does there |
|---|---|---|
| `resolvePreImageFloorDrop` (`:5326`) |
`.some(isPlatformOwnershipFloorPolicy)`: is the platform floor in play |
Nothing: the default is collected only when the held collection is
empty, so the floor is absent either way, and the default is never the
floor (identity provenance). Answer unchanged. |
| `checkAuthoredRowWrite` (`:5448`) | authored pre-check: a non-floor
policy with `using`; empty answers `abstain` | Counts as the declaration
it is, exactly as a held copy of it would, so it can answer `admit` for
a row it admits. Pinned. |
| `computeLayeredRlsFilter` Layer 1 (`:7222`) | read door, by-id
pre-image, bulk write filter, `getReadFilter` / analytics, explain;
empty means `layer1 = null`, no filter | Compiled into Layer 1: the
reads and writes it governs are narrowed. Pinned. |
| derive-from-select (`:7369`) | `update` / `delete` with no write-class
`using` re-collects `select` | A `select` default scopes the derived
write exactly as a held select policy does. |
| `computeWriteCheckFilter` (`:7657`) | post-image check via
`writeCheckPolicies`; empty means no check | The default's `check` (or
its `using`, by the schema's default) judges the post-image. Pinned:
handing your own row away is refused. |
| `assertControlledByParentWrite` master leg (`:8907`) |
`.some(isPlatformOwnershipFloorPolicy)` | Nothing, for the reason in the
first row. |
Which call sites read an empty collection as "no policy, no filter": the
Layer 1 compile (`:7222`, and `:7369` behind it) and the post-image
check (`:7657`). Which already refuse on empty: none refuses;
`checkAuthoredRowWrite` abstains (its fail-closed direction) and the two
floor probes answer `false`. On a compile failure every door fails
closed through `RLS_DENY_FILTER`.
### Cost of the read
The declaration is read off `ql.getSchema(object)`, the ObjectQL
registry's resolved object (the schema every find compiles against, and
the source `getObjectSecurityMeta` prefers): two in-memory map lookups
behind the registry's merged-object cache, made only when the held
collection is empty. No I/O and no parse on any path; a non-empty
collection pays nothing.
### Explain names the object default
Explain already identifies policies inside a composed filter by identity
(`compiledPolicyNameOf`). `RLSCompiler.compileFilter` now also records
when a compiled policy filter came from an object default
(`compiledObjectDefaultRowScopeOf`), and explain reads it:
- object-level: the `rls` layer's `detail` gains one sentence naming the
default by `name`, with its `label` and `description`, and the declaring
object, saying it is not a permission set. `contributors` stays `[]`
(the spec's contributor kinds are `permission_set` / `position` /
`system`; a structured object-level field would be a spec change, not
taken).
- record-grained: the rule is named after the default (`kind:
'rls_policy'`, `name` set to the default's own name, `via:
'object_default'`) instead of `business_rls`.
A filter from held sets is explained byte-for-byte as before.
### A `using` that does not lower: why the runtime refusal suffices here
(rider `6255162631`)
The default reaches the same compiler an authored policy does, so a
non-lowering `using` is dropped with the same "uncompilable predicate
... DROPPED" WARN and the clause fails closed to `RLS_DENY_FILTER`: zero
rows, never a silent admission or a silent drop. Pinned on the same
predicate in both forms (an object's default, and an authored set policy
on a sibling object): both read zero rows, both WARN naming their
policy, explain answers `denies` for both.
The authoring lint (`validate-rls-predicate-enforceability.ts`) is not
extended, for three reasons:
1. Extending it needs `RLS_PREDICATE_UNENFORCEABLE`'s explanation entry
in `packages/lint/src/rule-explanations.ts` to change: the entry's
shared `RLS_DROPPED_USING` paragraph says the object "disappears for
every holder of the permission set", which is wrong for a default. That
file has another in-flight holder (#23566), so per the claim it is not
edited here; it is reported to the seat.
2. The refusal is loud at runtime and fails closed, the same posture the
lint's own header accepts as survivable for authored policies.
3. Zero producers can write a non-lowering default today: no object in
the tree declares the key, the Studio form omits it, and the only
planned writers (#24341) copy literals that already pass the lint where
they live in the shipped sets.
The key's describe now says plainly that authoring checks do not judge
this predicate.
## Spec-lane riders (rider `6256199121`)
- `packages/spec/liveness/object.json`: `defaultRowScope` and its eight
members flip to `live`, citing `collectRLSPolicies`,
`objectDefaultRowScopePolicy` and explain's
`objectDefaultRowScopeSource` as read points; `authorWarn` /
`authorHint` dropped in the same edit. `label` / `description` are live
by the README's display-key rule: explain shows them to the
administrator. `state-counts/object.md` regenerated by
`gen:liveness-counts` (live 53 to 61, planned 8 to 0).
- `packages/spec/src/data/object.zod.ts`: the key's TSDoc and describe
say what the reader does, in place of "is to apply" and "no server reads
this key".
- `packages/spec/src/security/rls.zod.ts`: `DefaultRowScopeSchema`'s
TSDoc likewise.
- `packages/lint/src/validate-org-axis-red-lines.test.ts`: the title and
docblock name `defaultRowScope` as the one object-level policy; the
assertion is unchanged.
- Patch round 1 (claim surface extended by the seat's rework record
`6259617731`): `.changeset/pre/24338-object-default-row-scope.md`, the
pending #24338 release note, now says what the key does (see Acceptance
notes), and the Studio form ledger's omit row for
`object.defaultRowScope` in
`packages/spec/src/system/metadata-form-zod-reconciliation.test.ts`
gives the reason that is true now.
- Generated by their own generators (`check:generated --fix`, only the
two it proved stale):
`content/docs/references/{data/object,api/metadata,system/migration}.mdx`,
`packages/spec/liveness/state-counts/object.md`.
## Pins
(`packages/plugins/plugin-security/src/object-default-row-scope.test.ts`)
Real `SecurityPlugin` + `ObjectQL` over `SqlDriver`, the shipped sets,
rows written past every scope. The identity objects are the platform's
own declarations, each given in the fixture the default its sets copy
today (`sys_user`'s two literals as the one `||` policy the key allows,
rider A); `qa_note` is a test object.
1. No baseline, an authored `'*'` read set: reads only its own
`sys_user`, `sys_session`, `sys_scim_user` rows plus its organisation's
members on `sys_user`. CONTROL without the declarations: every row.
2. An authored policy on the object is applied alone (the default is not
OR-ed in); a held `'*'` policy counts; a held policy for another
operation, or outside the caller's positions, does not.
3. The write doors read the same collection: a by-id update of a row
outside the default answers `RECORD_NOT_FOUND` / 404 (an unreadable
target is absent), and handing your own row away fails the post-image
check with `PERMISSION_DENIED` / 403. `checkAuthoredRowWrite` answers
`admit` / `abstain` from the default.
4. The platform administrator reads every row, with and without the
defaults.
5. Explain names the default (object-level detail; record-grained rule
and `via`); CONTROL: an authored policy is not named as one.
6. A deployment with the baseline is byte-for-byte unchanged: for
`member_default`, `viewer_readonly`, `organization_admin` and the
platform admin, on the three identity objects, the served ids and the
`JSON.stringify` of explain (`read` and `update`) are identical with and
without the declarations.
7. A default whose `using` does not lower is refused as an authored one
is (zero rows, the WARN, explain `denies`).
**Ablation (once, committed first, then reverted):** `node
scripts/ablation-replace.mjs` replaced `if (held.length > 0) return
held;` with `if (held.length >= 0) return held;` (anchor 1 to 0, blob
`1e3792351de2` to `c54fe3ed549d`), ran the file: **10 failed / 6
passed**, the 10 being every default-dependent pin and the 6 exactly the
controls (no-declaration control, authored-alone, held `'*'`, platform
admin, authored explain control, baseline byte-for-byte). Restored: blob
`1e3792351de2` equals `HEAD`, `git diff HEAD` empty. Direction observed:
turned red, as expected.
## Tests and gates
Final head `7702f3ca2`: patch round 1 (`ef9a7a01e`, the two corrected
texts) with `origin/main` `26501ae24` merged in by
`scripts/pm/os-regen-merge.sh`. The merge was a merge commit (no rebase,
amend or force-push), and git carried the patch-round edit onto the
moved `.changeset/pre/24338-object-default-row-scope.md` (blob
`d5154221dd`). After a full `turbo run build`:
- `pnpm --filter @objectstack/spec test`: 698 files, 21286 passed, 1
todo. `typecheck` exit 0.
- The pin file: 16 passed. `pnpm --filter @objectstack/spec
check:generated`: all 14 generated artifacts up to date, so no
regeneration commit was owed after the merge.
- plugin-security and lint: incoming `main` touched neither package's
source, so their suites stand from the pre-merge head `1081739c9`
(plugin-security 188 files, 3754 passed, 45 skipped; lint 145 files,
6864 passed; both typecheck exit 0).
- Derived gate families: `node scripts/pm/dispatch-gates.mjs --commands
--repo objectstack-ai/objectstack` derives 117 commands for this diff
(17 paths, +788 / -102 against merge base `26501ae24`). All 117 were run
on `7702f3ca2`, each through `scripts/pm/os-verify-lock.sh` with the
command's own exit read from its VERDICT line, and `--ran` reconciles:
**117 derived, 117 run, 0 NOT-MEASURED, 0 UNRUN**. 115 exit 0.
- `node scripts/check-empty-changeset.mjs --base origin/main` exits 1,
by design: its foreign-changeset rule names
`.changeset/pre/24338-object-default-row-scope.md` as present on the
merge base and changed here. That is the DELIBERATE CORRECTION class in
Acceptance notes; `Check Changeset` is not a required context.
- `pnpm check:platform-checklist` exits 1 with one problem (ABSENT
SYMBOL
`packages/core/src/security/resolve-authz-context.ts#legacyGrantAnchorRetired`
in `areas/access-security.json`). Control leg: the same command in a
detached worktree at the merge base `26501ae24` exits 1 with the same
single problem, and earlier at `e22defb13` likewise. Pre-existing, not
this change's.
- The other changeset gates: `check-adr-0087-registration --base
origin/main` exit 0, `check-changeset-no-major --base origin/main` exit
0.
- Not run locally, declared to CI: `test:repo` (Test Core), and every
family CI runs beyond the derived list.
## Acceptance notes
- **A pending release note corrected in this PR (DELIBERATE CORRECTION,
for confirmation here):**
`.changeset/pre/24338-object-default-row-scope.md` is #24338's
changeset. The version release `725a5b131` moved it from `.changeset/`
into `.changeset/pre/`, and `release.yml` has the `pre exit` GA version
consume `.changeset/pre/*.md` again, so the GA changelog is built from
it. Its bullet "What it does today: nothing ..." and its sentence naming
the `liveness-planned-property` warning became false with this PR's
reader. Patch round 1 rewrites that one bullet to what the key does now
(`collectRLSPolicies` applies it when the caller's held sets carry no
row policy for the object and the operation) and drops the warning
sentence; level, `Clause-②`, heading and every other line are unchanged.
The edit rides the moved path through the merge of `main`. The
already-released `next` changelog text stays as released.
`check-empty-changeset`'s foreign-changeset rule refuses this file by
design (the DELIBERATE CORRECTION class: do not restore it; confirm it
on the PR), so `Check Changeset`, which is not a required context, stays
red until the correction is confirmed. `skip-changeset` is not applied.
- **The form ledger's omit reason corrected in this PR:** the omit row
for `object.defaultRowScope`
(`packages/spec/src/system/metadata-form-zod-reconciliation.test.ts`)
now says the reader is in and a row policy is a composite form-face
addition rather than a reconciliation. Prose only; the row's kind, path
and the assertion are unchanged.
- **Boundary, not filed:** the org-axis red-line rule
(`validate-org-axis-red-lines.ts` rule ①) walks permission-set RLS only,
so a `defaultRowScope.using` that walks the org parent is not judged
there. That is a lint not covering metadata the runtime honours, which
is outside the filing classes.
- **Explain on a failing default:** a default whose `using` does not
lower is explained as "composes to DENY ALL" without naming the default,
exactly as an authored policy in the same state (the compiled identity
is lost to the shared deny sentinel).
- **`check:platform-checklist` exits 1 on this head and at the merge
base alike** (one ABSENT SYMBOL in `areas/access-security.json`,
`resolve-authz-context.ts#legacyGrantAnchorRetired`); this diff touches
neither file. The control leg is in the gates section above.
---
_Generated by [Claude
Code](https://claude.ai/code/session_01Nk17Z26X5DB59iQztDBADH)_
---------
Co-authored-by: Claude <noreply@anthropic.com>1 parent e11ae4b commit 94e60c0
17 files changed
Lines changed: 788 additions & 102 deletions
File tree
- .changeset
- pre
- content/docs/references
- api
- data
- system
- packages
- lint/src
- plugins/plugin-security/src
- spec
- liveness
- state-counts
- src
- data
- security
- system
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 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 | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
| 14 | + | |
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
969 | 969 | | |
970 | 970 | | |
971 | 971 | | |
972 | | - | |
| 972 | + | |
973 | 973 | | |
974 | 974 | | |
975 | 975 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
173 | 173 | | |
174 | 174 | | |
175 | 175 | | |
176 | | - | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
0 commit comments