Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .changeset/38517-public-read-write-owner-delete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
---
'@objectstack/plugin-sharing': minor
'@objectstack/plugin-security': minor
'@objectstack/spec': patch
---

fix(sharing)!: on an object that declares `sharingModel: 'public_read_write'` and has an owner field, deleting a record follows the record's owner, as it already does on a private object

Clause-②: yes (narrowing)
Metadata-protocol: semantic
Skills-docs: follow-up #39217

Everyone who may edit such a record still may; only delete changes. A record of such an object can now be deleted by its owner, by a manager above the owner in the role hierarchy, and by a user holding Modify All on the object. A record with no owner can be deleted only by a Modify All holder. An app-authored row-level delete policy that admits a caller still lets that caller delete, as on any owned object. Who created the record no longer decides. The same rule answers a delete by id, a delete by filter (each matching row is judged on its own), a cascade delete of child records, and the permanent delete of a record from the recycle bin; restoring or purging a recycle-bin entry is unchanged. `security/explain` reports the same answer for delete.

**BREAKING** for three groups of users on such an object:

1. A member who created a record that someone else now owns can no longer delete it (they still can edit it). Reassigning the record back, or asking its owner, a manager above the owner, or a Modify All holder, is how it gets deleted.
2. A user whose organization membership role is not one of the built-in roles (a custom role string, so the platform's "only the creator deletes" floor never applied to them), and a session with no organization at all, could until now delete any record of such an object; they now delete only the records they own, like every member.
3. On a deployment with a single organization, or one whose organizations are walled with unbounded admin rights suppressed, organization owners and admins hold the administrator set without Modify All. They could until now delete any record of such an object; they now delete only the records they own or manage, exactly as on a private object. A deployment that wants its admins to clean up colleagues' records grants Modify All on the object, or the full-access admin set. The first platform administrator is unaffected.

External users follow the same rule as members. Where an external user's permission grant speaks for the object, the external owner of a record can now delete it and an external creator who no longer owns it cannot; where it does not, nothing changes (the object already behaves as private for them).

Objects that declare `public_read_write` without an owner field (a federated object whose owner field is only the platform's anchor, with no column behind it, among them), platform objects that declare no sharing model, and detail objects controlled by their parent keep today's behaviour. No metadata key, value or type changes and no stored metadata is refused.

<!-- adr-0087: not-required (no-migration-prescription) no key, value or metadata type is removed or renamed: what changes is who may delete a record of an owned public_read_write object, which no metadata rewrite can migrate -->
5 changes: 4 additions & 1 deletion content/docs/kernel/runtime-services/sharing-service.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ Each write gate has a primary **tri-state** form, `checkEdit` (update) and
- `abstain` — record sharing does not enforce on this row at all: a `public`
object, an object with no owner field, a bypass-listed platform internal, or an
object with no resolvable schema. The decision belongs to whatever else guards
the row. `checkDelete` abstains on exactly the rows `checkEdit` abstains on.
the row. `checkDelete` abstains on the rows `checkEdit` abstains on except
one class: on an object that declares `public_read_write` and has an owner
field, delete follows the record's owner, so `checkDelete` answers `allow`
or `deny` there as it does under `public_read`.
- `deny` — refused: a sharing-enforced row where the caller has none of the
bases above, a principal-less context, or a lookup that failed. A failure is
always `deny`, never `abstain`.
Expand Down
7 changes: 4 additions & 3 deletions content/docs/permissions/permissions-matrix.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,10 @@ policies are short-circuited only on objects whose posture permits it —
object, authored RLS still applies, and so does `member_default`'s creator-only
write floor (`created_by == current_user.id`) for `org_member` holders. Under
`public_read_write` the update floor does not apply (that OWD opens row updates)
and the delete floor does; on an object with no `owner_id` both apply. Where
record sharing enforces writes (an object with an `owner_id` whose OWD is
`private` or `public_read`), the sharing service's `allow` for a row replaces
and a delete follows the record's owner, as below; on an object with no
`owner_id` both floors apply. Where record sharing enforces writes (an object
with an `owner_id` whose OWD is `private` or `public_read`, or, for a delete
only, a declared `public_read_write`), the sharing service's `allow` for a row replaces
the floor for that row: ownership at the caller's write depth or
`modifyAllRecords`, and, for an update, an `edit` share. On an update, a row
sitting in a queue the caller belongs to gets the same `allow` under any OWD. A
Expand Down
28 changes: 20 additions & 8 deletions content/docs/permissions/sharing-rules.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ Two things the bits do **not** override, regardless of the OWD:
platform baseline `member_default` ships creator-only `update`/`delete`
policies (`created_by == current_user.id`, applicability domain
`org_member`). Under `public_read_write` the update policy does not apply
(that OWD opens row updates) and the delete policy does; under every other
OWD both apply, and record sharing can replace them row by row, as below.
(that OWD opens row updates) and the delete policy does, which record
sharing replaces row by row on an object with an owner column; under every
other OWD both apply, and record sharing can replace them row by row, as below.
A `controlled_by_parent` detail's write is judged by its master gate
instead, by id and by predicate alike: a caller who may edit the master (or
read it, where the detail declares `writeRequiresMasterRead`) updates and
Expand All @@ -74,7 +75,8 @@ Two things the bits do **not** override, regardless of the OWD:
`modifyAllRecords` does *not* short-circuit those policies
(`plugin-security/src/security-plugin.ts` `computeLayeredRlsFilter`).
Where record sharing enforces writes (an `owner_id` and a `private` or
`public_read` OWD), the sharing service's `allow` for a row replaces the
`public_read` OWD, or, for a delete only, an `owner_id` and a declared
`public_read_write` OWD), the sharing service's `allow` for a row replaces the
baseline floor for that row: ownership at the caller's write depth or
`modifyAllRecords`, and, for an update, an `edit` share. On an update, a
row sitting in a queue the caller belongs to gets the same `allow` under
Expand All @@ -91,12 +93,22 @@ Two things the bits do **not** override, regardless of the OWD:
a limit on deleting goes in a `beforeDelete` hook. For a master's details
the limit goes in a hook on the detail object.
A write made on
another user's behalf keeps the floor. Under
`public_read_write` the sharing service abstains on a delete, so the
delete floor stays; on an object with no `owner_id` it abstains on both,
so both floors stay. An app-authored policy is never replaced.
another user's behalf keeps the floor. Under a declared
`public_read_write` OWD a delete follows the record's owner: the sharing
service answers it as it does under `public_read` (ownership at the caller's
write depth, or `modifyAllRecords`), so a row's creator who does not own it
may not delete it, and a row with no owner only a `modifyAllRecords` holder
may delete; an update stays
open to everyone who may edit. On an object with no `owner_id` it abstains
on both, so both floors stay. An app-authored policy is never replaced.
Org admins (`org_admin` / `org_owner`) are outside the `org_member`
applicability domain and are not narrowed by the baseline.
applicability domain and are not narrowed by the baseline. Record sharing
still answers them: where their admin set carries no `modifyAllRecords`
(`organization_admin_no_bypass`, granted on a deployment with no wall
between organizations), they delete only the rows they own or manage of an
owned `public_read_write` object, exactly as on a `private` one. Grant
`modifyAllRecords` on the object, or `admin_full_access`, to let them
clean up colleagues' rows.
- **The Layer 0 tenant wall** (ADR-0095 D1) — always ANDs on top.

None of this is an enterprise/open-core split: both bits are enforced by the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ const ORG = 'org_ccp';
const ME = 'usr_ccp_me';
const OTHER = 'usr_ccp_other';

/** The parent: open to every member, so its own delete is never the refusal. */
/**
* The parent, owned by the caller so its own delete is never the refusal: delete on an owned
* `public_read_write` object follows the record's owner (ruling of record 7288570890).
*/
const ORDER = 'qa_ccp_order';
/** A record-shared child, owner-scoped (`private`), reached by two cascading lookups. */
const LINE = 'qa_ccp_line';
Expand Down Expand Up @@ -243,7 +246,7 @@ describe('cascade delete: security parity between id-shaped and predicate-shaped
* the caller at `edit` (read and update, never delete: ADR-0111 D3).
*/
const seedOrder = async (prefix: string, refused?: 'unreadable' | 'edit-shared') => {
await ql.insert(ORDER, { id: prefix, name: prefix }, SYS);
await ql.insert(ORDER, { id: prefix, name: prefix, owner_id: ME }, SYS);
await ql.insert(LINE, [
{ id: `${prefix}_a`, owner_id: ME, order: prefix },
{ id: `${prefix}_b`, owner_id: refused ? OTHER : ME, order: prefix },
Expand Down Expand Up @@ -309,7 +312,7 @@ describe('cascade delete: security parity between id-shaped and predicate-shaped

it('a cascade the caller may complete leaves none of the children its probe found', async () => {
const prefix = 'f_all';
await ql.insert(ORDER, { id: prefix }, SYS);
await ql.insert(ORDER, { id: prefix, owner_id: ME }, SYS);
const lines = Array.from({ length: 12 }, (_, i) => ({ id: `${prefix}_l${String(i).padStart(2, '0')}`, owner_id: ME, order: prefix }));
await ql.insert(LINE, lines, SYS);
await ql.insert(NOTE, [{ id: `${prefix}_n1`, order: prefix }, { id: `${prefix}_n2`, order: prefix }], SYS);
Expand All @@ -326,7 +329,7 @@ describe('cascade delete: security parity between id-shaped and predicate-shaped
describe('3. never more rows: the cascade deletes the children it probed and nothing else', () => {
it('rows of the child objects under another order, or under none, stay', async () => {
const prefix = 'm1';
await ql.insert(ORDER, [{ id: prefix }, { id: `${prefix}_other` }], SYS);
await ql.insert(ORDER, [{ id: prefix, owner_id: ME }, { id: `${prefix}_other`, owner_id: ME }], SYS);
await ql.insert(LINE, [
{ id: `${prefix}_mine`, owner_id: ME, order: prefix },
{ id: `${prefix}_other_line`, owner_id: ME, order: `${prefix}_other` },
Expand All @@ -345,7 +348,7 @@ describe('cascade delete: security parity between id-shaped and predicate-shaped

it('a child written after the probe (by a sibling\'s beforeDelete) is not deleted by this cascade', async () => {
const prefix = 'm2';
await ql.insert(ORDER, { id: prefix }, SYS);
await ql.insert(ORDER, { id: prefix, owner_id: ME }, SYS);
await ql.insert(LINE, [{ id: `${prefix}_a`, owner_id: ME, order: prefix }, { id: `${prefix}_b`, owner_id: ME, order: prefix }], SYS);
spawnFrom = `${prefix}_a`;

Expand All @@ -363,7 +366,7 @@ describe('cascade delete: security parity between id-shaped and predicate-shaped
describe('4. each child\'s delete-side work runs once per child', () => {
it('one audit delete row, every share revoked, and each object-less hook phase once, per child, a child two relations reach included', async () => {
const prefix = 'h1';
await ql.insert(ORDER, { id: prefix }, SYS);
await ql.insert(ORDER, { id: prefix, owner_id: ME }, SYS);
await ql.insert(LINE, [
{ id: `${prefix}_by_order`, owner_id: ME, order: prefix },
{ id: `${prefix}_by_both`, owner_id: ME, order: prefix, alt_order: prefix },
Expand Down
36 changes: 34 additions & 2 deletions packages/plugins/plugin-security/src/explain-engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import type {
ControlledByParentWriteUnresolvedReason,
} from '@objectstack/spec/contracts';
import type { FieldMaskingRule } from '@objectstack/spec/data';
import { controlledByParentMasterOf, controlledByParentWriteRequiresMasterRead } from '@objectstack/spec/data';
import { controlledByParentMasterOf, controlledByParentWriteRequiresMasterRead, isOwnerAnchorUnprovable } from '@objectstack/spec/data';
import type { PermissionSet } from '@objectstack/spec/security';
import type {
AuthzPosture,
Expand Down Expand Up @@ -572,6 +572,14 @@ export interface ExplainEngineDeps {
* explanation for a `delete` must consult this rather than the update gate.
*/
canDeleteRecord?: (object: string, recordId: string, context: any) => Promise<boolean>;
/**
* [Ruling of record 7288570890, option C] Whether the sharing service is
* installed, record id or not. Delete on an object that declares
* `public_read_write` with an owner column follows the record's owner only
* where it is, so the `owd_baseline` layer reads that delete as
* owner-scoped only then (`describeOwdFor`). Absent reads as not installed.
*/
sharingServiceWired?: boolean;
/**
* [#5493 / ADR-0105 D3] The by-id write gate's DEFERRAL: whether an
* APP-AUTHORED row-level policy admits the row for the refusing gate's verb
Expand Down Expand Up @@ -1336,6 +1344,30 @@ function describeOwd(schema: any): { model: string; declared: boolean; effect: '
return { model: `${String(m)} (unknown → private, fail-closed)`, declared: true, effect: 'private' };
}

/**
* [Ruling of record 7288570890, option C] The OWD reading for one RLS
* operation: {@link describeOwd}, except that a DELETE on an object that
* DECLARES `public_read_write` and carries the owner column meets the
* owner-writes baseline — plugin-sharing answers that delete by ownership,
* write depth and Modify All, exactly as on `public_read` (its
* `ownershipDecidesDeleteOnOpenWrites`). Edit on the same object stays open.
*
* Only where that answer exists: `sharingDecidesDelete` is whether the
* sharing service is installed. Without plugin-sharing no door reads
* the owner for that delete, so the report keeps the declared baseline and
* cannot claim a refusal the request would not meet.
*/
function describeOwdFor(schema: any, rlsOp: string, sharingDecidesDelete: boolean): ReturnType<typeof describeOwd> {
const owd = describeOwd(schema);
if (!sharingDecidesDelete) return owd;
const declared = schema?.sharingModel ?? schema?.security?.sharingModel;
// A federated object whose `owner_id` is only the injected anchor carries no
// owner column: plugin-sharing leaves its delete to the floor, so does this.
const owned = Boolean(schema?.fields && 'owner_id' in schema.fields) && !isOwnerAnchorUnprovable(schema);
if (rlsOp !== 'delete' || declared !== 'public_read_write' || !owned) return owd;
return { model: 'public_read_write (delete follows the record owner)', declared: true, effect: 'read' };
}

/** [ADR-0055] What each refusing leg of the master-detail write check means, for the report's prose. */
const MASTER_DENIAL_LEG_DETAIL: Record<ControlledByParentWriteDenialLeg, string> = {
object_permission: 'the principal holds no object-level update grant on a master',
Expand Down Expand Up @@ -3505,7 +3537,7 @@ async function explainObjectPass(deps: ExplainEngineDeps, input: ExplainInput, a
// stamps for plugin-sharing, so the report and the query cannot disagree.
const owdOpClass: 'read' | 'write' = dataOp === 'find' ? 'read' : 'write';
const owd = owdForPrincipal(
describeOwd(schema),
describeOwdFor(schema, rlsOp, deps.sharingServiceWired === true),
context,
isExternalAudienceContext(context) && deps.externalGrantSpeaks?.(sets, object, owdOpClass, dataOp, context) === true,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -997,9 +997,13 @@ const baseDefaultPermissionSets: PermissionSet[] = [
// (any member could edit/delete any record — #1985). These policies are
// ENFORCED on writes via the security middleware's pre-image check (a
// by-id update/delete never builds an RLS `where`, so the predicate is
// verified against the target row before the mutation). Objects that
// model transferable ownership with a dedicated owner field should
// override these with a per-object policy.
// verified against the target row before the mutation). On an object
// with an owner field record sharing answers the write by ownership and
// its `allow` replaces these floors (#5492), on every owned OWD — a
// `public_read_write` object's delete included (ruling of record
// 7288570890); they still decide alone on an object with no owner field
// or an undeclared model on a platform table, and for a write made on
// another user's behalf.
// [ADR-0090 P2] Applicability domain made EXPLICIT: with the baseline
// resolving additively for every authenticated principal (the
// `everyone` anchor — no more fallback cliff), these members-only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,15 +267,22 @@ export function owdDeclaresOpenRowWrites(schema: unknown): boolean {

/**
* The write class {@link owdDeclaresOpenRowWrites} opens — `update` and nothing
* else, so `owner_only_deletes` survives on a `public_read_write` object.
* else, so `owner_only_deletes` survives on a `public_read_write` object. Who
* deletes there is not this file's answer: on such an object with an owner
* column the record's owner, someone above the owner by depth and a Modify All
* holder delete, because record sharing answers that delete by ownership and
* its `allow` replaces the surviving floor (ruling of record 7288570890); the
* floor still decides it on such an object with no owner column, and for a
* write made on another user's behalf.
*
* This is the OWD vocabulary's own boundary, not a conservative guess:
* `public_read_write` is defined as "everyone can see and edit", and the legacy
* `full` alias that ALSO covered transfer/delete was refused a mechanical
* conversion precisely because it is "wider than `public_read_write`"
* (`spec/conversions/registry.ts`, ADR-0090 D4). An object that wants
* cross-creator deletes declares it with an app-authored policy or a share,
* both of which reach the compiler untouched.
* (`spec/conversions/registry.ts`, ADR-0090 D4). An object that wants deletes
* wider than ownership declares them with an app-authored policy, which
* reaches the compiler untouched (a share widens rows, never the delete verb,
* ADR-0111 D3).
*/
export function owdOpenWritesCoversOperation(operation: string): boolean {
return operation === 'update';
Expand Down
Loading
Loading