diff --git a/.changeset/33432-cbp-write-opt-in-wording.md b/.changeset/33432-cbp-write-opt-in-wording.md new file mode 100644 index 00000000000..a4f55374d00 --- /dev/null +++ b/.changeset/33432-cbp-write-opt-in-wording.md @@ -0,0 +1,10 @@ +--- +'@objectstack/skills': patch +--- + +docs(skills): `objectstack-data` states what `writeRequiresMasterRead` asks when a master is set or emptied, and whose ownership floor binds an on-behalf-of write + +Clause-②: no +Metadata-protocol: none + +objectstack-data's `rules/relationships.md` is more exact about a `controlled_by_parent` detail's two write opt-ins. Under `sharing.controlledByParent.writeRequiresMasterRead`, setting a master on a row and emptying one both ask read (the sentence read as if only emptying did), and both still ask edit under `ownerMayEdit`. On an on-behalf-of update or delete the ownership floor binds for both users, not one. The `ownerMayEdit` bullet now says "every other write, on-behalf-of included, still needs master edit" where it listed the writes, which pays for the added words: the file is the same size. The eval case for the key also fails an answer that writes `ownerMayEdit: true` beside it, in either order, or puts the key on the `master_detail` field. diff --git a/docs/adr/0055-master-detail-controlled-by-parent.md b/docs/adr/0055-master-detail-controlled-by-parent.md index 3f5b2d4a9c5..0ed8d4c4ad4 100644 --- a/docs/adr/0055-master-detail-controlled-by-parent.md +++ b/docs/adr/0055-master-detail-controlled-by-parent.md @@ -7,7 +7,7 @@ · **Amended** (2026-10-26, #25760, ruling `6398566164`) — **§3 gains one per-object opt-in**: `sharing.controlledByParent.ownerMayEdit: true` lets the OWNER of a detail row (its `owner_id`) pass the write gate on a by-id `update` of that row with **read** access to the master; every other caller, and every insert, delete, predicate update and on-behalf-of write, keeps the master-**edit** rule. The default is unchanged. See **"Amendment (2026-10-26, #25760): the owner of a detail row may update it with read on the master, by opt-in"** at the end. ⚠️ **Amended 2026-11-14 (#33250 / PR #33369)** — that "every other caller … keeps the master-edit rule" no longer holds on a detail that declares the second opt-in, `writeRequiresMasterRead`: there every write asks **read** on the master. The two opt-ins are refused together. See the 2026-11-14 line below. · **Amended** (2026-10-27, #26591 / PR #26658) — **the 2026-10-26 amendment's Lint bullet is narrowed in place**: the lint prescribes the opt-in only for an `owner_id`-keyed `update` / `all` policy on a `controlled_by_parent` detail that carries `owner_id` and has not opted in; any other caller-keyed update policy is flagged in both states with the `owner_id` remedy, never the opt-in. The gate, the spec and the lint are unchanged by this note. See the note under **Lint** in "What the opt-in does, exactly". · **Amended** (2026-11-06, #30905, maintainer ruling 「A」) — **§1 admits an optional master and §2 gains a null-master arm**: a `controlled_by_parent` object whose only `master_detail` is declared `required: false` derives an OPTIONAL master. A detail row that names its master is read through it, unchanged; a row whose master reference is empty is read by its owner (`owner_id`) and by View All on the detail, through a second arm OR-ed with the master arm inside the one read chokepoint, `computeControlledByParentFilter`. §3 (the write gate) is unchanged by this note: a write that leaves the reference empty is still refused. ⚠️ **Amended 2026-11-07 (#30906 / PR #31082)** — that §3 sentence no longer holds; see the next line. See **"Amendment (2026-11-06, #30905): an optional master, and the null-master row its owner reads"** at the end. -· **Amended** (2026-11-07, #30906 / PR #31082, the same ruling 「A」) — **§3 judges the null-master row by an owner rule**: a row of an optional master whose reference is empty is written by its owner (`owner_id`) and by Modify All on the detail, everyone else `403`; an insert naming no master is admitted; setting a master asks edit on it, emptying one asks edit on the stored master (the 2026-10-26 opt-in does not cover it); a chain hop with no master of its own ends the chain under the same rule. A required master is unchanged. See **"Amendment (2026-11-07, #30906): the null-master row its owner writes"** at the end. +· **Amended** (2026-11-07, #30906 / PR #31082, the same ruling 「A」) — **§3 judges the null-master row by an owner rule**: a row of an optional master whose reference is empty is written by its owner (`owner_id`) and by Modify All on the detail, everyone else `403`; an insert naming no master is admitted; setting a master asks edit on it, emptying one asks edit on the stored master (the 2026-10-26 opt-in does not cover it); a chain hop with no master of its own ends the chain under the same rule. A required master is unchanged. See **"Amendment (2026-11-07, #30906): the null-master row its owner writes"** at the end. ⚠️ **Amended 2026-11-14 (#33250 / PR #33369)** — that "setting a master asks edit on it, emptying one asks edit on the stored master" no longer holds on a detail that declares `writeRequiresMasterRead`: there the new master and the stored master are each asked **read**. The owner rule of the null-master row is unchanged. See the 2026-11-14 line below. · **Amended** (2026-11-14, #33250 / PR #33369, ruling A+ `6880588685`) — **§3 gains a second per-object opt-in, and for the objects that declare it the 2026-10-26 amendment's "Option 2 … was not chosen" line is lifted**: `sharing.controlledByParent.writeRequiresMasterRead: true` makes **read** on the master the master question for every write of the detail (insert, update and delete, by id or by predicate, and the lifecycle verbs); the detail's own object permissions, row-level security, field-level security and the platform ownership floors decide the rest. The default is unchanged: a write's answer moves only if its own object, or a `controlled_by_parent` master on its chain, declares the key. See **"Amendment (2026-11-14, #33250): read on the master is enough to write, by opt-in"** at the end. · **Amended** (2026-11-15, #33696, ruling 「只对管理员去掉」 `6893666857`) — **for one reader class the parent chain over a REQUIRED master is dropped, and that class alone reads that master's detail rows whose reference is empty or dangling**: a reader who holds View All on the detail AND whose every master hop answers unrestricted (the engine's per-hop scope, not `hasSuperuserReadBypass`) sees those rows — naming no master, or a master that does not exist — inside its own tenant wall. That is consistent with the 2026-11-06 ruling 「A」, whose reader of a row with no master, beside its owner, is View All on the detail. Every other reader, members included, keeps the chain unchanged. An optional master's two arms are outside the ruling, and §3 (the write gate) is not amended by this note. The ruling lifts ADR-0139 D6's ⛔ ("interim removal of the predicate for an unrestricted master scope") for that class only, and [ADR-0139](./0139-engine-internal-semi-join-leaf-readable-parent-ids.md) D6 as amended 2026-11-15 carries the ruling's binding bullets verbatim. This is the "ADR-0055's 10-22 note in step" the ruling orders, and it precedes the code: #33696's change lands only after it. See the note under **"The rules the read keeps"** in the 2026-11-06 amendment. **Deciders**: ObjectStack Protocol Architects @@ -138,6 +138,7 @@ So a two-level chain was enforced at level one and open at level two, under meta - **Read.** `packages/plugins/plugin-security/src/security-plugin.ts#computeControlledByParentFilter` AND-composes the master's **own** `controlled_by_parent` derivation as a third layer, resolved through **that same method**, so the recursive answer cannot drift from the top-level one. The master set is therefore point-for-point equal to what a direct read of the master returns **at every level** — the equality §2 established for one. ⚠️ **Amended 2026-10-22 (#24932).** The derivation no longer composes the master's layers itself: it answers the `ReadableIds` leaf over the master, and the **engine** composes the master's scope by asking this plugin's public doors — `canReadObject(master)` and `getReadFilter(master)`, the latter being this same derivation for a master that is itself `controlled_by_parent`, so the chain composes recursively, one nested subquery per hop, inside one statement (ADR-0139 D6 as amended). The equality holds for the same reason, one level up: the scope the engine composes IS the scope a direct read of the master runs under. - **Write.** `packages/plugins/plugin-security/src/security-plugin.ts#assertControlledByParentWrite` walks the chain hop by hop, running the same three master-edit legs — extracted verbatim as `packages/plugins/plugin-security/src/security-plugin.ts#assertMasterRowEditable` — on every hop until it reaches a master that governs its own rows. Each added refusal keeps the `403 PERMISSION_DENIED` envelope named for the **caller's own** object and operation, never for an ancestor the caller never asked about. + ⚠️ **Amended 2026-11-14 (#33250 / PR #33369).** "On every hop" no longer holds for a hop whose detail declares `writeRequiresMasterRead`: there the walk (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts#assertControlledByParentChainEditable`) asks whether the principal can **read** the master row in place of the three edit legs, and ends at that hop; the read door answers for the chain above it. A hop that does not declare the key runs the edit legs as before. See the 2026-11-14 amendment at the end. **Cost.** The per-request resolution cost booked under Consequences is now paid **per hop** — one extra master-id query per `controlled_by_parent` object on the chain, bounded as below. ⚠️ **Amended 2026-10-22 (#24932).** No extra query per hop: each hop is one nested subquery inside the detail's one statement, and the depth bound caps the statement's nesting, not a count of queries. The write gate's per-hop master-row probe is unchanged. @@ -270,7 +271,7 @@ Every `controlled_by_parent` object with a required master, byte for byte: its e ## Amendment (2026-11-14, #33250): read on the master is enough to write, by opt-in -**Ruling.** objectstack-ai/objectstack#33250, maintainer ruling A+ (Leehom, 2026-11-14T16:21:29Z; ruling record `6880588685`), verbatim: 「开关打开后,能读主记录的人按子对象自己的授权新增、修改、删除,默认不变。」 (With the switch on, whoever can read the master record inserts, updates and deletes the detail under the detail's own grants; the default is unchanged.) PR #33369 implements it (merged 2026-11-14). For an object that declares the key it lifts the 2026-10-26 amendment's "Option 2 … was **not** chosen" line and its "Option 2's door … stays closed" line; for every other object both stand, and neither is rewritten. The ruling left the key's name, the paths the swap covers, its relation to `ownerMayEdit` and the lint arm to the seat. This section records what shipped; the two seat calls the contract review (`6881744779`, ① items 5 and 6) named for the maintainer's veto window are under **The two seat calls** below. +**Ruling.** objectstack-ai/objectstack#33250, maintainer ruling A+ (Leehom, 2026-11-14T16:21:29Z; ruling record `6880588685`), verbatim: 「开关打开后,能读主记录的人按子对象自己的授权新增、修改、删除,默认不变。HotCRM 的设计授权全部兑现。」 (With the switch on, whoever can read the master record inserts, updates and deletes the detail under the detail's own grants; the default is unchanged. HotCRM's designed grants are all honoured.) PR #33369 implements it (merged 2026-11-14). For an object that declares the key it lifts the 2026-10-26 amendment's "Option 2 … was **not** chosen" line and its "Option 2's door … stays closed" line; for every other object both stand, and neither is rewritten. The ruling left the key's name, the paths the swap covers, its relation to `ownerMayEdit` and the lint arm to the seat. This section records what shipped; the two seat calls the contract review (`6881744779`, ① items 5 and 6) named for the maintainer's veto window are under **The two seat calls** below. ### What the opt-in does, exactly @@ -283,7 +284,7 @@ Every `controlled_by_parent` object with a required master, byte for byte: its e - A **predicate** update or delete keeps the floor, as before: among the rows it selects it touches only those the caller created. - A **delegated** (on-behalf-of) by-id update or delete keeps **both** principals' floors, the ADR-0090 D10 exclusion, unchanged. - **On behalf of.** Step 2.8 runs the gate once per principal, the agent and then the delegator, each asked the read under its own context: either one unable to read the master refuses the write, and both able admit it, subject to the floors above. -- **What a refusal answers.** A by-id update or delete by a caller who cannot read the master answers `404 RECORD_NOT_FOUND`, not `403`: the detail row's own read derives from its master (§2), so the read door (`callerCannotReadAddressedRow`, step 2.7) hides the row before the gate runs. That is the hidden-row rule (#7505), the same answer a detail that does not opt in gives. An insert or a re-point answers `403 PERMISSION_DENIED`, named for the caller's object and verb, "requires read access to its master record". `ISecurityService.checkControlledByParentWrite` answers `deny` for all of them, on `object_permission` (the master read is refused) or `row_level_security` (the master row is not returned); the closed leg union is not widened. `os explain` (`packages/plugins/plugin-security/src/explain-engine.ts#chainAsksMasterRead`) chooses prose that names the read question; its verdict still comes from the served member. +- **What a refusal answers.** A by-id update or delete by a caller who cannot read the master answers `404 RECORD_NOT_FOUND`, not `403`: the detail row's own read derives from its master (§2), so the read door (`callerCannotReadAddressedRow`, step 2.7) hides the row before the gate runs. That is the hidden-row rule (#7505), the same answer a detail that does not opt in gives. An insert or a re-point answers `403 PERMISSION_DENIED`, named for the caller's object and verb, "requires read access to its master record". `ISecurityService.checkControlledByParentWrite` answers `deny` for all of them, on `object_permission` (the master read is refused) or `row_level_security` (the master row is not returned); the closed leg union is not widened. `os explain` (`packages/plugins/plugin-security/src/explain-engine.ts#chainAsksMasterRead`) chooses prose that names the read question; its verdict still comes from the served member. A predicate (`multi: true`) update or delete by a caller who cannot read the master selects none of that master's rows, so it judges no master for them, writes none of them and answers no refusal, as on a detail that does not opt in: its matched set is narrowed to the rows the caller can read (`packages/plugins/plugin-security/src/security-plugin-addressed-writes.ts#readableRowsScopeForPredicateWrite`), a detail row's own read deriving from its master (§2), and the gate judges the masters of those rows only (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts#controlledByParentPredicateWriteMasters`). - **The null-master row.** A row of an optional master whose reference is empty has no master to read: on an opted-in detail the 2026-11-07 owner rule (`nullMasterRowWritable`) still decides it, and setting a master on it asks that rule, then read on the new master. - **Lint.** `security-controlled-by-parent-owner-policy-without-opt-in` stands down, both branches, on a detail that declares the key (`packages/lint/src/validate-security-posture.ts`): there a caller-keyed update policy decides among master readers as authored, whichever user field it keys. No rule is added. @@ -294,7 +295,7 @@ Every `controlled_by_parent` object with a required master, byte for byte: its e ### The invariant -A write's answer moves only if its own object, or a `controlled_by_parent` master on its chain, declares `writeRequiresMasterRead`. In a stack where no object declares it, every hop runs the edit legs and every refusal still says "requires edit access". The "What is unchanged" lists of the earlier amendments read as of their dates: where one says a detail is answered as before, that holds for a detail whose chain declares no `writeRequiresMasterRead`. +A write's answer moves only if its own object, or a `controlled_by_parent` master on its chain, declares `writeRequiresMasterRead`. In a stack where no object declares it, every hop runs the edit legs and every master-gate refusal still says "requires edit access". The "What is unchanged" lists of the earlier amendments read as of their dates: where one says a detail is answered as before, that holds for a detail whose chain declares no `writeRequiresMasterRead`. ### Fail-closed boundaries diff --git a/skills/objectstack-data/evals/objects-fields-relationships.json b/skills/objectstack-data/evals/objects-fields-relationships.json index e4c4ba34ac9..79dd03e3f36 100644 --- a/skills/objectstack-data/evals/objects-fields-relationships.json +++ b/skills/objectstack-data/evals/objects-fields-relationships.json @@ -305,7 +305,10 @@ "writeRequiresMasterRead: true" ], "must_not_contain": [ - "sharing: { writeRequiresMasterRead" + "sharing: { writeRequiresMasterRead", + "ownerMayEdit: true, writeRequiresMasterRead: true", + "writeRequiresMasterRead: true, ownerMayEdit: true", + "required: true, writeRequiresMasterRead" ] } }, diff --git a/skills/objectstack-data/rules/relationships.md b/skills/objectstack-data/rules/relationships.md index ac8f1cdb227..31cb7bf44d5 100644 --- a/skills/objectstack-data/rules/relationships.md +++ b/skills/objectstack-data/rules/relationships.md @@ -82,13 +82,13 @@ sharingModel: 'controlled_by_parent', sharing: { controlledByParent: { writeRequiresMasterRead: true } }, // or ownerMayEdit ``` -- `ownerMayEdit: true` widens only the row owner's (`owner_id`) by-id update; insert, - delete, predicate (`multi: true`) updates and on-behalf-of writes still need master edit. +- `ownerMayEdit: true` widens only the row owner's (`owner_id`) by-id update; every + other write, on-behalf-of included, still needs master edit. - `writeRequiresMasterRead: true`: whoever reads the master inserts, updates and deletes the detail under its own object permissions, RLS and FLS (re-points and each opted-in chain hop too; on-behalf-of, both users must read the master). The - ownership floor (rows you created) still binds predicate and on-behalf-of updates - and deletes. Refused beside `ownerMayEdit: true`, which it covers. Lint + ownership floor (rows you created) still binds predicate and, for both users, on-behalf-of + updates and deletes. Refused beside `ownerMayEdit: true`, which it covers. Lint `security-controlled-by-parent-owner-policy-without-opt-in` is silent here. The detail's own row policies AND in under both. Each is refused at parse under any @@ -107,8 +107,8 @@ account: { type: 'master_detail', reference: 'account', required: false }, A row with no master is its owner's (`owner_id`): the owner or View All on the detail reads it, the owner or Modify All writes it (no owner: View All / Modify All only). An insert naming no master is admitted. Setting a master asks edit -on it, emptying one edit on the stored master (even under `ownerMayEdit`; read -under `writeRequiresMasterRead`). A +on it, emptying one edit on the stored master (both even under `ownerMayEdit`; +read for both under `writeRequiresMasterRead`). A chain hop with no master ends there under the same rule. Refused beside a second `master_detail` or as `readonly`/`system`; `ObjectSchema.create()` reads an omitted `required` as `true`.