@astram/core 1.1.0 → 1.3.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.
Files changed (74) hide show
  1. package/dist/authentication/index.d.ts +1 -0
  2. package/dist/authentication/index.d.ts.map +1 -1
  3. package/dist/authentication/index.js +2 -0
  4. package/dist/authentication/index.js.map +1 -1
  5. package/dist/authentication/service-account-authenticator.d.ts +82 -0
  6. package/dist/authentication/service-account-authenticator.d.ts.map +1 -0
  7. package/dist/authentication/service-account-authenticator.js +74 -0
  8. package/dist/authentication/service-account-authenticator.js.map +1 -0
  9. package/dist/authorization/gates/object-type.d.ts.map +1 -1
  10. package/dist/authorization/gates/object-type.js +17 -8
  11. package/dist/authorization/gates/object-type.js.map +1 -1
  12. package/dist/authorization/gates/tenant.d.ts +7 -4
  13. package/dist/authorization/gates/tenant.d.ts.map +1 -1
  14. package/dist/authorization/gates/tenant.js +30 -7
  15. package/dist/authorization/gates/tenant.js.map +1 -1
  16. package/dist/authorization/index.d.ts +1 -0
  17. package/dist/authorization/index.d.ts.map +1 -1
  18. package/dist/authorization/index.js +2 -0
  19. package/dist/authorization/index.js.map +1 -1
  20. package/dist/authorization/ports.d.ts +65 -0
  21. package/dist/authorization/ports.d.ts.map +1 -1
  22. package/dist/authorization/record/list-scope.d.ts +198 -0
  23. package/dist/authorization/record/list-scope.d.ts.map +1 -0
  24. package/dist/authorization/record/list-scope.js +153 -0
  25. package/dist/authorization/record/list-scope.js.map +1 -0
  26. package/dist/encryption/encryption-service.d.ts +63 -0
  27. package/dist/encryption/encryption-service.d.ts.map +1 -0
  28. package/dist/encryption/encryption-service.js +184 -0
  29. package/dist/encryption/encryption-service.js.map +1 -0
  30. package/dist/encryption/index.d.ts +17 -0
  31. package/dist/encryption/index.d.ts.map +1 -0
  32. package/dist/encryption/index.js +15 -0
  33. package/dist/encryption/index.js.map +1 -0
  34. package/dist/encryption/ports.d.ts +84 -0
  35. package/dist/encryption/ports.d.ts.map +1 -0
  36. package/dist/encryption/ports.js +18 -0
  37. package/dist/encryption/ports.js.map +1 -0
  38. package/dist/identity/broker.d.ts.map +1 -1
  39. package/dist/identity/broker.js +6 -0
  40. package/dist/identity/broker.js.map +1 -1
  41. package/dist/identity/index.d.ts +16 -1
  42. package/dist/identity/index.d.ts.map +1 -1
  43. package/dist/identity/index.js.map +1 -1
  44. package/dist/index.d.ts +2 -0
  45. package/dist/index.d.ts.map +1 -1
  46. package/dist/index.js +2 -0
  47. package/dist/index.js.map +1 -1
  48. package/dist/secrets/index.d.ts +15 -0
  49. package/dist/secrets/index.d.ts.map +1 -0
  50. package/dist/secrets/index.js +14 -0
  51. package/dist/secrets/index.js.map +1 -0
  52. package/dist/secrets/ports.d.ts +45 -0
  53. package/dist/secrets/ports.d.ts.map +1 -0
  54. package/dist/secrets/ports.js +26 -0
  55. package/dist/secrets/ports.js.map +1 -0
  56. package/dist/secrets/resolve.d.ts +29 -0
  57. package/dist/secrets/resolve.d.ts.map +1 -0
  58. package/dist/secrets/resolve.js +49 -0
  59. package/dist/secrets/resolve.js.map +1 -0
  60. package/dist-cjs/authentication/index.js +2 -0
  61. package/dist-cjs/authentication/service-account-authenticator.js +78 -0
  62. package/dist-cjs/authorization/gates/object-type.js +17 -8
  63. package/dist-cjs/authorization/gates/tenant.js +30 -7
  64. package/dist-cjs/authorization/index.js +2 -0
  65. package/dist-cjs/authorization/record/list-scope.js +155 -0
  66. package/dist-cjs/encryption/encryption-service.js +189 -0
  67. package/dist-cjs/encryption/index.js +20 -0
  68. package/dist-cjs/encryption/ports.js +18 -0
  69. package/dist-cjs/identity/broker.js +6 -0
  70. package/dist-cjs/index.js +2 -0
  71. package/dist-cjs/secrets/index.js +21 -0
  72. package/dist-cjs/secrets/ports.js +29 -0
  73. package/dist-cjs/secrets/resolve.js +54 -0
  74. package/package.json +1 -1
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Engine seam: **Encryption** — per-tenant envelope encryption for data at rest (ADR-0031).
3
+ *
4
+ * `createEncryptionService` encrypts/decrypts a tenant's data with that tenant's own DEK; DEKs are
5
+ * wrapped by a KMS-held KEK and only wrapped DEKs are ever persisted. Pure + zero-dep (ADR-0003):
6
+ * crypto/KMS/persistence are injected ports, shipped as adapters in `@astram/guard`.
7
+ *
8
+ * THREAT MODEL (ADR-0031, stated honestly): defends the STORAGE boundary (stolen disk / DB dump /
9
+ * backup / leaked bucket → only ciphertext + wrapped DEKs). Does NOT defend a compromised app host
10
+ * or a compromised KMS. See `docs/Shield/140_Security_Hardening` + ADR-0031.
11
+ *
12
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB imports.
13
+ */
14
+ export { createEncryptionService, DecryptionError, EncryptionError, } from './encryption-service.js';
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/encryption/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAYH,OAAO,EACL,uBAAuB,EACvB,eAAe,EACf,eAAe,GAChB,MAAM,yBAAyB,CAAC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Encryption engine PORTS — the framework-agnostic contracts the {@link EncryptionService} uses,
3
+ * WITHOUT the engine ever knowing the algorithm, the KMS, or where wrapped DEKs are stored.
4
+ *
5
+ * ADR-0031 (envelope encryption / per-tenant DEKs) + ADR-0003 (zero-dep core): real crypto needs a
6
+ * library + native bindings and a KMS needs network/SDK — neither can live in `@astram/core`. The
7
+ * core defines only these interfaces; `@astram/guard` ships the concrete AEAD + KMS + DEK-store
8
+ * adapters and INJECTS them into `createEncryptionService`. Core stays at ZERO runtime deps.
9
+ *
10
+ * THREAT MODEL (ADR-0031, honest): this defends the STORAGE boundary (stolen disk / DB dump /
11
+ * backup / leaked bucket → only ciphertext + wrapped DEKs). It does NOT defend a compromised app
12
+ * host (the app must hold a tenant's DEK in memory to serve it) or a compromised KMS.
13
+ *
14
+ * SECURITY: no port implementation may log a plaintext, a DEK, or a plaintext key. DEKs and
15
+ * plaintext are transient inputs; they are never surfaced in a result, a reason, or a log.
16
+ */
17
+ /** An opaque data-encryption key (raw bytes). NEVER persisted in plaintext; NEVER logged. */
18
+ export type Dek = Uint8Array;
19
+ /** A DEK wrapped (encrypted) by the KEK — the ONLY form of a DEK that may be persisted. */
20
+ export type WrappedDek = Uint8Array;
21
+ /** Self-describing AEAD ciphertext (algorithm + nonce + tag + body). Opaque to the engine. */
22
+ export type Ciphertext = Uint8Array;
23
+ /**
24
+ * The cryptographic primitives, delegated to the adapter (AEAD in-process; KEK ops to a KMS). The
25
+ * engine composes these; it never sees the KEK and never picks an algorithm.
26
+ */
27
+ export interface CryptoPort {
28
+ /** A fresh, cryptographically-random DEK. */
29
+ generateDek(): Promise<Dek>;
30
+ /**
31
+ * Wrap (encrypt) a DEK with the tenant's KEK — a KMS operation in production. `tenantId` scopes
32
+ * the KEK / is bound so a wrapped DEK is meaningful only for that tenant.
33
+ */
34
+ wrapDek(dek: Dek, tenantId: string): Promise<WrappedDek>;
35
+ /** Unwrap (decrypt) a wrapped DEK with the tenant's KEK. Throws if the KEK can't unwrap it. */
36
+ unwrapDek(wrapped: WrappedDek, tenantId: string): Promise<Dek>;
37
+ /**
38
+ * Authenticated encryption of `plaintext` under `dek`. The `tenantId` MUST be bound as AAD so a
39
+ * ciphertext produced for one tenant cannot be decrypted as another (cross-tenant replay guard).
40
+ * Output is self-describing (algorithm + nonce + tag).
41
+ */
42
+ encrypt(plaintext: Uint8Array, dek: Dek, tenantId: string): Promise<Ciphertext>;
43
+ /**
44
+ * Authenticated decryption. MUST verify the AEAD tag AND the bound `tenantId` (AAD). A tag or
45
+ * AAD mismatch MUST throw — never return partial/garbage plaintext (fail-closed). Throws on any
46
+ * malformed ciphertext.
47
+ */
48
+ decrypt(ciphertext: Ciphertext, dek: Dek, tenantId: string): Promise<Uint8Array>;
49
+ }
50
+ /** A persisted wrapped-DEK record — ONLY the wrapped key + metadata; never a plaintext DEK. */
51
+ export interface WrappedDekRecord {
52
+ readonly tenantId: string;
53
+ /** Monotonic key version for the tenant (rotation increments it; highest is current). */
54
+ readonly version: number;
55
+ readonly wrapped: WrappedDek;
56
+ }
57
+ /**
58
+ * Persists wrapped DEKs (guard adapter → a dedicated table). The store NEVER holds a plaintext
59
+ * DEK. Unique on `(tenantId, version)`. Fail-closed: a load failure throws (never returns "no key"
60
+ * to mask an outage — the engine must distinguish "tenant has no DEK yet" from "store is down").
61
+ */
62
+ export interface DekStore {
63
+ /** The CURRENT (highest-version) wrapped DEK for a tenant, or `null` if the tenant has none. */
64
+ getCurrent(tenantId: string): Promise<WrappedDekRecord | null>;
65
+ /** A specific version's wrapped DEK (for decrypting data written under an older key), or `null`. */
66
+ getVersion(tenantId: string, version: number): Promise<WrappedDekRecord | null>;
67
+ /** Persist a new wrapped DEK at `version` for a tenant (atomic; unique per (tenant,version)). */
68
+ put(record: WrappedDekRecord): Promise<void>;
69
+ /**
70
+ * Permanently destroy ALL wrapped DEKs for a tenant (crypto-shred on offboard — the tenant's
71
+ * at-rest data becomes unrecoverable). Idempotent.
72
+ */
73
+ destroy(tenantId: string): Promise<void>;
74
+ }
75
+ /**
76
+ * A short-lived, memory-only cache of UNWRAPPED DEKs so the hot path unwraps at most once per
77
+ * tenant per TTL. NEVER persisted, NEVER logged. TTL-bounded. A miss is not an error.
78
+ */
79
+ export interface DekCache {
80
+ get(tenantId: string): Dek | undefined;
81
+ put(tenantId: string, dek: Dek): void;
82
+ evict(tenantId: string): void;
83
+ }
84
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/encryption/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,6FAA6F;AAC7F,MAAM,MAAM,GAAG,GAAG,UAAU,CAAC;AAE7B,2FAA2F;AAC3F,MAAM,MAAM,UAAU,GAAG,UAAU,CAAC;AAEpC,8FAA8F;AAC9F,MAAM,MAAM,UA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AAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC1C;AAED;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,GAAG,GAAG,SAAS,CAAC;IACvC,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,IAAI,CAAC;IACtC,KAAK,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Encryption engine PORTS — the framework-agnostic contracts the {@link EncryptionService} uses,
3
+ * WITHOUT the engine ever knowing the algorithm, the KMS, or where wrapped DEKs are stored.
4
+ *
5
+ * ADR-0031 (envelope encryption / per-tenant DEKs) + ADR-0003 (zero-dep core): real crypto needs a
6
+ * library + native bindings and a KMS needs network/SDK — neither can live in `@astram/core`. The
7
+ * core defines only these interfaces; `@astram/guard` ships the concrete AEAD + KMS + DEK-store
8
+ * adapters and INJECTS them into `createEncryptionService`. Core stays at ZERO runtime deps.
9
+ *
10
+ * THREAT MODEL (ADR-0031, honest): this defends the STORAGE boundary (stolen disk / DB dump /
11
+ * backup / leaked bucket → only ciphertext + wrapped DEKs). It does NOT defend a compromised app
12
+ * host (the app must hold a tenant's DEK in memory to serve it) or a compromised KMS.
13
+ *
14
+ * SECURITY: no port implementation may log a plaintext, a DEK, or a plaintext key. DEKs and
15
+ * plaintext are transient inputs; they are never surfaced in a result, a reason, or a log.
16
+ */
17
+ export {};
18
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/encryption/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
@@ -1 +1 @@
1
- {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAYpB,2EAA2E;AAC3E,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,EAAE,MAAM;CAI5B;AA8FD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAkBhB"}
1
+ {"version":3,"file":"broker.d.ts","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EACL,KAAK,mBAAmB,EAEzB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAEL,KAAK,cAAc,EAGpB,MAAM,YAAY,CAAC;AAYpB,2EAA2E;AAC3E,qBAAa,0BAA2B,SAAQ,KAAK;gBACvC,OAAO,EAAE,MAAM;CAI5B;AAoGD,gDAAgD;AAChD,MAAM,WAAW,2BAA2B;IAC1C;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAAE,CAAC;IAClD;;;;OAIG;IACH,QAAQ,CAAC,eAAe,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC9C;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,2BAAgC,GACxC,cAAc,CAkBhB"}
@@ -91,9 +91,15 @@ class BrokerImpl {
91
91
  // any raw claim here, so an attacker-controllable `superuser`/`isPlatformSuperuser`
92
92
  // claim cannot influence this value.
93
93
  const isRoot = candidate.trustedRootSignal === true;
94
+ // Scope (ADR-0027) — INTERIM default (Task 2.1): the active scope node IS the home
95
+ // tenant, and the reachable subtree is JUST that self-node (`[tenantId]`). This
96
+ // reproduces today's flat self-tenant isolation EXACTLY (non-widening) until Task 2.2
97
+ // populates the real closure-resolved subtree (self + descendants) at session establishment.
94
98
  return Object.freeze({
95
99
  kind,
96
100
  id,
101
+ activeScopeNodeId: tenantId,
102
+ scopeSubtreeNodeIds: Object.freeze([tenantId]),
97
103
  tenantId,
98
104
  roleIds,
99
105
  isRoot,
@@ -1 +1 @@
1
- {"version":3,"file":"broker.js","sourceRoot":"","sources":["../../src/identity/broker.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAEL,2BAA2B,GAC5B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,6BAA6B,EAAE,MAAM,uBAAuB,CAAC;AAQtE,iFAAiF;AACjF,MAAM,qBAAqB,GAA+B,IAAI,GAAG,CAAgB;IAC/E,MAAM;IACN,YAAY;IACZ,iBAAiB;CAClB,CAAC,CAAC;AAEH,8DAA8D;AAC9D,MAAM,sBAAsB,GAAkB,MAAM,CAAC;AAErD,2EAA2E;AAC3E,MAAM,OAAO,0BAA2B,SAAQ,KAAK;IACnD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,4BAA4B,CAAC;IAC3C,CAAC;CACF;AAED;;;GAGG;AACH,MAAM,UAAU;IACe;IAA7B,YAA6B,QAAqC;QAArC,aAAQ,GAAR,QAAQ,CAA6B;IAAG,CAAC;IAEtE,KAAK,CAAC,SAAS,CAAC,SAAoC;QAClD,8EAA8E;QAC9E,0EAA0E;QAC1E,sEAAsE;QACtE,2EAA2E;QAC3E,IAAI,SAAS,KAAK,IAAI,IAAI,OAAO,SAAS,KAAK,QAAQ,EAAE,CAAC;YACxD,MAAM,IAAI,0BAA0B,CAClC,4EAA4E,CAC7E,CAAC;QACJ,CAAC;QAED,4EA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,iBAAiB,EAAE,QAAQ;YAC3B,mBAAmB,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC,QAAQ,CAAC,CAAC;YAC9C,QAAQ;YACR,OAAO;YACP,MAAM;SACP,CAAC,CAAC;IACL,CAAC;IAED,8EAA8E;IACtE,WAAW,CACjB,aAAiC,EACjC,EAAU,EACV,MAAc;QAEd,IAAI,aAAa,KAAK,SAAS;YAAE,OAAO,sBAAsB,CAAC;QAC/D,IAAI,CAAC,qBAAqB,CAAC,GAAG,CAAC,aAA8B,CAAC,EAAE,CAAC;YAC/D,MAAM,IAAI,0BAA0B,CAClC,yBAAyB,EAAE,WAAW,MAAM,uBAAuB,aAAa,wDAAwD,CACzI,CAAC;QACJ,CAAC;QACD,OAAO,aAA8B,CAAC;IACxC,CAAC;CACF;AAmBD;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,UAAuC,EAAE;IAEzC,MAAM,QAAQ,GAAG,IAAI,2BAA2B,EAAE,CAAC;IAEnD,IAAI,OAAO,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAClC,QAAQ,CAAC,QAAQ,CACf,6BAA6B,CAC3B,OAAO,CAAC,eAAe,KAAK,SAAS;YACnC,CAAC,CAAC,EAAE,OAAO,EAAE,OAAO,CAAC,eAAe,EAAE;YACtC,CAAC,CAAC,EAAE,CACP,CACF,CAAC;IACJ,CAAC;SAAM,CAAC;QACN,KAAK,MAAM,MAAM,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;YACrC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IAED,OAAO,IAAI,UAAU,CAAC,QAAQ,CAAC,CAAC;AAClC,CAAC"}
@@ -29,7 +29,22 @@ export interface Principal {
29
29
  readonly kind: PrincipalKind;
30
30
  /** Stable opaque id (internal — never rendered to end users). */
31
31
  readonly id: string;
32
- /** The principal's home tenant — the default boundary for the tenant gate. */
32
+ /**
33
+ * The principal's ACTIVE SCOPE NODE — the node (company/tenant) the principal is currently
34
+ * acting under (ADR-0027). Historically "the home tenant"; under the scoped hierarchy it is the
35
+ * active binding's node. `tenantId` (below) is kept as an ALIAS of this for backward compatibility.
36
+ */
37
+ readonly activeScopeNodeId: string;
38
+ /**
39
+ * The active scope node + ALL its descendants (the reachable subtree), resolved ONCE at session
40
+ * establishment / scope-switch from `scope_closure` and CACHED (ADR-0011/0013) — NOT recomputed per
41
+ * request. The tenant gate (gate 3) tests `resource.tenantId ∈ scopeSubtreeNodeIds` as an in-memory
42
+ * set-membership check (zero per-request DB — the ADR-0024 parity guarantee). FAIL-CLOSED: an EMPTY
43
+ * array means "no reachable scope" → the tenant gate denies every foreign-node resource (a principal
44
+ * with no resolved subtree sees only same-node resources via the alias, and nothing cross-node).
45
+ */
46
+ readonly scopeSubtreeNodeIds: readonly string[];
47
+ /** The principal's home/active tenant — ALIAS of `activeScopeNodeId` (ADR-0027, back-compat). */
33
48
  readonly tenantId: string;
34
49
  /** Roles / groups this principal belongs to, by stable id. */
35
50
  readonly roleIds: readonly string[];
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,0EAA0E;AAC1E,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,YAAY,GAAG,iBAAiB,CAAC;AAEtE,2EAA2E;AAC3E,MAAM,WAAW,MAAM;IACrB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,kEAAkE;IAClE,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;CAC9B;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,iEAAiE;IACjE,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,8EAA8E;IAC9E,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,8DAA8D;IAC9D,QAA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AC,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC;CAC1B;AAED,sEAAsE;AACtE,MAAM,WAAW,yBAAyB;IACxC,yEAAyE;IACzE,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACpD;AAED;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,wEAAwE;IACxE,SAAS,CAAC,SAAS,EAAE,yBAAyB,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;CACrE;AAKD,cAAc,mBAAmB,CAAC;AAElC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,aAAa,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAgDH,gFAAgF;AAChF,6EAA6E;AAC7E,wBAAwB;AACxB,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,uBAAuB,CAAC;AACtC,gFAAgF;AAChF,cAAc,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA+DH,gFAAgF;AAChF,6EAA6E;AAC7E,wBAAwB;AACxB,cAAc,mBAAmB,CAAC;AAClC,wEAAwE;AACxE,cAAc,uBAAuB,CAAC;AACtC,gFAAgF;AAChF,cAAc,aAAa,CAAC"}
package/dist/index.d.ts CHANGED
@@ -38,6 +38,8 @@ export * from './session/index.js';
38
38
  export * from './risk/index.js';
39
39
  export * from './authorization/index.js';
40
40
  export * from './audit/index.js';
41
+ export * from './encryption/index.js';
42
+ export * from './secrets/index.js';
41
43
  export * from './metadata/index.js';
42
44
  export * from './admin/index.js';
43
45
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAGjC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAGH,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAGnC,cAAc,qBAAqB,CAAC;AAKpC,cAAc,kBAAkB,CAAC"}
package/dist/index.js CHANGED
@@ -39,6 +39,8 @@ export * from './session/index.js';
39
39
  export * from './risk/index.js';
40
40
  export * from './authorization/index.js';
41
41
  export * from './audit/index.js';
42
+ export * from './encryption/index.js';
43
+ export * from './secrets/index.js';
42
44
  // Module-registers-metadata contract + pure derivation rules + completeness check.
43
45
  export * from './metadata/index.js';
44
46
  // Admin Console (Layer 10) — a NEW top-level module (append-only; no frozen
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AAEjC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,kEAAkE;AAClE,cAAc,qBAAqB,CAAC;AACpC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC;AACtC,cAAc,oBAAoB,CAAC;AAEnC,mFAAmF;AACnF,cAAc,qBAAqB,CAAC;AAEpC,4EAA4E;AAC5E,iFAAiF;AACjF,6EAA6E;AAC7E,cAAc,kBAAkB,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Engine seam: **Secrets** — env holds references, credentials resolved at runtime + rotatable
3
+ * (ADR-0032). `secret-ref:<path>` in env is a pointer (safe to commit/log); `resolveSecretRefs`
4
+ * fetches the real value at boot via an injected `SecretsProvider`. Pure + zero-dep (ADR-0003);
5
+ * backends (encrypted on-box store now; Vault / AWS SM / GCP SM later) ship in `@astram/guard`.
6
+ *
7
+ * SECURITY: a secret value is never logged/surfaced (only paths + versions). Fail-closed: an
8
+ * unresolvable reference aborts boot; a literal value is unchanged (backward compatible).
9
+ *
10
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
11
+ */
12
+ export type { SecretPath, SecretsProvider } from './ports.js';
13
+ export { SecretNotFoundError } from './ports.js';
14
+ export { SECRET_REF_PREFIX, isSecretRef, secretRefPath, resolveSecretRefs, } from './resolve.js';
15
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/secrets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Engine seam: **Secrets** — env holds references, credentials resolved at runtime + rotatable
3
+ * (ADR-0032). `secret-ref:<path>` in env is a pointer (safe to commit/log); `resolveSecretRefs`
4
+ * fetches the real value at boot via an injected `SecretsProvider`. Pure + zero-dep (ADR-0003);
5
+ * backends (encrypted on-box store now; Vault / AWS SM / GCP SM later) ship in `@astram/guard`.
6
+ *
7
+ * SECURITY: a secret value is never logged/surfaced (only paths + versions). Fail-closed: an
8
+ * unresolvable reference aborts boot; a literal value is unchanged (backward compatible).
9
+ *
10
+ * ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
11
+ */
12
+ export { SecretNotFoundError } from './ports.js';
13
+ export { SECRET_REF_PREFIX, isSecretRef, secretRefPath, resolveSecretRefs, } from './resolve.js';
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/secrets/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEjD,OAAO,EACL,iBAAiB,EACjB,WAAW,EACX,aAAa,EACb,iBAAiB,GAClB,MAAM,cAAc,CAAC"}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Secrets provider PORT (ADR-0032) — the framework-agnostic contract for fetching + rotating
3
+ * credentials, so the runtime reads a REFERENCE from env (`secret-ref:db/prod/password`) and the
4
+ * real value is resolved at boot from a secrets backend, NEVER hard-coded in env/Git.
5
+ *
6
+ * ADR-0003 (zero-dep core): the backend is a real dependency (a network vault SDK, or an encrypted
7
+ * on-box store using node crypto) — it cannot live here. Core defines only this interface;
8
+ * `@astram/guard` ships the concrete backends (a reference encrypted on-box store now; Vault / AWS
9
+ * Secrets Manager / GCP Secret Manager as drop-in adapters) and INJECTS one. Core stays zero-dep.
10
+ *
11
+ * SECURITY: a secret VALUE is never logged, never in an error message, never in an audit record —
12
+ * only the PATH + version. A `SecretsProvider` implementation MUST likewise never log a value.
13
+ * Fail-closed: a missing secret THROWS (must never silently resolve to '' — that would start the
14
+ * app with a hole where a credential belongs).
15
+ */
16
+ /** A secret is addressed by an opaque path, e.g. `db/prod/password`. NOT the value; safe to log. */
17
+ export type SecretPath = string;
18
+ export interface SecretsProvider {
19
+ /**
20
+ * The CURRENT value of the secret at `path`. THROWS ({@link SecretNotFoundError}) if the secret
21
+ * does not exist — never returns '' or undefined to mask absence (fail-closed). MUST NOT log the
22
+ * value.
23
+ */
24
+ resolve(path: SecretPath): Promise<string>;
25
+ /**
26
+ * Store (create or overwrite) a secret value at `path`. Returns the new version. Used to seed a
27
+ * secret. MUST NOT log the value.
28
+ */
29
+ store(path: SecretPath, value: string): Promise<number>;
30
+ /**
31
+ * Rotate the secret at `path` to `newValue`, bumping its version (so a running app can detect the
32
+ * change and re-resolve). Returns the new version. The caller is responsible for applying the new
33
+ * value in the SOURCE system (e.g. the DB) FIRST — see the rotation flow in ADR-0032 §5. MUST NOT
34
+ * log the value.
35
+ */
36
+ rotate(path: SecretPath, newValue: string): Promise<number>;
37
+ /** The current version of a secret (for staleness / change detection), or 0 if it doesn't exist. */
38
+ currentVersion(path: SecretPath): Promise<number>;
39
+ }
40
+ /** Thrown by `resolve` when a referenced secret is absent — fail-closed (never a silent empty). */
41
+ export declare class SecretNotFoundError extends Error {
42
+ readonly cause?: unknown;
43
+ constructor(path: SecretPath, cause?: unknown);
44
+ }
45
+ //# sourceMappingURL=ports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/secrets/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,oGAAoG;AACpG,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC;AAEhC,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,OAAO,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3C;;;OAGG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAExD;;;;;OAKG;IACH,MAAM,CAAC,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE5D,oGAAoG;IACpG,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;CACnD;AAED,mGAAmG;AACnG,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBACtB,IAAI,EAAE,UAAU,EAAE,KAAK,CAAC,EAAE,OAAO;CAM9C"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Secrets provider PORT (ADR-0032) — the framework-agnostic contract for fetching + rotating
3
+ * credentials, so the runtime reads a REFERENCE from env (`secret-ref:db/prod/password`) and the
4
+ * real value is resolved at boot from a secrets backend, NEVER hard-coded in env/Git.
5
+ *
6
+ * ADR-0003 (zero-dep core): the backend is a real dependency (a network vault SDK, or an encrypted
7
+ * on-box store using node crypto) — it cannot live here. Core defines only this interface;
8
+ * `@astram/guard` ships the concrete backends (a reference encrypted on-box store now; Vault / AWS
9
+ * Secrets Manager / GCP Secret Manager as drop-in adapters) and INJECTS one. Core stays zero-dep.
10
+ *
11
+ * SECURITY: a secret VALUE is never logged, never in an error message, never in an audit record —
12
+ * only the PATH + version. A `SecretsProvider` implementation MUST likewise never log a value.
13
+ * Fail-closed: a missing secret THROWS (must never silently resolve to '' — that would start the
14
+ * app with a hole where a credential belongs).
15
+ */
16
+ /** Thrown by `resolve` when a referenced secret is absent — fail-closed (never a silent empty). */
17
+ export class SecretNotFoundError extends Error {
18
+ cause;
19
+ constructor(path, cause) {
20
+ // NOTE: includes the PATH (safe — a pointer, not a value), never the value.
21
+ super(`secret not found: '${path}'`);
22
+ this.name = 'SecretNotFoundError';
23
+ this.cause = cause;
24
+ }
25
+ }
26
+ //# sourceMappingURL=ports.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ports.js","sourceRoot":"","sources":["../../src/secrets/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA+BH,mGAAmG;AACnG,MAAM,OAAO,mBAAoB,SAAQ,KAAK;IAC1B,KAAK,CAAW;IAClC,YAAY,IAAgB,EAAE,KAAe;QAC3C,4EAA4E;QAC5E,KAAK,CAAC,sBAAsB,IAAI,GAAG,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;QAClC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IACrB,CAAC;CACF"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Secret-reference resolution (ADR-0032) — the PURE boot-time layer. An env value may be a
3
+ * reference `secret-ref:<path>` instead of a literal; this resolves every reference in an env-like
4
+ * bag via an injected {@link SecretsProvider}, producing a resolved bag the existing config loader
5
+ * consumes UNCHANGED. Zero-dep (ADR-0003) — no env/fs/network here; the provider does the fetching.
6
+ *
7
+ * FAIL-CLOSED: a reference that cannot be resolved ABORTS (throws) — the app never starts with a
8
+ * hole where a credential belongs. A LITERAL (no `secret-ref:` prefix) passes through untouched
9
+ * (full backward compatibility — a consumer not using references is unaffected).
10
+ *
11
+ * NO-LEAK: this never logs a resolved value; only paths/keys may appear in an error.
12
+ */
13
+ import type { SecretsProvider, SecretPath } from './ports.js';
14
+ /** The prefix that marks an env value as a secret REFERENCE (a pointer, safe to log/commit). */
15
+ export declare const SECRET_REF_PREFIX = "secret-ref:";
16
+ /** True if `value` is a secret reference (not a literal). */
17
+ export declare function isSecretRef(value: string | undefined): value is string;
18
+ /** Extract the secret path from a reference (`secret-ref:db/prod/pw` → `db/prod/pw`). */
19
+ export declare function secretRefPath(ref: string): SecretPath;
20
+ /**
21
+ * Resolve every `secret-ref:` value in `env` via `provider`, returning a NEW bag where references
22
+ * are replaced by their real values and literals are copied unchanged. Async (a fetch is I/O).
23
+ *
24
+ * Fail-closed: a reference with an EMPTY path, or one the provider cannot resolve, THROWS — the
25
+ * error names the ENV KEY + PATH (safe pointers), never the value. Non-string values are copied
26
+ * as-is. The input bag is not mutated.
27
+ */
28
+ export declare function resolveSecretRefs(env: Readonly<Record<string, string | undefined>>, provider: SecretsProvider): Promise<Record<string, string | undefined>>;
29
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/secrets/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAE9D,gGAAgG;AAChG,eAAO,MAAM,iBAAiB,gBAAgB,CAAC;AAE/C,6DAA6D;AAC7D,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,KAAK,IAAI,MAAM,CAEtE;AAED,yFAAyF;AACzF,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,UAAU,CAErD;AAED;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CACrC,GAAG,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,EACjD,QAAQ,EAAE,eAAe,GACxB,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC,CA2B7C"}
@@ -0,0 +1,49 @@
1
+ /** The prefix that marks an env value as a secret REFERENCE (a pointer, safe to log/commit). */
2
+ export const SECRET_REF_PREFIX = 'secret-ref:';
3
+ /** True if `value` is a secret reference (not a literal). */
4
+ export function isSecretRef(value) {
5
+ return typeof value === 'string' && value.startsWith(SECRET_REF_PREFIX);
6
+ }
7
+ /** Extract the secret path from a reference (`secret-ref:db/prod/pw` → `db/prod/pw`). */
8
+ export function secretRefPath(ref) {
9
+ return ref.slice(SECRET_REF_PREFIX.length);
10
+ }
11
+ /**
12
+ * Resolve every `secret-ref:` value in `env` via `provider`, returning a NEW bag where references
13
+ * are replaced by their real values and literals are copied unchanged. Async (a fetch is I/O).
14
+ *
15
+ * Fail-closed: a reference with an EMPTY path, or one the provider cannot resolve, THROWS — the
16
+ * error names the ENV KEY + PATH (safe pointers), never the value. Non-string values are copied
17
+ * as-is. The input bag is not mutated.
18
+ */
19
+ export async function resolveSecretRefs(env, provider) {
20
+ const out = {};
21
+ // Resolve sequentially-collected refs; a single failure aborts the whole resolution (fail-closed).
22
+ const refs = [];
23
+ for (const [key, value] of Object.entries(env)) {
24
+ if (isSecretRef(value)) {
25
+ const path = secretRefPath(value);
26
+ if (path.trim() === '') {
27
+ throw new Error(`invalid secret reference for env '${key}': empty path`);
28
+ }
29
+ refs.push({ key, path });
30
+ out[key] = undefined; // placeholder; filled below
31
+ }
32
+ else {
33
+ out[key] = value;
34
+ }
35
+ }
36
+ for (const { key, path } of refs) {
37
+ let resolved;
38
+ try {
39
+ resolved = await provider.resolve(path);
40
+ }
41
+ catch (cause) {
42
+ // Include the key + path (safe pointers), NEVER a value.
43
+ throw new Error(`could not resolve secret for env '${key}' (path '${path}')`, { cause });
44
+ }
45
+ out[key] = resolved;
46
+ }
47
+ return out;
48
+ }
49
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.js","sourceRoot":"","sources":["../../src/secrets/resolve.ts"],"names":[],"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,MAAM,QAAQ,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;QAC1C,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,yDAAyD;YACzD,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,YAAY,IAAI,IAAI,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;QAC3F,CAAC;QACD,GAAG,CAAC,GAAG,CAAC,GAAG,QAAQ,CAAC;IACtB,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC"}
@@ -40,3 +40,5 @@ __exportStar(require("./credential-resolver.js"), exports);
40
40
  __exportStar(require("./totp.js"), exports);
41
41
  // The Authentication engine + the `createAuthenticator` factory:
42
42
  __exportStar(require("./authenticator.js"), exports);
43
+ // Service-account API-key authentication (ADR-0033) — the machine/agent/MCP auth path:
44
+ __exportStar(require("./service-account-authenticator.js"), exports);
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.API_KEY_PREFIX = void 0;
4
+ exports.parseApiKey = parseApiKey;
5
+ exports.createServiceAuthenticator = createServiceAuthenticator;
6
+ /** The API-key prefix that identifies a service-account credential. */
7
+ exports.API_KEY_PREFIX = 'ask_';
8
+ /** Parse `ask_<accountId>_<secret>`. Returns null on ANY malformation (→ uniform deny). */
9
+ function parseApiKey(key) {
10
+ if (typeof key !== 'string' || !key.startsWith(exports.API_KEY_PREFIX))
11
+ return null;
12
+ const rest = key.slice(exports.API_KEY_PREFIX.length);
13
+ const sep = rest.indexOf('_');
14
+ if (sep <= 0)
15
+ return null; // must have a non-empty accountId AND a secret
16
+ const accountId = rest.slice(0, sep);
17
+ const secret = rest.slice(sep + 1);
18
+ if (accountId === '' || secret === '')
19
+ return null;
20
+ return { accountId, secret };
21
+ }
22
+ function createServiceAuthenticator(deps) {
23
+ const now = deps.now ?? (() => Date.now());
24
+ const fail = () => ({ ok: false, reason: 'invalid_key' });
25
+ return {
26
+ async authenticateApiKey(presentedKey) {
27
+ const parsed = parseApiKey(presentedKey);
28
+ if (parsed === null)
29
+ return fail(); // malformed → uniform deny (no enumeration)
30
+ let record;
31
+ try {
32
+ record = await deps.store.getByAccountId(parsed.accountId);
33
+ }
34
+ catch {
35
+ // Store outage → fail closed (authentication failure). Distinct from "unknown" only in
36
+ // the server log; the caller sees the same uniform failure.
37
+ return fail();
38
+ }
39
+ if (record === null) {
40
+ // Unknown account. Still spend a verify against a decoy? PasswordHasher.verify already runs
41
+ // near-constant-time; we simply deny. (Timing parity with the argon path is acceptable —
42
+ // the account id is not itself a secret.)
43
+ return fail();
44
+ }
45
+ // Verify the secret against the stored hash (constant-time). A malformed/mismatched hash →
46
+ // the hasher returns false or rejects; either way we deny (fail-closed).
47
+ let matches = false;
48
+ try {
49
+ matches = await deps.hasher.verify(record.secretHash, parsed.secret);
50
+ }
51
+ catch {
52
+ return fail();
53
+ }
54
+ if (matches !== true)
55
+ return fail(); // strict === true
56
+ // Lifecycle: revoked or expired → deny (fail-closed), even on a correct secret.
57
+ const t = now();
58
+ if (record.revokedAtMs !== undefined && record.revokedAtMs <= t)
59
+ return fail();
60
+ if (record.expiresAtMs !== undefined && record.expiresAtMs <= t)
61
+ return fail();
62
+ // Build the tenant-bound service_account Principal — the SAME shape the broker produces, so it
63
+ // flows through decide() unchanged. NEVER root; scope is the account's own (least privilege).
64
+ const principal = {
65
+ kind: 'service_account',
66
+ id: record.accountId,
67
+ activeScopeNodeId: record.tenantId,
68
+ scopeSubtreeNodeIds: record.scopeSubtreeNodeIds.length > 0
69
+ ? record.scopeSubtreeNodeIds
70
+ : [record.tenantId],
71
+ tenantId: record.tenantId,
72
+ roleIds: record.roleIds,
73
+ isRoot: false,
74
+ };
75
+ return { ok: true, principal };
76
+ },
77
+ };
78
+ }
@@ -105,14 +105,23 @@ function createObjectTypeGate() {
105
105
  return async function objectTypeGate(ctx) {
106
106
  const { principal, action, resource, deps } = ctx;
107
107
  const isRecordLevel = resource.level === 'record';
108
- // ── Cross-tenant grant path (§7.3.3): a non-root reaching a foreign
109
- // tenant proceeded past gate 3 ONLY via a cross-tenant grant, whose scope +
110
- // ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
111
- // pure), NOT the wrong-tenant coarse facts. Root is not grant-backed;
112
- // it falls through to the coarse-grants path.
113
- const crossesTenant = resource.tenantId !== undefined &&
114
- principal.tenantId !== resource.tenantId &&
115
- !(0, reason_codes_js_1.strictTrue)(principal.isRoot);
108
+ // ── Cross-tenant grant path (§7.3.3): a non-root reaching a resource OUTSIDE its
109
+ // active-scope SUBTREE proceeded past gate 3 ONLY via a cross-tenant grant, whose
110
+ // scope + ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
111
+ // pure), NOT the wrong-node coarse facts. Root is not grant-backed; it falls through
112
+ // to the coarse-grants path.
113
+ // ⛔ SUBTREE-AWARE (ADR-0027): a resource IN the principal's subtree (its active node
114
+ // or a descendant — additive-down inheritance) is NOT a cross-tenant reach; it is
115
+ // handled by the coarse grants (below), NOT the grant path. Mirrors the tenant gate's
116
+ // membership test (`resource.tenantId ∈ scopeSubtreeNodeIds`), so gates 3 and 5 agree
117
+ // on what "crosses" means. `Array.isArray` guards a malformed/absent subtree (deny —
118
+ // treated as "not in scope" ⇒ crosses ⇒ the grant path, which fail-closes without a
119
+ // grant). A self-node-only subtree reduces this to the old flat `tenantId !==` check.
120
+ const subtree = principal.scopeSubtreeNodeIds;
121
+ const inSubtree = resource.tenantId !== undefined &&
122
+ Array.isArray(subtree) &&
123
+ subtree.includes(resource.tenantId);
124
+ const crossesTenant = resource.tenantId !== undefined && !inSubtree && !(0, reason_codes_js_1.strictTrue)(principal.isRoot);
116
125
  if (crossesTenant) {
117
126
  // Re-resolve the grant through the SINGLE-SOURCE cross-tenant helper (TEAM C)
118
127
  // so gates 3/5/6 share ONE ceiling+scope+expiry implementation (RULING 1 /