From 5647b9f9800bb89aa4dc69d5162d8733fdc6ab7b Mon Sep 17 00:00:00 2001 From: Claude Date: Sat, 14 Nov 2026 20:10:54 +0000 Subject: [PATCH] =?UTF-8?q?docs(adr-0055):=20record=20the=202026-11-14=20a?= =?UTF-8?q?mendment,=20writeRequiresMasterRead=20=E2=80=94=20read=20on=20t?= =?UTF-8?q?he=20master=20is=20enough=20to=20write,=20by=20opt-in?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude --- ...0055-master-detail-controlled-by-parent.md | 53 ++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/adr/0055-master-detail-controlled-by-parent.md b/docs/adr/0055-master-detail-controlled-by-parent.md index 121d8204191..0bb36cf315a 100644 --- a/docs/adr/0055-master-detail-controlled-by-parent.md +++ b/docs/adr/0055-master-detail-controlled-by-parent.md @@ -3,10 +3,11 @@ **Status**: Accepted (2026-06-19) — implemented in this PR (P0–P2) · **Amended** (2026-09-07, #11082 / PR #11183 — the "Single-level only in v1" limit under Consequences and the "Transitive nested master-detail chains" **Non-goal** are both **reversed**: since `@objectstack/plugin-security` 17.3.0 (merged 2026-08-23) the read derivation and the write gate compose `controlled_by_parent` across a chain, bounded by a cycle guard and a cost ceiling that both fail **closed**. Nothing else in this record changes — §1–§4, the mechanism choice, the set-size limit and the share-table non-goal all stand. See **"Amendment (2026-09-07, #11082): transitive chains compose — the single-level non-goal is reversed"** at the end.) · **Revisited in part** (2026-10-10, [ADR-0139](./0139-engine-internal-semi-join-leaf-readable-parent-ids.md), Proposed) — §2's alternatives row (a) is reversed for ONE engine-internal, non-authorable leaf the engine composes from the compiler's output; the RLS compiler still has no subquery form, and §2's chosen mechanism (b), its `rlsMembership` IN-form and the set-size limit all stand. · **Amended** (2026-10-22, #24932, ruling B `6303721609` and Q1 C / Q2 A `6329027469`) — **§2's chosen mechanism (b) is retired for `controlled_by_parent`, and the set-size limit with it**: the read derivation (`packages/plugins/plugin-security/src/security-plugin.ts#computeControlledByParentFilter`) answers ADR-0139's `ReadableIds` leaf over the master, the engine composes it from this plugin's own `canReadObject` / `getReadFilter` of the master, and the driver compiles one statement with the master inside a subquery — the seventh consumer of that leaf, in the end-state form. No master id set is pre-resolved any more. The 2026-10-10 line above reads as of its date. What still stands: §1 (the one required `master_detail`), §3 (the write gate), the cycle guard and the depth bound (now the engine's own cut, judged first over the registry), and the RLS compiler's `rlsMembership` IN-form, which serves `current_user.` memberships and never served this derivation. The limit that replaces the set-size ceiling is ADR-0139 D5's two master shapes, which the boot refuses (#25144). -· **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-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-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. **Deciders**: ObjectStack Protocol Architects **Builds on**: [ADR-0049](./0049-no-unenforced-security-properties.md) (enforce-or-remove), [ADR-0054](./0054-runtime-proof-for-authorable-surface.md) (prove-it-runs) **Surfaced by**: an audit of master-detail permission semantics — `OWDModel.controlled_by_parent` is **declared but unenforced** (zero runtime consumers; not reachable through the object's `sharingModel` enum; the RLS compiler is relationship-blind). This is *false compliance* (ADR-0049) and *unproven liveness* (ADR-0054). @@ -68,6 +69,7 @@ In the pre-image block (`packages/plugins/plugin-security/src/security-plugin.ts - **Rule:** editing/deleting/creating a detail requires **edit** access to its master (Salesforce master-detail semantics). Reading a detail requires **read** access to its master (§2). ⚠️ **Amended 2026-10-26 (#25760) — one opt-in.** A detail that declares `sharing.controlledByParent.ownerMayEdit: true` lets the **owner** of a detail row (`owner_id`) pass this gate on a **by-id `update`** of that row with **read** access to the master. The rule above stands for every other caller and every other write; see the Amendment at the end before deriving an invariant from this line. ⚠️ **Amended 2026-11-07 (#30906 / PR #31082) — the null-master row.** For an **optional** master (§1 as amended), a row whose master reference is empty has no master to ask: its owner or Modify All on the detail writes it, an insert naming no master is admitted, and emptying a master asks edit on the stored master. See the 2026-11-07 amendment at the end. + ⚠️ **Amended 2026-11-14 (#33250 / PR #33369) — a second opt-in.** A detail that declares `sharing.controlledByParent.writeRequiresMasterRead: true` is asked **read** on its master in place of edit, for every write of its rows, and its own grants decide the rest. The rule above stands, at its own hop, for every detail that does not declare it; in a chain, a hop above it that declares the key asks read there (see the amendment). See the 2026-11-14 amendment at the end. This reuses the existing re-read-and-deny pattern; no new enforcement layer. @@ -171,6 +173,8 @@ An ADR recording a **narrower** enforcement than the runtime performs errs in th **Ruling.** objectstack-ai/objectstack#25760, maintainer ruling of record `6398566164` (batch #14 item 2, letter 1, 「同意」 2026-10-25): option 1 — a per-object opt-in on a `controlled_by_parent` detail, `sharing.controlledByParent.ownerMayEdit: true`. With it, the detail row's own owner passes the write gate with **read** on the master; everyone else still needs master **edit**. The default is unchanged. Option 2 (`writeRequires: 'read'`, the detail's own object permission and RLS deciding the write for everyone) was **not** chosen: it opens the write to everyone the detail's own grants admit, a wider door than the need. +⚠️ **Amended 2026-11-14 (#33250, ruling A+ `6880588685`) — lifted for opted-in objects only.** The maintainer ruled that wider door open for an object that declares `sharing.controlledByParent.writeRequiresMasterRead: true` (the shipped spelling of option 2, a boolean rather than `writeRequires: 'read'`): there, whoever can read the master writes the detail as the detail's own grants admit. The paragraph above stays the record of the 2026-10-25 ruling, and it still describes every detail that does not declare the key. See the 2026-11-14 amendment at the end. + ### The gap this closes §3 asks **edit** on the master for every write of a detail, and a detail's own row-level policies compose with that answer as an **AND** (§2: "composes with the detail's own tenant/owner RLS (all AND-ed)"). So an `update` policy written on a detail to let the row's owner write it — `owner_id == current_user.id` — could only ever **narrow** the master's editors to the owner; it never admitted an owner who merely reads the master. That is the common shape, not an app quirk: the person a task, an activity or an obligation is assigned to reads the account or the contract and does not edit it (the originating measurement: a `controlled_by_parent` obligation under a signed contract, whose owner's PATCH answered `403 … requires edit access to its master record (… row-level security)` while `security/explain` answered `allowed: true`). Salesforce, the model this record closes gaps against, keeps **"the owner of an activity always has full access to it"** under Activities OWD = Controlled by Parent; this platform had no equivalent. @@ -187,6 +191,8 @@ An ADR recording a **narrower** enforcement than the runtime performs errs in th The ruling names **update**. So the leg does not reach: an **insert** (no row to own; the master named in the body is asked for edit as before), a **delete** (deleting a child is still answered by the master, as §3 and `masterGateCoversOperation` have it), a **predicate** (`multi: true`) update (it judges every master of the rows it selects and has no single row whose owner could be asked), and a **delegated** write. Each is a widening of its own, to be ruled on its own evidence; none is implied by this one. Option 2's door — the detail's own grants deciding the write for everyone — stays closed. +⚠️ **Amended 2026-11-14 (#33250) — open on a detail that declares `writeRequiresMasterRead`, and only there.** On such a detail the insert, the delete, the predicate update and delete and the delegated write each ask **read** on the master, by the 2026-11-14 ruling, not by this one. The owner leg above is unchanged on a detail that does not declare the new key, and the parse refuses the two keys together. See the 2026-11-14 amendment at the end. + ### Fail-closed boundaries - An opt-in on an object whose schema carries no `owner_id` column (`ownership: 'business_unit' | 'org' | 'none'`, or a platform-managed object) names nobody: the relation resolver resolves `ownerMayEdit: false`, reports it once per object (`reportOwnerMayEditWithoutOwnerColumn`), and every write keeps the §3 rule. The parse cannot refuse this half (the injected-column plan imports `object.zod.ts`; the same cycle its attached-block refusal stops at), so it is said at resolution. @@ -245,6 +251,7 @@ The gate (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.t - **Insert.** An insert, single or batch, that names no optional master is admitted, and its creator becomes its owner. Every master a batch's rows do name is still asked. - **By-id update and delete** of a stored null-master row, and each null-master row a predicate write (`multi: true`) selects: the owner rule. - **Setting a master** on such a row asks the row's owner rule, then edit on the new master. **Emptying one** asks edit on the stored master through the §3 walk; the 2026-10-26 opt-in (`ownerMayEdit`) does not cover a body that empties an optional master. + ⚠️ **Amended 2026-11-14 (#33250 / PR #33369).** On a detail that declares `writeRequiresMasterRead`, the new master and the stored master are each asked **read**, not edit, through the same §3 walk; the stored null-master row's owner rule still runs first when a master is set on it. See the 2026-11-14 amendment. - **Chains.** A hop whose master is itself `controlled_by_parent` with an optional master of its own, left empty, ends the chain there and asks that row's owner rule, on its own object. - **On behalf of.** Each pass (agent, then delegator) asks the owner rule of its own principal. `ISecurityService.checkControlledByParentWrite` answers such a row `allow`, or `deny` with leg `master_chain`, never `unresolvable`. - **Proof (§4, ADR-0054).** `packages/verify/src/parent-write-reach.ts` proves an optional-master detail both under a master and with none (`masters: 'none'`), with the owner rule as the expectation. @@ -252,3 +259,47 @@ The gate (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.t ### What is unchanged Every `controlled_by_parent` object with a required master, byte for byte: its empty reference is still refused (`422 MISSING_REQUIRED_FIELD`). Ownership transfer stays on `allowTransfer`. §1, §2, the cycle guard and the depth bound. + +--- + +## 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. + +### What the opt-in does, exactly + +- **Spec.** `ObjectSchema`'s strict `sharing.controlledByParent` block gains `writeRequiresMasterRead: boolean`, optional, beside `ownerMayEdit` (`packages/spec/src/data/object.zod.ts`). The one reader is `controlledByParentWriteRequiresMasterRead`, exported from `@objectstack/spec/data`; only the boolean `true` opts in, and an absent block or schema answers `false`. The gate (through `CbpRelation.writeRequiresMasterRead`, resolved in `packages/plugins/plugin-security/src/security-plugin-cbp-relation.ts`), explain and the lint ask that one reader. +- **Two parse refusals** (`packages/spec/src/data/object.zod.ts#refuseControlledByParentWriteRequiresMasterReadMisplaced`). `true` on an object whose `sharingModel` is not `controlled_by_parent` is refused at `sharing.controlledByParent.writeRequiresMasterRead`: nothing reads it there (ADR-0049). `true` beside `ownerMayEdit: true` is refused at `sharing.controlledByParent.ownerMayEdit`, with the fix "Delete ownerMayEdit; writeRequiresMasterRead already admits the owner.": with read as the master question for every principal, the owner leg admits no one more. `false` is accepted everywhere. +- **Gate.** The swap is made at one place, the hop of the §3 chain walk (`packages/plugins/plugin-security/src/security-plugin-cbp-write-gate.ts#assertControlledByParentChainEditable`). A hop whose detail declares the key asks whether the principal can **read** the master row (`assertMasterRowReadable`) in place of the three edit legs, and the walk ends there. The read is asked of the read door under the principal's own context, so it is the answer a direct by-id read of the master gives: the master's object-level read grant, its row-level security and record sharing, and, for a master that is itself `controlled_by_parent`, the chain the engine composes above it (ADR-0139 D6). A hop that does not declare the key runs the edit legs, as before. +- **What reaches the walk.** Every shape the gate judges: an insert (single and batch); a by-id update or delete; a predicate (`multi: true`) update or delete, for every master of the rows it selects; a body that re-points the reference (the master it names and the one it leaves); a body that empties an optional master (the stored master). +- **What decides after the master question.** Unchanged: the detail's own object-level grant for the verb, its own row-level policies (step 2.7 of `packages/plugins/plugin-security/src/security-plugin-authz-middleware.ts`), field-level security, and the platform ownership floors. In plain words, "admitted when the caller can read the master" is always subject to those floors: + - A **by-id** update or delete hands the floor (`owner_only_writes` / `owner_only_deletes`, `created_by == current_user.id`, `packages/plugins/plugin-security/src/platform-ownership-policies.ts`) to the master gate, as it has for every `controlled_by_parent` detail through the coverage vouch (`masterGateCoversThisWrite`, step 2.7). So a master reader can update or delete a row they did not create. + - 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. +- **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. + +### The two seat calls (veto window) + +- **Chains: each hop asks what the object at that hop declares.** An opted-in detail under a master that is itself a non-opted `controlled_by_parent` detail asks read on that master and stops; the read door composes the chain above, so a hidden top master refuses the write. A detail that does **not** declare the key, under a `controlled_by_parent` master that **does**, asks the edit legs on its own master (that master's object-level update grant and authored update policies still run on the hop), and then that master's hop asks read on the master above it. So such a detail is written by someone who cannot edit the top master. It is the one case where an object that does not declare the key answers differently, which is why the invariant below names the chain. +- **Every verb.** The gate is verb-blind: step 2.8 runs it for `insert`, `update`, `delete`, `transfer`, `restore` and `purge`, so on an opted-in detail the lifecycle verbs ask read on the master too. The detail's own grants for those verbs still decide. + +### 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`. + +### Fail-closed boundaries + +- The reader answers `false` unless the key is the boolean `true`. +- A store fault during the master read propagates as raised, never as a verdict (`readUnlessRefused`). +- The edit hops below a read hop keep the cycle guard and the depth bound; the read hop ends the walk, and the read derivation it asks carries its own bound. + +### Proof + +The `[#33250]` describes in `packages/plugins/plugin-security/src/controlled-by-parent-owner-may-edit.test.ts` (admit for a master reader, refusal without the read, the detail's own grants, chains, on behalf of, the unchanged default, the served member); `packages/plugins/plugin-security/src/explain-controlled-by-parent-write.test.ts`; `packages/spec/src/data/controlled-by-parent-owner-may-edit.test.ts` (the key, the reader, both refusals); `packages/lint/src/validate-security-posture-owner-may-edit.test.ts`. Emptying an optional master and the lifecycle verbs reach the same walk and are covered by construction; neither is pinned under the opt-in yet (contract review `6881744779`, N4). + +### What is unchanged + +§1, §2, the cycle guard and the depth bound; the 2026-11-07 owner rule for a null-master row; the 2026-10-26 owner leg on a detail that does not declare the new key; and every detail whose chain declares no `writeRequiresMasterRead`.