@astram/core 0.1.0 → 1.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/dist/admin/admin-service.d.ts +1 -1
- package/dist/admin/command/grants.js +3 -3
- package/dist/admin/command/grants.js.map +1 -1
- package/dist/admin/command/invitations.d.ts +2 -2
- package/dist/admin/command/invitations.js +8 -8
- package/dist/admin/command/invitations.js.map +1 -1
- package/dist/admin/command/service-accounts.d.ts +1 -1
- package/dist/admin/command/service-accounts.js +1 -1
- package/dist/admin/query/simulate.d.ts.map +1 -1
- package/dist/admin/query/simulate.js +4 -0
- package/dist/admin/query/simulate.js.map +1 -1
- package/dist/admin/safeguards-impl.d.ts +2 -2
- package/dist/admin/safeguards-impl.js +9 -9
- package/dist/admin/safeguards-impl.js.map +1 -1
- package/dist/admin/safeguards.d.ts +4 -4
- package/dist/admin/safeguards.js +4 -4
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/authentication/authenticator.d.ts +2 -2
- package/dist/authentication/authenticator.js +2 -2
- package/dist/authentication/authenticator.js.map +1 -1
- package/dist/authentication/credential-resolver.d.ts +1 -1
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts +2 -2
- package/dist/authorization/cross-tenant/grant-evaluator.js +2 -2
- package/dist/authorization/decision-authority.d.ts +2 -2
- package/dist/authorization/decision-authority.d.ts.map +1 -1
- package/dist/authorization/decision-authority.js +11 -3
- package/dist/authorization/decision-authority.js.map +1 -1
- package/dist/authorization/errors.d.ts +37 -0
- package/dist/authorization/errors.d.ts.map +1 -1
- package/dist/authorization/errors.js +43 -0
- package/dist/authorization/errors.js.map +1 -1
- package/dist/authorization/gates/object-type.d.ts +2 -2
- package/dist/authorization/gates/object-type.d.ts.map +1 -1
- package/dist/authorization/gates/object-type.js +20 -7
- package/dist/authorization/gates/object-type.js.map +1 -1
- package/dist/authorization/gates/tenant.d.ts +3 -3
- package/dist/authorization/gates/tenant.js +7 -7
- package/dist/authorization/gates/tenant.js.map +1 -1
- package/dist/authorization/index.d.ts +33 -4
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +39 -4
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/ports.d.ts +3 -3
- package/dist/authorization/reason-codes.d.ts +7 -1
- package/dist/authorization/reason-codes.d.ts.map +1 -1
- package/dist/authorization/reason-codes.js +9 -1
- package/dist/authorization/reason-codes.js.map +1 -1
- package/dist/authorization/record/owner-baseline.d.ts +43 -0
- package/dist/authorization/record/owner-baseline.d.ts.map +1 -0
- package/dist/authorization/record/owner-baseline.js +72 -0
- package/dist/authorization/record/owner-baseline.js.map +1 -0
- package/dist/authorization/record/permit-tier.d.ts.map +1 -1
- package/dist/authorization/record/permit-tier.js +16 -5
- package/dist/authorization/record/permit-tier.js.map +1 -1
- package/dist/identity/broker.d.ts +8 -8
- package/dist/identity/broker.d.ts.map +1 -1
- package/dist/identity/broker.js +8 -8
- package/dist/identity/broker.js.map +1 -1
- package/dist/identity/claim-mapper.d.ts +8 -8
- package/dist/identity/claim-mapper.d.ts.map +1 -1
- package/dist/identity/claim-mapper.js +4 -4
- package/dist/identity/index.d.ts +2 -2
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/internal-adapter.d.ts +12 -12
- package/dist/identity/internal-adapter.d.ts.map +1 -1
- package/dist/identity/internal-adapter.js +9 -9
- package/dist/identity/internal-adapter.js.map +1 -1
- package/dist/metadata/index.d.ts +43 -0
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/index.js +6 -0
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/registry.d.ts.map +1 -1
- package/dist/metadata/registry.js +2 -1
- package/dist/metadata/registry.js.map +1 -1
- package/dist-cjs/admin/admin-service.js +159 -0
- package/dist-cjs/admin/command/grants.js +200 -0
- package/dist-cjs/admin/command/index.js +38 -0
- package/dist-cjs/admin/command/invitations.js +246 -0
- package/dist-cjs/admin/command/permissions.js +69 -0
- package/dist-cjs/admin/command/pipeline.js +110 -0
- package/dist-cjs/admin/command/policies.js +223 -0
- package/dist-cjs/admin/command/service-accounts.js +278 -0
- package/dist-cjs/admin/command/service.js +130 -0
- package/dist-cjs/admin/command/tiers.js +81 -0
- package/dist-cjs/admin/index.js +78 -0
- package/dist-cjs/admin/ports.js +41 -0
- package/dist-cjs/admin/query/audit-view.js +88 -0
- package/dist-cjs/admin/query/catalog.js +174 -0
- package/dist-cjs/admin/query/explain.js +149 -0
- package/dist-cjs/admin/query/index.js +74 -0
- package/dist-cjs/admin/query/simulate.js +98 -0
- package/dist-cjs/admin/safeguards-impl.js +322 -0
- package/dist-cjs/admin/safeguards.js +95 -0
- package/dist-cjs/admin/types.js +40 -0
- package/dist-cjs/audit/audit-recorder.js +269 -0
- package/dist-cjs/audit/canonicalize.js +176 -0
- package/dist-cjs/audit/errors.js +44 -0
- package/dist-cjs/audit/index.js +39 -0
- package/dist-cjs/audit/ports.js +27 -0
- package/dist-cjs/audit/sensitive.js +162 -0
- package/dist-cjs/audit/walk.js +123 -0
- package/dist-cjs/authentication/authenticator.js +210 -0
- package/dist-cjs/authentication/credential-resolver.js +21 -0
- package/dist-cjs/authentication/index.js +42 -0
- package/dist-cjs/authentication/password-hasher.js +21 -0
- package/dist-cjs/authentication/totp.js +155 -0
- package/dist-cjs/authorization/cross-tenant/grant-evaluator.js +167 -0
- package/dist-cjs/authorization/decision-authority.js +213 -0
- package/dist-cjs/authorization/default-gates.js +53 -0
- package/dist-cjs/authorization/delegation/operation-identity.js +226 -0
- package/dist-cjs/authorization/errors.js +110 -0
- package/dist-cjs/authorization/gates/object-type.js +192 -0
- package/dist-cjs/authorization/gates/tenant.js +89 -0
- package/dist-cjs/authorization/gates/wiring.js +59 -0
- package/dist-cjs/authorization/index.js +134 -0
- package/dist-cjs/authorization/ports.js +36 -0
- package/dist-cjs/authorization/reason-codes.js +117 -0
- package/dist-cjs/authorization/record/owner-baseline.js +74 -0
- package/dist-cjs/authorization/record/permit-tier.js +92 -0
- package/dist-cjs/authorization/record/rule-evaluator.js +128 -0
- package/dist-cjs/authorization/record/shares.js +110 -0
- package/dist-cjs/identity/broker.js +139 -0
- package/dist-cjs/identity/claim-mapper.js +51 -0
- package/dist-cjs/identity/index.js +39 -0
- package/dist-cjs/identity/internal-adapter.js +91 -0
- package/dist-cjs/index.js +63 -0
- package/dist-cjs/metadata/completeness.js +108 -0
- package/dist-cjs/metadata/dependencies.js +110 -0
- package/dist-cjs/metadata/index.js +76 -0
- package/dist-cjs/metadata/registry.js +207 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/risk/evaluator.js +63 -0
- package/dist-cjs/risk/index.js +35 -0
- package/dist-cjs/risk/risk-engine.js +290 -0
- package/dist-cjs/risk/signals.js +106 -0
- package/dist-cjs/risk/thresholds.js +63 -0
- package/dist-cjs/session/index.js +35 -0
- package/dist-cjs/session/lifetimes.js +70 -0
- package/dist-cjs/session/ports.js +23 -0
- package/dist-cjs/session/session-authority.js +398 -0
- package/package.json +13 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,aAAa,EACnB,MAAM,2BAA2B,CAAC;AAGnC,cAAc,mBAAmB,CAAC;AAKlC,cAAc,eAAe,CAAC;AAK9B,cAAc,mBAAmB,CAAC;AAElC,8EAA8E;AAC9E,MAAM,WAAW,eAAe;IAC9B,iEAAiE;IACjE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB;;;OAGG;IACH,QAAQ,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC;CACrC;AAED,yEAAyE;AACzE,MAAM,WAAW,oBAAoB;IACnC,gEAAgE;IAChE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC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,4EAA4E;IAC5E,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAC1B,mEAAmE;IACnE,QAAQ,CAAC,KAAK,EAAE,eAAe,CAAC;CACjC;AAED;;;;;;;;;;GAUG;AACH,MAAM,WAAW,cAAc;IAC7B,yEAAyE;IACzE,QAAQ,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI,CAAC;IAEzC;;;;OAIG;IACH,yBAAyB,CAAC,UAAU,EAAE,oBAAoB,GAAG,IAAI,CAAC;IAElE,6EAA6E;IAC7E,IAAI,IAAI,SAAS,cAAc,EAAE,CAAC;IAElC;;;;OAIG;IACH,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB,GAAG,SAAS,CAAC;IAErE;;;;OAIG;IACH,sBAAsB,CAAC,aAAa,EAAE,aAAa,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAEnF,8EAA8E;IAC9E,WAAW,IAAI,SAAS,gBAAgB,EAAE,CAAC;CAC5C"}
|
package/dist/metadata/index.js
CHANGED
|
@@ -25,6 +25,7 @@ export * from './registry.js';
|
|
|
25
25
|
// functions that derive the read-only lookups a permission implies from an
|
|
26
26
|
// object type's reference fields, honoring the neverAutoGrant escape hatch.
|
|
27
27
|
export * from './dependencies.js';
|
|
28
|
+
export const DEFAULT_CAPABILITY_PLANE = 'data';
|
|
28
29
|
/**
|
|
29
30
|
* Resolve an action's baseline access tier (§6, ADR-0004): the action's own
|
|
30
31
|
* `tier`, or `gated` when omitted — the fail-closed default. PURE. This is the
|
|
@@ -35,6 +36,11 @@ export * from './dependencies.js';
|
|
|
35
36
|
export function resolveTier(action) {
|
|
36
37
|
return action.tier ?? DEFAULT_ACCESS_TIER;
|
|
37
38
|
}
|
|
39
|
+
/** Resolve an action's plane, defaulting to `data` (fail-safe). Single source —
|
|
40
|
+
* never re-derive elsewhere. */
|
|
41
|
+
export function resolvePlane(action) {
|
|
42
|
+
return action.plane ?? DEFAULT_CAPABILITY_PLANE;
|
|
43
|
+
}
|
|
38
44
|
/**
|
|
39
45
|
* Derive an action's stable permission identity (ADR-0010) within its owning
|
|
40
46
|
* module: `moduleKey:typeKey:actionKey`. PURE — wraps {@link derivePermissionKey}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GAGpB,MAAM,2BAA2B,CAAC;AAEnC,iFAAiF;AACjF,cAAc,mBAAmB,CAAC;AAElC,4EAA4E;AAC5E,+EAA+E;AAC/E,oCAAoC;AACpC,cAAc,eAAe,CAAC;AAE9B,gFAAgF;AAChF,2EAA2E;AAC3E,4EAA4E;AAC5E,cAAc,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/metadata/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GAGpB,MAAM,2BAA2B,CAAC;AAEnC,iFAAiF;AACjF,cAAc,mBAAmB,CAAC;AAElC,4EAA4E;AAC5E,+EAA+E;AAC/E,oCAAoC;AACpC,cAAc,eAAe,CAAC;AAE9B,gFAAgF;AAChF,2EAA2E;AAC3E,4EAA4E;AAC5E,cAAc,mBAAmB,CAAC;AAyElC,MAAM,CAAC,MAAM,wBAAwB,GAAoB,MAAM,CAAC;AAkChE;;;;;;GAMG;AACH,MAAM,UAAU,WAAW,CAAC,MAAwB;IAClD,OAAO,MAAM,CAAC,IAAI,IAAI,mBAAmB,CAAC;AAC5C,CAAC;AAED;iCACiC;AACjC,MAAM,UAAU,YAAY,CAAC,MAAwB;IACnD,OAAO,MAAM,CAAC,KAAK,IAAI,wBAAwB,CAAC;AAClD,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,UAAU,0BAA0B,CACxC,SAAiB,EACjB,MAAwB;IAExB,OAAO,mBAAmB,CAAC,SAAS,EAAE,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;AAC1E,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/metadata/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/metadata/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EAML,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAsOpB;;;GAGG;AACH,wBAAgB,oBAAoB,IAAI,cAAc,CAErD"}
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* {@link resolveTier} — this file NEVER re-derives a key or re-applies the
|
|
15
15
|
* `?? 'gated'` default itself, so the single-source rules can't drift.
|
|
16
16
|
*/
|
|
17
|
-
import { resolveActionPermissionKey, resolveTier, } from './index.js';
|
|
17
|
+
import { resolveActionPermissionKey, resolveTier, resolvePlane, } from './index.js';
|
|
18
18
|
/**
|
|
19
19
|
* In-memory implementation of {@link ModuleRegistry}. Fail-closed posture
|
|
20
20
|
* (ADR-0002): any structural violation at intake throws LOUD so a malformed
|
|
@@ -76,6 +76,7 @@ class InMemoryModuleRegistry {
|
|
|
76
76
|
action,
|
|
77
77
|
permissionKey,
|
|
78
78
|
tier: resolveTier(action),
|
|
79
|
+
plane: resolvePlane(action),
|
|
79
80
|
});
|
|
80
81
|
}
|
|
81
82
|
// (3) Reference integrity — FieldDescriptor.referencesTypeKey and
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/metadata/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,EACL,0BAA0B,EAC1B,WAAW,
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/met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C;YAC9C,KAAK,MAAM,KAAK,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;gBACtC,MAAM,GAAG,GAAG,KAAK,CAAC,iBAAiB,CAAC;gBACpC,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC1C,MAAM,IAAI,KAAK,CACb,oCAAoC,SAAS,kBAAkB,UAAU,CAAC,OAAO,YAAY,KAAK,CAAC,GAAG,kCAAkC,CACzI,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;QAED,0EAA0E;QAC1E,KAAK,MAAM,MAAM,IAAI,QAAQ,CAAC,OAAO,EAAE,CAAC;YACtC,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,IAAI,EAAE,EAAE,CAAC;gBACtD,IAAI,GAAG,CAAC,OAAO,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBAC7B,MAAM,IAAI,KAAK,CACb,oCAAoC,SAAS,aAAa,MAAM,CAAC,SAAS,0DAA0D,CACrI,CAAC;gBACJ,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU,oBAAoB;IAClC,OAAO,IAAI,sBAAsB,EAAE,CAAC;AACtC,CAAC"}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Admin Console engine SEAM — the query/command service factories the three
|
|
4
|
+
* parallel teams fill (Layer 10).
|
|
5
|
+
*
|
|
6
|
+
* The PRELUDE freezes: the dependency bags ({@link AdminQueryDeps} /
|
|
7
|
+
* {@link AdminCommandDeps}), the two service interfaces ({@link AdminQueryService}
|
|
8
|
+
* / {@link AdminCommandService}), the two factories, and — critically — the
|
|
9
|
+
* MUTATING-COMMAND PIPELINE ORDER (encoded in {@link runCommandPipeline} + the
|
|
10
|
+
* comments below) that every command method routes through. Each method has a
|
|
11
|
+
* TRIVIAL FAIL-CLOSED default body (throw for a query it cannot answer / a `deny`
|
|
12
|
+
* CommandResult for a mutation) so the skeleton compiles and the teams replace
|
|
13
|
+
* method-by-method.
|
|
14
|
+
*
|
|
15
|
+
* OWNERSHIP:
|
|
16
|
+
* - QUERY methods (getCatalog / explain / simulate / auditView / listUnclassified)
|
|
17
|
+
* → **Team A**.
|
|
18
|
+
* - COMMAND methods (curatePermission / grant / revoke / authorPolicy / setTier /
|
|
19
|
+
* serviceAccount* / invitation*) → **Team B**, gated by the §11.3 safeguards in
|
|
20
|
+
* `./safeguards.ts` (also Team B).
|
|
21
|
+
*
|
|
22
|
+
* ⛔ NON-NEGOTIABLES the seam encodes:
|
|
23
|
+
* - ONE DECISION PATH: `simulate` + the delegated-admin check REUSE the injected
|
|
24
|
+
* {@link DecisionAuthority.decide} — never a second verdict (ADR-0001).
|
|
25
|
+
* - FAIL-CLOSED: unimplemented commands return a `deny` CommandResult; the
|
|
26
|
+
* safeguards default to deny/high-blast/confirm-required.
|
|
27
|
+
* - AUDIT: every applied mutation emits via the injected {@link AuditSink}.
|
|
28
|
+
* - NO RAW IDS out: the query engine resolves ids via {@link LabelResolver}.
|
|
29
|
+
*
|
|
30
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
31
|
+
*/
|
|
32
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
33
|
+
exports.runCommandPipeline = runCommandPipeline;
|
|
34
|
+
exports.createAdminQueryService = createAdminQueryService;
|
|
35
|
+
exports.createAdminCommandService = createAdminCommandService;
|
|
36
|
+
const safeguards_js_1 = require("./safeguards.js");
|
|
37
|
+
/**
|
|
38
|
+
* Run a mutating command through the frozen §11.3 pipeline (order above). The
|
|
39
|
+
* PRELUDE provides the ORCHESTRATION; Team B provides the per-command closures via
|
|
40
|
+
* {@link CommandPipelineStep}. Every deny short-circuits fail-closed BEFORE the
|
|
41
|
+
* mutation. Used by Team B's command-service method bodies.
|
|
42
|
+
*
|
|
43
|
+
* ⛔ `decide` is threaded into {@link checkDelegatedAdmin} — the ONE decision path.
|
|
44
|
+
*/
|
|
45
|
+
async function runCommandPipeline(step, decide, blastDeps) {
|
|
46
|
+
// (1) DELEGATED-ADMIN CHECK — fail-closed, reuses decide() (ADR-0001 / §3.2).
|
|
47
|
+
const delegated = await (0, safeguards_js_1.checkDelegatedAdmin)(step.mutation.admin, step.mutation, decide);
|
|
48
|
+
if (delegated.ok !== true) {
|
|
49
|
+
return { ok: false, reason: delegated.reason ?? 'delegated_admin_exceeds_authority' };
|
|
50
|
+
}
|
|
51
|
+
// (2) VALIDATE — structural (guided policy / tier≠public / legal transition).
|
|
52
|
+
const invalid = await step.validate();
|
|
53
|
+
if (invalid !== null) {
|
|
54
|
+
return invalid;
|
|
55
|
+
}
|
|
56
|
+
// (3) CONFIRM + BLAST-RADIUS — destructive/high-blast requires a confirm token.
|
|
57
|
+
if ((0, safeguards_js_1.requiresConfirm)(step.mutation) === true) {
|
|
58
|
+
if (step.hasConfirmToken !== true) {
|
|
59
|
+
return { ok: false, reason: 'confirm_required' };
|
|
60
|
+
}
|
|
61
|
+
// Computed for the audit record; Team B attaches it to the emitted event.
|
|
62
|
+
await (0, safeguards_js_1.computeBlastRadius)(step.mutation, blastDeps);
|
|
63
|
+
}
|
|
64
|
+
// (4) MUTATE — only reached after 1–3 pass (fail-closed order).
|
|
65
|
+
const value = await step.mutate();
|
|
66
|
+
// (5) AUDIT — every applied mutation is recorded (invariant #6).
|
|
67
|
+
await step.emitAudit(value);
|
|
68
|
+
return { ok: true, value };
|
|
69
|
+
}
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Factories — return fail-closed skeletons the teams replace method-by-method.
|
|
72
|
+
// ---------------------------------------------------------------------------
|
|
73
|
+
/**
|
|
74
|
+
* The fail-closed default a query method throws when it has no implementation yet.
|
|
75
|
+
* A THROW (not an empty result) so a not-yet-built query surfaces loudly in dev/CI
|
|
76
|
+
* rather than silently returning "no data" (which could read as "no access").
|
|
77
|
+
*/
|
|
78
|
+
function notImplementedQuery(method) {
|
|
79
|
+
throw new Error(`[admin-query] ${method} is not implemented yet — Team A fills this method (prelude skeleton).`);
|
|
80
|
+
}
|
|
81
|
+
/** The fail-closed default a command method returns when unimplemented — a DENY. */
|
|
82
|
+
function notImplementedCommand() {
|
|
83
|
+
return { ok: false, reason: 'not_implemented' };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create the admin QUERY service (Team A). The PRELUDE returns a skeleton whose
|
|
87
|
+
* methods FAIL CLOSED (throw `not_implemented`); Team A replaces each body.
|
|
88
|
+
* `deps` is captured for the real implementations.
|
|
89
|
+
*/
|
|
90
|
+
function createAdminQueryService(deps) {
|
|
91
|
+
// Captured for the team implementations; unused in the fail-closed skeleton.
|
|
92
|
+
void deps;
|
|
93
|
+
return {
|
|
94
|
+
async getCatalog() {
|
|
95
|
+
return notImplementedQuery('getCatalog');
|
|
96
|
+
},
|
|
97
|
+
async listUnclassified() {
|
|
98
|
+
return notImplementedQuery('listUnclassified');
|
|
99
|
+
},
|
|
100
|
+
async explain() {
|
|
101
|
+
return notImplementedQuery('explain');
|
|
102
|
+
},
|
|
103
|
+
async simulate() {
|
|
104
|
+
// ⛔ Team A: forward to deps.decide.decide(...) — the ONE path (ADR-0001).
|
|
105
|
+
return notImplementedQuery('simulate');
|
|
106
|
+
},
|
|
107
|
+
async auditView() {
|
|
108
|
+
return notImplementedQuery('auditView');
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Create the admin COMMAND service (Team B). The PRELUDE returns a skeleton whose
|
|
114
|
+
* methods FAIL CLOSED (return a `not_implemented` DENY); Team B replaces each body,
|
|
115
|
+
* routing through {@link runCommandPipeline} with `deps.decide` + the stores +
|
|
116
|
+
* `deps.audit`. `deps` is captured for the real implementations.
|
|
117
|
+
*/
|
|
118
|
+
function createAdminCommandService(deps) {
|
|
119
|
+
// Captured for the team implementations; unused in the fail-closed skeleton.
|
|
120
|
+
void deps;
|
|
121
|
+
return {
|
|
122
|
+
async curatePermission() {
|
|
123
|
+
return notImplementedCommand();
|
|
124
|
+
},
|
|
125
|
+
async grant() {
|
|
126
|
+
return notImplementedCommand();
|
|
127
|
+
},
|
|
128
|
+
async revoke() {
|
|
129
|
+
return notImplementedCommand();
|
|
130
|
+
},
|
|
131
|
+
async authorPolicy() {
|
|
132
|
+
return notImplementedCommand();
|
|
133
|
+
},
|
|
134
|
+
async setTier() {
|
|
135
|
+
return notImplementedCommand();
|
|
136
|
+
},
|
|
137
|
+
async createServiceAccount() {
|
|
138
|
+
return notImplementedCommand();
|
|
139
|
+
},
|
|
140
|
+
async scopeServiceAccount() {
|
|
141
|
+
return notImplementedCommand();
|
|
142
|
+
},
|
|
143
|
+
async rotateServiceAccountCredential() {
|
|
144
|
+
return notImplementedCommand();
|
|
145
|
+
},
|
|
146
|
+
async revokeServiceAccount() {
|
|
147
|
+
return notImplementedCommand();
|
|
148
|
+
},
|
|
149
|
+
async setServiceAccountExpiry() {
|
|
150
|
+
return notImplementedCommand();
|
|
151
|
+
},
|
|
152
|
+
async createInvitation() {
|
|
153
|
+
return notImplementedCommand();
|
|
154
|
+
},
|
|
155
|
+
async transitionInvitation() {
|
|
156
|
+
return notImplementedCommand();
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
}
|
|
@@ -0,0 +1,200 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Team B commands — **grant / revoke** (AC 4, AC 7).
|
|
4
|
+
*
|
|
5
|
+
* grant: bind a principal to a permission with an action subset (+ optional guided
|
|
6
|
+
* conditions), scoped to a tenant. Routes the full §11.3 pipeline — the
|
|
7
|
+
* delegated-admin gate (the admin can only grant what THEY hold, reused via
|
|
8
|
+
* decide()) → validate the action subset + conditions → mutate via {@link GrantStore}
|
|
9
|
+
* → audit. Additive → no confirm token required.
|
|
10
|
+
*
|
|
11
|
+
* revoke: remove a grant by id. DESTRUCTIVE — the pipeline requires a confirm token
|
|
12
|
+
* + computes the blast-radius (threaded into the audit event) before the store
|
|
13
|
+
* removes it. Idempotent at the store (a second revoke is a no-op).
|
|
14
|
+
*
|
|
15
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.makeGrant = makeGrant;
|
|
19
|
+
exports.makeRevoke = makeRevoke;
|
|
20
|
+
exports.extractHasConfirm = extractHasConfirm;
|
|
21
|
+
const reason_codes_js_1 = require("../../authorization/reason-codes.js");
|
|
22
|
+
const policies_js_1 = require("./policies.js");
|
|
23
|
+
const pipeline_js_1 = require("./pipeline.js");
|
|
24
|
+
let grantSeq = 0;
|
|
25
|
+
function defaultId() {
|
|
26
|
+
grantSeq += 1;
|
|
27
|
+
return `grant-${String(grantSeq)}-${String(Date.now())}`;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validate the guided conditions on a grant (structured field→operator→value only,
|
|
31
|
+
* no raw expression). An unknown/malformed condition rejects `invalid_policy` (the
|
|
32
|
+
* guided-builder invariant applies to grant conditions too, §3.4). We validate the
|
|
33
|
+
* SHAPE here; field-vs-registry validation is the policy validator's job and is
|
|
34
|
+
* applied when the grant declares a target object type via its permission key.
|
|
35
|
+
*/
|
|
36
|
+
function conditionsWellFormed(conditions) {
|
|
37
|
+
if (conditions === undefined) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
if (!Array.isArray(conditions)) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
return conditions.every((c) => (0, policies_js_1.isValidCondition)(c));
|
|
44
|
+
}
|
|
45
|
+
function makeGrant(deps) {
|
|
46
|
+
const clock = deps.now ?? Date.now;
|
|
47
|
+
const mint = deps.newId ?? defaultId;
|
|
48
|
+
return async function grant(inMutation, command) {
|
|
49
|
+
// ⛔ RULING 1 — SINGLE-SOURCE THE SAFEGUARD TENANT (braces).
|
|
50
|
+
// The grant LANDS in `command.tenantId` (the store write below). The delegated-
|
|
51
|
+
// admin safeguard + the `unilateral_cross_tenant` gate MUST evaluate that SAME
|
|
52
|
+
// landing tenant — never a caller-independent `inMutation.targetTenantId`, which
|
|
53
|
+
// could name a DIFFERENT tenant the admin does hold authority in (the escalation:
|
|
54
|
+
// targetTenantId=t1 passes the safeguard, command.tenantId=t2 lands the grant in
|
|
55
|
+
// the victim). Deriving `targetTenantId` from the write target closes the desync
|
|
56
|
+
// at its root: the own-authority `decide()` resource tenant (safeguards-impl.ts)
|
|
57
|
+
// and the cross-tenant gate now both see `command.tenantId`.
|
|
58
|
+
const mutation = (0, pipeline_js_1.withPayload)({ ...inMutation, targetTenantId: command.tenantId }, {
|
|
59
|
+
principalId: command.principalId,
|
|
60
|
+
permissionKey: command.permissionKey,
|
|
61
|
+
actions: command.actions,
|
|
62
|
+
tenantId: command.tenantId,
|
|
63
|
+
...(command.conditions !== undefined ? { conditions: command.conditions } : {}),
|
|
64
|
+
});
|
|
65
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
66
|
+
mutation,
|
|
67
|
+
hasConfirmToken: true, // additive — no confirm required
|
|
68
|
+
validate: () => {
|
|
69
|
+
if (typeof command.principalId !== 'string' ||
|
|
70
|
+
command.principalId.length === 0 ||
|
|
71
|
+
typeof command.permissionKey !== 'string' ||
|
|
72
|
+
command.permissionKey.length === 0 ||
|
|
73
|
+
typeof command.tenantId !== 'string' ||
|
|
74
|
+
command.tenantId.length === 0) {
|
|
75
|
+
return { ok: false, reason: 'not_found' };
|
|
76
|
+
}
|
|
77
|
+
// ⛔ RULING 1 — EXPLICIT CONSISTENCY GATE (belt). Reject fail-closed when
|
|
78
|
+
// the caller's declared `targetTenantId` disagrees with the tenant the
|
|
79
|
+
// grant actually lands in (`command.tenantId`). Mirrors createInvitation's
|
|
80
|
+
// owningTenantId !== targetTenantId gate (invitations.ts). Redundant with
|
|
81
|
+
// the single-source above (the safeguard already denies), but present so a
|
|
82
|
+
// FUTURE refactor that re-desyncs the two tenants is still caught here.
|
|
83
|
+
if (inMutation.targetTenantId !== command.tenantId) {
|
|
84
|
+
return {
|
|
85
|
+
ok: false,
|
|
86
|
+
reason: 'unilateral_cross_tenant',
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
if (!Array.isArray(command.actions) || command.actions.length === 0) {
|
|
90
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
91
|
+
}
|
|
92
|
+
if (command.actions.some((a) => typeof a !== 'string' || a.length === 0)) {
|
|
93
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
94
|
+
}
|
|
95
|
+
if (!conditionsWellFormed(command.conditions)) {
|
|
96
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
97
|
+
}
|
|
98
|
+
return null;
|
|
99
|
+
},
|
|
100
|
+
mutate: async () => {
|
|
101
|
+
await deps.grantStore.saveGrant({
|
|
102
|
+
grantId: mint(),
|
|
103
|
+
principalId: command.principalId,
|
|
104
|
+
permissionKey: command.permissionKey,
|
|
105
|
+
actions: command.actions,
|
|
106
|
+
...(command.conditions !== undefined
|
|
107
|
+
? { conditions: command.conditions }
|
|
108
|
+
: {}),
|
|
109
|
+
tenantId: command.tenantId,
|
|
110
|
+
});
|
|
111
|
+
},
|
|
112
|
+
emitAudit: async (_value, blastRadius) => {
|
|
113
|
+
const principalLabel = await deps.labels.resolve('principal', command.principalId, command.tenantId);
|
|
114
|
+
const permissionLabel = await deps.labels.resolve('permission', command.permissionKey, command.tenantId);
|
|
115
|
+
await deps.audit.record({
|
|
116
|
+
type: 'admin_action',
|
|
117
|
+
occurredAtMs: clock(),
|
|
118
|
+
actorId: mutation.admin.id,
|
|
119
|
+
// ⛔ RULING 1 — AUDIT THE LANDING TENANT. The trail must attribute the
|
|
120
|
+
// grant to the tenant it actually landed in (`command.tenantId`), not a
|
|
121
|
+
// desynced safeguard tenant. After the single-source above this equals
|
|
122
|
+
// `mutation.targetTenantId`, but we name the write target directly so the
|
|
123
|
+
// record stays truthful independent of how the mutation was assembled.
|
|
124
|
+
tenantId: command.tenantId,
|
|
125
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
126
|
+
action: 'grant',
|
|
127
|
+
principalLabel,
|
|
128
|
+
permissionLabel,
|
|
129
|
+
grantedActions: command.actions,
|
|
130
|
+
}),
|
|
131
|
+
});
|
|
132
|
+
},
|
|
133
|
+
}, deps.decide);
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
function makeRevoke(deps) {
|
|
137
|
+
const clock = deps.now ?? Date.now;
|
|
138
|
+
return async function revoke(mutation, grantId) {
|
|
139
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
140
|
+
mutation,
|
|
141
|
+
// DESTRUCTIVE — the pipeline enforces the confirm token at step 3; the
|
|
142
|
+
// caller signals it via the mutation payload's confirm flag (assembled by
|
|
143
|
+
// the service). Here we surface whether a token was presented.
|
|
144
|
+
hasConfirmToken: extractHasConfirm(mutation),
|
|
145
|
+
validate: async () => {
|
|
146
|
+
if (typeof grantId !== 'string' || grantId.length === 0) {
|
|
147
|
+
return { ok: false, reason: 'not_found' };
|
|
148
|
+
}
|
|
149
|
+
// ⛔ RULING 2 (round 2) — CROSS-TENANT REVOKE GATE. `revoke` is NOT
|
|
150
|
+
// authority-bounded (the delegated gate passes it through) and the
|
|
151
|
+
// `grantId` is an OPAQUE handle that can address a grant in ANOTHER
|
|
152
|
+
// tenant. Resolve the target grant's OWNING tenant and gate it against
|
|
153
|
+
// the admin's authority tenant (`mutation.targetTenantId`) — EXACTLY as
|
|
154
|
+
// every `service_account_*` command gates `existing.tenantId !==
|
|
155
|
+
// mutation.targetTenantId` (service-accounts.ts). A non-root
|
|
156
|
+
// revoking a foreign-tenant grant is refused `unilateral_cross_tenant`;
|
|
157
|
+
// a root bypasses (may revoke cross-tenant). A grant that does not
|
|
158
|
+
// resolve (unknown/absent handle) FAILS CLOSED — a deny, never a silent
|
|
159
|
+
// ok — so a bogus/foreign id can never slip through unchecked.
|
|
160
|
+
const existing = await deps.grantStore.getGrant(grantId);
|
|
161
|
+
if (existing === null) {
|
|
162
|
+
return { ok: false, reason: 'not_found' };
|
|
163
|
+
}
|
|
164
|
+
if (!(0, reason_codes_js_1.strictTrue)(mutation.admin.isRoot) &&
|
|
165
|
+
existing.tenantId !== mutation.targetTenantId) {
|
|
166
|
+
return {
|
|
167
|
+
ok: false,
|
|
168
|
+
reason: 'unilateral_cross_tenant',
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return null;
|
|
172
|
+
},
|
|
173
|
+
mutate: async () => {
|
|
174
|
+
await deps.grantStore.revokeGrant(grantId);
|
|
175
|
+
},
|
|
176
|
+
emitAudit: async (_value, blastRadius) => {
|
|
177
|
+
await deps.audit.record({
|
|
178
|
+
type: 'admin_action',
|
|
179
|
+
occurredAtMs: clock(),
|
|
180
|
+
actorId: mutation.admin.id,
|
|
181
|
+
tenantId: mutation.targetTenantId,
|
|
182
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
183
|
+
action: 'revoke',
|
|
184
|
+
grantId,
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
}, deps.decide);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Read the confirm flag from a destructive command's mutation payload. The service
|
|
193
|
+
* assembler places `{ confirm: ConfirmToken }` on the payload for destructive
|
|
194
|
+
* commands; a valid confirm token has `confirmed === true` (strict). Any other
|
|
195
|
+
* shape → no confirm token presented.
|
|
196
|
+
*/
|
|
197
|
+
function extractHasConfirm(mutation) {
|
|
198
|
+
const payload = mutation.payload;
|
|
199
|
+
return payload?.confirm?.confirmed === true;
|
|
200
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Team B COMMAND-engine barrel (Layer 10). Re-exports the real command service
|
|
4
|
+
* factory, the per-command builders, the guided-policy validator, the §11.3
|
|
5
|
+
* pipeline runner, and the invitation state-machine helpers.
|
|
6
|
+
*
|
|
7
|
+
* ⛔ INTEGRATION NOTE. The frozen `../index.ts` (admin barrel) does NOT yet
|
|
8
|
+
* re-export this module (it is append-only and Team-B-owned files were not known
|
|
9
|
+
* when it was frozen). The integration owner appends
|
|
10
|
+
* `export * from './command/index.js';` and `export * from './safeguards-impl.js';`
|
|
11
|
+
* to `../index.ts` to surface these on the package barrel — see team-b/DONE.md.
|
|
12
|
+
* Until then, consumers import from `@astram/core/.../admin/command/index.js`.
|
|
13
|
+
*
|
|
14
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
15
|
+
*/
|
|
16
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
17
|
+
if (k2 === undefined) k2 = k;
|
|
18
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
19
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
20
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
21
|
+
}
|
|
22
|
+
Object.defineProperty(o, k2, desc);
|
|
23
|
+
}) : (function(o, m, k, k2) {
|
|
24
|
+
if (k2 === undefined) k2 = k;
|
|
25
|
+
o[k2] = m[k];
|
|
26
|
+
}));
|
|
27
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
28
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
29
|
+
};
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
__exportStar(require("./pipeline.js"), exports);
|
|
32
|
+
__exportStar(require("./permissions.js"), exports);
|
|
33
|
+
__exportStar(require("./grants.js"), exports);
|
|
34
|
+
__exportStar(require("./policies.js"), exports);
|
|
35
|
+
__exportStar(require("./tiers.js"), exports);
|
|
36
|
+
__exportStar(require("./service-accounts.js"), exports);
|
|
37
|
+
__exportStar(require("./invitations.js"), exports);
|
|
38
|
+
__exportStar(require("./service.js"), exports);
|