Skip to content

Commit b08bf05

Browse files
committed
Merge origin/main into claude/issue-29933-release-notes-18-3
Co-Authored-By: Claude <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017ihL2gLghEqeDKTbDTC7Zd
2 parents 59058c4 + 21510bb commit b08bf05

24 files changed

Lines changed: 1736 additions & 85 deletions
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
---
2+
'@objectstack/plugin-security': minor
3+
'@objectstack/core': minor
4+
'@objectstack/spec': minor
5+
---
6+
7+
feat(plugin-security)!: under a walled tenancy posture every external object states its organization scope
8+
9+
Clause-②: no (narrowing) — under the `isolated` and `group` postures an external object (an `external` block) that states no organization scope is refused by name when the boot completes, and one registered after the boot answers no row and accepts no write; nothing is widened, and the `single` posture is unchanged.
10+
Metadata-protocol: narrowed
11+
12+
<!-- adr-0087: registered external-object-organization-scope-declared -->
13+
14+
**BREAKING** for a deployment running the `isolated` or `group` tenancy posture (`OS_TENANCY_POSTURE`) with an external object that states nothing about its organization scope.
15+
16+
- **The rule (ADR-0015 §10 as amended, ADR-0095 D1).** The platform provisions no storage for an external object, so the `organization_id` it injects into the registered schema is a column the remote may not carry. Whose rows an external object serves — one organization's or every organization's — is a fact only its author knows, and under a walled posture the object states it, in one of three ways: its own `organization_id` field (the remote rows carry the organization column and the driver returns it; a remote column of another name is mapped onto it with `external.columnMap: { <remote column>: 'organization_id' }`); `tenancy: { enabled: false }` (shared by every organization); or `systemFields: { tenant: false }` (the same opt-out on the system fields). These are the wall's own two opt-out clauses and the one column it reads; the whole-block `systemFields: false` states nothing.
17+
- **What the rule does.** `SecurityPlugin` refuses the boot from its `kernel:ready` handler, beside the ADR-0131 D5 refusal, naming every external object that states nothing and the three ways out (`ExternalObjectOrganizationScopeUndeclaredError`). An external object registered after the boot — a Studio import, a runtime datasource — that states nothing answers no row and accepts no write: the Layer 0 verdict is `deny` (`computeTenantLayer0Verdict`), the write wall refuses every insert, update and delete with a sentence naming the undeclared scope and the three ways out, and the plugin says so once in a warning. An object declaring its own `organization_id` is walled: a member of organization A reads only A's rows, through a driver that honours `where` and through one that ignores it (the engine's floor re-applies the predicate), and a row missing the column reads to no one. An object declaring `tenancy: { enabled: false }` or `systemFields: { tenant: false }` is shared.
18+
- **`tenancy.tenantField` on an external object is closed the same way.** The organization wall keys on `organization_id` alone, and a declared tenant field is read only by storage the platform provisions, which an external object has none of; so on an external object a `tenantField` naming another column is refused at boot and denied after it, with the remedy spelled out (`external.columnMap` onto `organization_id`, or `tenancy: { enabled: false }`). Local objects are unchanged.
19+
- **Who moves.** Every walled deployment with an external object stating nothing: declare one of the three and restart. The showcase's two federated analytics objects now declare `tenancy: { enabled: false }`. A `single`-posture deployment owes no declaration and behaves exactly as before.
20+
- **`@objectstack/core`.** `TenantLayer0Input` gains the optional `externalOrganizationScopeUndeclared`; set, the verdict is `deny` under a walled posture, ahead of the platform-admin crossing. Omitted, every existing caller reads as before.
21+
- **`@objectstack/spec`.** The ADR-0087 D3 entry `external-object-organization-scope-declared` tells an upgrading operator what to declare.
22+
23+
Skills-docs: follow-up #29866 — `content/docs/data-modeling/virtual-objects.mdx` (a multi-organization section), `skills/objectstack-data/rules/datasources.md` (the three declarations), `docs/adr/0015-external-datasource-federation.md` (the §10 and D7 amendment); the sibling docs PR on `claude/sec-hardening-g-docs`, governed (Tier H), landed by the maintainer's hand.

‎examples/app-showcase/src/data/objects/external/customer.object.ts‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ export const ExternalCustomer = ObjectSchema.create({
1515
// object is RLS-owned / intentionally public; without this the new secure
1616
// default (unset OWD => private) would owner-filter it.
1717
sharingModel: 'public_read_write',
18+
// [ADR-0015 §10] Under a walled tenancy posture every external object states
19+
// its organization scope. The remote `customers` table carries no
20+
// organization column — it is the deployment's analytics catalogue, read by
21+
// every organization alike — so this object declares itself shared. (The
22+
// other declaration is an `organization_id` field of its own, when the
23+
// remote rows carry one.)
24+
tenancy: { enabled: false },
1825
label: 'External Customer',
1926
pluralLabel: 'External Customers',
2027
icon: 'database',

‎examples/app-showcase/src/data/objects/external/order.object.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ export const ExternalOrder = ObjectSchema.create({
1313
// object is RLS-owned / intentionally public; without this the new secure
1414
// default (unset OWD => private) would owner-filter it.
1515
sharingModel: 'public_read_write',
16+
// [ADR-0015 §10] Under a walled tenancy posture every external object states
17+
// its organization scope. The remote `orders` table carries no organization
18+
// column — the deployment's shared analytics catalogue — so this object
19+
// declares itself shared, as `showcase_ext_customer` does.
20+
tenancy: { enabled: false },
1621
label: 'External Order',
1722
pluralLabel: 'External Orders',
1823
icon: 'shopping-cart',
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license.
2+
3+
/**
4+
* The Layer 0 verdict ladder (ADR-0095 D1 / ADR-0131 D8), rung by rung — in
5+
* particular the rung an external object reaches when it states no
6+
* organization scope under a walled posture (ADR-0015 §10): the wall DENIES,
7+
* it does not stand down.
8+
*/
9+
10+
import { describe, it, expect } from 'vitest';
11+
import { computeTenantLayer0Verdict, type TenantLayer0Input } from './tenant-layer0-verdict.js';
12+
13+
const member = (over: Partial<TenantLayer0Input> = {}): TenantLayer0Input => ({
14+
tenancyPosture: 'isolated',
15+
organizationId: 'org-1',
16+
objectHasOrgIdField: true,
17+
tenancyDisabled: false,
18+
posturePermitsCrossTenant: false,
19+
isPlatformAdmin: false,
20+
...over,
21+
});
22+
23+
describe('computeTenantLayer0Verdict — an external object that states no organization scope', () => {
24+
it('under `isolated` the wall denies: no provable scope, no row', () => {
25+
expect(computeTenantLayer0Verdict(member({ externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false })))
26+
.toEqual({ kind: 'deny' });
27+
});
28+
29+
it('under `group` the wall denies too — the union predicate has no column to name', () => {
30+
expect(computeTenantLayer0Verdict(member({
31+
tenancyPosture: 'group', accessibleOrgIds: ['org-1', 'org-2'],
32+
externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false,
33+
}))).toEqual({ kind: 'deny' });
34+
});
35+
36+
it('the denial precedes the platform-admin crossing: an undeclared object is a configuration defect, not a posture', () => {
37+
expect(computeTenantLayer0Verdict(member({
38+
externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false,
39+
isPlatformAdmin: true, posturePermitsCrossTenant: true,
40+
}))).toEqual({ kind: 'deny' });
41+
});
42+
43+
it('a declared opt-out (`tenancy.enabled: false`) still contributes nothing — the object is shared by every organization', () => {
44+
expect(computeTenantLayer0Verdict(member({ tenancyDisabled: true, externalOrganizationScopeUndeclared: false, objectHasOrgIdField: false })))
45+
.toEqual({ kind: 'none' });
46+
});
47+
48+
it('a declared `organization_id` keeps the wall', () => {
49+
expect(computeTenantLayer0Verdict(member({ externalOrganizationScopeUndeclared: false })))
50+
.toEqual({ kind: 'organization', organizationId: 'org-1' });
51+
});
52+
53+
it('CONTROL: under `single` nothing is read — an undeclared object answers `none` like every other', () => {
54+
expect(computeTenantLayer0Verdict(member({ tenancyPosture: 'single', externalOrganizationScopeUndeclared: true, objectHasOrgIdField: false })))
55+
.toEqual({ kind: 'none' });
56+
});
57+
58+
it('CONTROL: the flag omitted reads as every caller before it — a column-less object answers `none`', () => {
59+
expect(computeTenantLayer0Verdict(member({ objectHasOrgIdField: false }))).toEqual({ kind: 'none' });
60+
});
61+
});

‎packages/core/src/security/tenant-layer0-verdict.ts‎

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,19 @@ export interface TenantLayer0Input {
6969
* are NOT tenant objects; Layer 0 contributes nothing.
7070
*/
7171
tenancyDisabled: boolean;
72+
/**
73+
* [ADR-0015 §10] The object is EXTERNAL (ADR-0015 `external`: the platform
74+
* provisions none of its storage) and states no organization scope the wall
75+
* can enforce — neither its own `organization_id` field, nor
76+
* `tenancy.enabled: false`, nor `systemFields.tenant: false`; or it names a
77+
* `tenancy.tenantField` other than `organization_id`, which the wall does not
78+
* read. Under a walled posture such an object is DENIED: whose rows it serves
79+
* is a fact only its author can state, and an unstated scope fails toward
80+
* isolation, never toward exposure (the shape the owner anchor takes when no
81+
* owner is provable). The boot refuses such an object by name; this rung
82+
* meets the one registered after the boot. Omitted, nothing changes.
83+
*/
84+
externalOrganizationScopeUndeclared?: boolean;
7285
/**
7386
* Whether the object's POSTURE permits a platform admin to cross the tenant
7487
* wall — `private`, platform-global (`tenancy.enabled:false`), or
@@ -123,18 +136,28 @@ const LAYER0_DENY: TenantLayer0Verdict = Object.freeze({ kind: 'deny' as const }
123136
* (ADR-0105 D2).
124137
* - `deny` → a walled posture on a tenant object, but the context carries no
125138
* organization scope to enforce with (no active org under `isolated`, empty
126-
* access set under `group`) → fail closed (zero rows / write denied).
139+
* access set under `group`); or a walled posture on an external object that
140+
* states no organization scope (ADR-0015 §10) → fail closed (zero rows /
141+
* write denied).
127142
*/
128143
export function computeTenantLayer0Verdict(input: TenantLayer0Input): TenantLayer0Verdict {
129144
// `single` posture (incl. a degraded deployment, which resolves to `single`)
130145
// → parity with today's policy stripping.
131146
if (!postureEnforcesWall(input.tenancyPosture)) return LAYER0_NONE;
132147

133-
// Not a tenant object: platform-global (tenancy disabled) or simply carries no
134-
// `organization_id` column (e.g. better-auth identity tables like `sys_user`).
135-
// Layer 0 contributes nothing — the object's own business RLS (Layer 1, e.g.
148+
// Not a tenant object: platform-global (tenancy disabled). Layer 0
149+
// contributes nothing — the object's own business RLS (Layer 1, e.g.
136150
// `_self` carve-outs) is its only scoping.
137151
if (input.tenancyDisabled) return LAYER0_NONE;
152+
153+
// [ADR-0015 §10] An external object that states no organization scope is
154+
// denied under a wall — ahead of the column question (its `organization_id`
155+
// is the registry's, not the remote's) and ahead of the platform-admin
156+
// crossing (an unstated scope is a configuration defect, not a posture).
157+
if (input.externalOrganizationScopeUndeclared) return LAYER0_DENY;
158+
159+
// Simply carries no `organization_id` column (e.g. better-auth identity
160+
// tables like `sys_user`): not a tenant object, Layer 0 contributes nothing.
138161
if (input.objectHasOrgIdField === false) return LAYER0_NONE;
139162

140163
// Exemption is a Layer 0 rule (W2 fix): only a TRUE PLATFORM_ADMIN caller on an

0 commit comments

Comments
 (0)