@astram/core 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"file":"object-type.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AA2ClC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CAyEvD"}
1
+ {"version":3,"file":"object-type.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AA2ClC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CAmFvD"}
@@ -102,14 +102,23 @@ export function createObjectTypeGate() {
102
102
  return async function objectTypeGate(ctx) {
103
103
  const { principal, action, resource, deps } = ctx;
104
104
  const isRecordLevel = resource.level === 'record';
105
- // ── Cross-tenant grant path (§7.3.3): a non-root reaching a foreign
106
- // tenant proceeded past gate 3 ONLY via a cross-tenant grant, whose scope +
107
- // ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
108
- // pure), NOT the wrong-tenant coarse facts. Root is not grant-backed;
109
- // it falls through to the coarse-grants path.
110
- const crossesTenant = resource.tenantId !== undefined &&
111
- principal.tenantId !== resource.tenantId &&
112
- !strictTrue(principal.isRoot);
105
+ // ── Cross-tenant grant path (§7.3.3): a non-root reaching a resource OUTSIDE its
106
+ // active-scope SUBTREE proceeded past gate 3 ONLY via a cross-tenant grant, whose
107
+ // scope + ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
108
+ // pure), NOT the wrong-node coarse facts. Root is not grant-backed; it falls through
109
+ // to the coarse-grants path.
110
+ // ⛔ SUBTREE-AWARE (ADR-0027): a resource IN the principal's subtree (its active node
111
+ // or a descendant — additive-down inheritance) is NOT a cross-tenant reach; it is
112
+ // handled by the coarse grants (below), NOT the grant path. Mirrors the tenant gate's
113
+ // membership test (`resource.tenantId ∈ scopeSubtreeNodeIds`), so gates 3 and 5 agree
114
+ // on what "crosses" means. `Array.isArray` guards a malformed/absent subtree (deny —
115
+ // treated as "not in scope" ⇒ crosses ⇒ the grant path, which fail-closes without a
116
+ // grant). A self-node-only subtree reduces this to the old flat `tenantId !==` check.
117
+ const subtree = principal.scopeSubtreeNodeIds;
118
+ const inSubtree = resource.tenantId !== undefined &&
119
+ Array.isArray(subtree) &&
120
+ subtree.includes(resource.tenantId);
121
+ const crossesTenant = resource.tenantId !== undefined && !inSubtree && !strictTrue(principal.isRoot);
113
122
  if (crossesTenant) {
114
123
  // Re-resolve the grant through the SINGLE-SOURCE cross-tenant helper (TEAM C)
115
124
  // so gates 3/5/6 share ONE ceiling+scope+expiry implementation (RULING 1 /
@@ -1 +1 @@
1
- {"version":3,"file":"object-type.js","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EACL,SAAS,EACT,YAAY,EACZ,QAAQ,GAIT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC/F,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,YAAY,EAAE,MAAM,yBAAyB,CAAC;AAEvD;;;;;GAKG;AACH,SAAS,cAAc,CAAC,IAAa;IACnC,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ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S,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAChC,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAE7D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,yBAAyB,CACzE,SAAS,CAAC,EAAE,EACZ,SAAS,CAAC,QAAQ,CACnB,CAAC;QACF,+EAA+E;QAC/E,gFAAgF;QAChF,IAAI,MAAM,CAAC,kBAAkB,IAAI,cAAc,EAAE,CAAC;YAChD,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjF,CAAC"}
@@ -14,10 +14,13 @@
14
14
  * ── The order (deny wins; every ambiguity resolves to the deny/continue path,
15
15
  * never to a bypass):
16
16
  *
17
- * 1. SAME TENANT (`principal.tenantId === resource.tenantId`, OR the resource
18
- * carries no instance tenant) ⇒ `continue`. A feature/object-type-level
19
- * resource with no `tenantId` is same-tenant BY CONSTRUCTION — there is no
20
- * foreign instance to cross into, so it is the principal's own tenant.
17
+ * 1. IN SCOPE (`resource.tenantId ∈ principal.scopeSubtreeNodeIds` — the active
18
+ * node + all descendants, ADR-0027 — OR the resource carries no instance
19
+ * tenant) ⇒ `continue`. An in-memory set test against the login-cached subtree
20
+ * (zero per-request DB, ADR-0024). A feature/object-type-level resource with no
21
+ * `tenantId` is same-tenant BY CONSTRUCTION — there is no foreign instance to
22
+ * cross into. The subtree ALWAYS contains the active node itself, so this is a
23
+ * strict generalization of the old flat `tenantId === resource.tenantId`.
21
24
  * 2. MISMATCH + root (STRICT `=== true`) ⇒ `continue` (break-glass,
22
25
  * audited by a later layer — not this gate's concern).
23
26
  * 3. MISMATCH + not root ⇒ consult {@link CrossTenantGrantPort}:
@@ -1 +1 @@
1
- {"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AAEH,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAIlC;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CAwC/C"}
1
+ {"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAIlC;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CA8D/C"}
@@ -14,10 +14,13 @@
14
14
  * ── The order (deny wins; every ambiguity resolves to the deny/continue path,
15
15
  * never to a bypass):
16
16
  *
17
- * 1. SAME TENANT (`principal.tenantId === resource.tenantId`, OR the resource
18
- * carries no instance tenant) ⇒ `continue`. A feature/object-type-level
19
- * resource with no `tenantId` is same-tenant BY CONSTRUCTION — there is no
20
- * foreign instance to cross into, so it is the principal's own tenant.
17
+ * 1. IN SCOPE (`resource.tenantId ∈ principal.scopeSubtreeNodeIds` — the active
18
+ * node + all descendants, ADR-0027 — OR the resource carries no instance
19
+ * tenant) ⇒ `continue`. An in-memory set test against the login-cached subtree
20
+ * (zero per-request DB, ADR-0024). A feature/object-type-level resource with no
21
+ * `tenantId` is same-tenant BY CONSTRUCTION — there is no foreign instance to
22
+ * cross into. The subtree ALWAYS contains the active node itself, so this is a
23
+ * strict generalization of the old flat `tenantId === resource.tenantId`.
21
24
  * 2. MISMATCH + root (STRICT `=== true`) ⇒ `continue` (break-glass,
22
25
  * audited by a later layer — not this gate's concern).
23
26
  * 3. MISMATCH + not root ⇒ consult {@link CrossTenantGrantPort}:
@@ -51,9 +54,29 @@ import { isCrossTenantGrantApplicable } from '../cross-tenant/grant-evaluator.js
51
54
  export function createTenantGate() {
52
55
  return async function tenantGate(ctx) {
53
56
  const { principal, action, resource, deps } = ctx;
54
- // 1. Same tenant — including a feature/object-type resource with no instance
55
- // tenant (same-tenant by construction: no foreign instance to cross into).
56
- if (resource.tenantId === undefined || principal.tenantId === resource.tenantId) {
57
+ // 1. IN SCOPE — the resource's owning node is in the principal's active-scope
58
+ // SUBTREE (the node it acts under + all descendants, ADR-0027), OR there is
59
+ // no instance tenant (a feature/object-type resource with no foreign instance
60
+ // to cross into: same-tenant by construction).
61
+ // This is an IN-MEMORY set-membership test against the login-cached
62
+ // `scopeSubtreeNodeIds` — ZERO per-request DB (the ADR-0024 parity guarantee).
63
+ // A non-root principal reaches everything in its subtree (additive-down
64
+ // inheritance) and nothing outside it. `scopeSubtreeNodeIds` ALWAYS contains
65
+ // the active node itself (self-row, Task 2.2), so this GENERALIZES — never
66
+ // narrows — the old flat equality: the `tenantId === resource.tenantId` case
67
+ // is exactly the singleton-subtree case. Root's cross-tree span is NOT here;
68
+ // it is authoritative via `isRoot` (step 2 below). FAIL-CLOSED: an empty
69
+ // subtree makes `.includes` false for every node ⇒ falls through to root /
70
+ // cross-grant / deny (reaches nothing but its own via the self-node).
71
+ // DEFENSE-IN-DEPTH: `Array.isArray` guards a malformed/absent subtree (a
72
+ // JS-constructed Principal that omits the field despite the TS contract) —
73
+ // a non-array is treated as "no reachable scope" ⇒ deny, DETERMINISTICALLY,
74
+ // rather than relying on a thrown `undefined.includes` being caught as a
75
+ // fail-closed deny by the pipeline (fail-closed either way, but this is the
76
+ // explicit, non-crashy form).
77
+ const subtree = principal.scopeSubtreeNodeIds;
78
+ if (resource.tenantId === undefined ||
79
+ (Array.isArray(subtree) && subtree.includes(resource.tenantId))) {
57
80
  return gateContinue();
58
81
  }
59
82
  // 2. Mismatch + root (break-glass). STRICT === true — a truthy
@@ -1 +1 @@
1
- {"version":3,"file":"tenant.js","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QAChF,yEAAyE;QACzE,gFAAgF;QAChF,8EAA8E;QAC9E,gFAAgF;QAChF,iFAAiF;QACjF,8EAA8E;QAC9E,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,4BAA4B,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC/E,SAAS;YACT,MAAM;YACN,QAAQ;SACT,CAAC,CAAC;QAEH,IAAI,UAAU,EAAE,CAAC;YACf,0EAA0E;YAC1E,0EAA0E;YAC1E,OAAO,YAAY,EAAE,CAAC;QACxB,CAAC;QAED,gFAAgF;QAChF,iEAAiE;QACjE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
@@ -161,5 +161,6 @@ export * from './cross-tenant/grant-evaluator.js';
161
161
  export * from './delegation/operation-identity.js';
162
162
  export * from './record/owner-baseline.js';
163
163
  export * from './record/permit-tier.js';
164
+ export * from './record/list-scope.js';
164
165
  export * from './gates/wiring.js';
165
166
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,aAAa,GAAG,QAAQ,CAAC;AAEjE;;;GAGG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,sBAAsB,GAAG,OAAO,CAAC;AAErE;;;GAGG;AACH,eAAO,MAAM,mBAAmB,EAAE,UAAoB,CAAC;AAEvD;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,EAAE,OAAO,MAA4C,CAAC;AAE5F;;;;;;;;;GASG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG;IAAE,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAA;CAAE,CAAC;AAEjF;;;GA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AAkE;IAClE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,MAAM,CACJ,SAAS,EAAE,SAAS,EACpB,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,eAAe,GACvB,OAAO,CAAC,QAAQ,CAAC,CAAC;CACtB;AAMD,cAAc,aAAa,CAAC;AAE5B,cAAc,YAAY,CAAC;AAE3B,cAAc,mBAAmB,CAAC;AAGlC,cAAc,yBAAyB,CAAC;AAExC,cAAc,oBAAoB,CAAC;AAInC,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,4BAA4B,CAAC;AAE3C,cAAc,oBAAoB,CAAC;AAEnC,cAAc,mCAAmC,CAAC;AAElD,cAAc,oCAAoC,CAAC;AAEnD,cAAc,4BAA4B,CAAC;AAE3C,cAAc,yBAAyB,CAAC;AAExC,cAAc,wBAAwB,CAAC;AAEvC,cAAc,mBAAmB,CAAC"}
@@ -112,6 +112,8 @@ export * from './delegation/operation-identity.js';
112
112
  export * from './record/owner-baseline.js';
113
113
  // - INTEGRATION: the composed gate-6 record permit tier (baseline ∪ policy ∪ share, deny-wins):
114
114
  export * from './record/permit-tier.js';
115
+ // - LIST SCOPE: the decision-derived visible-set spec — sibling to decide() (Phase 1):
116
+ export * from './record/list-scope.js';
115
117
  // - INTEGRATION: the production gate-set wiring + fully-wired DecisionAuthority factory:
116
118
  export * from './gates/wiring.js';
117
119
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAe,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAkB,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AAC"}
@@ -34,6 +34,7 @@
34
34
  */
35
35
  import type { Principal } from '../identity/index.js';
36
36
  import type { Action, Resource } from './index.js';
37
+ import type { ScopeCondition } from './record/list-scope.js';
37
38
  /**
38
39
  * The coarse feature/object-type grants a principal holds in a tenant — the
39
40
  * ADR-0011 "facts" projected at session establish and consumed by gate 5. Kept
@@ -222,6 +223,70 @@ export interface CrossTenantGrantPort {
222
223
  */
223
224
  findActiveGrant(query: CrossTenantGrantQuery): Promise<CrossTenantGrant | null>;
224
225
  }
226
+ /**
227
+ * The policy condition-groups describing the policy-ALLOWED / policy-DENIED subsets of
228
+ * a LIST scope (ADR-0005, list form). Each side is a list of AND-GROUPS OR'd together:
229
+ * a row satisfies a group iff it satisfies ALL of the group's {@link ScopeCondition}s,
230
+ * and the subset is the UNION over groups. This preserves the guided-policy semantics
231
+ * (each policy is an AND of its conditions; multiple policies OR) so the guard translator
232
+ * can render it WITHOUT losing AND-vs-OR precedence.
233
+ */
234
+ export interface ListPolicyConditions {
235
+ /** AND-groups of conditions; a row is policy-ALLOWED if it satisfies ALL conditions of ANY group. */
236
+ readonly allow: readonly (readonly ScopeCondition[])[];
237
+ /** AND-groups of conditions; a row is policy-DENIED (deny-wins) if it satisfies ALL of ANY group. */
238
+ readonly deny: readonly (readonly ScopeCondition[])[];
239
+ }
240
+ /**
241
+ * The requesting principal's SUBJECT identity — the id + role ids the list-scope adapter
242
+ * uses to filter each policy rule GROUP by its `rpr_subject_kind` / `rpr_subject_value`,
243
+ * EXACTLY as the per-record rule adapter's `subjectMatches` does. Threading it makes the
244
+ * list scope enforce the SAME subject scoping `decide()` enforces per record.
245
+ */
246
+ export interface ListScopeSubject {
247
+ /** The requesting principal's id (for future subject kinds; parity with `subjectMatches`). */
248
+ readonly principalId: string;
249
+ /** The requesting principal's role ids — a `role`-subjected rule applies IFF this includes its value. */
250
+ readonly roleIds: readonly string[];
251
+ }
252
+ /**
253
+ * Resolves the policy allow/deny condition-groups governing the visible set for a LIST
254
+ * scope (ADR-0005, list form). SIBLING to {@link RecordPermissionRulePort.evaluate}
255
+ * (which answers ONE record with allow/explicitDeny booleans); this returns the abstract
256
+ * conditions the guard translator pushes into the WHERE for a whole collection.
257
+ *
258
+ * Concrete adapter (policy storage → condition-group projection) ships in `@astram/guard`.
259
+ */
260
+ export interface ListScopePort {
261
+ /**
262
+ * The policy allow/deny condition-groups governing the visible set for
263
+ * `(typeKey, tenantId, action)`. NO applicable policy ⇒ empty `allow` + empty `deny`
264
+ * (a normal ABSENCE — not an error, not a deny).
265
+ *
266
+ * @param subject the requesting principal's id + role ids, used to filter each rule
267
+ * group by its `rpr_subject_kind` / `rpr_subject_value` EXACTLY as the per-record rule
268
+ * adapter's `subjectMatches` does, so the list scope enforces the SAME subject scoping
269
+ * `decide()` enforces. Omitting it would project role-scoped rules to EVERY principal —
270
+ * a fail-open leak (HIGH-1): a `role`-subjected allow rule the principal's role does NOT
271
+ * hold would show rows `decide()` denies. The filter applies to BOTH allow AND deny
272
+ * groups (a role-subjected DENY not aimed at the principal must NOT over-restrict them).
273
+ *
274
+ * @throws {@link AuthorizationUnavailableError} if the store genuinely CANNOT answer
275
+ * (transient). It MUST NOT return empty to mask an outage — that would silently
276
+ * unbound/mis-scope the list. FAIL-CLOSED: a throw here PROPAGATES so the read fails,
277
+ * never "unbounded" (ADR-0016 / Invariant #8).
278
+ */
279
+ /**
280
+ * `tenantNodeIds` — the caller's reachable tenant NODE SET (its active-scope subtree:
281
+ * active node + descendants, ADR-0027), NOT just the active node. Policy rules scoped to
282
+ * ANY node in the subtree apply (a DENY at a descendant node must exclude that node's
283
+ * records for a parent admin — deny-wins inherits DOWN, exactly as `decide()` applies it
284
+ * per-record at the record's own node); plus global (NULL-tenant) rules. For a flat /
285
+ * self-node-only caller this is `[activeScopeNodeId]` — identical to the old single-tenant
286
+ * filter. The adapter filters `rpr_tenant_uuid IN (…nodes) OR rpr_tenant_uuid IS NULL`.
287
+ */
288
+ listPolicyConditions(typeKey: string, tenantNodeIds: readonly string[], action: string, subject: ListScopeSubject): Promise<ListPolicyConditions>;
289
+ }
225
290
  /**
226
291
  * A delegated authority a trusted operation declares for one of its steps
227
292
  * (ADR-0008). It is a SCOPED, non-wildcard authority under which gates 3–6 are
@@ -1 +1 @@
1
- {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/authorization/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAMnD;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;CACnD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;OAUG;IACH,yBAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAElF;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAChF;AAMD,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,gFAAgF;IAChF,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,oFAAoF;IACpF,QAAQ,CAAC,UAAU,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACzD;AAED;;;;GAIG;AACH,MAAM,WAAW,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AAO,EAAE,SAAS,MAAM,EAAE,CAAC;CACrC;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;;;;;;;;;OAiBG;IACH;;;;;;;;OAQG;IACH,oBAAoB,CAClB,OAAO,EAAE,MAAM,EACf,aAAa,EAAE,SAAS,MAAM,EAAE,EAChC,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAClC;AAMD;;;;;;;;GAQG;AACH,MAAM,WAAW,kBAAkB;IACjC;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAC;CAC5C;AAED;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB;IACrC;;;;;;;;;;OAUG;IACH,yBAAyB,CACvB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GACd,kBAAkB,GAAG,SAAS,CAAC;CACnC"}
@@ -0,0 +1,198 @@
1
+ /**
2
+ * Phase 1 — the decision-DERIVED **list scope** ({@link computeListScope}), the NEW
3
+ * SIBLING to `decide()` (§7.1). `decide(principal, action, resource, context)` answers
4
+ * "may this ONE record be accessed?" — allow/deny. A LIST endpoint instead needs the
5
+ * *set* of visible rows pushed into the SQL WHERE (Invariant #8 — filter in the query,
6
+ * NEVER fetch-then-discard). `decide()`'s 4-arg signature is FROZEN and returns
7
+ * allow/deny only, so this module adds a sibling contract that produces an ABSTRACT,
8
+ * DB-agnostic description of the visible set — a {@link ListScopeSpec} — computed by a
9
+ * pure function that reproduces the EXACT composition semantics the record-permit tier
10
+ * (`permit-tier.ts`) uses. Phase 2 (the guard) translates the spec to SQL; Phase 3
11
+ * injects it into the engine's `list()`. THIS module is pure core logic — no DB, no
12
+ * SQL, no adapter.
13
+ *
14
+ * ── THE SEMANTICS IT REPRODUCES (this is the whole point). The visible set equals the
15
+ * set `decide()` allows, row-by-row. The record-permit tier it mirrors composes:
16
+ *
17
+ * 1. policy = evaluateRecordPolicy(ctx) // allow + explicitDeny booleans
18
+ * 2. explicitDeny ⇒ DENY (deny-wins, SHORT-CIRCUITS before share)
19
+ * 3. baseline = evaluateOwnerBaseline(ctx)
20
+ * policy.allow || baseline ⇒ ALLOW
21
+ * 4. share = evaluateRecordShare(ctx) // same-tenant share ∪ cross-tenant grant
22
+ * share ⇒ ALLOW
23
+ * 5. else ⇒ DENY
24
+ *
25
+ * ⇒ a record is VISIBLE iff:
26
+ * NOT policyDeny AND (policyAllow OR ownerBaseline OR share OR crossTenant),
27
+ * all WITHIN the tenant bound. Deny-wins is load-bearing: an explicit policy deny
28
+ * REMOVES a row even if a share/owner would include it — so the deny set is an
29
+ * EXCLUSION applied over the union (Phase 2 translates it as `AND NOT (…deny…)`).
30
+ *
31
+ * ── The OWNER-BASELINE posture mapping mirrors `owner-baseline.ts` EXACTLY (same branch
32
+ * precedence): `system` ⇒ all; `tenantScoped && !owned` ⇒ all; `owned` ⇒ owned-only
33
+ * (`ownerId === principal.id`, modeled as `{kind:'owned', ownerField:'ownerId', …}`);
34
+ * no access / unknown type ⇒ none (fail-closed — a rule/share must include the row).
35
+ *
36
+ * ── FAIL-CLOSED (ADR-0016). The ONE port call ({@link ListScopePort.listPolicyConditions})
37
+ * may throw a transient {@link AuthorizationUnavailableError}; this function does NOT
38
+ * catch it — a throw PROPAGATES so the read fails, never "unbounded". Swallowing it
39
+ * into an empty/unbounded spec would silently mis-scope the list (Invariant #8).
40
+ *
41
+ * ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the only I/O is
42
+ * the single {@link ListScopePort} call (which reaches its store via the guard adapter).
43
+ */
44
+ import type { PolicyOperator } from '../../admin/types.js';
45
+ import type { Principal } from '../../identity/index.js';
46
+ import type { ObjectTypeDescriptor } from '../../metadata/index.js';
47
+ import type { ListScopePort } from '../ports.js';
48
+ /**
49
+ * One abstract condition of the visible set — the SAME 14-operator model the policy
50
+ * store uses ({@link PolicyOperator}). This is NOT SQL; Phase 2 (the guard translator)
51
+ * maps it to a real column + parameterized predicate.
52
+ */
53
+ export interface ScopeCondition {
54
+ /** Stable field key on the target object type (Phase 2 maps it to the real column). */
55
+ readonly field: string;
56
+ /** The comparison operator (closed set — no raw expression). */
57
+ readonly operator: PolicyOperator;
58
+ /** The comparand (operators that take no operand, e.g. `is_null`, ignore it). */
59
+ readonly value: unknown;
60
+ }
61
+ /**
62
+ * The tenant bound of the visible set. Every non-root list is bounded to the actor's
63
+ * REACHABLE SUBTREE (self + descendants, ADR-0027 — the scoped-hierarchy generalization
64
+ * of the flat tenant bound); root on the control-plane spans tenants.
65
+ *
66
+ * `tenantSubtree` carries the PRE-EXPANDED reachable node set (`principal.scopeSubtreeNodeIds`
67
+ * — resolved once at login from the closure and cached, Task 2.2), NOT just a root id: the
68
+ * guard translator emits `tenant_col IN (?, ...)` over these ids directly. This is the SAME
69
+ * set the tenant GATE tests membership against, so list ≡ decide holds BY CONSTRUCTION (no
70
+ * closure query at list time → no divergence from a stale/absent closure row). It is a STRICT,
71
+ * NON-BREAKING GENERALIZATION of the flat variant: a principal whose reachable subtree is just
72
+ * itself has `nodeIds = [activeScopeNodeId]` — identical to the old `tenantId = ?` behavior.
73
+ *
74
+ * The flat `tenantId` variant is KEPT for back-compat (some callers/tests may still
75
+ * construct it directly; the guard translator handles both).
76
+ */
77
+ export type ScopeTenantBound = {
78
+ readonly role: 'tenantId';
79
+ readonly value: string;
80
+ } | {
81
+ readonly role: 'tenantSubtree';
82
+ readonly nodeIds: readonly string[];
83
+ } | 'root-unbounded';
84
+ /**
85
+ * The owner-baseline contribution to the visible set — mirrors the `owner-baseline.ts`
86
+ * postures. `all` ⇒ every row of the type (system / tenantScoped); `owned` ⇒ only rows
87
+ * whose owner column equals the principal (DAC); `none` ⇒ no baseline (fail-closed —
88
+ * a rule/share must include the row).
89
+ */
90
+ export type ScopeOwnerBaseline = {
91
+ readonly kind: 'all';
92
+ } | {
93
+ readonly kind: 'owned';
94
+ readonly ownerField: string;
95
+ readonly principalId: string;
96
+ } | {
97
+ readonly kind: 'none';
98
+ };
99
+ /**
100
+ * A marker the guard adapter resolves to a `record_share` subquery (Phase 2/6). Kept
101
+ * abstract here — core has no DB. Its presence unions the principal's (and its roles')
102
+ * shared records into the visible set.
103
+ */
104
+ export type ScopeShareMarker = {
105
+ readonly kind: 'none';
106
+ } | {
107
+ readonly kind: 'shared-records';
108
+ readonly principalId: string;
109
+ readonly roleIds: readonly string[];
110
+ readonly action: string;
111
+ };
112
+ /**
113
+ * A cross-tenant grant descriptor the guard adapter resolves (Phase 4). Abstract here.
114
+ * Its presence unions the records reachable via an active, consented cross-tenant grant.
115
+ */
116
+ export type ScopeCrossTenant = {
117
+ readonly kind: 'none';
118
+ } | {
119
+ readonly kind: 'granted';
120
+ readonly principalId: string;
121
+ readonly roleIds: readonly string[];
122
+ readonly action: string;
123
+ };
124
+ /**
125
+ * The ABSTRACT, DB-agnostic description of the visible set — the list-form sibling to a
126
+ * `decide()` verdict. Mirrors the permit-tier composition:
127
+ *
128
+ * visible iff NOT policyDeny AND (policyAllow OR ownerBaseline OR share OR crossTenant),
129
+ * WITHIN {@link tenantBound}.
130
+ *
131
+ * {@link policyAllow} / {@link policyDeny} are AND-GROUPS OR'd together: a row satisfies
132
+ * the group iff it satisfies ALL conditions of the group; the subset is the UNION over
133
+ * groups. This preserves the guided-policy AND-of-conditions semantics (each policy is an
134
+ * AND of its conditions; multiple policies OR) so Phase 2 can translate WITHOUT losing
135
+ * AND-vs-OR. An empty `policyAllow`/`policyDeny` is a normal absence (no applicable policy).
136
+ */
137
+ export interface ListScopeSpec {
138
+ readonly typeKey: string;
139
+ readonly action: string;
140
+ readonly tenantBound: ScopeTenantBound;
141
+ readonly ownerBaseline: ScopeOwnerBaseline;
142
+ /** AND-groups OR'd: rows satisfying ALL conditions of ANY group are INCLUDED (unioned). */
143
+ readonly policyAllow: readonly (readonly ScopeCondition[])[];
144
+ /** AND-groups OR'd: rows satisfying ALL conditions of ANY group are EXCLUDED (deny-wins). */
145
+ readonly policyDeny: readonly (readonly ScopeCondition[])[];
146
+ /** shared records are INCLUDED (union) — resolved by the guard adapter. */
147
+ readonly share: ScopeShareMarker;
148
+ /** cross-tenant-granted records are INCLUDED (union) — resolved by the guard adapter. */
149
+ readonly crossTenant: ScopeCrossTenant;
150
+ }
151
+ /** The framework-owned dependencies {@link computeListScope} reads. */
152
+ export interface ComputeListScopeDeps {
153
+ /** Resolves the object type's access posture (same registry the engine uses). */
154
+ readonly registry: {
155
+ resolveObjectType(typeKey: string): ObjectTypeDescriptor | undefined;
156
+ };
157
+ /** The ONE port: the policy allow/deny condition-groups for the list scope. */
158
+ readonly listScope: ListScopePort;
159
+ }
160
+ /** The list-scope question — the actor + what/where they are listing. */
161
+ export interface ComputeListScopeQuery {
162
+ readonly principal: Principal;
163
+ readonly action: string;
164
+ readonly typeKey: string;
165
+ /** The actor's tenant — the bound for non-root. */
166
+ readonly tenantId: string;
167
+ }
168
+ /**
169
+ * Compute the abstract {@link ListScopeSpec} describing the set of records the principal
170
+ * may see for `(typeKey, action)` within their tenant — the list-form sibling to
171
+ * `decide()`, reproducing the record-permit tier's composition (§7.3.4 / ADR-0005/6/9).
172
+ *
173
+ * Logic (mirrors `permit-tier.ts`):
174
+ * - `tenantBound`: `principal.isRoot === true` ⇒ `'root-unbounded'` (root spans the
175
+ * control-plane; a data-plane list never reaches here for root — `decide()`'s coarse
176
+ * object-type gate already denied it upstream, so we simply honor `isRoot` for the
177
+ * bound). Else ⇒ `{role:'tenantSubtree', nodeIds: principal.scopeSubtreeNodeIds}`
178
+ * (every non-root list is bounded to the actor's REACHABLE SUBTREE — self + descendants,
179
+ * mirroring the tenant gate's `scopeSubtreeNodeIds` membership test, ADR-0027. Uniform —
180
+ * no per-type "is this hierarchy-scoped" flag. This is a NON-BREAKING generalization: a
181
+ * self-node-only principal's closure returns just that one node, i.e. the old flat
182
+ * `tenantId = ?` behavior. The guard translator, Task 3.3, expands the node set to the
183
+ * subtree via the `scope_closure` subquery — core carries only the root id(s), staying
184
+ * DB-agnostic).
185
+ * - `ownerBaseline`: root ⇒ `{kind:'all'}` (unbounded on control-plane). Else the
186
+ * posture mapping above.
187
+ * - `policyAllow`/`policyDeny`: from the ONE port call — mapped straight onto the spec.
188
+ * A transient throw PROPAGATES (NOT caught — fail-closed, ADR-0016).
189
+ * - `share`: always the abstract marker for the caller (Phase 2 resolves it). For root
190
+ * it is harmless (root's baseline is `all`, a superset); populated uniformly.
191
+ * - `crossTenant`: `{kind:'granted', …}` when NON-root (a non-root principal may hold a
192
+ * cross-tenant grant); root ⇒ `{kind:'none'}` — root needs no grant (it is unbounded
193
+ * on the control-plane; a data-plane list never reaches here for root).
194
+ *
195
+ * PURE except the ONE port call; NEVER throws except the propagated transient.
196
+ */
197
+ export declare function computeListScope(deps: ComputeListScopeDeps, query: ComputeListScopeQuery): Promise<ListScopeSpec>;
198
+ //# sourceMappingURL=list-scope.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-scope.d.ts","sourceRoot":"","sources":["../../../src/authorization/record/list-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAEH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACzD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;GAIG;AACH,MAAM,WAAW,cAAc;IAC7B,uFAAuF;IACvF,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,iFAAiF;IACjF,QAAQ,CAAC,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({@link computeListScope}), the NEW
3
+ * SIBLING to `decide()` (§7.1). `decide(principal, action, resource, context)` answers
4
+ * "may this ONE record be accessed?" — allow/deny. A LIST endpoint instead needs the
5
+ * *set* of visible rows pushed into the SQL WHERE (Invariant #8 — filter in the query,
6
+ * NEVER fetch-then-discard). `decide()`'s 4-arg signature is FROZEN and returns
7
+ * allow/deny only, so this module adds a sibling contract that produces an ABSTRACT,
8
+ * DB-agnostic description of the visible set — a {@link ListScopeSpec} — computed by a
9
+ * pure function that reproduces the EXACT composition semantics the record-permit tier
10
+ * (`permit-tier.ts`) uses. Phase 2 (the guard) translates the spec to SQL; Phase 3
11
+ * injects it into the engine's `list()`. THIS module is pure core logic — no DB, no
12
+ * SQL, no adapter.
13
+ *
14
+ * ── THE SEMANTICS IT REPRODUCES (this is the whole point). The visible set equals the
15
+ * set `decide()` allows, row-by-row. The record-permit tier it mirrors composes:
16
+ *
17
+ * 1. policy = evaluateRecordPolicy(ctx) // allow + explicitDeny booleans
18
+ * 2. explicitDeny ⇒ DENY (deny-wins, SHORT-CIRCUITS before share)
19
+ * 3. baseline = evaluateOwnerBaseline(ctx)
20
+ * policy.allow || baseline ⇒ ALLOW
21
+ * 4. share = evaluateRecordShare(ctx) // same-tenant share ∪ cross-tenant grant
22
+ * share ⇒ ALLOW
23
+ * 5. else ⇒ DENY
24
+ *
25
+ * ⇒ a record is VISIBLE iff:
26
+ * NOT policyDeny AND (policyAllow OR ownerBaseline OR share OR crossTenant),
27
+ * all WITHIN the tenant bound. Deny-wins is load-bearing: an explicit policy deny
28
+ * REMOVES a row even if a share/owner would include it — so the deny set is an
29
+ * EXCLUSION applied over the union (Phase 2 translates it as `AND NOT (…deny…)`).
30
+ *
31
+ * ── The OWNER-BASELINE posture mapping mirrors `owner-baseline.ts` EXACTLY (same branch
32
+ * precedence): `system` ⇒ all; `tenantScoped && !owned` ⇒ all; `owned` ⇒ owned-only
33
+ * (`ownerId === principal.id`, modeled as `{kind:'owned', ownerField:'ownerId', …}`);
34
+ * no access / unknown type ⇒ none (fail-closed — a rule/share must include the row).
35
+ *
36
+ * ── FAIL-CLOSED (ADR-0016). The ONE port call ({@link ListScopePort.listPolicyConditions})
37
+ * may throw a transient {@link AuthorizationUnavailableError}; this function does NOT
38
+ * catch it — a throw PROPAGATES so the read fails, never "unbounded". Swallowing it
39
+ * into an empty/unbounded spec would silently mis-scope the list (Invariant #8).
40
+ *
41
+ * ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the only I/O is
42
+ * the single {@link ListScopePort} call (which reaches its store via the guard adapter).
43
+ */
44
+ /**
45
+ * Map the object type's access posture to the owner-baseline scope contribution,
46
+ * mirroring `owner-baseline.ts` branch precedence EXACTLY:
47
+ * - no access posture / unknown type ⇒ `{kind:'none'}` (fail-closed).
48
+ * - `system` ⇒ `{kind:'all'}`.
49
+ * - `tenantScoped === true && owned !== true` ⇒ `{kind:'all'}` (the tenant bound
50
+ * already isolates; the record baseline adds no narrowing).
51
+ * - `owned === true` ⇒ `{kind:'owned', ownerField:'ownerId', principalId}` (DAC:
52
+ * only rows the principal owns). NOTE the precedence — a type that is BOTH
53
+ * `owned` and `tenantScoped` resolves via the OWNED branch (matches the baseline:
54
+ * its `tenantScoped` branch requires `owned !== true`).
55
+ * - explicitly ungoverned (all flags false) ⇒ `{kind:'none'}` (fail-closed).
56
+ */
57
+ function ownerBaselineFor(access, principalId) {
58
+ if (!access)
59
+ return { kind: 'none' };
60
+ if (access.system === true)
61
+ return { kind: 'all' };
62
+ if (access.tenantScoped === true && access.owned !== true)
63
+ return { kind: 'all' };
64
+ if (access.owned === true) {
65
+ return { kind: 'owned', ownerField: 'ownerId', principalId };
66
+ }
67
+ return { kind: 'none' };
68
+ }
69
+ /**
70
+ * Compute the abstract {@link ListScopeSpec} describing the set of records the principal
71
+ * may see for `(typeKey, action)` within their tenant — the list-form sibling to
72
+ * `decide()`, reproducing the record-permit tier's composition (§7.3.4 / ADR-0005/6/9).
73
+ *
74
+ * Logic (mirrors `permit-tier.ts`):
75
+ * - `tenantBound`: `principal.isRoot === true` ⇒ `'root-unbounded'` (root spans the
76
+ * control-plane; a data-plane list never reaches here for root — `decide()`'s coarse
77
+ * object-type gate already denied it upstream, so we simply honor `isRoot` for the
78
+ * bound). Else ⇒ `{role:'tenantSubtree', nodeIds: principal.scopeSubtreeNodeIds}`
79
+ * (every non-root list is bounded to the actor's REACHABLE SUBTREE — self + descendants,
80
+ * mirroring the tenant gate's `scopeSubtreeNodeIds` membership test, ADR-0027. Uniform —
81
+ * no per-type "is this hierarchy-scoped" flag. This is a NON-BREAKING generalization: a
82
+ * self-node-only principal's closure returns just that one node, i.e. the old flat
83
+ * `tenantId = ?` behavior. The guard translator, Task 3.3, expands the node set to the
84
+ * subtree via the `scope_closure` subquery — core carries only the root id(s), staying
85
+ * DB-agnostic).
86
+ * - `ownerBaseline`: root ⇒ `{kind:'all'}` (unbounded on control-plane). Else the
87
+ * posture mapping above.
88
+ * - `policyAllow`/`policyDeny`: from the ONE port call — mapped straight onto the spec.
89
+ * A transient throw PROPAGATES (NOT caught — fail-closed, ADR-0016).
90
+ * - `share`: always the abstract marker for the caller (Phase 2 resolves it). For root
91
+ * it is harmless (root's baseline is `all`, a superset); populated uniformly.
92
+ * - `crossTenant`: `{kind:'granted', …}` when NON-root (a non-root principal may hold a
93
+ * cross-tenant grant); root ⇒ `{kind:'none'}` — root needs no grant (it is unbounded
94
+ * on the control-plane; a data-plane list never reaches here for root).
95
+ *
96
+ * PURE except the ONE port call; NEVER throws except the propagated transient.
97
+ */
98
+ export async function computeListScope(deps, query) {
99
+ const { principal, action, typeKey } = query;
100
+ const isRoot = principal.isRoot === true;
101
+ // The reachable node set is the principal's CACHED subtree (self + descendants, resolved
102
+ // once at login — Task 2.2), the SAME set the tenant gate tests membership against. Using
103
+ // it directly (not re-querying the closure at list time) makes list ≡ decide equivalence
104
+ // hold BY CONSTRUCTION and keeps the list hot path closure-free. A fail-safe self-node-only
105
+ // principal has `[activeScopeNodeId]` here — identical to the old flat `tenantId = ?`.
106
+ const subtree = Array.isArray(principal.scopeSubtreeNodeIds) && principal.scopeSubtreeNodeIds.length > 0
107
+ ? principal.scopeSubtreeNodeIds
108
+ : [principal.activeScopeNodeId];
109
+ const tenantBound = isRoot
110
+ ? 'root-unbounded'
111
+ : { role: 'tenantSubtree', nodeIds: subtree };
112
+ const ownerBaseline = isRoot
113
+ ? { kind: 'all' }
114
+ : ownerBaselineFor(deps.registry.resolveObjectType(typeKey)?.access, principal.id);
115
+ // The ONE I/O call. A transient AuthorizationUnavailableError PROPAGATES (fail-closed):
116
+ // it is NEVER caught here — swallowing it into an empty/unbounded spec would silently
117
+ // mis-scope the list (ADR-0016 / Invariant #8).
118
+ //
119
+ // The SUBJECT (principal id + role ids) is threaded so the adapter filters each policy
120
+ // rule group by its `rpr_subject_kind` / `rpr_subject_value` EXACTLY as decide()'s
121
+ // per-record `subjectMatches` does — otherwise a role-scoped rule would project to EVERY
122
+ // principal, a fail-open leak (HIGH-1). Root's baseline is already 'all' (a superset), so
123
+ // passing the subject is harmless for root and correct for non-root.
124
+ // Fetch policy rules for the WHOLE reachable subtree (`subtree` = the active node +
125
+ // descendants), NOT just the active node: a DENY rule scoped to a DESCENDANT node must
126
+ // exclude that node's records for a parent admin (deny-wins inherits DOWN, exactly as
127
+ // decide() applies it per-record at the record's own node). Plus global (NULL-tenant)
128
+ // rules. For a flat/self-node caller this is `[activeScopeNodeId]` — the old behavior.
129
+ const policy = await deps.listScope.listPolicyConditions(typeKey, subtree, action, {
130
+ principalId: principal.id,
131
+ roleIds: principal.roleIds,
132
+ });
133
+ const share = {
134
+ kind: 'shared-records',
135
+ principalId: principal.id,
136
+ roleIds: principal.roleIds,
137
+ action,
138
+ };
139
+ const crossTenant = isRoot
140
+ ? { kind: 'none' }
141
+ : { kind: 'granted', principalId: principal.id, roleIds: principal.roleIds, action };
142
+ return {
143
+ typeKey,
144
+ action,
145
+ tenantBound,
146
+ ownerBaseline,
147
+ policyAllow: policy.allow,
148
+ policyDeny: policy.deny,
149
+ share,
150
+ crossTenant,
151
+ };
152
+ }
153
+ //# sourceMappingURL=list-scope.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-scope.js","sourceRoot":"","sources":["../../../src/authorization/record/list-scope.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAwIH;;;;;;;;;;;;GAYG;AACH,SAAS,gBAAgB,CACvB,MAAsC,EACtC,WAAmB;IAEnB,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;IACrC,IAAI,MAAM,CAAC,MAAM,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IACnD,IAAI,MAAM,CAAC,YAAY,KAAK,IAAI,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI;QAAE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;IAClF,IAAI,MAAM,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAC1B,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;AAC1B,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,IAA0B,EAC1B,KAA4B;IAE5B,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,KAAK,CAAC;IAC7C,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,KAAK,IAAI,CAAC;IAEzC,yFAAyF;IACzF,0FAA0F;IAC1F,yFAAyF;IACzF,4FAA4F;IAC5F,uFAAuF;IACvF,MAAM,OAAO,GACX,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,mBAAmB,CAAC,IAAI,SAAS,C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AAM,EAAE,CAAC;IAEvF,OAAO;QACL,OAAO;QACP,MAAM;QACN,WAAW;QACX,aAAa;QACb,WAAW,EAAE,MAAM,CAAC,KAAK;QACzB,UAAU,EAAE,MAAM,CAAC,IAAI;QACvB,KAAK;QACL,WAAW;KACZ,CAAC;AACJ,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAYpB,2EAA2E;AAC3E,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,EAAE,MAAM;CAI5B;AA8FD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAkBhB"}
1
+ {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAYpB,2EAA2E;AAC3E,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,EAAE,MAAM;CAI5B;AAoGD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAkBhB"}
@@ -91,9 +91,15 @@ class BrokerImpl {
91
91
  // any raw claim here, so an attacker-controllable `superuser`/`isPlatformSuperuser`
92
92
  // claim cannot influence this value.
93
93
  const isRoot = candidate.trustedRootSignal === true;
94
+ // Scope (ADR-0027) — INTERIM default (Task 2.1): the active scope node IS the home
95
+ // tenant, and the reachable subtree is JUST that self-node (`[tenantId]`). This
96
+ // reproduces today's flat self-tenant isolation EXACTLY (non-widening) until Task 2.2
97
+ // populates the real closure-resolved subtree (self + descendants) at session establishment.
94
98
  return Object.freeze({
95
99
  kind,
96
100
  id,
101
+ activeScopeNodeId: tenantId,
102
+ scopeSubtreeNodeIds: Object.freeze([tenantId]),
97
103
  tenantId,
98
104
  roleIds,
99
105
  isRoot,
@@ -1 +1 @@
1
- {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAEL,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAQtE,iFAAiF;AACjF,MAAM,qBAAqB,GAA+B,IAAI,GAAG,CAAgB;IAC/E,MAAM;IACN,YAAY;IACZ,iBAAiB;CAClB,CAAC,CAAC;AAEH,8DAA8D;AAC9D,MAAM,sBAAsB,GAAkB,MAAM,CAAC;AAErD,2EAA2E;AAC3E,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;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MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACrC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
@@ -29,7 +29,22 @@ export interface Principal {
29
29
  readonly kind: PrincipalKind;
30
30
  /** Stable opaque id (internal — never rendered to end users). */
31
31
  readonly id: string;
32
- /** The principal's home tenant — the default boundary for the tenant gate. */
32
+ /**
33
+ * The principal's ACTIVE SCOPE NODE — the node (company/tenant) the principal is currently
34
+ * acting under (ADR-0027). Historically "the home tenant"; under the scoped hierarchy it is the
35
+ * active binding's node. `tenantId` (below) is kept as an ALIAS of this for backward compatibility.
36
+ */
37
+ readonly activeScopeNodeId: string;
38
+ /**
39
+ * The active scope node + ALL its descendants (the reachable subtree), resolved ONCE at session
40
+ * establishment / scope-switch from `scope_closure` and CACHED (ADR-0011/0013) — NOT recomputed per
41
+ * request. The tenant gate (gate 3) tests `resource.tenantId ∈ scopeSubtreeNodeIds` as an in-memory
42
+ * set-membership check (zero per-request DB — the ADR-0024 parity guarantee). FAIL-CLOSED: an EMPTY
43
+ * array means "no reachable scope" → the tenant gate denies every foreign-node resource (a principal
44
+ * with no resolved subtree sees only same-node resources via the alias, and nothing cross-node).
45
+ */
46
+ readonly scopeSubtreeNodeIds: readonly string[];
47
+ /** The principal's home/active tenant — ALIAS of `activeScopeNodeId` (ADR-0027, back-compat). */
33
48
  readonly tenantId: string;
34
49
  /** Roles / groups this principal belongs to, by stable id. */
35
50
  readonly roleIds: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAEtE,2EAA2E;AAC3E,MAAM,WA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AM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB;;;;OAIG;IACH,QAAQ,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,mBAAmB,EAAE,SAAS,MAAM,EAAE,CAAC;IAChD,iGAAiG;IACjG,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,sEAAsE;AACtE,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,SAAS,CAAC,SAAS,EAAE,yBAAyB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACrE;AAKD,cAAc,mBAAmB,CAAC;AAElC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgDH,gFAAgF;AAChF,6EAA6E;AAC7E,wBAAwB;AACxB,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,uBAAuB,CAAC;AACtC,gFAAgF;AAChF,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA+DH,gFAAgF;AAChF,6EAA6E;AAC7E,wBAAwB;AACxB,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,uBAAuB,CAAC;AACtC,gFAAgF;AAChF,cAAc,aAAa,CAAC"}
@@ -105,14 +105,23 @@ function createObjectTypeGate() {
105
105
  return async function objectTypeGate(ctx) {
106
106
  const { principal, action, resource, deps } = ctx;
107
107
  const isRecordLevel = resource.level === 'record';
108
- // ── Cross-tenant grant path (§7.3.3): a non-root reaching a foreign
109
- // tenant proceeded past gate 3 ONLY via a cross-tenant grant, whose scope +
110
- // ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
111
- // pure), NOT the wrong-tenant coarse facts. Root is not grant-backed;
112
- // it falls through to the coarse-grants path.
113
- const crossesTenant = resource.tenantId !== undefined &&
114
- principal.tenantId !== resource.tenantId &&
115
- !(0, reason_codes_js_1.strictTrue)(principal.isRoot);
108
+ // ── Cross-tenant grant path (§7.3.3): a non-root reaching a resource OUTSIDE its
109
+ // active-scope SUBTREE proceeded past gate 3 ONLY via a cross-tenant grant, whose
110
+ // scope + ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
111
+ // pure), NOT the wrong-node coarse facts. Root is not grant-backed; it falls through
112
+ // to the coarse-grants path.
113
+ // ⛔ SUBTREE-AWARE (ADR-0027): a resource IN the principal's subtree (its active node
114
+ // or a descendant — additive-down inheritance) is NOT a cross-tenant reach; it is
115
+ // handled by the coarse grants (below), NOT the grant path. Mirrors the tenant gate's
116
+ // membership test (`resource.tenantId ∈ scopeSubtreeNodeIds`), so gates 3 and 5 agree
117
+ // on what "crosses" means. `Array.isArray` guards a malformed/absent subtree (deny —
118
+ // treated as "not in scope" ⇒ crosses ⇒ the grant path, which fail-closes without a
119
+ // grant). A self-node-only subtree reduces this to the old flat `tenantId !==` check.
120
+ const subtree = principal.scopeSubtreeNodeIds;
121
+ const inSubtree = resource.tenantId !== undefined &&
122
+ Array.isArray(subtree) &&
123
+ subtree.includes(resource.tenantId);
124
+ const crossesTenant = resource.tenantId !== undefined && !inSubtree && !(0, reason_codes_js_1.strictTrue)(principal.isRoot);
116
125
  if (crossesTenant) {
117
126
  // Re-resolve the grant through the SINGLE-SOURCE cross-tenant helper (TEAM C)
118
127
  // so gates 3/5/6 share ONE ceiling+scope+expiry implementation (RULING 1 /
@@ -15,10 +15,13 @@
15
15
  * ── The order (deny wins; every ambiguity resolves to the deny/continue path,
16
16
  * never to a bypass):
17
17
  *
18
- * 1. SAME TENANT (`principal.tenantId === resource.tenantId`, OR the resource
19
- * carries no instance tenant) ⇒ `continue`. A feature/object-type-level
20
- * resource with no `tenantId` is same-tenant BY CONSTRUCTION — there is no
21
- * foreign instance to cross into, so it is the principal's own tenant.
18
+ * 1. IN SCOPE (`resource.tenantId ∈ principal.scopeSubtreeNodeIds` — the active
19
+ * node + all descendants, ADR-0027 — OR the resource carries no instance
20
+ * tenant) ⇒ `continue`. An in-memory set test against the login-cached subtree
21
+ * (zero per-request DB, ADR-0024). A feature/object-type-level resource with no
22
+ * `tenantId` is same-tenant BY CONSTRUCTION — there is no foreign instance to
23
+ * cross into. The subtree ALWAYS contains the active node itself, so this is a
24
+ * strict generalization of the old flat `tenantId === resource.tenantId`.
22
25
  * 2. MISMATCH + root (STRICT `=== true`) ⇒ `continue` (break-glass,
23
26
  * audited by a later layer — not this gate's concern).
24
27
  * 3. MISMATCH + not root ⇒ consult {@link CrossTenantGrantPort}:
@@ -54,9 +57,29 @@ const grant_evaluator_js_1 = require("../cross-tenant/grant-evaluator.js");
54
57
  function createTenantGate() {
55
58
  return async function tenantGate(ctx) {
56
59
  const { principal, action, resource, deps } = ctx;
57
- // 1. Same tenant — including a feature/object-type resource with no instance
58
- // tenant (same-tenant by construction: no foreign instance to cross into).
59
- if (resource.tenantId === undefined || principal.tenantId === resource.tenantId) {
60
+ // 1. IN SCOPE — the resource's owning node is in the principal's active-scope
61
+ // SUBTREE (the node it acts under + all descendants, ADR-0027), OR there is
62
+ // no instance tenant (a feature/object-type resource with no foreign instance
63
+ // to cross into: same-tenant by construction).
64
+ // This is an IN-MEMORY set-membership test against the login-cached
65
+ // `scopeSubtreeNodeIds` — ZERO per-request DB (the ADR-0024 parity guarantee).
66
+ // A non-root principal reaches everything in its subtree (additive-down
67
+ // inheritance) and nothing outside it. `scopeSubtreeNodeIds` ALWAYS contains
68
+ // the active node itself (self-row, Task 2.2), so this GENERALIZES — never
69
+ // narrows — the old flat equality: the `tenantId === resource.tenantId` case
70
+ // is exactly the singleton-subtree case. Root's cross-tree span is NOT here;
71
+ // it is authoritative via `isRoot` (step 2 below). FAIL-CLOSED: an empty
72
+ // subtree makes `.includes` false for every node ⇒ falls through to root /
73
+ // cross-grant / deny (reaches nothing but its own via the self-node).
74
+ // DEFENSE-IN-DEPTH: `Array.isArray` guards a malformed/absent subtree (a
75
+ // JS-constructed Principal that omits the field despite the TS contract) —
76
+ // a non-array is treated as "no reachable scope" ⇒ deny, DETERMINISTICALLY,
77
+ // rather than relying on a thrown `undefined.includes` being caught as a
78
+ // fail-closed deny by the pipeline (fail-closed either way, but this is the
79
+ // explicit, non-crashy form).
80
+ const subtree = principal.scopeSubtreeNodeIds;
81
+ if (resource.tenantId === undefined ||
82
+ (Array.isArray(subtree) && subtree.includes(resource.tenantId))) {
60
83
  return (0, decision_authority_js_1.gateContinue)();
61
84
  }
62
85
  // 2. Mismatch + root (break-glass). STRICT === true — a truthy
@@ -130,5 +130,7 @@ __exportStar(require("./delegation/operation-identity.js"), exports);
130
130
  __exportStar(require("./record/owner-baseline.js"), exports);
131
131
  // - INTEGRATION: the composed gate-6 record permit tier (baseline ∪ policy ∪ share, deny-wins):
132
132
  __exportStar(require("./record/permit-tier.js"), exports);
133
+ // - LIST SCOPE: the decision-derived visible-set spec — sibling to decide() (Phase 1):
134
+ __exportStar(require("./record/list-scope.js"), exports);
133
135
  // - INTEGRATION: the production gate-set wiring + fully-wired DecisionAuthority factory:
134
136
  __exportStar(require("./gates/wiring.js"), exports);
@@ -0,0 +1,155 @@
1
+ "use strict";
2
+ /**
3
+ * Phase 1 — the decision-DERIVED **list scope** ({@link computeListScope}), the NEW
4
+ * SIBLING to `decide()` (§7.1). `decide(principal, action, resource, context)` answers
5
+ * "may this ONE record be accessed?" — allow/deny. A LIST endpoint instead needs the
6
+ * *set* of visible rows pushed into the SQL WHERE (Invariant #8 — filter in the query,
7
+ * NEVER fetch-then-discard). `decide()`'s 4-arg signature is FROZEN and returns
8
+ * allow/deny only, so this module adds a sibling contract that produces an ABSTRACT,
9
+ * DB-agnostic description of the visible set — a {@link ListScopeSpec} — computed by a
10
+ * pure function that reproduces the EXACT composition semantics the record-permit tier
11
+ * (`permit-tier.ts`) uses. Phase 2 (the guard) translates the spec to SQL; Phase 3
12
+ * injects it into the engine's `list()`. THIS module is pure core logic — no DB, no
13
+ * SQL, no adapter.
14
+ *
15
+ * ── THE SEMANTICS IT REPRODUCES (this is the whole point). The visible set equals the
16
+ * set `decide()` allows, row-by-row. The record-permit tier it mirrors composes:
17
+ *
18
+ * 1. policy = evaluateRecordPolicy(ctx) // allow + explicitDeny booleans
19
+ * 2. explicitDeny ⇒ DENY (deny-wins, SHORT-CIRCUITS before share)
20
+ * 3. baseline = evaluateOwnerBaseline(ctx)
21
+ * policy.allow || baseline ⇒ ALLOW
22
+ * 4. share = evaluateRecordShare(ctx) // same-tenant share ∪ cross-tenant grant
23
+ * share ⇒ ALLOW
24
+ * 5. else ⇒ DENY
25
+ *
26
+ * ⇒ a record is VISIBLE iff:
27
+ * NOT policyDeny AND (policyAllow OR ownerBaseline OR share OR crossTenant),
28
+ * all WITHIN the tenant bound. Deny-wins is load-bearing: an explicit policy deny
29
+ * REMOVES a row even if a share/owner would include it — so the deny set is an
30
+ * EXCLUSION applied over the union (Phase 2 translates it as `AND NOT (…deny…)`).
31
+ *
32
+ * ── The OWNER-BASELINE posture mapping mirrors `owner-baseline.ts` EXACTLY (same branch
33
+ * precedence): `system` ⇒ all; `tenantScoped && !owned` ⇒ all; `owned` ⇒ owned-only
34
+ * (`ownerId === principal.id`, modeled as `{kind:'owned', ownerField:'ownerId', …}`);
35
+ * no access / unknown type ⇒ none (fail-closed — a rule/share must include the row).
36
+ *
37
+ * ── FAIL-CLOSED (ADR-0016). The ONE port call ({@link ListScopePort.listPolicyConditions})
38
+ * may throw a transient {@link AuthorizationUnavailableError}; this function does NOT
39
+ * catch it — a throw PROPAGATES so the read fails, never "unbounded". Swallowing it
40
+ * into an empty/unbounded spec would silently mis-scope the list (Invariant #8).
41
+ *
42
+ * ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the only I/O is
43
+ * the single {@link ListScopePort} call (which reaches its store via the guard adapter).
44
+ */
45
+ Object.defineProperty(exports, "__esModule", { value: true });
46
+ exports.computeListScope = computeListScope;
47
+ /**
48
+ * Map the object type's access posture to the owner-baseline scope contribution,
49
+ * mirroring `owner-baseline.ts` branch precedence EXACTLY:
50
+ * - no access posture / unknown type ⇒ `{kind:'none'}` (fail-closed).
51
+ * - `system` ⇒ `{kind:'all'}`.
52
+ * - `tenantScoped === true && owned !== true` ⇒ `{kind:'all'}` (the tenant bound
53
+ * already isolates; the record baseline adds no narrowing).
54
+ * - `owned === true` ⇒ `{kind:'owned', ownerField:'ownerId', principalId}` (DAC:
55
+ * only rows the principal owns). NOTE the precedence — a type that is BOTH
56
+ * `owned` and `tenantScoped` resolves via the OWNED branch (matches the baseline:
57
+ * its `tenantScoped` branch requires `owned !== true`).
58
+ * - explicitly ungoverned (all flags false) ⇒ `{kind:'none'}` (fail-closed).
59
+ */
60
+ function ownerBaselineFor(access, principalId) {
61
+ if (!access)
62
+ return { kind: 'none' };
63
+ if (access.system === true)
64
+ return { kind: 'all' };
65
+ if (access.tenantScoped === true && access.owned !== true)
66
+ return { kind: 'all' };
67
+ if (access.owned === true) {
68
+ return { kind: 'owned', ownerField: 'ownerId', principalId };
69
+ }
70
+ return { kind: 'none' };
71
+ }
72
+ /**
73
+ * Compute the abstract {@link ListScopeSpec} describing the set of records the principal
74
+ * may see for `(typeKey, action)` within their tenant — the list-form sibling to
75
+ * `decide()`, reproducing the record-permit tier's composition (§7.3.4 / ADR-0005/6/9).
76
+ *
77
+ * Logic (mirrors `permit-tier.ts`):
78
+ * - `tenantBound`: `principal.isRoot === true` ⇒ `'root-unbounded'` (root spans the
79
+ * control-plane; a data-plane list never reaches here for root — `decide()`'s coarse
80
+ * object-type gate already denied it upstream, so we simply honor `isRoot` for the
81
+ * bound). Else ⇒ `{role:'tenantSubtree', nodeIds: principal.scopeSubtreeNodeIds}`
82
+ * (every non-root list is bounded to the actor's REACHABLE SUBTREE — self + descendants,
83
+ * mirroring the tenant gate's `scopeSubtreeNodeIds` membership test, ADR-0027. Uniform —
84
+ * no per-type "is this hierarchy-scoped" flag. This is a NON-BREAKING generalization: a
85
+ * self-node-only principal's closure returns just that one node, i.e. the old flat
86
+ * `tenantId = ?` behavior. The guard translator, Task 3.3, expands the node set to the
87
+ * subtree via the `scope_closure` subquery — core carries only the root id(s), staying
88
+ * DB-agnostic).
89
+ * - `ownerBaseline`: root ⇒ `{kind:'all'}` (unbounded on control-plane). Else the
90
+ * posture mapping above.
91
+ * - `policyAllow`/`policyDeny`: from the ONE port call — mapped straight onto the spec.
92
+ * A transient throw PROPAGATES (NOT caught — fail-closed, ADR-0016).
93
+ * - `share`: always the abstract marker for the caller (Phase 2 resolves it). For root
94
+ * it is harmless (root's baseline is `all`, a superset); populated uniformly.
95
+ * - `crossTenant`: `{kind:'granted', …}` when NON-root (a non-root principal may hold a
96
+ * cross-tenant grant); root ⇒ `{kind:'none'}` — root needs no grant (it is unbounded
97
+ * on the control-plane; a data-plane list never reaches here for root).
98
+ *
99
+ * PURE except the ONE port call; NEVER throws except the propagated transient.
100
+ */
101
+ async function computeListScope(deps, query) {
102
+ const { principal, action, typeKey } = query;
103
+ const isRoot = principal.isRoot === true;
104
+ // The reachable node set is the principal's CACHED subtree (self + descendants, resolved
105
+ // once at login — Task 2.2), the SAME set the tenant gate tests membership against. Using
106
+ // it directly (not re-querying the closure at list time) makes list ≡ decide equivalence
107
+ // hold BY CONSTRUCTION and keeps the list hot path closure-free. A fail-safe self-node-only
108
+ // principal has `[activeScopeNodeId]` here — identical to the old flat `tenantId = ?`.
109
+ const subtree = Array.isArray(principal.scopeSubtreeNodeIds) && principal.scopeSubtreeNodeIds.length > 0
110
+ ? principal.scopeSubtreeNodeIds
111
+ : [principal.activeScopeNodeId];
112
+ const tenantBound = isRoot
113
+ ? 'root-unbounded'
114
+ : { role: 'tenantSubtree', nodeIds: subtree };
115
+ const ownerBaseline = isRoot
116
+ ? { kind: 'all' }
117
+ : ownerBaselineFor(deps.registry.resolveObjectType(typeKey)?.access, principal.id);
118
+ // The ONE I/O call. A transient AuthorizationUnavailableError PROPAGATES (fail-closed):
119
+ // it is NEVER caught here — swallowing it into an empty/unbounded spec would silently
120
+ // mis-scope the list (ADR-0016 / Invariant #8).
121
+ //
122
+ // The SUBJECT (principal id + role ids) is threaded so the adapter filters each policy
123
+ // rule group by its `rpr_subject_kind` / `rpr_subject_value` EXACTLY as decide()'s
124
+ // per-record `subjectMatches` does — otherwise a role-scoped rule would project to EVERY
125
+ // principal, a fail-open leak (HIGH-1). Root's baseline is already 'all' (a superset), so
126
+ // passing the subject is harmless for root and correct for non-root.
127
+ // Fetch policy rules for the WHOLE reachable subtree (`subtree` = the active node +
128
+ // descendants), NOT just the active node: a DENY rule scoped to a DESCENDANT node must
129
+ // exclude that node's records for a parent admin (deny-wins inherits DOWN, exactly as
130
+ // decide() applies it per-record at the record's own node). Plus global (NULL-tenant)
131
+ // rules. For a flat/self-node caller this is `[activeScopeNodeId]` — the old behavior.
132
+ const policy = await deps.listScope.listPolicyConditions(typeKey, subtree, action, {
133
+ principalId: principal.id,
134
+ roleIds: principal.roleIds,
135
+ });
136
+ const share = {
137
+ kind: 'shared-records',
138
+ principalId: principal.id,
139
+ roleIds: principal.roleIds,
140
+ action,
141
+ };
142
+ const crossTenant = isRoot
143
+ ? { kind: 'none' }
144
+ : { kind: 'granted', principalId: principal.id, roleIds: principal.roleIds, action };
145
+ return {
146
+ typeKey,
147
+ action,
148
+ tenantBound,
149
+ ownerBaseline,
150
+ policyAllow: policy.allow,
151
+ policyDeny: policy.deny,
152
+ share,
153
+ crossTenant,
154
+ };
155
+ }
@@ -96,9 +96,15 @@ class BrokerImpl {
96
96
  // any raw claim here, so an attacker-controllable `superuser`/`isPlatformSuperuser`
97
97
  // claim cannot influence this value.
98
98
  const isRoot = candidate.trustedRootSignal === true;
99
+ // Scope (ADR-0027) — INTERIM default (Task 2.1): the active scope node IS the home
100
+ // tenant, and the reachable subtree is JUST that self-node (`[tenantId]`). This
101
+ // reproduces today's flat self-tenant isolation EXACTLY (non-widening) until Task 2.2
102
+ // populates the real closure-resolved subtree (self + descendants) at session establishment.
99
103
  return Object.freeze({
100
104
  kind,
101
105
  id,
106
+ activeScopeNodeId: tenantId,
107
+ scopeSubtreeNodeIds: Object.freeze([tenantId]),
102
108
  tenantId,
103
109
  roleIds,
104
110
  isRoot,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astram/core",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "license": "MIT",
5
5
  "description": "Astram framework — sealed security core (Identity, Authentication, Session, Risk, Authorization, Audit). ZERO framework deps — the portable decision brain (ADR-0003). The frozen public contract consumers build against; installed, not edited (ADR-0023).",
6
6
  "type": "module",