@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,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate 6 — the FINAL **record permit tier** composer (INTEGRATION owner) — §7.3.4 /
|
|
3
|
+
* §9, ADR-0005 (policy) + ADR-0006 (share) + ADR-0009 (cross-tenant grant).
|
|
4
|
+
*
|
|
5
|
+
* Gate 6 is the ONE record-level permit gate the pipeline calls. It is a UNION of two
|
|
6
|
+
* WIDENING permit sources under a DENY-WINS policy — assembled here from TEAM B's
|
|
7
|
+
* policy half and TEAM C's share/cross-tenant-grant half (neither team's file ships
|
|
8
|
+
* the final gate; each ships only its own slice + a slice-only view for testing):
|
|
9
|
+
*
|
|
10
|
+
* gate6 = (policy allows) OR (share / cross-tenant grant permits) [union widens]
|
|
11
|
+
* — but an EXPLICIT policy deny OVERRIDES everything [deny-wins]
|
|
12
|
+
*
|
|
13
|
+
* ── THE ONE COMPOSER (B's & C's DONE.md snippets were proven equivalent by a
|
|
14
|
+
* reviewer; this is that single agreed composer):
|
|
15
|
+
*
|
|
16
|
+
* 1. Evaluate the POLICY (TEAM B `evaluateRecordPolicy`).
|
|
17
|
+
* 2. `policy.explicitDeny` ⇒ `deny(explicit_deny_policy)` — DENY-WINS, and it
|
|
18
|
+
* SHORT-CIRCUITS *before* the share is ever consulted. A share can NEVER beat
|
|
19
|
+
* an explicit policy deny (that is the load-bearing invariant of this gate).
|
|
20
|
+
* 3. else evaluate the SHARE (TEAM C `evaluateRecordShare` — same-tenant share ∪
|
|
21
|
+
* applicable cross-tenant grant) and union it with the policy allow:
|
|
22
|
+
* `policy.allow || share` ⇒ `allow`.
|
|
23
|
+
* 4. else ⇒ `deny(no_record_permit)` (no permit from ANY source).
|
|
24
|
+
*
|
|
25
|
+
* ── DENY-WINS IS LOAD-BEARING. The explicit-deny check happens BEFORE `evaluateRecordShare`
|
|
26
|
+
* is called, so a share is not merely ignored — it is never even consulted when the
|
|
27
|
+
* policy explicitly denies. (Consulting it would be harmless too, since the deny
|
|
28
|
+
* already short-circuited, but not calling it is the clearest expression of
|
|
29
|
+
* "deny beats every widening" and avoids a needless port round-trip.)
|
|
30
|
+
*
|
|
31
|
+
* ── TRANSIENT-vs-DENY (ADR-0016). This composer NEVER catches. A genuine transient
|
|
32
|
+
* ({@link AuthorizationUnavailableError}) thrown by EITHER evaluator PROPAGATES so
|
|
33
|
+
* the pipeline's top-level catch re-throws it (503-retryable); any OTHER throw also
|
|
34
|
+
* propagates (the pipeline fail-closes it to `deny_by_default`). A transient is
|
|
35
|
+
* NEVER swallowed into a deny/allow. (Because the policy is evaluated first and an
|
|
36
|
+
* explicit deny short-circuits, a transient in the SHARE evaluator is only surfaced
|
|
37
|
+
* on a policy-silent, non-explicit-deny record — exactly the path where the share
|
|
38
|
+
* is legitimately consulted.)
|
|
39
|
+
*
|
|
40
|
+
* ── PURE + zero-dep (ADR-0003). No framework / HTTP / DB / node imports; the only I/O
|
|
41
|
+
* is through the two team evaluators (which reach their ports via `ctx.deps`).
|
|
42
|
+
*/
|
|
43
|
+
import { gateAllow, gateDeny } from '../decision-authority.js';
|
|
44
|
+
import { denyExplicitPolicy, denyNoRecordPermit } from '../reason-codes.js';
|
|
45
|
+
import { evaluateRecordPolicy } from './rule-evaluator.js';
|
|
46
|
+
import { evaluateRecordShare } from './shares.js';
|
|
47
|
+
/**
|
|
48
|
+
* Build the FINAL gate-6 {@link RecordPermitFn} — the composed policy ∪ share
|
|
49
|
+
* permit tier with deny-wins. This is the ONLY `recordPermit` gate the integration
|
|
50
|
+
* owner injects as `DecisionAuthorityDeps.gates.recordPermit`; do NOT inject either
|
|
51
|
+
* team's slice-only view (`createRecordPolicyGate` ignores shares;
|
|
52
|
+
* `createRecordShareGate` ignores policy).
|
|
53
|
+
*
|
|
54
|
+
* @param options optional injectables threaded into TEAM C's share evaluator (the
|
|
55
|
+
* deterministic `now` clock for cross-tenant-grant expiry); defaults to the
|
|
56
|
+
* helper's own `Date.now`.
|
|
57
|
+
*/
|
|
58
|
+
export function createRecordPermitGate(options = {}) {
|
|
59
|
+
return async function recordPermit(ctx) {
|
|
60
|
+
// 1. POLICY (TEAM B). Deny-wins is resolved inside `evaluateRecordPolicy` under
|
|
61
|
+
// strict `=== true`; a transient throw PROPAGATES (not caught).
|
|
62
|
+
const policy = await evaluateRecordPolicy(ctx);
|
|
63
|
+
// 2. DENY-WINS — an explicit policy deny SHORT-CIRCUITS *before* the share is
|
|
64
|
+
// consulted. A share can never beat an explicit deny (load-bearing).
|
|
65
|
+
if (policy.explicitDeny) {
|
|
66
|
+
return gateDeny(denyExplicitPolicy());
|
|
67
|
+
}
|
|
68
|
+
// 3. UNION — policy allow ∪ share/cross-tenant-grant permit. The share is only
|
|
69
|
+
// consulted now that the policy did not explicitly deny. A transient throw
|
|
70
|
+
// from the share evaluator PROPAGATES (not caught).
|
|
71
|
+
const share = await evaluateRecordShare(ctx, options);
|
|
72
|
+
if (policy.allow || share) {
|
|
73
|
+
return gateAllow();
|
|
74
|
+
}
|
|
75
|
+
// 4. No permit from any source ⇒ a normal `no_record_permit` deny input.
|
|
76
|
+
return gateDeny(denyNoRecordPermit());
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=permit-tier.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"permit-tier.js","sourceRoot":"","sources":["../../../src/authorization/record/permit-tier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyCG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAGlD;;;;;;;;;;GAUG;AACH,MAAM,UAAU,sBAAsB,CACpC,UAAuC,EAAE;IAEzC,OAAO,KAAK,UAAU,YAAY,CAAC,GAAgB;QACjD,gFAAgF;QAChF,mEAAmE;QACnE,MAAM,MAAM,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAE/C,8EAA8E;QAC9E,wEAAwE;QACxE,IAAI,MAAM,CAAC,YAAY,EAAE,CAAC;YACxB,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACxC,CAAC;QAED,+EAA+E;QAC/E,8EAA8E;QAC9E,uDAAuD;QACvD,MAAM,KAAK,GAAG,MAAM,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QACtD,IAAI,MAAM,CAAC,KAAK,IAAI,KAAK,EAAE,CAAC;YAC1B,OAAO,SAAS,EAAE,CAAC;QACrB,CAAC;QAED,yEAAyE;QACzE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEAM B — the **record_permission_rule POLICY evaluator** (gate 6, POLICY half).
|
|
3
|
+
*
|
|
4
|
+
* Gate 6 (§7.3.4, ADR-0005) permits a record-level resource when EITHER the
|
|
5
|
+
* administrator POLICY allows OR a share / cross-tenant grant grants — a UNION —
|
|
6
|
+
* with an EXPLICIT policy DENY overriding everything (deny-wins). This file owns
|
|
7
|
+
* ONLY the POLICY half:
|
|
8
|
+
*
|
|
9
|
+
* - {@link evaluateRecordPolicy} — a PURE policy evaluator. It calls
|
|
10
|
+
* {@link RecordPermissionRulePort.evaluate} and applies the deny-wins
|
|
11
|
+
* resolution AT THE SEAM, returning a {@link PolicyVerdict} (`allow` +
|
|
12
|
+
* `explicitDeny`). It does NOT compose with shares and does NOT return a final
|
|
13
|
+
* {@link GateOutcome}. Composing policy ∪ share (deny-wins over both) is the
|
|
14
|
+
* INTEGRATION owner's job (or a thin composer they write) — see the module
|
|
15
|
+
* contract note below.
|
|
16
|
+
*
|
|
17
|
+
* - {@link createRecordPolicyGate} — a POLICY-ONLY {@link RecordPermitFn} that
|
|
18
|
+
* turns the {@link PolicyVerdict} into a {@link GateOutcome}, so the policy
|
|
19
|
+
* evaluator is independently testable AND usable if the integration owner wants
|
|
20
|
+
* policy-only wiring. ⚠️ THIS IS NOT THE FINAL GATE 6 — see below.
|
|
21
|
+
*
|
|
22
|
+
* ── ⛔ GATE-6 COMPOSITION CONTRACT (read before wiring) ─────────────────────────
|
|
23
|
+
* FINAL gate 6 = (policyAllow OR shareGrant) with policyExplicitDeny WINS.
|
|
24
|
+
*
|
|
25
|
+
* `createRecordPolicyGate` implements the POLICY-ONLY view: a policy-silent
|
|
26
|
+
* record (no allow, no deny) maps to `deny(no_record_permit)` — but in the REAL
|
|
27
|
+
* integrated gate a Team-C share (or cross-tenant grant) could STILL permit that
|
|
28
|
+
* same silent record. So the integration owner MUST compose this evaluator's
|
|
29
|
+
* {@link PolicyVerdict} with Team C's share evaluator:
|
|
30
|
+
*
|
|
31
|
+
* 1. `explicitDeny` (policy) ⇒ `deny(explicit_deny_policy)` — deny-wins, final.
|
|
32
|
+
* 2. else if `policyAllow OR shareGrant` ⇒ `allow`.
|
|
33
|
+
* 3. else ⇒ `deny(no_record_permit)`.
|
|
34
|
+
*
|
|
35
|
+
* Do NOT ship `createRecordPolicyGate` as the final gate 6 — it ignores shares.
|
|
36
|
+
*
|
|
37
|
+
* ── ADR-0016 (transient-vs-deny) ───────────────────────────────────────────────
|
|
38
|
+
* The port distinguishes data-absence (`{allow:false, explicitDeny:false}` — a
|
|
39
|
+
* normal Deny input) from a transient outage (throws
|
|
40
|
+
* {@link AuthorizationUnavailableError}). This evaluator NEVER catches: an
|
|
41
|
+
* `AuthorizationUnavailableError` propagates (the pipeline re-throws it → the
|
|
42
|
+
* request fails closed as 503-retryable), and any OTHER throw also propagates (the
|
|
43
|
+
* pipeline's top-level catch fail-closes it to `deny_by_default`). A throw is NEVER
|
|
44
|
+
* swallowed into a permit.
|
|
45
|
+
*
|
|
46
|
+
* ── STRICT `=== true` (the Layer-5/6 fail-open bug class) ──────────────────────
|
|
47
|
+
* BOTH port booleans route through {@link strictTrue}. A truthy-non-boolean
|
|
48
|
+
* `allow` (`"true"`, `1`) is NOT a permit. A truthy-non-boolean `explicitDeny` is
|
|
49
|
+
* NOT a deny — only a real boolean `true` denies. This is fail-CLOSED overall: a
|
|
50
|
+
* non-boolean `allow` cannot open the gate, and a non-boolean `explicitDeny` that
|
|
51
|
+
* doesn't count as a deny still leaves the policy SILENT (no allow either) ⇒ the
|
|
52
|
+
* policy-only gate denies `no_record_permit`. There is no input that fails open.
|
|
53
|
+
*
|
|
54
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports; zero-dep.
|
|
55
|
+
*/
|
|
56
|
+
import { type GateContext, type RecordPermitFn } from '../decision-authority.js';
|
|
57
|
+
/**
|
|
58
|
+
* The resolved administrator-policy verdict for one record+action — the POLICY half
|
|
59
|
+
* of gate 6. Mirrors {@link RulePermit} but is the evaluator's OWN, strict-`===true`-
|
|
60
|
+
* resolved output (deny-wins already applied):
|
|
61
|
+
*
|
|
62
|
+
* - `explicitDeny` — a policy rule EXPLICITLY denies (deny-wins; overrides any
|
|
63
|
+
* share/grant). `true` ONLY when the port's `explicitDeny === true`.
|
|
64
|
+
* - `allow` — a policy rule affirmatively permits AND no explicit deny applies.
|
|
65
|
+
* `true` ONLY when the port's `allow === true` AND `explicitDeny !== true`
|
|
66
|
+
* (deny-wins is baked in: an explicit deny forces `allow` to `false`).
|
|
67
|
+
*
|
|
68
|
+
* When BOTH are `false` the policy is SILENT — it neither permits nor denies; a
|
|
69
|
+
* share / cross-tenant grant may still permit (that is the gate-6 union, resolved by
|
|
70
|
+
* the integration owner). Silence is a normal Deny INPUT, not an error.
|
|
71
|
+
*/
|
|
72
|
+
export interface PolicyVerdict {
|
|
73
|
+
readonly allow: boolean;
|
|
74
|
+
readonly explicitDeny: boolean;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* PURE record-policy evaluator (gate 6 policy half, ADR-0005, deny-wins).
|
|
78
|
+
*
|
|
79
|
+
* Calls {@link RecordPermissionRulePort.evaluate} with the record-level question and
|
|
80
|
+
* resolves its {@link RulePermit} into a {@link PolicyVerdict} under STRICT
|
|
81
|
+
* `=== true` + deny-wins:
|
|
82
|
+
*
|
|
83
|
+
* - `explicitDeny = strictTrue(result.explicitDeny)` — only a real `true` denies.
|
|
84
|
+
* - `allow = strictTrue(result.allow) && !explicitDeny` — a real allow that an
|
|
85
|
+
* explicit deny has NOT overridden.
|
|
86
|
+
*
|
|
87
|
+
* Does NOT compose with shares and does NOT produce a {@link GateOutcome} — the
|
|
88
|
+
* integration owner unions this with Team C's share evaluator (see the module
|
|
89
|
+
* contract note). Propagates every throw (ADR-0016): an
|
|
90
|
+
* {@link AuthorizationUnavailableError} from the port bubbles up so the pipeline
|
|
91
|
+
* re-throws it; any other throw bubbles up so the pipeline fail-closes it. NEVER
|
|
92
|
+
* swallows a throw into a permit.
|
|
93
|
+
*
|
|
94
|
+
* @param ctx the shared gate context; the port + record resource + attributes are
|
|
95
|
+
* read from it (`ctx.deps.recordRule`, `ctx.resource`, `ctx.context.attributes`).
|
|
96
|
+
*/
|
|
97
|
+
export declare function evaluateRecordPolicy(ctx: GateContext): Promise<PolicyVerdict>;
|
|
98
|
+
/**
|
|
99
|
+
* Build a POLICY-ONLY {@link RecordPermitFn} (gate 6) from {@link evaluateRecordPolicy}.
|
|
100
|
+
*
|
|
101
|
+
* ⚠️ NOT THE FINAL GATE 6 — this maps the policy verdict alone to a
|
|
102
|
+
* {@link GateOutcome}; it does NOT consider shares / cross-tenant grants. Use it for
|
|
103
|
+
* policy-only wiring / independent testing; the integration owner composes
|
|
104
|
+
* {@link evaluateRecordPolicy} with Team C's share evaluator for the real gate 6
|
|
105
|
+
* (see the module contract note).
|
|
106
|
+
*
|
|
107
|
+
* Mapping (policy-only):
|
|
108
|
+
* - `explicitDeny` ⇒ `deny(explicit_deny_policy)` (deny-wins).
|
|
109
|
+
* - `allow` (and not `explicitDeny`) ⇒ `allow`.
|
|
110
|
+
* - policy silent (neither) ⇒ `deny(no_record_permit)` (a share COULD still permit
|
|
111
|
+
* in the integrated gate — this policy-only view does not see it).
|
|
112
|
+
*
|
|
113
|
+
* Every throw propagates (ADR-0016) — see {@link evaluateRecordPolicy}.
|
|
114
|
+
*/
|
|
115
|
+
export declare function createRecordPolicyGate(): RecordPermitFn;
|
|
116
|
+
//# sourceMappingURL=rule-evaluator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-evaluator.d.ts","sourceRoot":"","sources":["../../../src/authorization/record/rule-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,EAGL,KAAK,WAAW,EAEhB,KAAK,cAAc,EACpB,MAAM,0BAA0B,CAAC;AAIlC;;;;;;;;;;;;;;GAcG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;IACxB,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;CAChC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAsB,oBAAoB,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,aAAa,CAAC,CAgBnF;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,IAAI,cAAc,CAavD"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TEAM B — the **record_permission_rule POLICY evaluator** (gate 6, POLICY half).
|
|
3
|
+
*
|
|
4
|
+
* Gate 6 (§7.3.4, ADR-0005) permits a record-level resource when EITHER the
|
|
5
|
+
* administrator POLICY allows OR a share / cross-tenant grant grants — a UNION —
|
|
6
|
+
* with an EXPLICIT policy DENY overriding everything (deny-wins). This file owns
|
|
7
|
+
* ONLY the POLICY half:
|
|
8
|
+
*
|
|
9
|
+
* - {@link evaluateRecordPolicy} — a PURE policy evaluator. It calls
|
|
10
|
+
* {@link RecordPermissionRulePort.evaluate} and applies the deny-wins
|
|
11
|
+
* resolution AT THE SEAM, returning a {@link PolicyVerdict} (`allow` +
|
|
12
|
+
* `explicitDeny`). It does NOT compose with shares and does NOT return a final
|
|
13
|
+
* {@link GateOutcome}. Composing policy ∪ share (deny-wins over both) is the
|
|
14
|
+
* INTEGRATION owner's job (or a thin composer they write) — see the module
|
|
15
|
+
* contract note below.
|
|
16
|
+
*
|
|
17
|
+
* - {@link createRecordPolicyGate} — a POLICY-ONLY {@link RecordPermitFn} that
|
|
18
|
+
* turns the {@link PolicyVerdict} into a {@link GateOutcome}, so the policy
|
|
19
|
+
* evaluator is independently testable AND usable if the integration owner wants
|
|
20
|
+
* policy-only wiring. ⚠️ THIS IS NOT THE FINAL GATE 6 — see below.
|
|
21
|
+
*
|
|
22
|
+
* ── ⛔ GATE-6 COMPOSITION CONTRACT (read before wiring) ─────────────────────────
|
|
23
|
+
* FINAL gate 6 = (policyAllow OR shareGrant) with policyExplicitDeny WINS.
|
|
24
|
+
*
|
|
25
|
+
* `createRecordPolicyGate` implements the POLICY-ONLY view: a policy-silent
|
|
26
|
+
* record (no allow, no deny) maps to `deny(no_record_permit)` — but in the REAL
|
|
27
|
+
* integrated gate a Team-C share (or cross-tenant grant) could STILL permit that
|
|
28
|
+
* same silent record. So the integration owner MUST compose this evaluator's
|
|
29
|
+
* {@link PolicyVerdict} with Team C's share evaluator:
|
|
30
|
+
*
|
|
31
|
+
* 1. `explicitDeny` (policy) ⇒ `deny(explicit_deny_policy)` — deny-wins, final.
|
|
32
|
+
* 2. else if `policyAllow OR shareGrant` ⇒ `allow`.
|
|
33
|
+
* 3. else ⇒ `deny(no_record_permit)`.
|
|
34
|
+
*
|
|
35
|
+
* Do NOT ship `createRecordPolicyGate` as the final gate 6 — it ignores shares.
|
|
36
|
+
*
|
|
37
|
+
* ── ADR-0016 (transient-vs-deny) ───────────────────────────────────────────────
|
|
38
|
+
* The port distinguishes data-absence (`{allow:false, explicitDeny:false}` — a
|
|
39
|
+
* normal Deny input) from a transient outage (throws
|
|
40
|
+
* {@link AuthorizationUnavailableError}). This evaluator NEVER catches: an
|
|
41
|
+
* `AuthorizationUnavailableError` propagates (the pipeline re-throws it → the
|
|
42
|
+
* request fails closed as 503-retryable), and any OTHER throw also propagates (the
|
|
43
|
+
* pipeline's top-level catch fail-closes it to `deny_by_default`). A throw is NEVER
|
|
44
|
+
* swallowed into a permit.
|
|
45
|
+
*
|
|
46
|
+
* ── STRICT `=== true` (the Layer-5/6 fail-open bug class) ──────────────────────
|
|
47
|
+
* BOTH port booleans route through {@link strictTrue}. A truthy-non-boolean
|
|
48
|
+
* `allow` (`"true"`, `1`) is NOT a permit. A truthy-non-boolean `explicitDeny` is
|
|
49
|
+
* NOT a deny — only a real boolean `true` denies. This is fail-CLOSED overall: a
|
|
50
|
+
* non-boolean `allow` cannot open the gate, and a non-boolean `explicitDeny` that
|
|
51
|
+
* doesn't count as a deny still leaves the policy SILENT (no allow either) ⇒ the
|
|
52
|
+
* policy-only gate denies `no_record_permit`. There is no input that fails open.
|
|
53
|
+
*
|
|
54
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports; zero-dep.
|
|
55
|
+
*/
|
|
56
|
+
import { gateAllow, gateDeny, } from '../decision-authority.js';
|
|
57
|
+
import { denyExplicitPolicy, denyNoRecordPermit, strictTrue } from '../reason-codes.js';
|
|
58
|
+
/**
|
|
59
|
+
* PURE record-policy evaluator (gate 6 policy half, ADR-0005, deny-wins).
|
|
60
|
+
*
|
|
61
|
+
* Calls {@link RecordPermissionRulePort.evaluate} with the record-level question and
|
|
62
|
+
* resolves its {@link RulePermit} into a {@link PolicyVerdict} under STRICT
|
|
63
|
+
* `=== true` + deny-wins:
|
|
64
|
+
*
|
|
65
|
+
* - `explicitDeny = strictTrue(result.explicitDeny)` — only a real `true` denies.
|
|
66
|
+
* - `allow = strictTrue(result.allow) && !explicitDeny` — a real allow that an
|
|
67
|
+
* explicit deny has NOT overridden.
|
|
68
|
+
*
|
|
69
|
+
* Does NOT compose with shares and does NOT produce a {@link GateOutcome} — the
|
|
70
|
+
* integration owner unions this with Team C's share evaluator (see the module
|
|
71
|
+
* contract note). Propagates every throw (ADR-0016): an
|
|
72
|
+
* {@link AuthorizationUnavailableError} from the port bubbles up so the pipeline
|
|
73
|
+
* re-throws it; any other throw bubbles up so the pipeline fail-closes it. NEVER
|
|
74
|
+
* swallows a throw into a permit.
|
|
75
|
+
*
|
|
76
|
+
* @param ctx the shared gate context; the port + record resource + attributes are
|
|
77
|
+
* read from it (`ctx.deps.recordRule`, `ctx.resource`, `ctx.context.attributes`).
|
|
78
|
+
*/
|
|
79
|
+
export async function evaluateRecordPolicy(ctx) {
|
|
80
|
+
// Build the input, OMITTING `attributes` when absent (exactOptionalPropertyTypes:
|
|
81
|
+
// an explicit `attributes: undefined` is not assignable to the optional prop).
|
|
82
|
+
const input = {
|
|
83
|
+
principal: ctx.principal,
|
|
84
|
+
action: ctx.action,
|
|
85
|
+
resource: ctx.resource,
|
|
86
|
+
...(ctx.context.attributes === undefined ? {} : { attributes: ctx.context.attributes }),
|
|
87
|
+
};
|
|
88
|
+
const result = await ctx.deps.recordRule.evaluate(input);
|
|
89
|
+
// Deny-wins, resolved at the seam under STRICT === true.
|
|
90
|
+
const explicitDeny = strictTrue(result.explicitDeny);
|
|
91
|
+
const allow = strictTrue(result.allow) && !explicitDeny;
|
|
92
|
+
return { allow, explicitDeny };
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Build a POLICY-ONLY {@link RecordPermitFn} (gate 6) from {@link evaluateRecordPolicy}.
|
|
96
|
+
*
|
|
97
|
+
* ⚠️ NOT THE FINAL GATE 6 — this maps the policy verdict alone to a
|
|
98
|
+
* {@link GateOutcome}; it does NOT consider shares / cross-tenant grants. Use it for
|
|
99
|
+
* policy-only wiring / independent testing; the integration owner composes
|
|
100
|
+
* {@link evaluateRecordPolicy} with Team C's share evaluator for the real gate 6
|
|
101
|
+
* (see the module contract note).
|
|
102
|
+
*
|
|
103
|
+
* Mapping (policy-only):
|
|
104
|
+
* - `explicitDeny` ⇒ `deny(explicit_deny_policy)` (deny-wins).
|
|
105
|
+
* - `allow` (and not `explicitDeny`) ⇒ `allow`.
|
|
106
|
+
* - policy silent (neither) ⇒ `deny(no_record_permit)` (a share COULD still permit
|
|
107
|
+
* in the integrated gate — this policy-only view does not see it).
|
|
108
|
+
*
|
|
109
|
+
* Every throw propagates (ADR-0016) — see {@link evaluateRecordPolicy}.
|
|
110
|
+
*/
|
|
111
|
+
export function createRecordPolicyGate() {
|
|
112
|
+
return async (ctx) => {
|
|
113
|
+
const verdict = await evaluateRecordPolicy(ctx);
|
|
114
|
+
if (verdict.explicitDeny) {
|
|
115
|
+
return gateDeny(denyExplicitPolicy());
|
|
116
|
+
}
|
|
117
|
+
if (verdict.allow) {
|
|
118
|
+
return gateAllow();
|
|
119
|
+
}
|
|
120
|
+
// Policy silent — no permit from policy. In the integrated gate a share may
|
|
121
|
+
// still permit; the policy-only gate denies no_record_permit.
|
|
122
|
+
return gateDeny(denyNoRecordPermit());
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
//# sourceMappingURL=rule-evaluator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rule-evaluator.js","sourceRoot":"","sources":["../../../src/authorization/record/rule-evaluator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsDG;AAEH,OAAO,EACL,SAAS,EACT,QAAQ,GAIT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAuBxF;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,KAAK,UAAU,oBAAoB,CAAC,GAAgB;IACzD,kFAAkF;IAClF,+EAA+E;IAC/E,MAAM,KAAK,GAAoB;QAC7B,SAAS,EAAE,GAAG,CAAC,SAAS;QACxB,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,QAAQ,EAAE,GAAG,CAAC,QAAQ;QACtB,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,UAAU,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,UAAU,EAAE,GAAG,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC;KACxF,CAAC;IACF,MAAM,MAAM,GAAe,MAAM,GAAG,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAErE,yDAAyD;IACzD,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC;IACrD,MAAM,KAAK,GAAG,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,CAAC;IAExD,OAAO,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;AACjC,CAAC;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,sBAAsB;IACpC,OAAO,KAAK,EAAE,GAAgB,EAAwB,EAAE;QACtD,MAAM,OAAO,GAAG,MAAM,oBAAoB,CAAC,GAAG,CAAC,CAAC;QAChD,IAAI,OAAO,CAAC,YAAY,EAAE,CAAC;YACzB,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;QACxC,CAAC;QACD,IAAI,OAAO,CAAC,KAAK,EAAE,CAAC;YAClB,OAAO,SAAS,EAAE,CAAC;QACrB,CAAC;QACD,4EAA4E;QAC5E,8DAA8D;QAC9D,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-record SHARE + cross-tenant-grant half of gate 6 (§7.3.4 / §9.2, ADR-0006 +
|
|
3
|
+
* ADR-0009) — TEAM C's slice of the record permit tier.
|
|
4
|
+
*
|
|
5
|
+
* ⛔ THIS IS NOT THE FINAL GATE 6. Gate 6 is a UNION of two widening permit sources
|
|
6
|
+
* under a deny-wins policy:
|
|
7
|
+
*
|
|
8
|
+
* gate6 = (policy allows) OR (share/cross-tenant grant permits) [union]
|
|
9
|
+
* — but an EXPLICIT policy deny OVERRIDES everything [deny-wins]
|
|
10
|
+
*
|
|
11
|
+
* TEAM B owns the POLICY half (`record/rule-evaluator.ts`: rule allow + explicitDeny).
|
|
12
|
+
* TEAM C (this file) owns the SHARE + CROSS-TENANT-GRANT half. The INTEGRATION owner
|
|
13
|
+
* composes the two into the single `recordPermit` `RecordPermitFn` the pipeline calls
|
|
14
|
+
* at gate 6, applying deny-wins (explicit policy deny beats any share widening). The
|
|
15
|
+
* `createRecordShareGate` exported here is a SHARE-ONLY view for INDEPENDENT testing —
|
|
16
|
+
* it is NOT the final gate 6 and MUST NOT be injected as such (in the composed gate a
|
|
17
|
+
* policy rule could still permit even when no share exists).
|
|
18
|
+
*
|
|
19
|
+
* ── WHAT A SHARE PERMITS (`evaluateRecordShare`), record-level resources only:
|
|
20
|
+
* (1) **Same-tenant share** — {@link RecordSharePort.hasShare} is `true` (STRICT
|
|
21
|
+
* `=== true`) for this principal/roles on this record+action (ADR-0006).
|
|
22
|
+
* (2) **Cross-tenant grant** — when the principal's tenant differs from the
|
|
23
|
+
* resource's owning tenant, a cross-tenant grant covering this record+action is
|
|
24
|
+
* ITSELF the share for the cross-tenant case (§7.3.4). Evaluated via the shared
|
|
25
|
+
* {@link isCrossTenantGrantApplicable} helper (the SAME ceiling+scope logic
|
|
26
|
+
* gates 3 and 5 use — single-sourced, no duplication).
|
|
27
|
+
* The two are UNIONED: permitted if (1) OR (2).
|
|
28
|
+
*
|
|
29
|
+
* ── STRICT `=== true` on the port boolean (the Layer-5/6 fail-open bug class): the
|
|
30
|
+
* share verdict is routed through `strictTrue` — a truthy non-boolean is NOT a
|
|
31
|
+
* permit.
|
|
32
|
+
*
|
|
33
|
+
* ── TRANSIENT-vs-DENY (ADR-0016): neither path catches. A `false`/`null` from a port
|
|
34
|
+
* is a normal data-absence (no permit). An {@link AuthorizationUnavailableError}
|
|
35
|
+
* (or any other error) PROPAGATES so `decide()` can classify it — a transient is
|
|
36
|
+
* NEVER swallowed into a "no permit". A share/grant is never fabricated on error.
|
|
37
|
+
*
|
|
38
|
+
* ── PURE + zero-dep (ADR-0003): no framework / DB / node imports; the only I/O is
|
|
39
|
+
* through the injected ports reached via `ctx.deps`.
|
|
40
|
+
*/
|
|
41
|
+
import type { GateContext, RecordPermitFn } from '../decision-authority.js';
|
|
42
|
+
import { type CrossTenantGrantEvalOptions } from '../cross-tenant/grant-evaluator.js';
|
|
43
|
+
/**
|
|
44
|
+
* Does a same-tenant share OR an in-scope cross-tenant grant permit `ctx.action` on
|
|
45
|
+
* `ctx.resource` for `ctx.principal`? The pure boolean the composed gate 6 unions with
|
|
46
|
+
* TEAM B's policy result.
|
|
47
|
+
*
|
|
48
|
+
* Only meaningful for `resource.level === 'record'` (shares + record-scoped grants are
|
|
49
|
+
* record-level). For a non-record resource there is no per-record share to evaluate →
|
|
50
|
+
* returns `false` (no share permit; the coarse gate 5 already governs feature/
|
|
51
|
+
* object-type level, and the caller/integration never invokes this off the record path).
|
|
52
|
+
*
|
|
53
|
+
* @returns `true` iff (same-tenant share) OR (applicable cross-tenant grant). Any
|
|
54
|
+
* transient/other error from a consulted port PROPAGATES (never swallowed).
|
|
55
|
+
*/
|
|
56
|
+
export declare function evaluateRecordShare(ctx: GateContext, options?: CrossTenantGrantEvalOptions): Promise<boolean>;
|
|
57
|
+
/**
|
|
58
|
+
* Build the SHARE-ONLY gate 6 view — a {@link RecordPermitFn} that decides purely on
|
|
59
|
+
* the share/cross-tenant-grant half, for INDEPENDENT testing of TEAM C's slice.
|
|
60
|
+
*
|
|
61
|
+
* ⛔ NOT the final gate 6. It renders:
|
|
62
|
+
* - a share/grant permits ⇒ `gateAllow()` (via {@link evaluateRecordShare});
|
|
63
|
+
* - none permits ⇒ `gateDeny(denyNoRecordPermit())`.
|
|
64
|
+
* It has NO knowledge of policy rules — in the COMPOSED gate 6 a policy rule could
|
|
65
|
+
* still permit (union) even when this returns deny, and an explicit policy deny would
|
|
66
|
+
* override even a share permit (deny-wins). The integration owner composes this with
|
|
67
|
+
* TEAM B's rule evaluator; do NOT inject this as `DecisionAuthorityDeps.gates.recordPermit`.
|
|
68
|
+
*/
|
|
69
|
+
export declare function createRecordShareGate(options?: CrossTenantGrantEvalOptions): RecordPermitFn;
|
|
70
|
+
//# sourceMappingURL=shares.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shares.d.ts","sourceRoot":"","sources":["../../../src/authorization/record/shares.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAe,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAGzF,OAAO,EAEL,KAAK,2BAA2B,EACjC,MAAM,oCAAoC,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,wBAAsB,mBAAmB,CACvC,GAAG,EAAE,WAAW,EAChB,OAAO,GAAE,2BAAgC,GACxC,OAAO,CAAC,OAAO,CAAC,CA0ClB;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAQhB"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-record SHARE + cross-tenant-grant half of gate 6 (§7.3.4 / §9.2, ADR-0006 +
|
|
3
|
+
* ADR-0009) — TEAM C's slice of the record permit tier.
|
|
4
|
+
*
|
|
5
|
+
* ⛔ THIS IS NOT THE FINAL GATE 6. Gate 6 is a UNION of two widening permit sources
|
|
6
|
+
* under a deny-wins policy:
|
|
7
|
+
*
|
|
8
|
+
* gate6 = (policy allows) OR (share/cross-tenant grant permits) [union]
|
|
9
|
+
* — but an EXPLICIT policy deny OVERRIDES everything [deny-wins]
|
|
10
|
+
*
|
|
11
|
+
* TEAM B owns the POLICY half (`record/rule-evaluator.ts`: rule allow + explicitDeny).
|
|
12
|
+
* TEAM C (this file) owns the SHARE + CROSS-TENANT-GRANT half. The INTEGRATION owner
|
|
13
|
+
* composes the two into the single `recordPermit` `RecordPermitFn` the pipeline calls
|
|
14
|
+
* at gate 6, applying deny-wins (explicit policy deny beats any share widening). The
|
|
15
|
+
* `createRecordShareGate` exported here is a SHARE-ONLY view for INDEPENDENT testing —
|
|
16
|
+
* it is NOT the final gate 6 and MUST NOT be injected as such (in the composed gate a
|
|
17
|
+
* policy rule could still permit even when no share exists).
|
|
18
|
+
*
|
|
19
|
+
* ── WHAT A SHARE PERMITS (`evaluateRecordShare`), record-level resources only:
|
|
20
|
+
* (1) **Same-tenant share** — {@link RecordSharePort.hasShare} is `true` (STRICT
|
|
21
|
+
* `=== true`) for this principal/roles on this record+action (ADR-0006).
|
|
22
|
+
* (2) **Cross-tenant grant** — when the principal's tenant differs from the
|
|
23
|
+
* resource's owning tenant, a cross-tenant grant covering this record+action is
|
|
24
|
+
* ITSELF the share for the cross-tenant case (§7.3.4). Evaluated via the shared
|
|
25
|
+
* {@link isCrossTenantGrantApplicable} helper (the SAME ceiling+scope logic
|
|
26
|
+
* gates 3 and 5 use — single-sourced, no duplication).
|
|
27
|
+
* The two are UNIONED: permitted if (1) OR (2).
|
|
28
|
+
*
|
|
29
|
+
* ── STRICT `=== true` on the port boolean (the Layer-5/6 fail-open bug class): the
|
|
30
|
+
* share verdict is routed through `strictTrue` — a truthy non-boolean is NOT a
|
|
31
|
+
* permit.
|
|
32
|
+
*
|
|
33
|
+
* ── TRANSIENT-vs-DENY (ADR-0016): neither path catches. A `false`/`null` from a port
|
|
34
|
+
* is a normal data-absence (no permit). An {@link AuthorizationUnavailableError}
|
|
35
|
+
* (or any other error) PROPAGATES so `decide()` can classify it — a transient is
|
|
36
|
+
* NEVER swallowed into a "no permit". A share/grant is never fabricated on error.
|
|
37
|
+
*
|
|
38
|
+
* ── PURE + zero-dep (ADR-0003): no framework / DB / node imports; the only I/O is
|
|
39
|
+
* through the injected ports reached via `ctx.deps`.
|
|
40
|
+
*/
|
|
41
|
+
import { gateAllow, gateDeny } from '../decision-authority.js';
|
|
42
|
+
import { denyNoRecordPermit, strictTrue } from '../reason-codes.js';
|
|
43
|
+
import { isCrossTenantGrantApplicable, } from '../cross-tenant/grant-evaluator.js';
|
|
44
|
+
/**
|
|
45
|
+
* Does a same-tenant share OR an in-scope cross-tenant grant permit `ctx.action` on
|
|
46
|
+
* `ctx.resource` for `ctx.principal`? The pure boolean the composed gate 6 unions with
|
|
47
|
+
* TEAM B's policy result.
|
|
48
|
+
*
|
|
49
|
+
* Only meaningful for `resource.level === 'record'` (shares + record-scoped grants are
|
|
50
|
+
* record-level). For a non-record resource there is no per-record share to evaluate →
|
|
51
|
+
* returns `false` (no share permit; the coarse gate 5 already governs feature/
|
|
52
|
+
* object-type level, and the caller/integration never invokes this off the record path).
|
|
53
|
+
*
|
|
54
|
+
* @returns `true` iff (same-tenant share) OR (applicable cross-tenant grant). Any
|
|
55
|
+
* transient/other error from a consulted port PROPAGATES (never swallowed).
|
|
56
|
+
*/
|
|
57
|
+
export async function evaluateRecordShare(ctx, options = {}) {
|
|
58
|
+
const { principal, action, resource, deps } = ctx;
|
|
59
|
+
// Shares/ACL + record-scoped grants are RECORD-level. Off the record path there is
|
|
60
|
+
// no per-record share source to widen with — no share permit.
|
|
61
|
+
if (resource.level !== 'record') {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
// A record-level resource without a record id cannot be matched to a share/grant —
|
|
65
|
+
// fail closed (no permit).
|
|
66
|
+
if (resource.recordId === undefined || resource.recordId.length === 0) {
|
|
67
|
+
return false;
|
|
68
|
+
}
|
|
69
|
+
// (1) Same-tenant share (ADR-0006). STRICT `=== true` — a truthy non-boolean from a
|
|
70
|
+
// misbehaving adapter is NOT a permit. A transient throw propagates (not caught).
|
|
71
|
+
const shareVerdict = await deps.recordShare.hasShare(principal.id, principal.roleIds, resource.typeKey, resource.recordId, action.key);
|
|
72
|
+
if (strictTrue(shareVerdict)) {
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
// (2) Cross-tenant grant as the share (§7.3.4) — ONLY when the principal is reaching
|
|
76
|
+
// ACROSS a tenant boundary. Same-tenant callers never consult the cross-tenant path
|
|
77
|
+
// (a same-tenant record is governed by the same-tenant share + policy alone).
|
|
78
|
+
if (resource.tenantId !== undefined && principal.tenantId !== resource.tenantId) {
|
|
79
|
+
const verdict = await isCrossTenantGrantApplicable(deps.crossTenantGrant, { principal, action, resource }, options);
|
|
80
|
+
if (verdict.applicable) {
|
|
81
|
+
return true;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Build the SHARE-ONLY gate 6 view — a {@link RecordPermitFn} that decides purely on
|
|
88
|
+
* the share/cross-tenant-grant half, for INDEPENDENT testing of TEAM C's slice.
|
|
89
|
+
*
|
|
90
|
+
* ⛔ NOT the final gate 6. It renders:
|
|
91
|
+
* - a share/grant permits ⇒ `gateAllow()` (via {@link evaluateRecordShare});
|
|
92
|
+
* - none permits ⇒ `gateDeny(denyNoRecordPermit())`.
|
|
93
|
+
* It has NO knowledge of policy rules — in the COMPOSED gate 6 a policy rule could
|
|
94
|
+
* still permit (union) even when this returns deny, and an explicit policy deny would
|
|
95
|
+
* override even a share permit (deny-wins). The integration owner composes this with
|
|
96
|
+
* TEAM B's rule evaluator; do NOT inject this as `DecisionAuthorityDeps.gates.recordPermit`.
|
|
97
|
+
*/
|
|
98
|
+
export function createRecordShareGate(options = {}) {
|
|
99
|
+
return async (ctx) => {
|
|
100
|
+
const permitted = await evaluateRecordShare(ctx, options);
|
|
101
|
+
// A share/grant is a WIDENING permit; absence of one is a normal `no_record_permit`
|
|
102
|
+
// Deny INPUT (not an error). This share-only view never returns `explicit_deny_policy`
|
|
103
|
+
// (that is TEAM B's policy signal) and never `continue` (the record tier is terminal).
|
|
104
|
+
return permitted ? gateAllow() : gateDeny(denyNoRecordPermit());
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=shares.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shares.js","sourceRoot":"","sources":["../../../src/authorization/record/shares.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAuCG;AAGH,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EACL,4BAA4B,GAE7B,MAAM,oCAAoC,CAAC;AAE5C;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,GAAgB,EAChB,UAAuC,EAAE;IAEzC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAElD,mFAAmF;IACnF,8DAA8D;IAC9D,IAAI,QAAQ,CAAC,KAAK,KAAK,QAAQ,EAAE,CAAC;QAChC,OAAO,KAAK,CAAC;IACf,CAAC;IACD,mFAAmF;IACnF,2BAA2B;IAC3B,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,IAAI,QAAQ,CAAC,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACtE,OAAO,KAAK,CAAC;IACf,CAAC;IAED,oFAAoF;IACpF,kFAAkF;IAClF,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,WAAW,CAAC,QAAQ,CAClD,SAAS,CAAC,EAAE,EACZ,SAAS,CAAC,OAAO,EACjB,QAAQ,CAAC,OAAO,EAChB,QAAQ,CAAC,QAAQ,EACjB,MAAM,CAAC,GAAG,CACX,CAAC;IACF,IAAI,UAAU,CAAC,YAAY,CAAC,EAAE,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED,qFAAqF;IACrF,oFAAoF;IACpF,8EAA8E;IAC9E,IAAI,QAAQ,CAAC,QAAQ,KAAK,SAAS,IAAI,SAAS,CAAC,QAAQ,KAAK,QAAQ,CAAC,QAAQ,EAAE,CAAC;QAChF,MAAM,OAAO,GAAG,MAAM,4BAA4B,CAChD,IAAI,CAAC,gBAAgB,EACrB,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,EAC/B,OAAO,CACR,CAAC;QACF,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;YACvB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,qBAAqB,CACnC,UAAuC,EAAE;IAEzC,OAAO,KAAK,EAAE,GAAgB,EAAwB,EAAE;QACtD,MAAM,SAAS,GAAG,MAAM,mBAAmB,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAC1D,oFAAoF;QACpF,uFAAuF;QACvF,uFAAuF;QACvF,OAAO,SAAS,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAClE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Identity **normalization core** — the body behind the frozen
|
|
3
|
+
* {@link IdentityBroker} seam (`./index.ts`). Turns an ALREADY-VERIFIED
|
|
4
|
+
* {@link ExternalIdentityAssertion} into ONE tenant-bound {@link Principal},
|
|
5
|
+
* uniformly for every principal kind (ADR-0007: no is-this-a-machine branch).
|
|
6
|
+
*
|
|
7
|
+
* SCOPE — shape the WHO, nothing more:
|
|
8
|
+
* - dispatch on `assertion.source` → the registered {@link IdentityClaimMapper};
|
|
9
|
+
* - map claims → candidate fields;
|
|
10
|
+
* - VALIDATE + tenant-bind → a safe Principal, or REJECT (fail-closed).
|
|
11
|
+
*
|
|
12
|
+
* OUT of scope (later steps, deliberately absent here): proving identity
|
|
13
|
+
* (no credential/MFA/WebAuthn verification — Authentication, step 5), session
|
|
14
|
+
* lifecycle (step 6), service-account credential lifecycle (Authentication). This
|
|
15
|
+
* core ASSUMES the assertion is authentic and only maps + tenant-binds + rejects
|
|
16
|
+
* malformed/unknown.
|
|
17
|
+
*
|
|
18
|
+
* Two security invariants, both fail-closed:
|
|
19
|
+
* 1. TENANT-BINDING — every Principal MUST be bound to exactly one non-empty
|
|
20
|
+
* tenant; a missing/empty tenant REJECTS (§2/§7.3, tenant is the boundary).
|
|
21
|
+
* 2. SUPERUSER SAFETY — `isPlatformSuperuser` defaults `false` and is honored
|
|
22
|
+
* ONLY from a mapper's trusted `trustedSuperuserSignal`; an attacker-supplied
|
|
23
|
+
* `superuser`/`isPlatformSuperuser` claim can never flip it (default-deny).
|
|
24
|
+
*
|
|
25
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB imports.
|
|
26
|
+
*/
|
|
27
|
+
import { type IdentityClaimMapper } from './claim-mapper.js';
|
|
28
|
+
import { type IdentityBroker } from './index.js';
|
|
29
|
+
/** Thrown when an assertion cannot be normalized into a safe Principal. */
|
|
30
|
+
export declare class IdentityNormalizationError extends Error {
|
|
31
|
+
constructor(message: string);
|
|
32
|
+
}
|
|
33
|
+
/** Options for {@link createIdentityBroker}. */
|
|
34
|
+
export interface CreateIdentityBrokerOptions {
|
|
35
|
+
/**
|
|
36
|
+
* Explicit set of claim mappers (IdP adapters) to register. When provided, the
|
|
37
|
+
* broker uses EXACTLY these — the built-in Internal adapter is NOT auto-added
|
|
38
|
+
* (so a deployment can opt out of it). When omitted, a single Internal adapter
|
|
39
|
+
* is registered by default (see {@link internalSuperuserIds}).
|
|
40
|
+
*/
|
|
41
|
+
readonly mappers?: readonly IdentityClaimMapper[];
|
|
42
|
+
/**
|
|
43
|
+
* SUPERUSER SAFETY allowlist for the DEFAULT Internal adapter (only used when
|
|
44
|
+
* `mappers` is omitted). Server-side trusted ids that are platform superusers.
|
|
45
|
+
* Default: empty ⇒ no superusers (default-deny).
|
|
46
|
+
*/
|
|
47
|
+
readonly internalSuperuserIds?: readonly string[];
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Wire the mapper registry + adapters and return an object implementing the
|
|
51
|
+
* frozen {@link IdentityBroker}. This is the engine's public entry point.
|
|
52
|
+
*
|
|
53
|
+
* - No `mappers` given ⇒ registers ONE reference Internal adapter (canonical
|
|
54
|
+
* claim shape) with the given (default empty) superuser allowlist.
|
|
55
|
+
* - `mappers` given ⇒ registers exactly those (the seam future protocol adapters
|
|
56
|
+
* plug into). Duplicate sources fail-closed at registration.
|
|
57
|
+
*/
|
|
58
|
+
export declare function createIdentityBroker(options?: CreateIdentityBrokerOptions): IdentityBroker;
|
|
59
|
+
//# sourceMappingURL=broker.d.ts.map
|
|
@@ -0,0 +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,oBAAoB,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CACnD;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAkBhB"}
|