@astram/core 1.2.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.
- package/dist/authentication/index.d.ts +1 -0
- package/dist/authentication/index.d.ts.map +1 -1
- package/dist/authentication/index.js +2 -0
- package/dist/authentication/index.js.map +1 -1
- package/dist/authentication/service-account-authenticator.d.ts +82 -0
- package/dist/authentication/service-account-authenticator.d.ts.map +1 -0
- package/dist/authentication/service-account-authenticator.js +74 -0
- package/dist/authentication/service-account-authenticator.js.map +1 -0
- package/dist/encryption/encryption-service.d.ts +63 -0
- package/dist/encryption/encryption-service.d.ts.map +1 -0
- package/dist/encryption/encryption-service.js +184 -0
- package/dist/encryption/encryption-service.js.map +1 -0
- package/dist/encryption/index.d.ts +17 -0
- package/dist/encryption/index.d.ts.map +1 -0
- package/dist/encryption/index.js +15 -0
- package/dist/encryption/index.js.map +1 -0
- package/dist/encryption/ports.d.ts +84 -0
- package/dist/encryption/ports.d.ts.map +1 -0
- package/dist/encryption/ports.js +18 -0
- package/dist/encryption/ports.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/secrets/index.d.ts +15 -0
- package/dist/secrets/index.d.ts.map +1 -0
- package/dist/secrets/index.js +14 -0
- package/dist/secrets/index.js.map +1 -0
- package/dist/secrets/ports.d.ts +45 -0
- package/dist/secrets/ports.d.ts.map +1 -0
- package/dist/secrets/ports.js +26 -0
- package/dist/secrets/ports.js.map +1 -0
- package/dist/secrets/resolve.d.ts +29 -0
- package/dist/secrets/resolve.d.ts.map +1 -0
- package/dist/secrets/resolve.js +49 -0
- package/dist/secrets/resolve.js.map +1 -0
- package/dist-cjs/authentication/index.js +2 -0
- package/dist-cjs/authentication/service-account-authenticator.js +78 -0
- package/dist-cjs/encryption/encryption-service.js +189 -0
- package/dist-cjs/encryption/index.js +20 -0
- package/dist-cjs/encryption/ports.js +18 -0
- package/dist-cjs/index.js +2 -0
- package/dist-cjs/secrets/index.js +21 -0
- package/dist-cjs/secrets/ports.js +29 -0
- package/dist-cjs/secrets/resolve.js +54 -0
- package/package.json +1 -1
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;
|
|
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":[],"mappings":"AAcA,gGAAgG;AAChG,MAAM,CAAC,MAAM,iBAAiB,GAAG,aAAa,CAAC;AAE/C,6DAA6D;AAC7D,MAAM,UAAU,WAAW,CAAC,KAAyB;IACnD,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,CAAC,UAAU,CAAC,iBAAiB,CAAC,CAAC;AAC1E,CAAC;AAED,yFAAyF;AACzF,MAAM,UAAU,aAAa,CAAC,GAAW;IACvC,OAAO,GAAG,CAAC,KAAK,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAC7C,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,GAAiD,EACjD,QAAyB;IAEzB,MAAM,GAAG,GAAuC,EAAE,CAAC;IACnD,mGAAmG;IACnG,MAAM,IAAI,GAA6C,EAAE,CAAC;IAC1D,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;QAC/C,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC;YACvB,MAAM,IAAI,GAAG,aAAa,CAAC,KAAK,CAAC,CAAC;YAClC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;gBACvB,MAAM,IAAI,KAAK,CAAC,qCAAqC,GAAG,eAAe,CAAC,CAAC;YAC3E,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC;YACzB,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,CAAC,4BAA4B;QACpD,CAAC;aAAM,CAAC;YACN,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACnB,CAAC;IACH,CAAC;IACD,KAAK,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,IAAI,EAAE,CAAC;QACjC,IAAI,QAAgB,CAAC;QACrB,IAAI,CAAC;YACH,QAAQ,GAAG,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
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The **Encryption engine** (ADR-0031) — per-tenant envelope encryption for data at rest.
|
|
4
|
+
*
|
|
5
|
+
* `createEncryptionService({ crypto, dekStore, dekCache })` returns the ONE service the platform
|
|
6
|
+
* uses to encrypt/decrypt a tenant's data with that tenant's own DEK. It is PURE + zero-dep: all
|
|
7
|
+
* crypto, KMS, and persistence are injected ports (ADR-0003). The service:
|
|
8
|
+
* • resolves a tenant's DEK: cache → else load the WRAPPED DEK from the store → `crypto.unwrapDek`
|
|
9
|
+
* → cache it (so the hot path unwraps at most once per tenant per TTL);
|
|
10
|
+
* • PROVISIONS a DEK on first encrypt for a tenant (generate → wrap → persist the wrapped DEK);
|
|
11
|
+
* • binds the versioned ciphertext so a decrypt loads the exact DEK the data was written under
|
|
12
|
+
* (survives key rotation);
|
|
13
|
+
* • supports rotation (`rotateDek`) — the engine mints + persists a new DEK version; the batch
|
|
14
|
+
* re-encryption of existing rows is the consumer's job (the engine exposes the primitive).
|
|
15
|
+
*
|
|
16
|
+
* FAIL-CLOSED: a decrypt that can't resolve/unwrap the DEK or fails the AEAD tag THROWS — never
|
|
17
|
+
* returns plaintext, ciphertext, or empty. An encrypt that can't provision/wrap a DEK THROWS — a
|
|
18
|
+
* plaintext is NEVER written unencrypted as a fallback.
|
|
19
|
+
*
|
|
20
|
+
* THREAT MODEL (ADR-0031): defends the STORAGE boundary (disk/dump/backup → ciphertext only). Does
|
|
21
|
+
* NOT defend a compromised app host (it must hold the DEK in memory) or a compromised KMS.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.EncryptionError = exports.DecryptionError = void 0;
|
|
25
|
+
exports.createEncryptionService = createEncryptionService;
|
|
26
|
+
/** Thrown when a decrypt cannot proceed (missing/unwrappable DEK, tag mismatch). Fail-closed. */
|
|
27
|
+
class DecryptionError extends Error {
|
|
28
|
+
/** Underlying cause (a port outage, a tag mismatch) — for admin logging; never surfaced/leaked. */
|
|
29
|
+
cause;
|
|
30
|
+
constructor(message, cause) {
|
|
31
|
+
super(message);
|
|
32
|
+
this.name = 'DecryptionError';
|
|
33
|
+
this.cause = cause;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
exports.DecryptionError = DecryptionError;
|
|
37
|
+
/** Thrown when an encrypt cannot provision/wrap a DEK. No plaintext is ever written unencrypted. */
|
|
38
|
+
class EncryptionError extends Error {
|
|
39
|
+
/** Underlying cause — for admin logging; never surfaced/leaked. */
|
|
40
|
+
cause;
|
|
41
|
+
constructor(message, cause) {
|
|
42
|
+
super(message);
|
|
43
|
+
this.name = 'EncryptionError';
|
|
44
|
+
this.cause = cause;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.EncryptionError = EncryptionError;
|
|
48
|
+
function requireTenant(tenantId) {
|
|
49
|
+
if (typeof tenantId !== 'string' || tenantId.trim() === '') {
|
|
50
|
+
throw new EncryptionError('tenantId is required (non-empty).');
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
function createEncryptionService(deps) {
|
|
54
|
+
const { crypto, dekStore, dekCache } = deps;
|
|
55
|
+
/** Resolve a tenant's CURRENT DEK: cache → store(current) → unwrap → cache. Provisions on absence. */
|
|
56
|
+
async function currentDek(tenantId) {
|
|
57
|
+
// The cache holds the CURRENT dek only; a version bump evicts it (see rotateDek).
|
|
58
|
+
const cached = dekCache?.get(tenantId);
|
|
59
|
+
let record;
|
|
60
|
+
try {
|
|
61
|
+
record = await dekStore.getCurrent(tenantId);
|
|
62
|
+
}
|
|
63
|
+
catch (cause) {
|
|
64
|
+
// Store outage is NOT "no key" — fail closed loudly, never provision-over-an-outage.
|
|
65
|
+
throw new EncryptionError('DEK store unavailable', cause);
|
|
66
|
+
}
|
|
67
|
+
if (record === null) {
|
|
68
|
+
// First use for this tenant: provision a DEK (generate → wrap → persist v1).
|
|
69
|
+
return provisionDek(tenantId);
|
|
70
|
+
}
|
|
71
|
+
if (cached !== undefined)
|
|
72
|
+
return { dek: cached, version: record.version };
|
|
73
|
+
let dek;
|
|
74
|
+
try {
|
|
75
|
+
dek = await crypto.unwrapDek(record.wrapped, tenantId);
|
|
76
|
+
}
|
|
77
|
+
catch (cause) {
|
|
78
|
+
throw new EncryptionError('could not unwrap the current DEK', cause);
|
|
79
|
+
}
|
|
80
|
+
dekCache?.put(tenantId, dek);
|
|
81
|
+
return { dek, version: record.version };
|
|
82
|
+
}
|
|
83
|
+
/** Resolve a SPECIFIC version's DEK (for decrypting data under an older key). No provisioning. */
|
|
84
|
+
async function dekForVersion(tenantId, version) {
|
|
85
|
+
let record;
|
|
86
|
+
try {
|
|
87
|
+
record = await dekStore.getVersion(tenantId, version);
|
|
88
|
+
}
|
|
89
|
+
catch (cause) {
|
|
90
|
+
throw new DecryptionError('DEK store unavailable', cause);
|
|
91
|
+
}
|
|
92
|
+
if (record === null) {
|
|
93
|
+
throw new DecryptionError(`no DEK version ${version} for tenant '${tenantId}'`);
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
return await crypto.unwrapDek(record.wrapped, tenantId);
|
|
97
|
+
}
|
|
98
|
+
catch (cause) {
|
|
99
|
+
throw new DecryptionError('could not unwrap the DEK', cause);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
async function provisionDek(tenantId) {
|
|
103
|
+
let dek;
|
|
104
|
+
let wrapped;
|
|
105
|
+
try {
|
|
106
|
+
dek = await crypto.generateDek();
|
|
107
|
+
wrapped = await crypto.wrapDek(dek, tenantId);
|
|
108
|
+
}
|
|
109
|
+
catch (cause) {
|
|
110
|
+
throw new EncryptionError('could not generate/wrap a new DEK', cause);
|
|
111
|
+
}
|
|
112
|
+
const version = 1;
|
|
113
|
+
try {
|
|
114
|
+
await dekStore.put({ tenantId, version, wrapped });
|
|
115
|
+
}
|
|
116
|
+
catch (cause) {
|
|
117
|
+
// A concurrent provision may have created v1 first — re-read the current and use it (idempotent-ish).
|
|
118
|
+
const existing = await dekStore.getCurrent(tenantId).catch(() => null);
|
|
119
|
+
if (existing) {
|
|
120
|
+
const existingDek = await crypto.unwrapDek(existing.wrapped, tenantId);
|
|
121
|
+
dekCache?.put(tenantId, existingDek);
|
|
122
|
+
return { dek: existingDek, version: existing.version };
|
|
123
|
+
}
|
|
124
|
+
throw new EncryptionError('could not persist the new DEK', cause);
|
|
125
|
+
}
|
|
126
|
+
dekCache?.put(tenantId, dek);
|
|
127
|
+
return { dek, version };
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
async encryptFor(tenantId, plaintext) {
|
|
131
|
+
requireTenant(tenantId);
|
|
132
|
+
const { dek, version } = await currentDek(tenantId);
|
|
133
|
+
let ciphertext;
|
|
134
|
+
try {
|
|
135
|
+
ciphertext = await crypto.encrypt(plaintext, dek, tenantId);
|
|
136
|
+
}
|
|
137
|
+
catch (cause) {
|
|
138
|
+
throw new EncryptionError('encryption failed', cause);
|
|
139
|
+
}
|
|
140
|
+
return { tenantId, version, ciphertext };
|
|
141
|
+
},
|
|
142
|
+
async decryptFor(tenantId, envelope) {
|
|
143
|
+
requireTenant(tenantId);
|
|
144
|
+
// Defence in depth: the caller-supplied tenant MUST match the envelope's stamp.
|
|
145
|
+
if (envelope.tenantId !== tenantId) {
|
|
146
|
+
throw new DecryptionError('tenant mismatch between caller and envelope (cross-tenant guard)');
|
|
147
|
+
}
|
|
148
|
+
// Prefer the cached current DEK when the envelope is at the current version; else load by version.
|
|
149
|
+
const dek = await dekForVersion(tenantId, envelope.version);
|
|
150
|
+
try {
|
|
151
|
+
return await crypto.decrypt(envelope.ciphertext, dek, tenantId);
|
|
152
|
+
}
|
|
153
|
+
catch (cause) {
|
|
154
|
+
// A tag/AAD mismatch or malformed ciphertext → fail closed. Never leak plaintext/ciphertext.
|
|
155
|
+
throw new DecryptionError('decryption failed (tag mismatch or malformed ciphertext)', cause);
|
|
156
|
+
}
|
|
157
|
+
},
|
|
158
|
+
async rotateDek(tenantId) {
|
|
159
|
+
requireTenant(tenantId);
|
|
160
|
+
let current;
|
|
161
|
+
try {
|
|
162
|
+
current = await dekStore.getCurrent(tenantId);
|
|
163
|
+
}
|
|
164
|
+
catch (cause) {
|
|
165
|
+
throw new EncryptionError('DEK store unavailable', cause);
|
|
166
|
+
}
|
|
167
|
+
const nextVersion = (current?.version ?? 0) + 1;
|
|
168
|
+
let dek;
|
|
169
|
+
let wrapped;
|
|
170
|
+
try {
|
|
171
|
+
dek = await crypto.generateDek();
|
|
172
|
+
wrapped = await crypto.wrapDek(dek, tenantId);
|
|
173
|
+
await dekStore.put({ tenantId, version: nextVersion, wrapped });
|
|
174
|
+
}
|
|
175
|
+
catch (cause) {
|
|
176
|
+
throw new EncryptionError('could not rotate the DEK', cause);
|
|
177
|
+
}
|
|
178
|
+
// The new DEK is now current; drop the stale cached one so the next op unwraps the new one.
|
|
179
|
+
dekCache?.evict(tenantId);
|
|
180
|
+
dekCache?.put(tenantId, dek);
|
|
181
|
+
return nextVersion;
|
|
182
|
+
},
|
|
183
|
+
async destroyTenantKeys(tenantId) {
|
|
184
|
+
requireTenant(tenantId);
|
|
185
|
+
dekCache?.evict(tenantId);
|
|
186
|
+
await dekStore.destroy(tenantId);
|
|
187
|
+
},
|
|
188
|
+
};
|
|
189
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Engine seam: **Encryption** — per-tenant envelope encryption for data at rest (ADR-0031).
|
|
4
|
+
*
|
|
5
|
+
* `createEncryptionService` encrypts/decrypts a tenant's data with that tenant's own DEK; DEKs are
|
|
6
|
+
* wrapped by a KMS-held KEK and only wrapped DEKs are ever persisted. Pure + zero-dep (ADR-0003):
|
|
7
|
+
* crypto/KMS/persistence are injected ports, shipped as adapters in `@astram/guard`.
|
|
8
|
+
*
|
|
9
|
+
* THREAT MODEL (ADR-0031, stated honestly): defends the STORAGE boundary (stolen disk / DB dump /
|
|
10
|
+
* backup / leaked bucket → only ciphertext + wrapped DEKs). Does NOT defend a compromised app host
|
|
11
|
+
* or a compromised KMS. See `docs/Shield/140_Security_Hardening` + ADR-0031.
|
|
12
|
+
*
|
|
13
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB imports.
|
|
14
|
+
*/
|
|
15
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
16
|
+
exports.EncryptionError = exports.DecryptionError = exports.createEncryptionService = void 0;
|
|
17
|
+
var encryption_service_js_1 = require("./encryption-service.js");
|
|
18
|
+
Object.defineProperty(exports, "createEncryptionService", { enumerable: true, get: function () { return encryption_service_js_1.createEncryptionService; } });
|
|
19
|
+
Object.defineProperty(exports, "DecryptionError", { enumerable: true, get: function () { return encryption_service_js_1.DecryptionError; } });
|
|
20
|
+
Object.defineProperty(exports, "EncryptionError", { enumerable: true, get: function () { return encryption_service_js_1.EncryptionError; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Encryption engine PORTS — the framework-agnostic contracts the {@link EncryptionService} uses,
|
|
4
|
+
* WITHOUT the engine ever knowing the algorithm, the KMS, or where wrapped DEKs are stored.
|
|
5
|
+
*
|
|
6
|
+
* ADR-0031 (envelope encryption / per-tenant DEKs) + ADR-0003 (zero-dep core): real crypto needs a
|
|
7
|
+
* library + native bindings and a KMS needs network/SDK — neither can live in `@astram/core`. The
|
|
8
|
+
* core defines only these interfaces; `@astram/guard` ships the concrete AEAD + KMS + DEK-store
|
|
9
|
+
* adapters and INJECTS them into `createEncryptionService`. Core stays at ZERO runtime deps.
|
|
10
|
+
*
|
|
11
|
+
* THREAT MODEL (ADR-0031, honest): this defends the STORAGE boundary (stolen disk / DB dump /
|
|
12
|
+
* backup / leaked bucket → only ciphertext + wrapped DEKs). It does NOT defend a compromised app
|
|
13
|
+
* host (the app must hold a tenant's DEK in memory to serve it) or a compromised KMS.
|
|
14
|
+
*
|
|
15
|
+
* SECURITY: no port implementation may log a plaintext, a DEK, or a plaintext key. DEKs and
|
|
16
|
+
* plaintext are transient inputs; they are never surfaced in a result, a reason, or a log.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
package/dist-cjs/index.js
CHANGED
|
@@ -55,6 +55,8 @@ __exportStar(require("./session/index.js"), exports);
|
|
|
55
55
|
__exportStar(require("./risk/index.js"), exports);
|
|
56
56
|
__exportStar(require("./authorization/index.js"), exports);
|
|
57
57
|
__exportStar(require("./audit/index.js"), exports);
|
|
58
|
+
__exportStar(require("./encryption/index.js"), exports);
|
|
59
|
+
__exportStar(require("./secrets/index.js"), exports);
|
|
58
60
|
// Module-registers-metadata contract + pure derivation rules + completeness check.
|
|
59
61
|
__exportStar(require("./metadata/index.js"), exports);
|
|
60
62
|
// Admin Console (Layer 10) — a NEW top-level module (append-only; no frozen
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Engine seam: **Secrets** — env holds references, credentials resolved at runtime + rotatable
|
|
4
|
+
* (ADR-0032). `secret-ref:<path>` in env is a pointer (safe to commit/log); `resolveSecretRefs`
|
|
5
|
+
* fetches the real value at boot via an injected `SecretsProvider`. Pure + zero-dep (ADR-0003);
|
|
6
|
+
* backends (encrypted on-box store now; Vault / AWS SM / GCP SM later) ship in `@astram/guard`.
|
|
7
|
+
*
|
|
8
|
+
* SECURITY: a secret value is never logged/surfaced (only paths + versions). Fail-closed: an
|
|
9
|
+
* unresolvable reference aborts boot; a literal value is unchanged (backward compatible).
|
|
10
|
+
*
|
|
11
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / fs imports.
|
|
12
|
+
*/
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.resolveSecretRefs = exports.secretRefPath = exports.isSecretRef = exports.SECRET_REF_PREFIX = exports.SecretNotFoundError = void 0;
|
|
15
|
+
var ports_js_1 = require("./ports.js");
|
|
16
|
+
Object.defineProperty(exports, "SecretNotFoundError", { enumerable: true, get: function () { return ports_js_1.SecretNotFoundError; } });
|
|
17
|
+
var resolve_js_1 = require("./resolve.js");
|
|
18
|
+
Object.defineProperty(exports, "SECRET_REF_PREFIX", { enumerable: true, get: function () { return resolve_js_1.SECRET_REF_PREFIX; } });
|
|
19
|
+
Object.defineProperty(exports, "isSecretRef", { enumerable: true, get: function () { return resolve_js_1.isSecretRef; } });
|
|
20
|
+
Object.defineProperty(exports, "secretRefPath", { enumerable: true, get: function () { return resolve_js_1.secretRefPath; } });
|
|
21
|
+
Object.defineProperty(exports, "resolveSecretRefs", { enumerable: true, get: function () { return resolve_js_1.resolveSecretRefs; } });
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Secrets provider PORT (ADR-0032) — the framework-agnostic contract for fetching + rotating
|
|
4
|
+
* credentials, so the runtime reads a REFERENCE from env (`secret-ref:db/prod/password`) and the
|
|
5
|
+
* real value is resolved at boot from a secrets backend, NEVER hard-coded in env/Git.
|
|
6
|
+
*
|
|
7
|
+
* ADR-0003 (zero-dep core): the backend is a real dependency (a network vault SDK, or an encrypted
|
|
8
|
+
* on-box store using node crypto) — it cannot live here. Core defines only this interface;
|
|
9
|
+
* `@astram/guard` ships the concrete backends (a reference encrypted on-box store now; Vault / AWS
|
|
10
|
+
* Secrets Manager / GCP Secret Manager as drop-in adapters) and INJECTS one. Core stays zero-dep.
|
|
11
|
+
*
|
|
12
|
+
* SECURITY: a secret VALUE is never logged, never in an error message, never in an audit record —
|
|
13
|
+
* only the PATH + version. A `SecretsProvider` implementation MUST likewise never log a value.
|
|
14
|
+
* Fail-closed: a missing secret THROWS (must never silently resolve to '' — that would start the
|
|
15
|
+
* app with a hole where a credential belongs).
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.SecretNotFoundError = void 0;
|
|
19
|
+
/** Thrown by `resolve` when a referenced secret is absent — fail-closed (never a silent empty). */
|
|
20
|
+
class SecretNotFoundError extends Error {
|
|
21
|
+
cause;
|
|
22
|
+
constructor(path, cause) {
|
|
23
|
+
// NOTE: includes the PATH (safe — a pointer, not a value), never the value.
|
|
24
|
+
super(`secret not found: '${path}'`);
|
|
25
|
+
this.name = 'SecretNotFoundError';
|
|
26
|
+
this.cause = cause;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
exports.SecretNotFoundError = SecretNotFoundError;
|