@astram/core 0.1.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.
- package/LICENSE +21 -0
- package/README.md +47 -0
- package/dist/admin/admin-service.d.ts +221 -0
- package/dist/admin/admin-service.d.ts.map +1 -0
- package/dist/admin/admin-service.js +155 -0
- package/dist/admin/admin-service.js.map +1 -0
- package/dist/admin/command/grants.d.ts +40 -0
- package/dist/admin/command/grants.d.ts.map +1 -0
- package/dist/admin/command/grants.js +196 -0
- package/dist/admin/command/grants.js.map +1 -0
- package/dist/admin/command/index.d.ts +23 -0
- package/dist/admin/command/index.d.ts.map +1 -0
- package/dist/admin/command/index.js +23 -0
- package/dist/admin/command/index.js.map +1 -0
- package/dist/admin/command/invitations.d.ts +72 -0
- package/dist/admin/command/invitations.d.ts.map +1 -0
- package/dist/admin/command/invitations.js +241 -0
- package/dist/admin/command/invitations.js.map +1 -0
- package/dist/admin/command/permissions.d.ts +33 -0
- package/dist/admin/command/permissions.d.ts.map +1 -0
- package/dist/admin/command/permissions.js +67 -0
- package/dist/admin/command/permissions.js.map +1 -0
- package/dist/admin/command/pipeline.d.ts +79 -0
- package/dist/admin/command/pipeline.d.ts.map +1 -0
- package/dist/admin/command/pipeline.js +106 -0
- package/dist/admin/command/pipeline.js.map +1 -0
- package/dist/admin/command/policies.d.ts +50 -0
- package/dist/admin/command/policies.d.ts.map +1 -0
- package/dist/admin/command/policies.js +219 -0
- package/dist/admin/command/policies.js.map +1 -0
- package/dist/admin/command/service-accounts.d.ts +58 -0
- package/dist/admin/command/service-accounts.d.ts.map +1 -0
- package/dist/admin/command/service-accounts.js +272 -0
- package/dist/admin/command/service-accounts.js.map +1 -0
- package/dist/admin/command/service.d.ts +65 -0
- package/dist/admin/command/service.d.ts.map +1 -0
- package/dist/admin/command/service.js +128 -0
- package/dist/admin/command/service.js.map +1 -0
- package/dist/admin/command/tiers.d.ts +40 -0
- package/dist/admin/command/tiers.d.ts.map +1 -0
- package/dist/admin/command/tiers.js +79 -0
- package/dist/admin/command/tiers.js.map +1 -0
- package/dist/admin/index.d.ts +36 -0
- package/dist/admin/index.d.ts.map +1 -0
- package/dist/admin/index.js +63 -0
- package/dist/admin/index.js.map +1 -0
- package/dist/admin/ports.d.ts +288 -0
- package/dist/admin/ports.d.ts.map +1 -0
- package/dist/admin/ports.js +39 -0
- package/dist/admin/ports.js.map +1 -0
- package/dist/admin/query/audit-view.d.ts +52 -0
- package/dist/admin/query/audit-view.d.ts.map +1 -0
- package/dist/admin/query/audit-view.js +84 -0
- package/dist/admin/query/audit-view.js.map +1 -0
- package/dist/admin/query/catalog.d.ts +70 -0
- package/dist/admin/query/catalog.d.ts.map +1 -0
- package/dist/admin/query/catalog.js +169 -0
- package/dist/admin/query/catalog.js.map +1 -0
- package/dist/admin/query/explain.d.ts +52 -0
- package/dist/admin/query/explain.d.ts.map +1 -0
- package/dist/admin/query/explain.js +145 -0
- package/dist/admin/query/explain.js.map +1 -0
- package/dist/admin/query/index.d.ts +45 -0
- package/dist/admin/query/index.d.ts.map +1 -0
- package/dist/admin/query/index.js +58 -0
- package/dist/admin/query/index.js.map +1 -0
- package/dist/admin/query/simulate.d.ts +42 -0
- package/dist/admin/query/simulate.d.ts.map +1 -0
- package/dist/admin/query/simulate.js +91 -0
- package/dist/admin/query/simulate.js.map +1 -0
- package/dist/admin/safeguards-impl.d.ts +67 -0
- package/dist/admin/safeguards-impl.d.ts.map +1 -0
- package/dist/admin/safeguards-impl.js +318 -0
- package/dist/admin/safeguards-impl.js.map +1 -0
- package/dist/admin/safeguards.d.ts +89 -0
- package/dist/admin/safeguards.d.ts.map +1 -0
- package/dist/admin/safeguards.js +91 -0
- package/dist/admin/safeguards.js.map +1 -0
- package/dist/admin/types.d.ts +485 -0
- package/dist/admin/types.d.ts.map +1 -0
- package/dist/admin/types.js +38 -0
- package/dist/admin/types.js.map +1 -0
- package/dist/audit/audit-recorder.d.ts +129 -0
- package/dist/audit/audit-recorder.d.ts.map +1 -0
- package/dist/audit/audit-recorder.js +265 -0
- package/dist/audit/audit-recorder.js.map +1 -0
- package/dist/audit/canonicalize.d.ts +38 -0
- package/dist/audit/canonicalize.d.ts.map +1 -0
- package/dist/audit/canonicalize.js +174 -0
- package/dist/audit/canonicalize.js.map +1 -0
- package/dist/audit/errors.d.ts +56 -0
- package/dist/audit/errors.d.ts.map +1 -0
- package/dist/audit/errors.js +41 -0
- package/dist/audit/errors.js.map +1 -0
- package/dist/audit/index.d.ts +45 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +24 -0
- package/dist/audit/index.js.map +1 -0
- package/dist/audit/ports.d.ts +131 -0
- package/dist/audit/ports.d.ts.map +1 -0
- package/dist/audit/ports.js +27 -0
- package/dist/audit/ports.js.map +1 -0
- package/dist/audit/sensitive.d.ts +68 -0
- package/dist/audit/sensitive.d.ts.map +1 -0
- package/dist/audit/sensitive.js +159 -0
- package/dist/audit/sensitive.js.map +1 -0
- package/dist/audit/walk.d.ts +109 -0
- package/dist/audit/walk.d.ts.map +1 -0
- package/dist/audit/walk.js +117 -0
- package/dist/audit/walk.js.map +1 -0
- package/dist/authentication/authenticator.d.ts +74 -0
- package/dist/authentication/authenticator.d.ts.map +1 -0
- package/dist/authentication/authenticator.js +208 -0
- package/dist/authentication/authenticator.js.map +1 -0
- package/dist/authentication/credential-resolver.d.ts +76 -0
- package/dist/authentication/credential-resolver.d.ts.map +1 -0
- package/dist/authentication/credential-resolver.js +21 -0
- package/dist/authentication/credential-resolver.js.map +1 -0
- package/dist/authentication/index.d.ts +52 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +27 -0
- package/dist/authentication/index.js.map +1 -0
- package/dist/authentication/password-hasher.d.ts +41 -0
- package/dist/authentication/password-hasher.d.ts.map +1 -0
- package/dist/authentication/password-hasher.js +21 -0
- package/dist/authentication/password-hasher.js.map +1 -0
- package/dist/authentication/totp.d.ts +101 -0
- package/dist/authentication/totp.d.ts.map +1 -0
- package/dist/authentication/totp.js +151 -0
- package/dist/authentication/totp.js.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts +90 -0
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts.map +1 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js +165 -0
- package/dist/authorization/cross-tenant/grant-evaluator.js.map +1 -0
- package/dist/authorization/decision-authority.d.ts +212 -0
- package/dist/authorization/decision-authority.d.ts.map +1 -0
- package/dist/authorization/decision-authority.js +200 -0
- package/dist/authorization/decision-authority.js.map +1 -0
- package/dist/authorization/default-gates.d.ts +41 -0
- package/dist/authorization/default-gates.d.ts.map +1 -0
- package/dist/authorization/default-gates.js +47 -0
- package/dist/authorization/default-gates.js.map +1 -0
- package/dist/authorization/delegation/operation-identity.d.ts +132 -0
- package/dist/authorization/delegation/operation-identity.d.ts.map +1 -0
- package/dist/authorization/delegation/operation-identity.js +220 -0
- package/dist/authorization/delegation/operation-identity.js.map +1 -0
- package/dist/authorization/errors.d.ts +54 -0
- package/dist/authorization/errors.d.ts.map +1 -0
- package/dist/authorization/errors.js +63 -0
- package/dist/authorization/errors.js.map +1 -0
- package/dist/authorization/gates/object-type.d.ts +63 -0
- package/dist/authorization/gates/object-type.d.ts.map +1 -0
- package/dist/authorization/gates/object-type.js +177 -0
- package/dist/authorization/gates/object-type.js.map +1 -0
- package/dist/authorization/gates/tenant.d.ts +50 -0
- package/dist/authorization/gates/tenant.d.ts.map +1 -0
- package/dist/authorization/gates/tenant.js +87 -0
- package/dist/authorization/gates/tenant.js.map +1 -0
- package/dist/authorization/gates/wiring.d.ts +57 -0
- package/dist/authorization/gates/wiring.d.ts.map +1 -0
- package/dist/authorization/gates/wiring.js +56 -0
- package/dist/authorization/gates/wiring.js.map +1 -0
- package/dist/authorization/index.d.ts +136 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +82 -0
- package/dist/authorization/index.js.map +1 -0
- package/dist/authorization/ports.d.ts +271 -0
- package/dist/authorization/ports.d.ts.map +1 -0
- package/dist/authorization/ports.js +36 -0
- package/dist/authorization/ports.js.map +1 -0
- package/dist/authorization/reason-codes.d.ts +75 -0
- package/dist/authorization/reason-codes.d.ts.map +1 -0
- package/dist/authorization/reason-codes.js +98 -0
- package/dist/authorization/reason-codes.js.map +1 -0
- package/dist/authorization/record/permit-tier.d.ts +57 -0
- package/dist/authorization/record/permit-tier.d.ts.map +1 -0
- package/dist/authorization/record/permit-tier.js +79 -0
- package/dist/authorization/record/permit-tier.js.map +1 -0
- package/dist/authorization/record/rule-evaluator.d.ts +116 -0
- package/dist/authorization/record/rule-evaluator.d.ts.map +1 -0
- package/dist/authorization/record/rule-evaluator.js +125 -0
- package/dist/authorization/record/rule-evaluator.js.map +1 -0
- package/dist/authorization/record/shares.d.ts +70 -0
- package/dist/authorization/record/shares.d.ts.map +1 -0
- package/dist/authorization/record/shares.js +107 -0
- package/dist/authorization/record/shares.js.map +1 -0
- package/dist/identity/broker.d.ts +59 -0
- package/dist/identity/broker.d.ts.map +1 -0
- package/dist/identity/broker.js +135 -0
- package/dist/identity/broker.js.map +1 -0
- package/dist/identity/claim-mapper.d.ts +84 -0
- package/dist/identity/claim-mapper.d.ts.map +1 -0
- package/dist/identity/claim-mapper.js +48 -0
- package/dist/identity/claim-mapper.js.map +1 -0
- package/dist/identity/index.d.ts +60 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +24 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/internal-adapter.d.ts +54 -0
- package/dist/identity/internal-adapter.d.ts.map +1 -0
- package/dist/identity/internal-adapter.js +88 -0
- package/dist/identity/internal-adapter.js.map +1 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +48 -0
- package/dist/index.js.map +1 -0
- package/dist/metadata/completeness.d.ts +136 -0
- package/dist/metadata/completeness.d.ts.map +1 -0
- package/dist/metadata/completeness.js +106 -0
- package/dist/metadata/completeness.js.map +1 -0
- package/dist/metadata/dependencies.d.ts +114 -0
- package/dist/metadata/dependencies.d.ts.map +1 -0
- package/dist/metadata/dependencies.js +105 -0
- package/dist/metadata/dependencies.js.map +1 -0
- package/dist/metadata/index.d.ts +153 -0
- package/dist/metadata/index.d.ts.map +1 -0
- package/dist/metadata/index.js +51 -0
- package/dist/metadata/index.js.map +1 -0
- package/dist/metadata/registry.d.ts +23 -0
- package/dist/metadata/registry.d.ts.map +1 -0
- package/dist/metadata/registry.js +204 -0
- package/dist/metadata/registry.js.map +1 -0
- package/dist/risk/evaluator.d.ts +76 -0
- package/dist/risk/evaluator.d.ts.map +1 -0
- package/dist/risk/evaluator.js +59 -0
- package/dist/risk/evaluator.js.map +1 -0
- package/dist/risk/index.d.ts +40 -0
- package/dist/risk/index.d.ts.map +1 -0
- package/dist/risk/index.js +20 -0
- package/dist/risk/index.js.map +1 -0
- package/dist/risk/risk-engine.d.ts +76 -0
- package/dist/risk/risk-engine.d.ts.map +1 -0
- package/dist/risk/risk-engine.js +287 -0
- package/dist/risk/risk-engine.js.map +1 -0
- package/dist/risk/signals.d.ts +60 -0
- package/dist/risk/signals.d.ts.map +1 -0
- package/dist/risk/signals.js +104 -0
- package/dist/risk/signals.js.map +1 -0
- package/dist/risk/thresholds.d.ts +54 -0
- package/dist/risk/thresholds.d.ts.map +1 -0
- package/dist/risk/thresholds.js +60 -0
- package/dist/risk/thresholds.js.map +1 -0
- package/dist/session/index.d.ts +47 -0
- package/dist/session/index.d.ts.map +1 -0
- package/dist/session/index.js +20 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/lifetimes.d.ts +50 -0
- package/dist/session/lifetimes.d.ts.map +1 -0
- package/dist/session/lifetimes.js +67 -0
- package/dist/session/lifetimes.js.map +1 -0
- package/dist/session/ports.d.ts +266 -0
- package/dist/session/ports.d.ts.map +1 -0
- package/dist/session/ports.js +23 -0
- package/dist/session/ports.js.map +1 -0
- package/dist/session/session-authority.d.ts +97 -0
- package/dist/session/session-authority.d.ts.map +1 -0
- package/dist/session/session-authority.js +393 -0
- package/dist/session/session-authority.js.map +1 -0
- package/package.json +32 -0
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-tenant consented GRANT evaluator (ADR-0009 / §10bis) — the single, reusable
|
|
3
|
+
* "does an active cross-tenant grant permit THIS action on THIS resource?" helper
|
|
4
|
+
* consulted by gate 3 (tenant, TEAM A), gate 5 (object-type, TEAM A), AND gate 6's
|
|
5
|
+
* share-half (per-record permit, TEAM C — this file's owner).
|
|
6
|
+
*
|
|
7
|
+
* A cross-tenant grant is the ONLY sanctioned way (short of a platform superuser) a
|
|
8
|
+
* principal reaches a resource owned by a DIFFERENT tenant. It is NEVER a superuser
|
|
9
|
+
* bypass: it is a HARD action-ceiling (ADR-0009). This helper enforces AC 13 — the
|
|
10
|
+
* two hard bounds a grant may never exceed:
|
|
11
|
+
*
|
|
12
|
+
* 1. **Action ceiling** — the attempted action key MUST be a member of the grant's
|
|
13
|
+
* `allowedActions` set (STRICT membership). A `view`+`edit` grant DENIES `delete`.
|
|
14
|
+
* 2. **Scope coverage** — the grant must cover THIS resource: same object type, and
|
|
15
|
+
* for a `record`-scoped grant the exact record id. A grant scoped to one record
|
|
16
|
+
* (or one object type) DENIES every other record / object type.
|
|
17
|
+
*
|
|
18
|
+
* ── FAIL-CLOSED on ANY ambiguity. Any condition that is not affirmatively satisfied
|
|
19
|
+
* yields `applicable: false` — never a permit. An UNKNOWN scope shape is treated as
|
|
20
|
+
* "does not apply" (a hostile/garbage `scope` can never open access). Expiry is
|
|
21
|
+
* re-checked defensively even though the port is contracted to return only ACTIVE
|
|
22
|
+
* grants (defense-in-depth, per the {@link CrossTenantGrantPort.findActiveGrant}
|
|
23
|
+
* contract — "the engine additionally re-checks the returned grant's allowedActions
|
|
24
|
+
* + expiresAtMs").
|
|
25
|
+
*
|
|
26
|
+
* ── TRANSIENT-vs-DENY (ADR-0016). This helper NEVER catches. A `null` grant from the
|
|
27
|
+
* port is a normal data-absence → `applicable: false`. A transient
|
|
28
|
+
* {@link AuthorizationUnavailableError} (or any other throw) from the port
|
|
29
|
+
* PROPAGATES unchanged so `decide()` can re-throw it (503-retryable). We never
|
|
30
|
+
* swallow a transient into a "not applicable" — that would silently downgrade an
|
|
31
|
+
* outage to a Deny.
|
|
32
|
+
*
|
|
33
|
+
* ── PURE + zero-dep. No I/O of its own beyond the injected port; no framework / DB /
|
|
34
|
+
* node imports (ADR-0003). The `now` clock is injectable for deterministic tests;
|
|
35
|
+
* it defaults to `Date.now`, matching the port contract ("the clock is the
|
|
36
|
+
* engine's").
|
|
37
|
+
*/
|
|
38
|
+
import { strictTrue } from '../reason-codes.js';
|
|
39
|
+
const NOT_APPLICABLE = Object.freeze({
|
|
40
|
+
applicable: false,
|
|
41
|
+
grant: null,
|
|
42
|
+
});
|
|
43
|
+
/**
|
|
44
|
+
* Resolve whether an ACTIVE, consented cross-tenant grant permits `subject.action`
|
|
45
|
+
* on `subject.resource` for `subject.principal` — the single-source AC-13 ceiling +
|
|
46
|
+
* scope evaluator shared across gates 3/5/6.
|
|
47
|
+
*
|
|
48
|
+
* Sequence (all conditions must hold, else `applicable:false`):
|
|
49
|
+
* 1. Ask {@link CrossTenantGrantPort.findActiveGrant} for a grant covering the
|
|
50
|
+
* resource's owning tenant + object type + action (+ record id for record-scoped).
|
|
51
|
+
* `null` ⇒ no consent ⇒ not applicable.
|
|
52
|
+
* 2. **Action ceiling** — `action.key` ∈ `grant.allowedActions` (strict membership).
|
|
53
|
+
* 3. **Scope coverage** — `object_type`-scoped covers every record of that type;
|
|
54
|
+
* `record`-scoped covers ONLY its `recordId`. Object type must match. Unknown
|
|
55
|
+
* scope shape ⇒ not applicable.
|
|
56
|
+
* 4. **Expiry (defensive)** — `grant.expiresAtMs > now`, even though the port
|
|
57
|
+
* should only return active grants.
|
|
58
|
+
*
|
|
59
|
+
* @throws propagates any {@link AuthorizationUnavailableError} (or other error) the
|
|
60
|
+
* port throws — a transient must NOT be swallowed into "not applicable".
|
|
61
|
+
*/
|
|
62
|
+
export async function isCrossTenantGrantApplicable(port, subject, options = {}) {
|
|
63
|
+
const { principal, action, resource } = subject;
|
|
64
|
+
const owningTenantId = resource.tenantId;
|
|
65
|
+
// A grant is only meaningful for a resource with a known owning tenant. Absent one,
|
|
66
|
+
// there is nothing to consent across — fail closed.
|
|
67
|
+
if (owningTenantId === undefined || owningTenantId.length === 0) {
|
|
68
|
+
return NOT_APPLICABLE;
|
|
69
|
+
}
|
|
70
|
+
// Ask the port. A transient throw PROPAGATES (never caught here) so the pipeline
|
|
71
|
+
// re-throws it (ADR-0016); a `null` is a normal data-absence (no active consent).
|
|
72
|
+
// `recordId` is only included when present (exactOptionalPropertyTypes: no explicit
|
|
73
|
+
// `undefined` on an optional field).
|
|
74
|
+
const query = {
|
|
75
|
+
grantee: principal.id,
|
|
76
|
+
roleIds: principal.roleIds,
|
|
77
|
+
owningTenantId,
|
|
78
|
+
typeKey: resource.typeKey,
|
|
79
|
+
action: action.key,
|
|
80
|
+
...(resource.recordId !== undefined ? { recordId: resource.recordId } : {}),
|
|
81
|
+
};
|
|
82
|
+
const grant = await port.findActiveGrant(query);
|
|
83
|
+
if (grant === null) {
|
|
84
|
+
return NOT_APPLICABLE;
|
|
85
|
+
}
|
|
86
|
+
// From here the port RETURNED a grant, but we do NOT trust it blindly — the ceiling
|
|
87
|
+
// + scope + expiry are re-verified (defense-in-depth per the port contract). Any
|
|
88
|
+
// failing check ⇒ the grant exists but does not apply (return it for the consumer,
|
|
89
|
+
// `applicable:false`).
|
|
90
|
+
if (!clearsActionCeiling(grant, action.key)) {
|
|
91
|
+
return { applicable: false, grant };
|
|
92
|
+
}
|
|
93
|
+
if (!coversResource(grant, resource)) {
|
|
94
|
+
return { applicable: false, grant };
|
|
95
|
+
}
|
|
96
|
+
if (!isUnexpired(grant, options.now ?? Date.now)) {
|
|
97
|
+
return { applicable: false, grant };
|
|
98
|
+
}
|
|
99
|
+
return { applicable: true, grant };
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* AC-13 ACTION CEILING — the attempted action key must be a member of the grant's
|
|
103
|
+
* `allowedActions`. STRICT membership (exact string equality, no wildcard, no prefix):
|
|
104
|
+
* a `['view','edit']` grant must DENY `delete`. Defends against a malformed
|
|
105
|
+
* `allowedActions` (non-array / non-string members) by treating it as empty (no
|
|
106
|
+
* action permitted) — fail-closed.
|
|
107
|
+
*/
|
|
108
|
+
function clearsActionCeiling(grant, actionKey) {
|
|
109
|
+
const allowed = grant.allowedActions;
|
|
110
|
+
if (!Array.isArray(allowed)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
// Strict membership: only an exact-string match permits. `strictTrue` guards the
|
|
114
|
+
// final boolean so a hostile array (e.g. containing objects) can never fail open.
|
|
115
|
+
return strictTrue(allowed.some((a) => a === actionKey));
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* AC-13 SCOPE COVERAGE — does the grant's scope cover THIS resource?
|
|
119
|
+
* - object type MUST match the grant's `typeKey` (a grant on type A never covers B);
|
|
120
|
+
* - `object_type` scope covers every record of that type (record id irrelevant);
|
|
121
|
+
* - `record` scope covers ONLY its declared `recordId`, and requires the resource to
|
|
122
|
+
* carry a matching `recordId`;
|
|
123
|
+
* - any OTHER (unknown) scope shape ⇒ NOT covered (fail-closed on ambiguity).
|
|
124
|
+
*/
|
|
125
|
+
function coversResource(grant, resource) {
|
|
126
|
+
// Object type must match regardless of scope.
|
|
127
|
+
if (grant.typeKey !== resource.typeKey) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
switch (grant.scope) {
|
|
131
|
+
case 'object_type':
|
|
132
|
+
// Whole-type grant — covers every record of this object type.
|
|
133
|
+
return true;
|
|
134
|
+
case 'record': {
|
|
135
|
+
// Record-scoped grant — covers ONLY its exact record. Both the grant and the
|
|
136
|
+
// resource must name the SAME non-empty record id.
|
|
137
|
+
const grantRecordId = grant.recordId;
|
|
138
|
+
const resourceRecordId = resource.recordId;
|
|
139
|
+
if (grantRecordId === undefined ||
|
|
140
|
+
grantRecordId.length === 0 ||
|
|
141
|
+
resourceRecordId === undefined ||
|
|
142
|
+
resourceRecordId.length === 0) {
|
|
143
|
+
return false;
|
|
144
|
+
}
|
|
145
|
+
return grantRecordId === resourceRecordId;
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
// Unknown / hostile scope shape — never covers anything (fail-closed).
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* Defensive expiry re-check (ADR-0009). The port is contracted to return only ACTIVE
|
|
154
|
+
* grants, but the engine re-checks `expiresAtMs` as defense-in-depth: a grant with
|
|
155
|
+
* `expiresAtMs <= now` is INACTIVE and does not apply. A non-finite/absent expiry is
|
|
156
|
+
* treated as expired (fail-closed) — an active grant MUST carry a real future expiry.
|
|
157
|
+
*/
|
|
158
|
+
function isUnexpired(grant, now) {
|
|
159
|
+
const expiresAtMs = grant.expiresAtMs;
|
|
160
|
+
if (typeof expiresAtMs !== 'number' || !Number.isFinite(expiresAtMs)) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
return expiresAtMs > now();
|
|
164
|
+
}
|
|
165
|
+
//# sourceMappingURL=grant-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grant-evaluator.js","sourceRoot":"","sources":["../../../src/authorization/cross-tenant/grant-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAIH,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAiChD,MAAM,cAAc,GAA4B,MAAM,CAAC,MAAM,CAAC;IAC5D,UAAU,EAAE,KAAK;IACjB,KAAK,EAAE,IAAI;CACZ,CAAC,CAAC;AAQH;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAChD,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AAa,KAAK,gBAAgB,CAAC;QAC5C,CAAC;QACD;YACE,uEAAuE;YACvE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,WAAW,CAAC,KAAuB,EAAE,GAAiB;IAC7D,MAAM,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;IACtC,IAAI,OAAO,WAAW,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,EAAE,CAAC;QACrE,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,WAAW,GAAG,GAAG,EAAE,CAAC;AAC7B,CAAC"}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Authorization **engine** — the body behind the FROZEN {@link DecisionAuthority}
|
|
3
|
+
* seam (`./index.ts`). `decide(principal, action, resource, context) → Decision`,
|
|
4
|
+
* THE single decision authority (§7.1). Every enforcement point calls this one
|
|
5
|
+
* path; there is NO divergent per-feature/resource-level/principal-type logic.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the Session engine (`../session/session-authority.ts`) EXACTLY: a pure
|
|
8
|
+
* `createDecisionAuthority(...)` factory over INJECTED deps (ports + registry +
|
|
9
|
+
* per-request session facts + the four team-supplied gate functions), a stateless
|
|
10
|
+
* impl, STRICT `=== true` gates over verdict-returning ports, and a top-level
|
|
11
|
+
* try/catch → fail-closed.
|
|
12
|
+
*
|
|
13
|
+
* ── THE ONE DECISION PATH — gate order (KICKOFF §"The one decision path", verbatim
|
|
14
|
+
* §7.3 hard gates → permit tier; deny wins). `decide()` runs EXACTLY this
|
|
15
|
+
* sequence; EVERY Allow traverses it and escapes via a short-circuit; the
|
|
16
|
+
* terminal is a fail-closed Deny. There is no second route to Allow.
|
|
17
|
+
*
|
|
18
|
+
* 0. Resource registration → `resource_not_registered` if unregistered.
|
|
19
|
+
* 1. Tier + Public → tier `public` ⇒ Allow, consulting NO port.
|
|
20
|
+
* 2. Authentication gate → non-public + unauth ⇒ `not_authenticated`.
|
|
21
|
+
* 3. Tenant gate → mismatch + no grant + not superuser ⇒
|
|
22
|
+
* `tenant_mismatch` (TEAM A/C, via a gate-fn).
|
|
23
|
+
* 4. Authenticated-Global → tier `authenticated_global` ⇒ Allow, AFTER 3.
|
|
24
|
+
* 5. Feature/Object-type gate → gated + no grant ⇒ `missing_object_type_grant`
|
|
25
|
+
* (TEAM A, via a gate-fn); feature/object level
|
|
26
|
+
* terminates here (Allow if held).
|
|
27
|
+
* 6. Record permit tier → record level only; deny-wins; rule ∪ share ∪
|
|
28
|
+
* grant (TEAM B/C, via a gate-fn).
|
|
29
|
+
* 7. Delegation overlay → trusted operation identity (TEAM D, via a
|
|
30
|
+
* gate-fn); re-evaluates 3–6 under the operation
|
|
31
|
+
* scope; tenant STILL applies; never wildcard.
|
|
32
|
+
* 8. Fail-closed default → any unresolved path / unexpected exception ⇒
|
|
33
|
+
* `deny_by_default`. Typed transient ⇒ RE-THROW.
|
|
34
|
+
*
|
|
35
|
+
* ── ADR-0016 CLASSIFICATION (KICKOFF §"BINDING ARCHITECT DECISION"): the top-level
|
|
36
|
+
* catch RE-THROWS a {@link AuthorizationUnavailableError} unchanged (a genuine
|
|
37
|
+
* transient must propagate to the enforcement adapter → 503-retryable, request
|
|
38
|
+
* unserved). ANY OTHER thrown error → fail-closed `deny_by_default` (never
|
|
39
|
+
* throw-to-open, never an unavailable masquerade).
|
|
40
|
+
*
|
|
41
|
+
* ── PRELUDE SCOPE: this file implements the PIPELINE STRUCTURE + the pure/trivial
|
|
42
|
+
* short-circuits (gates 0, 1, 2, 4, 8) + the ADR-0016 classification. Gates 3,
|
|
43
|
+
* 5, 6, 7 are SEAM functions (`TenantGateFn`, `ObjectTypeGateFn`,
|
|
44
|
+
* `RecordPermitFn`, `DelegationOverlayFn`) that Teams A/B/C/D implement and the
|
|
45
|
+
* integration owner injects. The prelude ships trivial DENY-BY-DEFAULT defaults
|
|
46
|
+
* (see `./default-gates.js`) so the file compiles + tests pass NOW; teams
|
|
47
|
+
* replace the defaults with real evaluators.
|
|
48
|
+
*
|
|
49
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
50
|
+
*/
|
|
51
|
+
import type { Principal } from '../identity/index.js';
|
|
52
|
+
import type { ModuleRegistry } from '../metadata/index.js';
|
|
53
|
+
import type { Action, AccessTier, Decision, DecisionAuthority, DecisionContext, Resource } from './index.js';
|
|
54
|
+
import type { CrossTenantGrantPort, OperationAuthorityPort, PermissionFactsPort, RecordPermissionRulePort, RecordSharePort } from './ports.js';
|
|
55
|
+
/**
|
|
56
|
+
* The result a seam gate reports back to the pipeline — a three-way discriminated
|
|
57
|
+
* union so a gate can say ALLOW (short-circuit success), DENY (short-circuit with a
|
|
58
|
+
* specific reason built via `./reason-codes.js`), or CONTINUE (this gate is
|
|
59
|
+
* satisfied/not-applicable; proceed to the next gate).
|
|
60
|
+
*
|
|
61
|
+
* ⛔ A gate MUST NOT fabricate an out-of-enum reason and MUST NOT swallow a genuine
|
|
62
|
+
* transient into a `deny` — on a transient-unavailable port it THROWS
|
|
63
|
+
* {@link AuthorizationUnavailableError}, which the pipeline re-throws (ADR-0016).
|
|
64
|
+
*/
|
|
65
|
+
export type GateOutcome = {
|
|
66
|
+
readonly kind: 'allow';
|
|
67
|
+
} | {
|
|
68
|
+
readonly kind: 'deny';
|
|
69
|
+
readonly decision: Decision;
|
|
70
|
+
} | {
|
|
71
|
+
readonly kind: 'continue';
|
|
72
|
+
};
|
|
73
|
+
/** Constructor: this gate is satisfied / not applicable — proceed. */
|
|
74
|
+
export declare function gateContinue(): GateOutcome;
|
|
75
|
+
/** Constructor: this gate short-circuits to ALLOW. */
|
|
76
|
+
export declare function gateAllow(): GateOutcome;
|
|
77
|
+
/** Constructor: this gate short-circuits to DENY with a reason-mapped Decision. */
|
|
78
|
+
export declare function gateDeny(decision: Decision): GateOutcome;
|
|
79
|
+
/**
|
|
80
|
+
* The shared, read-only context every seam gate receives — the request's inputs
|
|
81
|
+
* plus the engine's injected capabilities (ports, registry, and the per-request
|
|
82
|
+
* session facts). Teams reach the ports/registry/facts THROUGH this object so no
|
|
83
|
+
* gate has to re-plumb dependencies; the pipeline owns the wiring.
|
|
84
|
+
*/
|
|
85
|
+
export interface GateContext {
|
|
86
|
+
readonly principal: Principal;
|
|
87
|
+
readonly action: Action;
|
|
88
|
+
readonly resource: Resource;
|
|
89
|
+
readonly context: DecisionContext;
|
|
90
|
+
/** The resolved baseline tier for this action (from `resolveTier`, gate 1). */
|
|
91
|
+
readonly tier: AccessTier;
|
|
92
|
+
/** Injected ports + registry + per-request session facts (see {@link DecisionAuthorityDeps}). */
|
|
93
|
+
readonly deps: ResolvedGateDeps;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Gate 3 — TENANT gate (TEAM A, with the cross-tenant proceed-hook from TEAM C).
|
|
97
|
+
* Returns `deny(tenant_mismatch)` on a cross-tenant attempt with no active grant
|
|
98
|
+
* and not a platform superuser; `continue` when same-tenant / superuser / a grant
|
|
99
|
+
* lets evaluation PROCEED (the grant is a hard action-ceiling, never an allow here).
|
|
100
|
+
* MUST NOT return `allow` (the tenant gate only permits PROCEEDING).
|
|
101
|
+
*/
|
|
102
|
+
export type TenantGateFn = (ctx: GateContext) => Promise<GateOutcome>;
|
|
103
|
+
/**
|
|
104
|
+
* Gate 5 — FEATURE / OBJECT-TYPE gate (TEAM A). Reads session `cachedFacts` first,
|
|
105
|
+
* then {@link PermissionFactsPort} on miss/stale-version, plus any covering
|
|
106
|
+
* cross-tenant grant scope. Returns `deny(missing_object_type_grant)` for a gated
|
|
107
|
+
* action with no applicable grant; `allow` when the grant is held AND the resource
|
|
108
|
+
* is feature/object-type level (terminates here); `continue` when the resource is
|
|
109
|
+
* RECORD level and the coarse gate passed (proceed to gate 6).
|
|
110
|
+
*/
|
|
111
|
+
export type ObjectTypeGateFn = (ctx: GateContext) => Promise<GateOutcome>;
|
|
112
|
+
/**
|
|
113
|
+
* Gate 6 — RECORD PERMIT tier (TEAM B policy + TEAM C shares/grants), record level
|
|
114
|
+
* only, reached only after gates 0–5 passed. Deny-wins: an explicit rule deny ⇒
|
|
115
|
+
* `deny(explicit_deny_policy)`; else the union (rule allow ∪ share ∪ cross-tenant
|
|
116
|
+
* grant) — a permit ⇒ `allow`; no permit ⇒ `deny(no_record_permit)`. Never
|
|
117
|
+
* `continue` (the record tier is terminal for record-level resources).
|
|
118
|
+
*/
|
|
119
|
+
export type RecordPermitFn = (ctx: GateContext) => Promise<GateOutcome>;
|
|
120
|
+
/**
|
|
121
|
+
* Gate 7 — DELEGATION overlay (TEAM D), trusted operation identity (ADR-0008).
|
|
122
|
+
* When the operation declares a scoped delegated authority (via
|
|
123
|
+
* {@link OperationAuthorityPort}), gates 3–6 are re-evaluated under the OPERATION's
|
|
124
|
+
* scope (tenant STILL applies; never a wildcard; cannot exceed declared scope),
|
|
125
|
+
* yielding `allow`/`deny`. `undefined`-authority ⇒ pass-through ⇒ `continue`
|
|
126
|
+
* (the decision already computed by gates 0–6 stands).
|
|
127
|
+
*/
|
|
128
|
+
export type DelegationOverlayFn = (ctx: GateContext,
|
|
129
|
+
/** The decision gates 0–6 produced (the pass-through result if no delegation). */
|
|
130
|
+
baseline: Decision) => Promise<GateOutcome>;
|
|
131
|
+
/**
|
|
132
|
+
* The four team-supplied gate functions the pipeline calls at gates 3/5/6/7. The
|
|
133
|
+
* integration owner injects the REAL ones; the prelude injects deny-by-default
|
|
134
|
+
* defaults (`./default-gates.js`) so it compiles + tests pass.
|
|
135
|
+
*/
|
|
136
|
+
export interface GateFunctions {
|
|
137
|
+
readonly tenantGate: TenantGateFn;
|
|
138
|
+
readonly objectTypeGate: ObjectTypeGateFn;
|
|
139
|
+
readonly recordPermit: RecordPermitFn;
|
|
140
|
+
readonly delegationOverlay: DelegationOverlayFn;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Reads the CURRENT request's session facts (ADR-0011) for gate 5. Gate 5 consumes
|
|
144
|
+
* `cachedFacts` FIRST (the hot path, no port call) and only falls back to
|
|
145
|
+
* {@link PermissionFactsPort} on a miss/stale-version.
|
|
146
|
+
*
|
|
147
|
+
* ⛔ DESIGN DECISION (KICKOFF §Ports): the frozen `decide()` signature is 4-arg
|
|
148
|
+
* (`principal, action, resource, context`) and MUST stay byte-identical — so the
|
|
149
|
+
* per-request `cachedFacts` + `permissionsVersion` do NOT ride on a 5th arg. They
|
|
150
|
+
* are supplied by an EXPLICIT `sessionFacts` dep that the enforcement adapter
|
|
151
|
+
* populates PER REQUEST (the adapter already read the hot session via
|
|
152
|
+
* `readHotSession`, so it has these). This keeps the seam frozen while giving gate
|
|
153
|
+
* 5 the hot facts without a port round-trip on the common path.
|
|
154
|
+
*/
|
|
155
|
+
export interface SessionFactsReader {
|
|
156
|
+
/**
|
|
157
|
+
* The opaque `cachedFacts` slot for THIS request (ADR-0011), or `null` when not
|
|
158
|
+
* yet projected (gate 5 then projects via {@link PermissionFactsPort}). The
|
|
159
|
+
* engine passes it through opaque; gate 5 (TEAM A) interprets it as
|
|
160
|
+
* {@link CoarseGrants}.
|
|
161
|
+
*/
|
|
162
|
+
readonly cachedFacts: unknown;
|
|
163
|
+
/**
|
|
164
|
+
* The permission version bound to `cachedFacts` (ADR-0011). Gate 5 compares it to
|
|
165
|
+
* {@link PermissionFactsPort.currentPermissionsVersion}; a lower value ⇒ STALE ⇒
|
|
166
|
+
* reload (so a revoke takes effect within the version bound).
|
|
167
|
+
*/
|
|
168
|
+
readonly permissionsVersion: number;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The injected ports + registry + per-request session facts, resolved onto one
|
|
172
|
+
* object the pipeline hands to every gate via {@link GateContext.deps}. Teams reach
|
|
173
|
+
* their port(s) here rather than re-plumbing.
|
|
174
|
+
*/
|
|
175
|
+
export interface ResolvedGateDeps {
|
|
176
|
+
readonly registry: ModuleRegistry;
|
|
177
|
+
readonly permissionFacts: PermissionFactsPort;
|
|
178
|
+
readonly recordRule: RecordPermissionRulePort;
|
|
179
|
+
readonly recordShare: RecordSharePort;
|
|
180
|
+
readonly crossTenantGrant: CrossTenantGrantPort;
|
|
181
|
+
readonly operationAuthority: OperationAuthorityPort;
|
|
182
|
+
/** THIS request's session facts (ADR-0011), populated by the adapter per-request. */
|
|
183
|
+
readonly sessionFacts: SessionFactsReader;
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* The full dependency set {@link createDecisionAuthority} injects — the six ports,
|
|
187
|
+
* the {@link ModuleRegistry}, the per-request {@link SessionFactsReader}, and the
|
|
188
|
+
* four team-supplied gate functions. The integration owner assembles the real ones;
|
|
189
|
+
* the prelude supplies deny-by-default gate defaults.
|
|
190
|
+
*/
|
|
191
|
+
export interface DecisionAuthorityDeps {
|
|
192
|
+
readonly registry: ModuleRegistry;
|
|
193
|
+
readonly permissionFacts: PermissionFactsPort;
|
|
194
|
+
readonly recordRule: RecordPermissionRulePort;
|
|
195
|
+
readonly recordShare: RecordSharePort;
|
|
196
|
+
readonly crossTenantGrant: CrossTenantGrantPort;
|
|
197
|
+
readonly operationAuthority: OperationAuthorityPort;
|
|
198
|
+
/** Per-request session facts (ADR-0011) — the adapter populates this each request. */
|
|
199
|
+
readonly sessionFacts: SessionFactsReader;
|
|
200
|
+
/** Team-supplied gates 3/5/6/7. Prelude defaults deny-by-default. */
|
|
201
|
+
readonly gates: GateFunctions;
|
|
202
|
+
}
|
|
203
|
+
/** Options for {@link createDecisionAuthority} (mirrors CreateSessionAuthorityOptions). */
|
|
204
|
+
export type CreateDecisionAuthorityOptions = DecisionAuthorityDeps;
|
|
205
|
+
/**
|
|
206
|
+
* Wire the injected deps and return an object implementing the FROZEN
|
|
207
|
+
* {@link DecisionAuthority}. The engine's public entry point (mirrors
|
|
208
|
+
* `createSessionAuthority`). PURE — no I/O at construction; the gates + ports do
|
|
209
|
+
* their work lazily inside `decide()`.
|
|
210
|
+
*/
|
|
211
|
+
export declare function createDecisionAuthority(deps: CreateDecisionAuthorityOptions): DecisionAuthority;
|
|
212
|
+
//# sourceMappingURL=decision-authority.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-authority.d.ts","sourceRoot":"","sources":["../../src/authorization/decision-authority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,OAAO,KAAK,EACV,MAAM,EACN,UAAU,EACV,QAAQ,EACR,iBAAiB,EACjB,eAAe,EACf,QAAQ,EACT,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,oBAAoB,EACpB,sBAAsB,EACtB,mBAAmB,EACnB,wBAAwB,EACxB,eAAe,EAChB,MAAM,YAAY,CAAC;AAYpB;;;;;;;;;GASG;AACH,MAAM,MAAM,WAAW,GACnB;IAAE,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAA;CAAE,GAC1B;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAA;CAAE,GACtD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAA;CAAE,CAAC;AAElC,sEAAsE;AACtE,wBAAgB,YAAY,IAAI,WAAW,CAE1C;AAED,sDAAsD;AACtD,wBAAgB,SAAS,IAAI,WAAW,CAEvC;AAED,mFAAmF;AACnF,wBAAgB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,GAAG,WAAW,CAExD;AAED;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC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WAAW,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,oBAAoB,CAAC;IAChD,QAAQ,CAAC,kBAAkB,EAAE,sBAAsB,CAAC;IACpD,qFAAqF;IACrF,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;CAC3C;AAED;;;;;GAKG;AACH,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;IAClC,QAAQ,CAAC,eAAe,EAAE,mBAAmB,CAAC;IAC9C,QAAQ,CAAC,UAAU,EAAE,wBAAwB,CAAC;IAC9C,QAAQ,CAAC,WAAW,EAAE,eAAe,CAAC;IACtC,QAAQ,CAAC,gBAAgB,EAAE,oBAAoB,CAAC;IAChD,QAAQ,CAAC,kBAAkB,EAAE,sBAAsB,CAAC;IACpD,sFAAsF;IACtF,QAAQ,CAAC,YAAY,EAAE,kBAAkB,CAAC;IAC1C,qEAAqE;IACrE,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;CAC/B;AA6ID,2FAA2F;AAC3F,MAAM,MAAM,8BAA8B,GAAG,qBAAqB,CAAC;AAEnE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CACrC,IAAI,EAAE,8BAA8B,GACnC,iBAAiB,CAEnB"}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Authorization **engine** — the body behind the FROZEN {@link DecisionAuthority}
|
|
3
|
+
* seam (`./index.ts`). `decide(principal, action, resource, context) → Decision`,
|
|
4
|
+
* THE single decision authority (§7.1). Every enforcement point calls this one
|
|
5
|
+
* path; there is NO divergent per-feature/resource-level/principal-type logic.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the Session engine (`../session/session-authority.ts`) EXACTLY: a pure
|
|
8
|
+
* `createDecisionAuthority(...)` factory over INJECTED deps (ports + registry +
|
|
9
|
+
* per-request session facts + the four team-supplied gate functions), a stateless
|
|
10
|
+
* impl, STRICT `=== true` gates over verdict-returning ports, and a top-level
|
|
11
|
+
* try/catch → fail-closed.
|
|
12
|
+
*
|
|
13
|
+
* ── THE ONE DECISION PATH — gate order (KICKOFF §"The one decision path", verbatim
|
|
14
|
+
* §7.3 hard gates → permit tier; deny wins). `decide()` runs EXACTLY this
|
|
15
|
+
* sequence; EVERY Allow traverses it and escapes via a short-circuit; the
|
|
16
|
+
* terminal is a fail-closed Deny. There is no second route to Allow.
|
|
17
|
+
*
|
|
18
|
+
* 0. Resource registration → `resource_not_registered` if unregistered.
|
|
19
|
+
* 1. Tier + Public → tier `public` ⇒ Allow, consulting NO port.
|
|
20
|
+
* 2. Authentication gate → non-public + unauth ⇒ `not_authenticated`.
|
|
21
|
+
* 3. Tenant gate → mismatch + no grant + not superuser ⇒
|
|
22
|
+
* `tenant_mismatch` (TEAM A/C, via a gate-fn).
|
|
23
|
+
* 4. Authenticated-Global → tier `authenticated_global` ⇒ Allow, AFTER 3.
|
|
24
|
+
* 5. Feature/Object-type gate → gated + no grant ⇒ `missing_object_type_grant`
|
|
25
|
+
* (TEAM A, via a gate-fn); feature/object level
|
|
26
|
+
* terminates here (Allow if held).
|
|
27
|
+
* 6. Record permit tier → record level only; deny-wins; rule ∪ share ∪
|
|
28
|
+
* grant (TEAM B/C, via a gate-fn).
|
|
29
|
+
* 7. Delegation overlay → trusted operation identity (TEAM D, via a
|
|
30
|
+
* gate-fn); re-evaluates 3–6 under the operation
|
|
31
|
+
* scope; tenant STILL applies; never wildcard.
|
|
32
|
+
* 8. Fail-closed default → any unresolved path / unexpected exception ⇒
|
|
33
|
+
* `deny_by_default`. Typed transient ⇒ RE-THROW.
|
|
34
|
+
*
|
|
35
|
+
* ── ADR-0016 CLASSIFICATION (KICKOFF §"BINDING ARCHITECT DECISION"): the top-level
|
|
36
|
+
* catch RE-THROWS a {@link AuthorizationUnavailableError} unchanged (a genuine
|
|
37
|
+
* transient must propagate to the enforcement adapter → 503-retryable, request
|
|
38
|
+
* unserved). ANY OTHER thrown error → fail-closed `deny_by_default` (never
|
|
39
|
+
* throw-to-open, never an unavailable masquerade).
|
|
40
|
+
*
|
|
41
|
+
* ── PRELUDE SCOPE: this file implements the PIPELINE STRUCTURE + the pure/trivial
|
|
42
|
+
* short-circuits (gates 0, 1, 2, 4, 8) + the ADR-0016 classification. Gates 3,
|
|
43
|
+
* 5, 6, 7 are SEAM functions (`TenantGateFn`, `ObjectTypeGateFn`,
|
|
44
|
+
* `RecordPermitFn`, `DelegationOverlayFn`) that Teams A/B/C/D implement and the
|
|
45
|
+
* integration owner injects. The prelude ships trivial DENY-BY-DEFAULT defaults
|
|
46
|
+
* (see `./default-gates.js`) so the file compiles + tests pass NOW; teams
|
|
47
|
+
* replace the defaults with real evaluators.
|
|
48
|
+
*
|
|
49
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
50
|
+
*/
|
|
51
|
+
import { AuthorizationUnavailableError } from './errors.js';
|
|
52
|
+
import { allow, denyByDefault, denyNotAuthenticated, denyResourceNotRegistered, } from './reason-codes.js';
|
|
53
|
+
/** Constructor: this gate is satisfied / not applicable — proceed. */
|
|
54
|
+
export function gateContinue() {
|
|
55
|
+
return { kind: 'continue' };
|
|
56
|
+
}
|
|
57
|
+
/** Constructor: this gate short-circuits to ALLOW. */
|
|
58
|
+
export function gateAllow() {
|
|
59
|
+
return { kind: 'allow' };
|
|
60
|
+
}
|
|
61
|
+
/** Constructor: this gate short-circuits to DENY with a reason-mapped Decision. */
|
|
62
|
+
export function gateDeny(decision) {
|
|
63
|
+
return { kind: 'deny', decision };
|
|
64
|
+
}
|
|
65
|
+
// ---------------------------------------------------------------------------
|
|
66
|
+
// The engine.
|
|
67
|
+
// ---------------------------------------------------------------------------
|
|
68
|
+
/** Stateless per call; holds only the injected deps. From {@link createDecisionAuthority}. */
|
|
69
|
+
class DecisionAuthorityImpl {
|
|
70
|
+
deps;
|
|
71
|
+
constructor(deps) {
|
|
72
|
+
this.deps = deps;
|
|
73
|
+
}
|
|
74
|
+
async decide(principal, action, resource, context) {
|
|
75
|
+
try {
|
|
76
|
+
return await this.runPipeline(principal, action, resource, context);
|
|
77
|
+
}
|
|
78
|
+
catch (err) {
|
|
79
|
+
// ── ADR-0016 CLASSIFICATION — the single point where transient ≠ deny. ──
|
|
80
|
+
// A genuine transient must PROPAGATE (adapter → 503-retryable, request
|
|
81
|
+
// unserved). Everything else is an UNEXPECTED failure → fail-closed deny
|
|
82
|
+
// (never throw-to-open, never fabricate an unavailable).
|
|
83
|
+
if (err instanceof AuthorizationUnavailableError) {
|
|
84
|
+
throw err;
|
|
85
|
+
}
|
|
86
|
+
return denyByDefault();
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/** The ONE decision path (gates 0→8). Every Allow escapes via a short-circuit. */
|
|
90
|
+
async runPipeline(principal, action, resource, context) {
|
|
91
|
+
const { registry, gates } = this.deps;
|
|
92
|
+
// ── Gate 0 — Resource registration (§5.4/5.5). Unregistered ⇒ Deny. ───────
|
|
93
|
+
const objectType = registry.resolveObjectType(resource.typeKey);
|
|
94
|
+
if (objectType === undefined) {
|
|
95
|
+
return denyResourceNotRegistered();
|
|
96
|
+
}
|
|
97
|
+
// ── Gate 1 — Tier resolution + Public short-circuit (§6/§7.3.1). ─────────
|
|
98
|
+
// A `public` action is reachable with NO authz and consults NO port. Resolve
|
|
99
|
+
// the action's baseline tier from the registry via the canonical `resolveTier`
|
|
100
|
+
// rule (never re-implement the `?? 'gated'` default). We locate the registered
|
|
101
|
+
// action by its (typeKey, actionKey) over the frozen `listActions()` surface;
|
|
102
|
+
// an action not registered for this type resolves to the fail-closed `gated`
|
|
103
|
+
// default (it will be denied downstream — never silently opened).
|
|
104
|
+
const registered = registry
|
|
105
|
+
.listActions()
|
|
106
|
+
.find((a) => a.action.typeKey === resource.typeKey && a.action.actionKey === action.key);
|
|
107
|
+
// Prefer the registry's ALREADY-RESOLVED `tier` (single-source; the registry
|
|
108
|
+
// derived it via the canonical `resolveTier` at registration) over re-calling
|
|
109
|
+
// `resolveTier(registered.action)` here — behavior identical. An action not
|
|
110
|
+
// registered for this type resolves to the fail-closed `gated` default.
|
|
111
|
+
const tier = registered === undefined ? 'gated' : registered.tier;
|
|
112
|
+
if (tier === 'public') {
|
|
113
|
+
return allow();
|
|
114
|
+
}
|
|
115
|
+
// ── Gate 2 — Authentication gate (§7.3.1). Non-public + unauth ⇒ Deny. ───
|
|
116
|
+
if (context.isAuthenticated !== true) {
|
|
117
|
+
return denyNotAuthenticated();
|
|
118
|
+
}
|
|
119
|
+
// Assemble the shared gate context once (ports + registry + per-request facts).
|
|
120
|
+
const gctx = {
|
|
121
|
+
principal,
|
|
122
|
+
action,
|
|
123
|
+
resource,
|
|
124
|
+
context,
|
|
125
|
+
tier,
|
|
126
|
+
deps: {
|
|
127
|
+
registry: this.deps.registry,
|
|
128
|
+
permissionFacts: this.deps.permissionFacts,
|
|
129
|
+
recordRule: this.deps.recordRule,
|
|
130
|
+
recordShare: this.deps.recordShare,
|
|
131
|
+
crossTenantGrant: this.deps.crossTenantGrant,
|
|
132
|
+
operationAuthority: this.deps.operationAuthority,
|
|
133
|
+
sessionFacts: this.deps.sessionFacts,
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
// ── Gate 3 — Tenant gate (TEAM A/C). deny(tenant_mismatch) | continue. ───
|
|
137
|
+
const tenant = await gates.tenantGate(gctx);
|
|
138
|
+
if (tenant.kind === 'deny')
|
|
139
|
+
return tenant.decision;
|
|
140
|
+
if (tenant.kind === 'allow') {
|
|
141
|
+
// The tenant gate must not short-circuit to Allow (it only lets eval proceed);
|
|
142
|
+
// treat an unexpected `allow` as fail-closed rather than trusting it.
|
|
143
|
+
return denyByDefault();
|
|
144
|
+
}
|
|
145
|
+
// ── Gate 4 — Authenticated-Global short-circuit (§6.2), AFTER gate 3. ────
|
|
146
|
+
// Tenant scoping is NEVER relaxed, so this comes strictly after the tenant gate.
|
|
147
|
+
if (tier === 'authenticated_global') {
|
|
148
|
+
return allow();
|
|
149
|
+
}
|
|
150
|
+
// ── Gate 5 — Feature / Object-type gate (TEAM A). ────────────────────────
|
|
151
|
+
// allow ⇒ feature/object-type level held (terminates); continue ⇒ record level.
|
|
152
|
+
// deny ⇒ becomes the BASELINE (not an early return) so gate 7 (delegation) gets
|
|
153
|
+
// its chance to override it for a delegated step (§10.1/AC-15, RULING 3). A
|
|
154
|
+
// non-delegated request is unaffected: gate 7 passes through and this deny stands
|
|
155
|
+
// verbatim; a `tenant_mismatch` (from a covering-grant proceed path) is likewise
|
|
156
|
+
// never overridden (isOverridablePermissionDeny → false).
|
|
157
|
+
const objectGate = await gates.objectTypeGate(gctx);
|
|
158
|
+
let baseline;
|
|
159
|
+
if (objectGate.kind === 'deny') {
|
|
160
|
+
baseline = objectGate.decision;
|
|
161
|
+
}
|
|
162
|
+
else if (objectGate.kind === 'allow') {
|
|
163
|
+
baseline = allow();
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
// ── Gate 6 — Record permit tier (TEAM B/C), record level only. ─────────
|
|
167
|
+
const permit = await gates.recordPermit(gctx);
|
|
168
|
+
if (permit.kind === 'deny') {
|
|
169
|
+
baseline = permit.decision;
|
|
170
|
+
}
|
|
171
|
+
else if (permit.kind === 'allow') {
|
|
172
|
+
baseline = allow();
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
// A record gate that neither allows nor denies is an unresolved path.
|
|
176
|
+
baseline = denyByDefault();
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
// ── Gate 7 — Delegation overlay (TEAM D). Pass-through ⇒ baseline stands. ─
|
|
180
|
+
const overlay = await gates.delegationOverlay(gctx, baseline);
|
|
181
|
+
if (overlay.kind === 'deny')
|
|
182
|
+
return overlay.decision;
|
|
183
|
+
if (overlay.kind === 'allow')
|
|
184
|
+
return allow();
|
|
185
|
+
// ── Gate 8 — Fail-closed terminal. The baseline (Allow if a gate granted it,
|
|
186
|
+
// else a specific deny / deny_by_default). Every Allow reached here came
|
|
187
|
+
// from a gate short-circuit above; there is no other route to Allow.
|
|
188
|
+
return baseline;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Wire the injected deps and return an object implementing the FROZEN
|
|
193
|
+
* {@link DecisionAuthority}. The engine's public entry point (mirrors
|
|
194
|
+
* `createSessionAuthority`). PURE — no I/O at construction; the gates + ports do
|
|
195
|
+
* their work lazily inside `decide()`.
|
|
196
|
+
*/
|
|
197
|
+
export function createDecisionAuthority(deps) {
|
|
198
|
+
return new DecisionAuthorityImpl(deps);
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=decision-authority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decision-authority.js","sourceRoot":"","sources":["../../src/authorization/decision-authority.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAIH,OAAO,EAAE,6BAA6B,EAAE,MAAM,aAAa,CAAC;AAgB5D,OAAO,EACL,KAAK,EACL,aAAa,EACb,oBAAoB,EACpB,yBAAyB,GAC1B,MAAM,mBAAmB,CAAC;AAqB3B,sEAAsE;AACtE,MAAM,UAAU,YAAY;IAC1B,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC;AAC9B,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,SAAS;IACvB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;AAC3B,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,QAAQ,CAAC,QAAkB;IACzC,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;AACpC,CAAC;AA6ID,8EAA8E;AAC9E,cAAc;AACd,8EAA8E;AAE9E,8FAA8F;AAC9F,MAAM,qBAAqB;IACI;IAA7B,YAA6B,IAA2B;QAA3B,SAAI,GAAJ,IAAI,CAAuB;IAAG,CAAC;IAE5D,KAAK,CAAC,MAAM,CACV,SAAoB,EACpB,MAAc,EACd,Q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-closed placeholders for the four seam gate
|
|
3
|
+
* functions (gates 3/5/6/7) so `createDecisionAuthority(...)` compiles and the
|
|
4
|
+
* prelude's own guarantees are testable NOW, BEFORE Teams A/B/C/D ship the real
|
|
5
|
+
* evaluators.
|
|
6
|
+
*
|
|
7
|
+
* ⛔ These are DELIBERATELY the most conservative possible bodies — deny-by-default
|
|
8
|
+
* everywhere (the tenant gate `continue`s ONLY so the pipeline can be exercised
|
|
9
|
+
* end-to-end; every other gate denies). They implement NO real authorization logic.
|
|
10
|
+
* The integration owner REPLACES each with the corresponding team's evaluator when
|
|
11
|
+
* wiring the real `DecisionAuthorityDeps.gates`.
|
|
12
|
+
*
|
|
13
|
+
* - `defaultTenantGate` → `continue` (same-tenant assumption for the skeleton
|
|
14
|
+
* ONLY; TEAM A/C replace it with the real tenant + cross-tenant-grant gate).
|
|
15
|
+
* - `defaultObjectTypeGate` → `deny(deny_by_default)` (TEAM A replaces).
|
|
16
|
+
* - `defaultRecordPermit` → `deny(deny_by_default)` (TEAM B/C replace).
|
|
17
|
+
* - `defaultDelegationOverlay` → `continue` (pass-through: baseline stands;
|
|
18
|
+
* TEAM D replaces with the real delegation overlay).
|
|
19
|
+
*
|
|
20
|
+
* A default-wired authority therefore DENIES every gated/authenticated request
|
|
21
|
+
* (fail-closed) except the pure short-circuits the pipeline owns (public tier,
|
|
22
|
+
* authenticated_global) — exactly what a not-yet-filled authority must do.
|
|
23
|
+
*
|
|
24
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
25
|
+
*/
|
|
26
|
+
import { type DelegationOverlayFn, type GateFunctions, type ObjectTypeGateFn, type RecordPermitFn, type TenantGateFn } from './decision-authority.js';
|
|
27
|
+
/** Prelude default: let evaluation PROCEED past the tenant gate (skeleton only). */
|
|
28
|
+
export declare const defaultTenantGate: TenantGateFn;
|
|
29
|
+
/** Prelude default: DENY at the feature/object-type gate (fail-closed until TEAM A). */
|
|
30
|
+
export declare const defaultObjectTypeGate: ObjectTypeGateFn;
|
|
31
|
+
/** Prelude default: DENY at the record permit tier (fail-closed until TEAM B/C). */
|
|
32
|
+
export declare const defaultRecordPermit: RecordPermitFn;
|
|
33
|
+
/** Prelude default: pass-through delegation overlay (baseline stands until TEAM D). */
|
|
34
|
+
export declare const defaultDelegationOverlay: DelegationOverlayFn;
|
|
35
|
+
/**
|
|
36
|
+
* The complete deny-by-default gate set — inject this as `DecisionAuthorityDeps.gates`
|
|
37
|
+
* to get a compiling, fail-closed authority the prelude tests exercise. Teams replace
|
|
38
|
+
* each member with the real evaluator at integration.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_DENY_BY_DEFAULT_GATES: GateFunctions;
|
|
41
|
+
//# sourceMappingURL=default-gates.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"default-gates.d.ts","sourceRoot":"","sources":["../../src/authorization/default-gates.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAGL,KAAK,mBAAmB,EACxB,KAAK,aAAa,EAClB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAC;AAGjC,oFAAoF;AACpF,eAAO,MAAM,iBAAiB,EAAE,YAAyC,CAAC;AAE1E,wFAAwF;AACxF,eAAO,MAAM,qBAAqB,EAAE,gBACT,CAAC;AAE5B,oFAAoF;AACpF,eAAO,MAAM,mBAAmB,EAAE,cAAsD,CAAC;AAEzF,uFAAuF;AACvF,eAAO,MAAM,wBAAwB,EAAE,mBAAgD,CAAC;AAExF;;;;GAIG;AACH,eAAO,MAAM,6BAA6B,EAAE,aAK1C,CAAC"}
|