@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.
- 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/authorization/gates/object-type.d.ts.map +1 -1
- package/dist/authorization/gates/object-type.js +17 -8
- package/dist/authorization/gates/object-type.js.map +1 -1
- package/dist/authorization/gates/tenant.d.ts +7 -4
- package/dist/authorization/gates/tenant.d.ts.map +1 -1
- package/dist/authorization/gates/tenant.js +30 -7
- package/dist/authorization/gates/tenant.js.map +1 -1
- package/dist/authorization/index.d.ts +1 -0
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +2 -0
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/ports.d.ts +65 -0
- package/dist/authorization/ports.d.ts.map +1 -1
- package/dist/authorization/record/list-scope.d.ts +198 -0
- package/dist/authorization/record/list-scope.d.ts.map +1 -0
- package/dist/authorization/record/list-scope.js +153 -0
- package/dist/authorization/record/list-scope.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/identity/broker.d.ts.map +1 -1
- package/dist/identity/broker.js +6 -0
- package/dist/identity/broker.js.map +1 -1
- package/dist/identity/index.d.ts +16 -1
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js.map +1 -1
- 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/authorization/gates/object-type.js +17 -8
- package/dist-cjs/authorization/gates/tenant.js +30 -7
- package/dist-cjs/authorization/index.js +2 -0
- package/dist-cjs/authorization/record/list-scope.js +155 -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/identity/broker.js +6 -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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AAEtD,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAAG,UAAU,GAAG,MAAM,GAAG,UAAU,GAAG,eAAe,CAAC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OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;CACrD;AAED,4CAA4C;AAC5C,MAAM,MAAM,qBAAqB,GAAG,eAAe,GAAG,cAAc,GAAG,UAAU,CAAC;AAElF,mDAAmD;AACnD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,OAAO,EAAE,qBAAqB,CAAC;IACxC,uDAAuD;IACvD,QAAQ,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC;IAC/B,yEAAyE;IACzE,QAAQ,CAAC,gBAAgB,EAAE,SAAS,UAAU,EAAE,CAAC;IACjD,+EAA+E;IAC/E,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B;;;OAGG;IACH,YAAY,CACV,YAAY,EAAE,MAAM,EACpB,WAAW,EAAE,SAAS,UAAU,EAAE,GACjC,OAAO,CAAC,oBAAoB,CAAC,CAAC;CAClC;AAKD,cAAc,sBAAsB,CAAC;AAGrC,cAAc,0BAA0B,CAAC;AAEzC,cAAc,WAAW,CAAC;AAE1B,cAAc,oBAAoB,CAAC;AAEnC,cAAc,oCAAoC,CAAC"}
|
|
@@ -24,4 +24,6 @@ export * from './credential-resolver.js';
|
|
|
24
24
|
export * from './totp.js';
|
|
25
25
|
// The Authentication engine + the `createAuthenticator` factory:
|
|
26
26
|
export * from './authenticator.js';
|
|
27
|
+
// Service-account API-key authentication (ADR-0033) — the machine/agent/MCP auth path:
|
|
28
|
+
export * from './service-account-authenticator.js';
|
|
27
29
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2CH,iFAAiF;AACjF,iFAAiF;AACjF,aAAa;AACb,cAAc,sBAAsB,CAAC;AACrC,kFAAkF;AAClF,qBAAqB;AACrB,cAAc,0BAA0B,CAAC;AACzC,qFAAqF;AACrF,cAAc,WAAW,CAAC;AAC1B,iEAAiE;AACjE,cAAc,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authentication/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AA2CH,iFAAiF;AACjF,iFAAiF;AACjF,aAAa;AACb,cAAc,sBAAsB,CAAC;AACrC,kFAAkF;AAClF,qBAAqB;AACrB,cAAc,0BAA0B,CAAC;AACzC,qFAAqF;AACrF,cAAc,WAAW,CAAC;AAC1B,iEAAiE;AACjE,cAAc,oBAAoB,CAAC;AACnC,uFAAuF;AACvF,cAAc,oCAAoC,CAAC"}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service-account API-key authentication (ADR-0033) — the machine auth path. An agent / MCP server /
|
|
3
|
+
* script presents an API key (`ask_<accountId>_<secret>`); this engine verifies it and produces a
|
|
4
|
+
* tenant-bound `service_account` {@link Principal} that then flows through the SAME `decide()` as a
|
|
5
|
+
* human (ADR-0001 — no agent-special enforcement path).
|
|
6
|
+
*
|
|
7
|
+
* SECURITY (ADR-0033):
|
|
8
|
+
* - HASH-ONLY: the store holds only the Argon2id hash of the secret (reuses {@link PasswordHasher},
|
|
9
|
+
* the same bar as passwords/refresh-tokens) — a store breach yields no usable key.
|
|
10
|
+
* - CONSTANT-TIME verify (via PasswordHasher.verify); a malformed/unknown/expired/revoked key ⇒ a
|
|
11
|
+
* UNIFORM authentication failure (no enumeration of which accounts exist).
|
|
12
|
+
* - FAIL-CLOSED: expired, revoked, or a store/hasher outage ⇒ deny (never allow, never a partial
|
|
13
|
+
* principal). The secret is NEVER logged / returned / audited (only the account id/label/version).
|
|
14
|
+
* - LEAST PRIVILEGE + tenant-bound: the resolved Principal carries ONLY the account's own scope and
|
|
15
|
+
* tenant — a hijacked (prompt-injected) agent is bounded by scope + tenant + attribution, not by
|
|
16
|
+
* trusting the agent.
|
|
17
|
+
*
|
|
18
|
+
* Pure + zero-dep (ADR-0003): the hasher + store are injected ports; `@astram/guard` ships adapters.
|
|
19
|
+
*/
|
|
20
|
+
import type { Principal } from '../identity/index.js';
|
|
21
|
+
import type { PasswordHasher } from './password-hasher.js';
|
|
22
|
+
/** The API-key prefix that identifies a service-account credential. */
|
|
23
|
+
export declare const API_KEY_PREFIX = "ask_";
|
|
24
|
+
/**
|
|
25
|
+
* A stored API-key record — HASH ONLY, never the secret. Looked up by `accountId` (parsed from the
|
|
26
|
+
* presented key). Carries the fields the engine needs to build the Principal + enforce lifecycle.
|
|
27
|
+
*/
|
|
28
|
+
export interface ApiKeyRecord {
|
|
29
|
+
readonly accountId: string;
|
|
30
|
+
readonly tenantId: string;
|
|
31
|
+
/** The account's scope subtree (ADR-0027) — the reachable tenant nodes for its Principal. */
|
|
32
|
+
readonly scopeSubtreeNodeIds: readonly string[];
|
|
33
|
+
/** Role ids the service account holds (drive its object-type grants). */
|
|
34
|
+
readonly roleIds: readonly string[];
|
|
35
|
+
/** Argon2id hash of the key's secret (from PasswordHasher.hash). NEVER the plaintext. */
|
|
36
|
+
readonly secretHash: string;
|
|
37
|
+
/** Monotonic key version (rotation increments it). */
|
|
38
|
+
readonly version: number;
|
|
39
|
+
/** Absolute expiry (epoch-ms); `undefined` = non-expiring (discouraged; opt-in at issue). */
|
|
40
|
+
readonly expiresAtMs?: number;
|
|
41
|
+
/** Set when the key has been revoked (epoch-ms); a revoked key fails closed. */
|
|
42
|
+
readonly revokedAtMs?: number;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Loads an API-key record by the account id parsed from the presented key. Fail-closed: a store
|
|
46
|
+
* OUTAGE must THROW (the engine maps it to an authentication failure) — it must NOT return `null`
|
|
47
|
+
* to mask an outage (that would be indistinguishable from "unknown account", which is fine for
|
|
48
|
+
* enumeration but the throw lets the engine log the outage distinctly server-side).
|
|
49
|
+
*/
|
|
50
|
+
export interface ApiKeyStore {
|
|
51
|
+
/** The current key record for an account, or `null` if the account/key is unknown. */
|
|
52
|
+
getByAccountId(accountId: string): Promise<ApiKeyRecord | null>;
|
|
53
|
+
}
|
|
54
|
+
/** The result of an API-key authentication attempt. Success carries the resolved Principal. */
|
|
55
|
+
export type ServiceAuthResult = {
|
|
56
|
+
readonly ok: true;
|
|
57
|
+
readonly principal: Principal;
|
|
58
|
+
} | {
|
|
59
|
+
readonly ok: false;
|
|
60
|
+
readonly reason: 'invalid_key';
|
|
61
|
+
};
|
|
62
|
+
export interface ServiceAuthenticatorDeps {
|
|
63
|
+
readonly store: ApiKeyStore;
|
|
64
|
+
readonly hasher: PasswordHasher;
|
|
65
|
+
/** Injectable clock (epoch-ms) for expiry/revocation checks; defaults to Date.now. */
|
|
66
|
+
readonly now?: () => number;
|
|
67
|
+
}
|
|
68
|
+
/** Parse `ask_<accountId>_<secret>`. Returns null on ANY malformation (→ uniform deny). */
|
|
69
|
+
export declare function parseApiKey(key: string): {
|
|
70
|
+
accountId: string;
|
|
71
|
+
secret: string;
|
|
72
|
+
} | null;
|
|
73
|
+
export interface ServiceAuthenticator {
|
|
74
|
+
/**
|
|
75
|
+
* Authenticate a presented API key → a `service_account` Principal, or a uniform failure. NEVER
|
|
76
|
+
* throws on a bad key (returns `{ok:false}`); NEVER logs/returns the secret. Fail-closed on
|
|
77
|
+
* expiry/revocation/outage.
|
|
78
|
+
*/
|
|
79
|
+
authenticateApiKey(presentedKey: string): Promise<ServiceAuthResult>;
|
|
80
|
+
}
|
|
81
|
+
export declare function createServiceAuthenticator(deps: ServiceAuthenticatorDeps): ServiceAuthenticator;
|
|
82
|
+
//# sourceMappingURL=service-account-authenticator.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-account-authenticator.d.ts","sourceRoot":"","sources":["../../src/authentication/service-account-authenticator.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,OAAO,KAAK,EAAE,SAAS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AC;CAC7B;AAED,2FAA2F;AAC3F,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CASrF;AAED,MAAM,WAAW,oBAAoB;IACnC;;;;OAIG;IACH,kBAAkB,CAAC,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAAC;CACtE;AAED,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,wBAAwB,GAAG,oBAAoB,CAuD/F"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/** The API-key prefix that identifies a service-account credential. */
|
|
2
|
+
export const API_KEY_PREFIX = 'ask_';
|
|
3
|
+
/** Parse `ask_<accountId>_<secret>`. Returns null on ANY malformation (→ uniform deny). */
|
|
4
|
+
export function parseApiKey(key) {
|
|
5
|
+
if (typeof key !== 'string' || !key.startsWith(API_KEY_PREFIX))
|
|
6
|
+
return null;
|
|
7
|
+
const rest = key.slice(API_KEY_PREFIX.length);
|
|
8
|
+
const sep = rest.indexOf('_');
|
|
9
|
+
if (sep <= 0)
|
|
10
|
+
return null; // must have a non-empty accountId AND a secret
|
|
11
|
+
const accountId = rest.slice(0, sep);
|
|
12
|
+
const secret = rest.slice(sep + 1);
|
|
13
|
+
if (accountId === '' || secret === '')
|
|
14
|
+
return null;
|
|
15
|
+
return { accountId, secret };
|
|
16
|
+
}
|
|
17
|
+
export function createServiceAuthenticator(deps) {
|
|
18
|
+
const now = deps.now ?? (() => Date.now());
|
|
19
|
+
const fail = () => ({ ok: false, reason: 'invalid_key' });
|
|
20
|
+
return {
|
|
21
|
+
async authenticateApiKey(presentedKey) {
|
|
22
|
+
const parsed = parseApiKey(presentedKey);
|
|
23
|
+
if (parsed === null)
|
|
24
|
+
return fail(); // malformed → uniform deny (no enumeration)
|
|
25
|
+
let record;
|
|
26
|
+
try {
|
|
27
|
+
record = await deps.store.getByAccountId(parsed.accountId);
|
|
28
|
+
}
|
|
29
|
+
catch {
|
|
30
|
+
// Store outage → fail closed (authentication failure). Distinct from "unknown" only in
|
|
31
|
+
// the server log; the caller sees the same uniform failure.
|
|
32
|
+
return fail();
|
|
33
|
+
}
|
|
34
|
+
if (record === null) {
|
|
35
|
+
// Unknown account. Still spend a verify against a decoy? PasswordHasher.verify already runs
|
|
36
|
+
// near-constant-time; we simply deny. (Timing parity with the argon path is acceptable —
|
|
37
|
+
// the account id is not itself a secret.)
|
|
38
|
+
return fail();
|
|
39
|
+
}
|
|
40
|
+
// Verify the secret against the stored hash (constant-time). A malformed/mismatched hash →
|
|
41
|
+
// the hasher returns false or rejects; either way we deny (fail-closed).
|
|
42
|
+
let matches = false;
|
|
43
|
+
try {
|
|
44
|
+
matches = await deps.hasher.verify(record.secretHash, parsed.secret);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return fail();
|
|
48
|
+
}
|
|
49
|
+
if (matches !== true)
|
|
50
|
+
return fail(); // strict === true
|
|
51
|
+
// Lifecycle: revoked or expired → deny (fail-closed), even on a correct secret.
|
|
52
|
+
const t = now();
|
|
53
|
+
if (record.revokedAtMs !== undefined && record.revokedAtMs <= t)
|
|
54
|
+
return fail();
|
|
55
|
+
if (record.expiresAtMs !== undefined && record.expiresAtMs <= t)
|
|
56
|
+
return fail();
|
|
57
|
+
// Build the tenant-bound service_account Principal — the SAME shape the broker produces, so it
|
|
58
|
+
// flows through decide() unchanged. NEVER root; scope is the account's own (least privilege).
|
|
59
|
+
const principal = {
|
|
60
|
+
kind: 'service_account',
|
|
61
|
+
id: record.accountId,
|
|
62
|
+
activeScopeNodeId: record.tenantId,
|
|
63
|
+
scopeSubtreeNodeIds: record.scopeSubtreeNodeIds.length > 0
|
|
64
|
+
? record.scopeSubtreeNodeIds
|
|
65
|
+
: [record.tenantId],
|
|
66
|
+
tenantId: record.tenantId,
|
|
67
|
+
roleIds: record.roleIds,
|
|
68
|
+
isRoot: false,
|
|
69
|
+
};
|
|
70
|
+
return { ok: true, principal };
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
//# sourceMappingURL=service-account-authenticator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"service-account-authenticator.js","sourceRoot":"","sources":["../../src/authentication/service-account-authenticator.ts"],"names":[],"mappings":"AAsBA,uEAAuE;AACvE,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAC;AA8CrC,2FAA2F;AAC3F,MAAM,UAAU,WAAW,CAAC,GAAW;IACrC,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,UAAU,CAAC,cAAc,CAAC;QAAE,OAAO,IAAI,CAAC;IAC5E,MAAM,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9C,MAAM,GAAG,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC9B,IAAI,GAAG,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC,CAAC,+CAA+C;IAC1E,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;IACrC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC;IACnC,IAAI,SAAS,KAAK,EAAE,IAAI,MAAM,KAAK,EAAE;QAAE,OAAO,IAAI,CAAC;IACnD,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC;AAC/B,CAAC;AAWD,MAAM,UAAU,0BAA0B,CAAC,IAA8B;IACvE,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC3C,MAAM,IAAI,GAAG,GAAsB,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,aAAa,EAAE,CAAC,CAAC;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;gBAC3B,IAAI,EAAE,iBAAiB;gBACvB,EAAE,EAAE,MAAM,CAAC,SAAS;gBACpB,iBAAiB,EAAE,MAAM,CAAC,QAAQ;gBAClC,mBAAmB,EAAE,MAAM,CAAC,mBAAmB,CAAC,MAAM,GAAG,CAAC;oBACxD,CAAC,CAAC,MAAM,CAAC,mBAAmB;oBAC5B,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,OAAO,EAAE,MAAM,CAAC,OAAO;gBACvB,MAAM,EAAE,KAAK;aACd,CAAC;YACF,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;QACjC,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AA2ClC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,
|
|
1
|
+
{"version":3,"file":"object-type.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/object-type.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAGH,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,0BAA0B,CAAC;AA2ClC;;;;;;GAMG;AACH,wBAAgB,oBAAoB,IAAI,gBAAgB,CAmFvD"}
|
|
@@ -102,14 +102,23 @@ export function createObjectTypeGate() {
|
|
|
102
102
|
return async function objectTypeGate(ctx) {
|
|
103
103
|
const { principal, action, resource, deps } = ctx;
|
|
104
104
|
const isRecordLevel = resource.level === 'record';
|
|
105
|
-
// ── Cross-tenant grant path (§7.3.3): a non-root reaching a
|
|
106
|
-
//
|
|
107
|
-
// ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
|
|
108
|
-
// pure), NOT the wrong-
|
|
109
|
-
//
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
// ── Cross-tenant grant path (§7.3.3): a non-root reaching a resource OUTSIDE its
|
|
106
|
+
// active-scope SUBTREE proceeded past gate 3 ONLY via a cross-tenant grant, whose
|
|
107
|
+
// scope + ceiling SERVES AS the object-type grant. Re-resolve it here (gate 3 is
|
|
108
|
+
// pure), NOT the wrong-node coarse facts. Root is not grant-backed; it falls through
|
|
109
|
+
// to the coarse-grants path.
|
|
110
|
+
// ⛔ SUBTREE-AWARE (ADR-0027): a resource IN the principal's subtree (its active node
|
|
111
|
+
// or a descendant — additive-down inheritance) is NOT a cross-tenant reach; it is
|
|
112
|
+
// handled by the coarse grants (below), NOT the grant path. Mirrors the tenant gate's
|
|
113
|
+
// membership test (`resource.tenantId ∈ scopeSubtreeNodeIds`), so gates 3 and 5 agree
|
|
114
|
+
// on what "crosses" means. `Array.isArray` guards a malformed/absent subtree (deny —
|
|
115
|
+
// treated as "not in scope" ⇒ crosses ⇒ the grant path, which fail-closes without a
|
|
116
|
+
// grant). A self-node-only subtree reduces this to the old flat `tenantId !==` check.
|
|
117
|
+
const subtree = principal.scopeSubtreeNodeIds;
|
|
118
|
+
const inSubtree = resource.tenantId !== undefined &&
|
|
119
|
+
Array.isArray(subtree) &&
|
|
120
|
+
subtree.includes(resource.tenantId);
|
|
121
|
+
const crossesTenant = resource.tenantId !== undefined && !inSubtree && !strictTrue(principal.isRoot);
|
|
113
122
|
if (crossesTenant) {
|
|
114
123
|
// Re-resolve the grant through the SINGLE-SOURCE cross-tenant helper (TEAM C)
|
|
115
124
|
// so gates 3/5/6 share ONE ceiling+scope+expiry implementation (RULING 1 /
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"object-type.js","sourceRoot":"","sources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D,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,CAAC;YACxC,OAAO,QAAQ,CAAC,0BAA0B,EAAE,CAAC,CAAC;QAChD,CAAC;QAED,0EAA0E;QAC1E,iEAAiE;QACjE,OAAO,aAAa,CAAC,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC;IACtD,CAAC,CAAC;AACJ,CAAC;AAED;;;;;;;;GAQG;AACH,KAAK,UAAU,mBAAmB,CAChC,GAAgB,EAChB,YAAoB;IAEpB,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;IAChC,MAAM,MAAM,GAAG,cAAc,CAAC,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC;IAE7D,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,MAAM,cAAc,GAAG,MAAM,IAAI,CAAC,eAAe,CAAC,yBAAyB,CACzE,SAAS,CAAC,EAAE,EACZ,SAAS,CAAC,QAAQ,CACnB,CAAC;QACF,+EAA+E;QAC/E,gFAAgF;QAChF,IAAI,MAAM,CAAC,kBAAkB,IAAI,cAAc,EAAE,CAAC;YAChD,OAAO,MAAM,CAAC;QAChB,CAAC;IACH,CAAC;IAED,mEAAmE;IACnE,OAAO,IAAI,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,CAAC,EAAE,EAAE,SAAS,CAAC,QAAQ,CAAC,CAAC;AACjF,CAAC"}
|
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
* ── The order (deny wins; every ambiguity resolves to the deny/continue path,
|
|
15
15
|
* never to a bypass):
|
|
16
16
|
*
|
|
17
|
-
* 1.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* 1. IN SCOPE (`resource.tenantId ∈ principal.scopeSubtreeNodeIds` — the active
|
|
18
|
+
* node + all descendants, ADR-0027 — OR the resource carries no instance
|
|
19
|
+
* tenant) ⇒ `continue`. An in-memory set test against the login-cached subtree
|
|
20
|
+
* (zero per-request DB, ADR-0024). A feature/object-type-level resource with no
|
|
21
|
+
* `tenantId` is same-tenant BY CONSTRUCTION — there is no foreign instance to
|
|
22
|
+
* cross into. The subtree ALWAYS contains the active node itself, so this is a
|
|
23
|
+
* strict generalization of the old flat `tenantId === resource.tenantId`.
|
|
21
24
|
* 2. MISMATCH + root (STRICT `=== true`) ⇒ `continue` (break-glass,
|
|
22
25
|
* audited by a later layer — not this gate's concern).
|
|
23
26
|
* 3. MISMATCH + not root ⇒ consult {@link CrossTenantGrantPort}:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tenant.d.ts","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EAKL,KAAK,YAAY,EAClB,MAAM,0BAA0B,CAAC;AAIlC;;;;;GAKG;AACH,wBAAgB,gBAAgB,IAAI,YAAY,CA8D/C"}
|
|
@@ -14,10 +14,13 @@
|
|
|
14
14
|
* ── The order (deny wins; every ambiguity resolves to the deny/continue path,
|
|
15
15
|
* never to a bypass):
|
|
16
16
|
*
|
|
17
|
-
* 1.
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
17
|
+
* 1. IN SCOPE (`resource.tenantId ∈ principal.scopeSubtreeNodeIds` — the active
|
|
18
|
+
* node + all descendants, ADR-0027 — OR the resource carries no instance
|
|
19
|
+
* tenant) ⇒ `continue`. An in-memory set test against the login-cached subtree
|
|
20
|
+
* (zero per-request DB, ADR-0024). A feature/object-type-level resource with no
|
|
21
|
+
* `tenantId` is same-tenant BY CONSTRUCTION — there is no foreign instance to
|
|
22
|
+
* cross into. The subtree ALWAYS contains the active node itself, so this is a
|
|
23
|
+
* strict generalization of the old flat `tenantId === resource.tenantId`.
|
|
21
24
|
* 2. MISMATCH + root (STRICT `=== true`) ⇒ `continue` (break-glass,
|
|
22
25
|
* audited by a later layer — not this gate's concern).
|
|
23
26
|
* 3. MISMATCH + not root ⇒ consult {@link CrossTenantGrantPort}:
|
|
@@ -51,9 +54,29 @@ import { isCrossTenantGrantApplicable } from '../cross-tenant/grant-evaluator.js
|
|
|
51
54
|
export function createTenantGate() {
|
|
52
55
|
return async function tenantGate(ctx) {
|
|
53
56
|
const { principal, action, resource, deps } = ctx;
|
|
54
|
-
// 1.
|
|
55
|
-
//
|
|
56
|
-
|
|
57
|
+
// 1. IN SCOPE — the resource's owning node is in the principal's active-scope
|
|
58
|
+
// SUBTREE (the node it acts under + all descendants, ADR-0027), OR there is
|
|
59
|
+
// no instance tenant (a feature/object-type resource with no foreign instance
|
|
60
|
+
// to cross into: same-tenant by construction).
|
|
61
|
+
// This is an IN-MEMORY set-membership test against the login-cached
|
|
62
|
+
// `scopeSubtreeNodeIds` — ZERO per-request DB (the ADR-0024 parity guarantee).
|
|
63
|
+
// A non-root principal reaches everything in its subtree (additive-down
|
|
64
|
+
// inheritance) and nothing outside it. `scopeSubtreeNodeIds` ALWAYS contains
|
|
65
|
+
// the active node itself (self-row, Task 2.2), so this GENERALIZES — never
|
|
66
|
+
// narrows — the old flat equality: the `tenantId === resource.tenantId` case
|
|
67
|
+
// is exactly the singleton-subtree case. Root's cross-tree span is NOT here;
|
|
68
|
+
// it is authoritative via `isRoot` (step 2 below). FAIL-CLOSED: an empty
|
|
69
|
+
// subtree makes `.includes` false for every node ⇒ falls through to root /
|
|
70
|
+
// cross-grant / deny (reaches nothing but its own via the self-node).
|
|
71
|
+
// DEFENSE-IN-DEPTH: `Array.isArray` guards a malformed/absent subtree (a
|
|
72
|
+
// JS-constructed Principal that omits the field despite the TS contract) —
|
|
73
|
+
// a non-array is treated as "no reachable scope" ⇒ deny, DETERMINISTICALLY,
|
|
74
|
+
// rather than relying on a thrown `undefined.includes` being caught as a
|
|
75
|
+
// fail-closed deny by the pipeline (fail-closed either way, but this is the
|
|
76
|
+
// explicit, non-crashy form).
|
|
77
|
+
const subtree = principal.scopeSubtreeNodeIds;
|
|
78
|
+
if (resource.tenantId === undefined ||
|
|
79
|
+
(Array.isArray(subtree) && subtree.includes(resource.tenantId))) {
|
|
57
80
|
return gateContinue();
|
|
58
81
|
}
|
|
59
82
|
// 2. Mismatch + root (break-glass). STRICT === true — a truthy
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tenant.js","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"tenant.js","sourceRoot":"","sources":["../../../src/authorization/gates/tenant.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AAEH,OAAO,EACL,YAAY,EACZ,QAAQ,GAIT,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,kBAAkB,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAElF;;;;;GAKG;AACH,MAAM,UAAU,gBAAgB;IAC9B,OAAO,KAAK,UAAU,UAAU,CAAC,GAAgB;QAC/C,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC;QAElD,8EAA8E;QAC9E,+EAA+E;QAC/E,iFAAiF;QACjF,kDAAkD;QAClD,uEAAuE;QACvE,kFAAkF;QAClF,2EAA2E;QAC3E,gFAAgF;QAChF,8EAA8E;QAC9E,gFAAgF;QAChF,gFAAgF;QAChF,4EAA4E;QAC5E,8EAA8E;QAC9E,yEAAyE;QACzE,4EAA4E;QAC5E,8EAA8E;QAC9E,+EAA+E;QAC/E,4EAA4E;QAC5E,+EAA+E;QAC/E,iCAAiC;QACjC,MAAM,OAAO,GAAG,SAAS,CAAC,mBAAmB,CAAC;QAC9C,IACE,QAAQ,CAAC,QAAQ,KAAK,SAAS;YAC/B,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,IAAI,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,EAC/D,CAAC;YACD,OAAO,YAAY,EAAE,CAAC;QACxB,CAAC;QAED,+DAA+D;QAC/D,gEAAgE;QAChE,IAAI,UAAU,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC;YACjC,OAAO,YAAY,EAAE,CAAC;QACxB,CAAC;QAED,sEAAsE;QACtE,gFAAgF;QAChF,yEAAyE;QACzE,gFAAgF;QAChF,8EAA8E;QAC9E,gFAAgF;QAChF,iFAAiF;QACjF,8EAA8E;QAC9E,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,4BAA4B,CAAC,IAAI,CAAC,gBAAgB,EAAE;YAC/E,SAAS;YACT,MAAM;YACN,QAAQ;SACT,CAAC,CAAC;QAEH,IAAI,UAAU,EAAE,CAAC;YACf,0EAA0E;YAC1E,0EAA0E;YAC1E,OAAO,YAAY,EAAE,CAAC;QACxB,CAAC;QAED,gFAAgF;QAChF,iEAAiE;QACjE,OAAO,QAAQ,CAAC,kBAAkB,EAAE,CAAC,CAAC;IACxC,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -161,5 +161,6 @@ export * from './cross-tenant/grant-evaluator.js';
|
|
|
161
161
|
export * from './delegation/operation-identity.js';
|
|
162
162
|
export * from './record/owner-baseline.js';
|
|
163
163
|
export * from './record/permit-tier.js';
|
|
164
|
+
export * from './record/list-scope.js';
|
|
164
165
|
export * from './gates/wiring.js';
|
|
165
166
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK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
|
113
113
|
// - INTEGRATION: the composed gate-6 record permit tier (baseline ∪ policy ∪ share, deny-wins):
|
|
114
114
|
export * from './record/permit-tier.js';
|
|
115
|
+
// - LIST SCOPE: the decision-derived visible-set spec — sibling to decide() (Phase 1):
|
|
116
|
+
export * from './record/list-scope.js';
|
|
115
117
|
// - INTEGRATION: the production gate-set wiring + fully-wired DecisionAuthority factory:
|
|
116
118
|
export * from './gates/wiring.js';
|
|
117
119
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/authorization/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAgBH;;;GAGG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAe,OAAO,CAAC;AAEvD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAkB,MAAM,CAAC,2BAA2B,CAAC,CAAC;AAc5F;;;GAGG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAY,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAC;AAElD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,mBAAmB,CACjC,SAAiB,EACjB,OAAe,EACf,SAAiB;IAEjB,KAAK,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,IAAI;QACxB,CAAC,WAAW,EAAE,SAAS,CAAC;QACxB,CAAC,SAAS,EAAE,OAAO,CAAC;QACpB,CAAC,WAAW,EAAE,SAAS,CAAC;KAChB,EAAE,CAAC;QACX,0EAA0E;QAC1E,4EAA4E;QAC5E,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACrB,MAAM,IAAI,KAAK,CAAC,wBAAwB,IAAI,oBAAoB,CAAC,CAAC;QACpE,CAAC;QACD,IAAI,GAAG,CAAC,QAAQ,CAAC,wBAAwB,CAAC,EAAE,CAAC;YAC3C,MAAM,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FAAoF;AACpF,cAAc,mBAAmB,CAAC;AAClC,6EAA6E;AAC7E,gFAAgF;AAChF,cAAc,yBAAyB,CAAC;AACxC,kFAAkF;AAClF,cAAc,oBAAoB,CAAC;AACnC,sFAAsF;AACtF,qEAAqE;AACrE,sEAAsE;AACtE,cAAc,mBAAmB,CAAC;AAClC,cAAc,wBAAwB,CAAC;AACvC,4EAA4E;AAC5E,cAAc,4BAA4B,CAAC;AAC3C,6EAA6E;AAC7E,cAAc,oBAAoB,CAAC;AACnC,sFAAsF;AACtF,cAAc,mCAAmC,CAAC;AAClD,wEAAwE;AACxE,cAAc,oCAAoC,CAAC;AACnD,4FAA4F;AAC5F,cAAc,4BAA4B,CAAC;AAC3C,kGAAkG;AAClG,cAAc,yBAAyB,CAAC;AACxC,yFAAyF;AACzF,cAAc,wBAAwB,CAAC;AACvC,2FAA2F;AAC3F,cAAc,mBAAmB,CAAC"}
|
|
@@ -34,6 +34,7 @@
|
|
|
34
34
|
*/
|
|
35
35
|
import type { Principal } from '../identity/index.js';
|
|
36
36
|
import type { Action, Resource } from './index.js';
|
|
37
|
+
import type { ScopeCondition } from './record/list-scope.js';
|
|
37
38
|
/**
|
|
38
39
|
* The coarse feature/object-type grants a principal holds in a tenant — the
|
|
39
40
|
* ADR-0011 "facts" projected at session establish and consumed by gate 5. Kept
|
|
@@ -222,6 +223,70 @@ export interface CrossTenantGrantPort {
|
|
|
222
223
|
*/
|
|
223
224
|
findActiveGrant(query: CrossTenantGrantQuery): Promise<CrossTenantGrant | null>;
|
|
224
225
|
}
|
|
226
|
+
/**
|
|
227
|
+
* The policy condition-groups describing the policy-ALLOWED / policy-DENIED subsets of
|
|
228
|
+
* a LIST scope (ADR-0005, list form). Each side is a list of AND-GROUPS OR'd together:
|
|
229
|
+
* a row satisfies a group iff it satisfies ALL of the group's {@link ScopeCondition}s,
|
|
230
|
+
* and the subset is the UNION over groups. This preserves the guided-policy semantics
|
|
231
|
+
* (each policy is an AND of its conditions; multiple policies OR) so the guard translator
|
|
232
|
+
* can render it WITHOUT losing AND-vs-OR precedence.
|
|
233
|
+
*/
|
|
234
|
+
export interface ListPolicyConditions {
|
|
235
|
+
/** AND-groups of conditions; a row is policy-ALLOWED if it satisfies ALL conditions of ANY group. */
|
|
236
|
+
readonly allow: readonly (readonly ScopeCondition[])[];
|
|
237
|
+
/** AND-groups of conditions; a row is policy-DENIED (deny-wins) if it satisfies ALL of ANY group. */
|
|
238
|
+
readonly deny: readonly (readonly ScopeCondition[])[];
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* The requesting principal's SUBJECT identity — the id + role ids the list-scope adapter
|
|
242
|
+
* uses to filter each policy rule GROUP by its `rpr_subject_kind` / `rpr_subject_value`,
|
|
243
|
+
* EXACTLY as the per-record rule adapter's `subjectMatches` does. Threading it makes the
|
|
244
|
+
* list scope enforce the SAME subject scoping `decide()` enforces per record.
|
|
245
|
+
*/
|
|
246
|
+
export interface ListScopeSubject {
|
|
247
|
+
/** The requesting principal's id (for future subject kinds; parity with `subjectMatches`). */
|
|
248
|
+
readonly principalId: string;
|
|
249
|
+
/** The requesting principal's role ids — a `role`-subjected rule applies IFF this includes its value. */
|
|
250
|
+
readonly roleIds: readonly string[];
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Resolves the policy allow/deny condition-groups governing the visible set for a LIST
|
|
254
|
+
* scope (ADR-0005, list form). SIBLING to {@link RecordPermissionRulePort.evaluate}
|
|
255
|
+
* (which answers ONE record with allow/explicitDeny booleans); this returns the abstract
|
|
256
|
+
* conditions the guard translator pushes into the WHERE for a whole collection.
|
|
257
|
+
*
|
|
258
|
+
* Concrete adapter (policy storage → condition-group projection) ships in `@astram/guard`.
|
|
259
|
+
*/
|
|
260
|
+
export interface ListScopePort {
|
|
261
|
+
/**
|
|
262
|
+
* The policy allow/deny condition-groups governing the visible set for
|
|
263
|
+
* `(typeKey, tenantId, action)`. NO applicable policy ⇒ empty `allow` + empty `deny`
|
|
264
|
+
* (a normal ABSENCE — not an error, not a deny).
|
|
265
|
+
*
|
|
266
|
+
* @param subject the requesting principal's id + role ids, used to filter each rule
|
|
267
|
+
* group by its `rpr_subject_kind` / `rpr_subject_value` EXACTLY as the per-record rule
|
|
268
|
+
* adapter's `subjectMatches` does, so the list scope enforces the SAME subject scoping
|
|
269
|
+
* `decide()` enforces. Omitting it would project role-scoped rules to EVERY principal —
|
|
270
|
+
* a fail-open leak (HIGH-1): a `role`-subjected allow rule the principal's role does NOT
|
|
271
|
+
* hold would show rows `decide()` denies. The filter applies to BOTH allow AND deny
|
|
272
|
+
* groups (a role-subjected DENY not aimed at the principal must NOT over-restrict them).
|
|
273
|
+
*
|
|
274
|
+
* @throws {@link AuthorizationUnavailableError} if the store genuinely CANNOT answer
|
|
275
|
+
* (transient). It MUST NOT return empty to mask an outage — that would silently
|
|
276
|
+
* unbound/mis-scope the list. FAIL-CLOSED: a throw here PROPAGATES so the read fails,
|
|
277
|
+
* never "unbounded" (ADR-0016 / Invariant #8).
|
|
278
|
+
*/
|
|
279
|
+
/**
|
|
280
|
+
* `tenantNodeIds` — the caller's reachable tenant NODE SET (its active-scope subtree:
|
|
281
|
+
* active node + descendants, ADR-0027), NOT just the active node. Policy rules scoped to
|
|
282
|
+
* ANY node in the subtree apply (a DENY at a descendant node must exclude that node's
|
|
283
|
+
* records for a parent admin — deny-wins inherits DOWN, exactly as `decide()` applies it
|
|
284
|
+
* per-record at the record's own node); plus global (NULL-tenant) rules. For a flat /
|
|
285
|
+
* self-node-only caller this is `[activeScopeNodeId]` — identical to the old single-tenant
|
|
286
|
+
* filter. The adapter filters `rpr_tenant_uuid IN (…nodes) OR rpr_tenant_uuid IS NULL`.
|
|
287
|
+
*/
|
|
288
|
+
listPolicyConditions(typeKey: string, tenantNodeIds: readonly string[], action: string, subject: ListScopeSubject): Promise<ListPolicyConditions>;
|
|
289
|
+
}
|
|
225
290
|
/**
|
|
226
291
|
* A delegated authority a trusted operation declares for one of its steps
|
|
227
292
|
* (ADR-0008). It is a SCOPED, non-wildcard authority under which gates 3–6 are
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/authorization/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"ports.d.ts","sourceRoot":"","sources":["../../src/authorization/ports.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAInD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAM7D;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,CAAC;IACpC;;;;;OAKG;IACH,QAAQ,CAAC,qBAAqB,EAAE,SAAS,MAAM,EAAE,CAAC;CACnD;AAED;;;;;;;GAOG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;;;;OAUG;IACH,yBAAyB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAElF;;;;;;;;;;OAUG;IACH,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;CAChF;AAMD,sFAAsF;AACtF,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,MAAM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