@astram/guard 0.39.0 → 0.40.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/agent/agent-provenance.d.ts +24 -0
- package/dist/agent/agent-provenance.d.ts.map +1 -1
- package/dist/agent/agent-provenance.js +33 -1
- package/dist/auth/auth.module.d.ts.map +1 -1
- package/dist/auth/auth.module.js +40 -2
- package/dist/auth/tokens.d.ts +14 -0
- package/dist/auth/tokens.d.ts.map +1 -1
- package/dist/auth/tokens.js +16 -2
- package/dist/authentication/service-account-principal.d.ts +29 -0
- package/dist/authentication/service-account-principal.d.ts.map +1 -0
- package/dist/authentication/service-account-principal.js +55 -0
- package/dist/enforcement/facts-version.d.ts +22 -0
- package/dist/enforcement/facts-version.d.ts.map +1 -0
- package/dist/enforcement/facts-version.js +34 -0
- package/dist/enforcement/global-enforcement.guard.d.ts +9 -26
- package/dist/enforcement/global-enforcement.guard.d.ts.map +1 -1
- package/dist/enforcement/global-enforcement.guard.js +48 -177
- package/dist/enforcement/session-facts-reload.d.ts +66 -0
- package/dist/enforcement/session-facts-reload.d.ts.map +1 -0
- package/dist/enforcement/session-facts-reload.js +168 -0
- package/dist/identity/identity-actions.d.ts +1 -1
- package/dist/identity/identity-actions.d.ts.map +1 -1
- package/dist/identity/identity-actions.js +4 -0
- package/dist/internal.d.ts +23 -0
- package/dist/internal.d.ts.map +1 -1
- package/dist/internal.js +36 -1
- package/dist/module/shield-tokens.d.ts +60 -11
- package/dist/module/shield-tokens.d.ts.map +1 -1
- package/dist/notifications/notification.service.d.ts +3 -0
- package/dist/notifications/notification.service.d.ts.map +1 -1
- package/dist/notifications/notification.service.js +9 -0
- package/dist/request-auth/request-principal.d.ts +5 -0
- package/dist/request-auth/request-principal.d.ts.map +1 -1
- package/dist/request-auth/request-principal.js +7 -1
- package/dist/request-auth/session-token-binder.d.ts +79 -6
- package/dist/request-auth/session-token-binder.d.ts.map +1 -1
- package/dist/request-auth/session-token-binder.js +264 -173
- package/dist/session/call-principals.d.ts +54 -0
- package/dist/session/call-principals.d.ts.map +1 -0
- package/dist/session/call-principals.js +38 -0
- package/dist/session/session-principal.d.ts +86 -0
- package/dist/session/session-principal.d.ts.map +1 -0
- package/dist/session/session-principal.js +139 -0
- package/package.json +5 -5
|
@@ -14,21 +14,19 @@ var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
|
14
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
15
|
exports.GlobalEnforcementGuard = void 0;
|
|
16
16
|
exports.requestFactsVersion = requestFactsVersion;
|
|
17
|
+
exports.requestServiceKeyVersion = requestServiceKeyVersion;
|
|
17
18
|
const common_1 = require("@nestjs/common");
|
|
18
19
|
const core_1 = require("@nestjs/core");
|
|
19
20
|
const classification_decorator_js_1 = require("./classification.decorator.js");
|
|
20
21
|
const shield_tokens_js_1 = require("../module/shield-tokens.js");
|
|
21
22
|
const tokens_js_1 = require("../request-auth/tokens.js");
|
|
22
|
-
const session_token_binder_js_1 = require("../request-auth/session-token-binder.js");
|
|
23
23
|
const request_principal_js_1 = require("../request-auth/request-principal.js");
|
|
24
24
|
const tokens_js_2 = require("../auth/tokens.js");
|
|
25
|
-
const session_facts_als_js_1 = require("../request-auth/session-facts-als.js");
|
|
26
25
|
const request_principal_als_js_1 = require("../request-auth/request-principal-als.js");
|
|
27
26
|
const reenroll_allowlist_js_1 = require("./reenroll-allowlist.js");
|
|
28
27
|
const session_restriction_js_1 = require("../session/session-restriction.js");
|
|
29
28
|
const mfa_requirement_service_js_1 = require("../session/mfa-requirement-service.js");
|
|
30
|
-
|
|
31
|
-
const SUBTREE_REDERIVE_FAILED = Symbol('subtree-rederive-failed');
|
|
29
|
+
const session_facts_reload_js_1 = require("./session-facts-reload.js");
|
|
32
30
|
/**
|
|
33
31
|
* The permission version gate 5 derived each request's `req.principal` (roles and subtree) under
|
|
34
32
|
* (G-036 M1, agent-read-capabilities SPEC §5 run-loop "Manifest"). Keyed by the request object, so
|
|
@@ -53,15 +51,24 @@ function requestFactsVersion(req) {
|
|
|
53
51
|
return REQUEST_FACTS_VERSION.get(req);
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
56
|
-
* The
|
|
57
|
-
*
|
|
54
|
+
* The verified `ask_` key version of each request whose principal is a service account
|
|
55
|
+
* (background-agent-tasks SPEC v3 §5 B), keyed by the request object like
|
|
56
|
+
* {@link REQUEST_FACTS_VERSION}: nothing on the request can set or spoof it. Written only by
|
|
57
|
+
* {@link GlobalEnforcementGuard}, beside `req.principal`; read only through
|
|
58
|
+
* {@link requestServiceKeyVersion}.
|
|
58
59
|
*/
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
const REQUEST_SERVICE_KEY_VERSION = new WeakMap();
|
|
61
|
+
/**
|
|
62
|
+
* The key version the enforcement guard verified this request's `ask_` key at (core
|
|
63
|
+
* `ServiceAuthResult.keyVersion`). `undefined` for a session request, a request the guard did not
|
|
64
|
+
* authenticate, a public route, a non-object, or an authenticator that reported none (callers fail
|
|
65
|
+
* closed). On `@astram/guard/internal` for `@astram/agent` only: an unattended task stores it, so a
|
|
66
|
+
* key rotation stops the task. Never an input to a decision.
|
|
67
|
+
*/
|
|
68
|
+
function requestServiceKeyVersion(req) {
|
|
69
|
+
if (req === null || typeof req !== 'object')
|
|
70
|
+
return undefined;
|
|
71
|
+
return REQUEST_SERVICE_KEY_VERSION.get(req);
|
|
65
72
|
}
|
|
66
73
|
/**
|
|
67
74
|
* Global, fail-closed enforcement guard (ADR-0002) — now with REAL request
|
|
@@ -166,101 +173,42 @@ let GlobalEnforcementGuard = class GlobalEnforcementGuard {
|
|
|
166
173
|
this.enforceRestriction(claims, req);
|
|
167
174
|
// Attach the resolved principal so downstream handlers can act as this user.
|
|
168
175
|
req.principal = principal;
|
|
169
|
-
//
|
|
170
|
-
//
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
// the decision authority) reads the SAME `SHIELD_SESSION_FACTS_ALS` store inside
|
|
174
|
-
// decide(), so gate 5 gets these facts and can serve the coarse decision from cache
|
|
175
|
-
// (no DB reload) when the cached version is still fresh.
|
|
176
|
-
//
|
|
177
|
-
// CROSS-PRINCIPAL ISOLATION: `als.run(store, cb)` binds `store` to this async
|
|
178
|
-
// context and everything decide() awaits, and ONLY that context — a concurrent
|
|
179
|
-
// request runs its own `run()` with its own store, so getStore() never returns
|
|
180
|
-
// another request's facts. The store is built HERE from THIS request's claims.
|
|
181
|
-
//
|
|
182
|
-
// FAIL-CLOSED: no projector wired / absent / malformed binding → `claims.cachedFacts`
|
|
183
|
-
// is undefined → the store carries `cachedFacts: null` → gate 5 DB-reloads (today's
|
|
184
|
-
// behavior). The cache is only ever consulted; it never fabricates a permit.
|
|
185
|
-
//
|
|
186
|
-
// RELOAD SIGNAL (security hardening Phase 1C): when gate 5 reloads THIS principal's grants,
|
|
187
|
-
// the framework-built authority reports the reloaded (authoritative) version here.
|
|
188
|
-
//
|
|
189
|
-
// TIME BOUND (ADR-0035): cached facts at or past their `validUntilMs` (the next start or end of
|
|
190
|
-
// a role posting's window — a change no version bump marks) are treated as ABSENT, so gate 5
|
|
191
|
-
// reloads them (and the roles with them, below).
|
|
192
|
-
let reloaded;
|
|
193
|
-
const usableFacts = usableCachedFacts(claims.cachedFacts, Date.now());
|
|
194
|
-
const factsStore = {
|
|
195
|
-
cachedFacts: usableFacts,
|
|
196
|
-
permissionsVersion: usableFacts?.permissionsVersion ?? 0,
|
|
197
|
-
onReload: (principalId, tenantId, grants) => {
|
|
198
|
-
if (principalId === principal.id && tenantId === principal.tenantId) {
|
|
199
|
-
reloaded = grants;
|
|
200
|
-
}
|
|
201
|
-
},
|
|
202
|
-
};
|
|
203
|
-
const decision = await session_facts_als_js_1.SHIELD_SESSION_FACTS_ALS.run(factsStore, () => this.decisionAuthority.decide(principal, { key: classification.action }, { level: 'object_type', typeKey: classification.typeKey, tenantId: principal.tenantId }, { isAuthenticated: true }));
|
|
204
|
-
// The type-level decision above is on the principal's OWN tenant, which every subtree
|
|
205
|
-
// contains, so it does not depend on the subtree; the handler (engine record checks, the
|
|
206
|
-
// ADR-0034 create wall) is what reads it. Hence: decide first, then hand the handler the
|
|
207
|
-
// re-derived principal.
|
|
208
|
-
//
|
|
209
|
-
// LIVE ROLES (ADR-0035, GAPS #4): the reload also carries the principal's in-effect roles (when
|
|
210
|
-
// the app port reports them). The handler gets them on THIS request (role-keyed record rules,
|
|
211
|
-
// list scope, shares, the engine's record checks all read `req.principal.roleIds`), and the
|
|
212
|
-
// binding is rewritten with the reloaded facts + roles together, so the next requests are
|
|
213
|
-
// served from the cache (GAPS #6) with the same live roles.
|
|
214
|
-
// MANDATORY 2FA (auth capabilities R2.5, AC-9): re-evaluate when the permission version moved
|
|
215
|
-
// past the session's requirement stamp — gate 5 just told us the version (its reload, or the
|
|
216
|
-
// fresh cached facts it served). Unchanged version ⇒ no DB query. A failed evaluation denies
|
|
217
|
-
// this request (503) and caches nothing, so the next request reloads and retries.
|
|
218
|
-
let enforced = claims;
|
|
219
|
-
let mfaFailed = false;
|
|
220
|
-
const mfa = this.mfaRequirement;
|
|
221
|
-
if (mfa !== undefined && mfa !== null) {
|
|
222
|
-
const token = (0, request_principal_js_1.extractBearerToken)(authHeader);
|
|
223
|
-
try {
|
|
224
|
-
enforced = await mfa.refresh(token ?? '', claims, {
|
|
225
|
-
version: reloaded?.permissionsVersion ?? usableFacts?.permissionsVersion,
|
|
226
|
-
grants: reloaded ?? usableFacts ?? undefined,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
catch {
|
|
230
|
-
mfaFailed = true;
|
|
231
|
-
}
|
|
176
|
+
// Background-agent-tasks SPEC v3 §5 B: the verified `ask_` key version beside it (service
|
|
177
|
+
// accounts only; cleared otherwise so a reused request object never carries a stale one).
|
|
178
|
+
if (principal.kind === 'service_account' && resolved.keyVersion !== undefined) {
|
|
179
|
+
REQUEST_SERVICE_KEY_VERSION.set(req, resolved.keyVersion);
|
|
232
180
|
}
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
const liveRoles = (0, session_token_binder_js_1.liveRoleIds)(reloaded);
|
|
236
|
-
const current = liveRoles !== undefined ? { ...claims, roleIds: liveRoles } : claims;
|
|
237
|
-
const rederived = await this.rederiveSubtreeOnVersionMove(authHeader, current, reloaded.permissionsVersion);
|
|
238
|
-
subtreeStale = rederived === SUBTREE_REDERIVE_FAILED;
|
|
239
|
-
// A subtree re-derive that was due but FAILED (resolver error / empty) keeps the facts
|
|
240
|
-
// uncached, so the next request reloads and retries it (the Phase 1C retry guarantee).
|
|
241
|
-
if (rederived !== SUBTREE_REDERIVE_FAILED) {
|
|
242
|
-
await this.rebindReloadedGrants(authHeader, claims, reloaded, liveRoles);
|
|
243
|
-
}
|
|
244
|
-
if (rederived !== null && rederived !== SUBTREE_REDERIVE_FAILED) {
|
|
245
|
-
req.principal = rederived;
|
|
246
|
-
}
|
|
247
|
-
else if (liveRoles !== undefined) {
|
|
248
|
-
const withRoles = (0, request_principal_js_1.principalFromClaims)(current);
|
|
249
|
-
if (withRoles !== null)
|
|
250
|
-
req.principal = withRoles;
|
|
251
|
-
}
|
|
181
|
+
else {
|
|
182
|
+
REQUEST_SERVICE_KEY_VERSION.delete(req);
|
|
252
183
|
}
|
|
184
|
+
// ── GATE 5 ON THE SESSION FACTS, AND WHAT FOLLOWS IT (ADR-0011, ADR-0035) ────
|
|
185
|
+
// decide() inside the session-facts ALS scope (cached facts served while fresh and inside
|
|
186
|
+
// their time bound, else gate 5 reloads them), the mandatory-2FA recompute, the live roles,
|
|
187
|
+
// the subtree re-derive and the write-back of a reload. ONE implementation, shared with the
|
|
188
|
+
// off-request session facts refresh (background-agent-tasks SPEC v9 §5 C), Shield #3: see
|
|
189
|
+
// `session-facts-reload.ts`. The handler gets the re-derived principal (subtree / live roles).
|
|
190
|
+
const outcome = await (0, session_facts_reload_js_1.decideOnSessionFacts)({
|
|
191
|
+
decisionAuthority: this.decisionAuthority,
|
|
192
|
+
tokenBinder: this.tokenBinder,
|
|
193
|
+
scopeSubtreeResolver: this.scopeSubtreeResolver,
|
|
194
|
+
mfaRequirement: this.mfaRequirement,
|
|
195
|
+
}, {
|
|
196
|
+
principal,
|
|
197
|
+
claims,
|
|
198
|
+
accessToken: (0, request_principal_js_1.extractBearerToken)(authHeader),
|
|
199
|
+
classification,
|
|
200
|
+
nowMs: Date.now(),
|
|
201
|
+
});
|
|
202
|
+
const { decision, enforced, mfaFailed } = outcome;
|
|
203
|
+
if (outcome.principal !== principal)
|
|
204
|
+
req.principal = outcome.principal;
|
|
253
205
|
// G-036 M1 (SPEC §5 run-loop): record the version the principal above was derived under, from
|
|
254
206
|
// what gate 5 already reported (no new read). Absent when gate 5 reported none or the subtree
|
|
255
207
|
// re-derive failed (the principal's subtree then belongs to no single version). For a ROOT
|
|
256
208
|
// principal gate 5 loads and checks no grants (core decides root by its flag and plane), so
|
|
257
209
|
// cached facts it never compared with the tenant's version say nothing (SPEC v8): absent.
|
|
258
|
-
const derivedUnder =
|
|
259
|
-
|
|
260
|
-
if (!subtreeStale &&
|
|
261
|
-
typeof derivedUnder === 'number' &&
|
|
262
|
-
Number.isSafeInteger(derivedUnder) &&
|
|
263
|
-
derivedUnder >= 0) {
|
|
210
|
+
const derivedUnder = outcome.factsVersion;
|
|
211
|
+
if (derivedUnder !== undefined) {
|
|
264
212
|
REQUEST_FACTS_VERSION.set(req, derivedUnder);
|
|
265
213
|
}
|
|
266
214
|
else {
|
|
@@ -297,83 +245,6 @@ let GlobalEnforcementGuard = class GlobalEnforcementGuard {
|
|
|
297
245
|
throw new common_1.ForbiddenException({ error: (0, session_restriction_js_1.restrictionErrorCode)(reason) });
|
|
298
246
|
}
|
|
299
247
|
}
|
|
300
|
-
/**
|
|
301
|
-
* Write gate 5's reloaded grants and the live roles onto the session binding (ADR-0035). Session
|
|
302
|
-
* bindings only: a service-account key has no binding (its roles and scope are read live per
|
|
303
|
-
* request by the key store). Best-effort and conditional (same session, same tenant, fresher
|
|
304
|
-
* facts, `XX`): a miss or a Redis error only means the next request reloads again.
|
|
305
|
-
*/
|
|
306
|
-
async rebindReloadedGrants(authHeader, claims, grants, liveRoles) {
|
|
307
|
-
if (this.tokenBinder === undefined)
|
|
308
|
-
return;
|
|
309
|
-
if (claims.sessionId === '' || claims.kind === 'service_account')
|
|
310
|
-
return;
|
|
311
|
-
const token = (0, request_principal_js_1.extractBearerToken)(authHeader);
|
|
312
|
-
if (token === null)
|
|
313
|
-
return;
|
|
314
|
-
try {
|
|
315
|
-
await this.tokenBinder.refreshGrants(token, claims.sessionId, claims.tenantId, grants, liveRoles);
|
|
316
|
-
}
|
|
317
|
-
catch {
|
|
318
|
-
// Best-effort: the decision and the handler's principal already use the reloaded grants.
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* Re-derive the session's scope subtree after gate 5 reloaded facts at `reloadedVersion`
|
|
323
|
-
* (security hardening Phase 1C). Identity bumps a tenant's permission version when a company is
|
|
324
|
-
* created, moved or deleted under it, so a reload at a version newer than the bound subtree's
|
|
325
|
-
* stamp means the subtree may be stale: resolve it again with the SAME resolver login uses,
|
|
326
|
-
* rebind it (token + session entries) and return the principal the handler should see.
|
|
327
|
-
*
|
|
328
|
-
* Off the hot path: runs only for a session binding that carries a subtree, with a resolver
|
|
329
|
-
* wired, and a reload NEWER than its stamp (or no stamp yet — once, then stamped). That is the
|
|
330
|
-
* only DB read added (one closure query), and only on a version change.
|
|
331
|
-
*
|
|
332
|
-
* FAIL-CLOSED, NON-WIDENING: a resolver error, a non-array or an EMPTY result →
|
|
333
|
-
* {@link SUBTREE_REDERIVE_FAILED}: the bound subtree stays (never replaced by a guess, never
|
|
334
|
-
* widened), the stamp is not advanced, the reloaded facts are not cached (ADR-0035), and the next
|
|
335
|
-
* request reloads and retries. `null` = no re-derive was due. A failed Redis rebind still returns the fresh principal for this request
|
|
336
|
-
* (the DB answer is authoritative); the next reload retries the rebind.
|
|
337
|
-
*/
|
|
338
|
-
async rederiveSubtreeOnVersionMove(authHeader, claims, reloadedVersion) {
|
|
339
|
-
const resolver = this.scopeSubtreeResolver;
|
|
340
|
-
if (resolver === undefined || resolver === null || this.tokenBinder === undefined)
|
|
341
|
-
return null;
|
|
342
|
-
// Session bindings only: a service-account key has no binding (its scope is read live per
|
|
343
|
-
// request by the key store) and no session id.
|
|
344
|
-
if (claims.sessionId === '' || claims.kind === 'service_account')
|
|
345
|
-
return null;
|
|
346
|
-
// Only a binding that carries a subtree: an absent one is the self-node fallback (no resolver
|
|
347
|
-
// or a failed login-time resolve) and stays that way until the next login/refresh.
|
|
348
|
-
if (claims.scopeSubtreeNodeIds === undefined || claims.scopeSubtreeNodeIds.length === 0) {
|
|
349
|
-
return null;
|
|
350
|
-
}
|
|
351
|
-
const stamp = claims.scopeSubtreeVersion;
|
|
352
|
-
if (stamp !== undefined && reloadedVersion <= stamp)
|
|
353
|
-
return null;
|
|
354
|
-
let subtree;
|
|
355
|
-
try {
|
|
356
|
-
const resolved = await resolver.resolveSubtree(claims.tenantId);
|
|
357
|
-
if (!Array.isArray(resolved) || resolved.length === 0)
|
|
358
|
-
return SUBTREE_REDERIVE_FAILED;
|
|
359
|
-
if (resolved.some((n) => typeof n !== 'string' || n.length === 0)) {
|
|
360
|
-
return SUBTREE_REDERIVE_FAILED;
|
|
361
|
-
}
|
|
362
|
-
subtree = [...resolved];
|
|
363
|
-
}
|
|
364
|
-
catch {
|
|
365
|
-
return SUBTREE_REDERIVE_FAILED;
|
|
366
|
-
}
|
|
367
|
-
const token = (0, request_principal_js_1.extractBearerToken)(authHeader);
|
|
368
|
-
if (token !== null) {
|
|
369
|
-
await this.tokenBinder.rederiveScopeSubtree(token, claims.sessionId, claims.tenantId, subtree, reloadedVersion);
|
|
370
|
-
}
|
|
371
|
-
return (0, request_principal_js_1.principalFromClaims)({
|
|
372
|
-
...claims,
|
|
373
|
-
scopeSubtreeNodeIds: subtree,
|
|
374
|
-
scopeSubtreeVersion: reloadedVersion,
|
|
375
|
-
});
|
|
376
|
-
}
|
|
377
248
|
};
|
|
378
249
|
exports.GlobalEnforcementGuard = GlobalEnforcementGuard;
|
|
379
250
|
exports.GlobalEnforcementGuard = GlobalEnforcementGuard = __decorate([
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Gate 5 on a session's facts, and everything the enforcement guard does after it (ADR-0011,
|
|
3
|
+
* ADR-0035, security hardening Phase 1C, auth capabilities R2.5): the ONE implementation shared by
|
|
4
|
+
* {@link import('./global-enforcement.guard.js').GlobalEnforcementGuard} (every classified request)
|
|
5
|
+
* and the off-request session facts refresh (`session/session-principal.ts`
|
|
6
|
+
* `refreshSessionFacts`, background-agent-tasks SPEC v9 §5 C), so both reload, recompute and write
|
|
7
|
+
* back the same way (Shield #3).
|
|
8
|
+
*
|
|
9
|
+
* In order:
|
|
10
|
+
* 1. `decide()` inside the session-facts ALS scope with the binding's USABLE cached facts (absent
|
|
11
|
+
* or past `validUntilMs` ⇒ none, so gate 5 reloads them through the app's
|
|
12
|
+
* `PermissionFactsPort.loadCoarseGrants`: the one MariaDB read of a reload). The reload, if
|
|
13
|
+
* any, is reported through `onReload`.
|
|
14
|
+
* 2. The mandatory-2FA recompute (`MfaRequirementService.refresh`), which reads the database only
|
|
15
|
+
* when the version moved past the session's requirement stamp.
|
|
16
|
+
* 3. After a reload: the live roles, the scope-subtree re-derive when the reload is newer than the
|
|
17
|
+
* bound subtree's stamp (one closure read, only then), and the write-back of the reloaded facts
|
|
18
|
+
* and roles onto the binding (`SessionTokenBinder.refreshGrants`, conditional and best-effort).
|
|
19
|
+
* 4. The version the returned principal was derived under ({@link derivedFactsVersion}).
|
|
20
|
+
*
|
|
21
|
+
* The caller decides what a deny, an MFA failure or a restriction means for it (the guard answers
|
|
22
|
+
* 403 / 503; the refresh answers `null`). A `decide()` error propagates.
|
|
23
|
+
*/
|
|
24
|
+
import type { Principal } from '@astram/core';
|
|
25
|
+
import type { CoreDecision, CoreDecisionAuthority } from './core-seam.js';
|
|
26
|
+
import { type BoundPrincipalClaims, type SessionTokenBinder } from '../request-auth/session-token-binder.js';
|
|
27
|
+
import type { ScopeSubtreeResolver } from '../auth/ports/scope-subtree-resolver.js';
|
|
28
|
+
import type { MfaRequirementService } from '../session/mfa-requirement-service.js';
|
|
29
|
+
/** What the shared path needs (the guard's own collaborators). */
|
|
30
|
+
export interface SessionFactsReloadDeps {
|
|
31
|
+
readonly decisionAuthority: CoreDecisionAuthority;
|
|
32
|
+
readonly tokenBinder: Pick<SessionTokenBinder, 'refreshGrants' | 'rederiveScopeSubtree'>;
|
|
33
|
+
readonly scopeSubtreeResolver?: ScopeSubtreeResolver | null | undefined;
|
|
34
|
+
readonly mfaRequirement?: MfaRequirementService | null | undefined;
|
|
35
|
+
}
|
|
36
|
+
export interface SessionFactsReloadInput {
|
|
37
|
+
/** The principal built from `claims` ({@link principalFromClaims}). */
|
|
38
|
+
readonly principal: Principal;
|
|
39
|
+
readonly claims: BoundPrincipalClaims;
|
|
40
|
+
/**
|
|
41
|
+
* The access token whose binding is written back beside the session-claims entry: the bearer
|
|
42
|
+
* token of the request; `null` off-request (the binder then uses the token currently bound to
|
|
43
|
+
* the session, if any).
|
|
44
|
+
*/
|
|
45
|
+
readonly accessToken: string | null;
|
|
46
|
+
/** The route classification `decide()` runs for (the gate 5 reload happens inside it). */
|
|
47
|
+
readonly classification: {
|
|
48
|
+
readonly typeKey: string;
|
|
49
|
+
readonly action: string;
|
|
50
|
+
};
|
|
51
|
+
readonly nowMs: number;
|
|
52
|
+
}
|
|
53
|
+
export interface SessionFactsReloadResult {
|
|
54
|
+
readonly decision: CoreDecision;
|
|
55
|
+
/** The principal to act as: re-derived subtree or live roles after a reload, else the input. */
|
|
56
|
+
readonly principal: Principal;
|
|
57
|
+
/** The claims after the mandatory-2FA recompute (the input claims when nothing changed). */
|
|
58
|
+
readonly enforced: BoundPrincipalClaims;
|
|
59
|
+
/** The recompute failed: the guard answers 503, the refresh `null`; nothing was cached. */
|
|
60
|
+
readonly mfaFailed: boolean;
|
|
61
|
+
/** {@link derivedFactsVersion} for the returned principal (`undefined` ⇒ callers fail closed). */
|
|
62
|
+
readonly factsVersion: number | undefined;
|
|
63
|
+
}
|
|
64
|
+
/** Steps 1–4 above. Throws only what `decide()` throws. */
|
|
65
|
+
export declare function decideOnSessionFacts(deps: SessionFactsReloadDeps, input: SessionFactsReloadInput): Promise<SessionFactsReloadResult>;
|
|
66
|
+
//# sourceMappingURL=session-facts-reload.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-facts-reload.d.ts","sourceRoot":"","sources":["../../src/enforcement/session-facts-reload.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,OAAO,KAAK,EAAgB,SAAS,EAAE,MAAM,cAAc,CAAC;AAC5D,OAAO,KAAK,EAAE,YAAY,EAAE,qBAAqB,EAAE,MAAM,gBAAgB,CAAC;AAC1E,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,kBAAkB,EACxB,MAAM,yCAAyC,CAAC;AAMjD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,yCAAyC,CAAC;AACpF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAMnF,kEAAkE;AAClE,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,iBAAiB,EAAE,qBAAqB,CAAC;IAClD,QAAQ,CAAC,WAAW,EAAE,IAAI,CAAC,kBAAkB,EAAE,eAAe,GAAG,sBAAsB,CAAC,CAAC;IACzF,QAAQ,CAAC,oBAAoB,CAAC,EAAE,oBAAoB,GAAG,IAAI,GAAG,SAAS,CAAC;IACxE,QAAQ,CAAC,cAAc,CAAC,EAAE,qBAAqB,GAAG,IAAI,GAAG,SAAS,CAAC;CACpE;AAED,MAAM,WAAW,uBAAuB;IACtC,uEAAuE;IACvE,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,QAAQ,CAAC,MAAM,EAAE,oBAAoB,CAAC;IACtC;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,0FAA0F;IAC1F,QAAQ,CAAC,cAAc,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC/E,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;CACxB;AAED,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,QAAQ,EAAE,YAAY,CAAC;IAChC,gGAAgG;IAChG,QAAQ,CAAC,SAAS,EAAE,SAAS,CAAC;IAC9B,4FAA4F;IAC5F,QAAQ,CAAC,QAAQ,EAAE,oBAAoB,CAAC;IACxC,2FAA2F;IAC3F,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAC5B,kGAAkG;IAClG,QAAQ,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC;CAC3C;AAED,2DAA2D;AAC3D,wBAAsB,oBAAoB,CACxC,IAAI,EAAE,sBAAsB,EAC5B,KAAK,EAAE,uBAAuB,GAC7B,OAAO,CAAC,wBAAwB,CAAC,CAsGnC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decideOnSessionFacts = decideOnSessionFacts;
|
|
4
|
+
const session_token_binder_js_1 = require("../request-auth/session-token-binder.js");
|
|
5
|
+
const request_principal_js_1 = require("../request-auth/request-principal.js");
|
|
6
|
+
const session_facts_als_js_1 = require("../request-auth/session-facts-als.js");
|
|
7
|
+
const facts_version_js_1 = require("./facts-version.js");
|
|
8
|
+
/** A subtree re-derive that was due but could not be done (resolver error / empty / junk). */
|
|
9
|
+
const SUBTREE_REDERIVE_FAILED = Symbol('subtree-rederive-failed');
|
|
10
|
+
/** Steps 1–4 above. Throws only what `decide()` throws. */
|
|
11
|
+
async function decideOnSessionFacts(deps, input) {
|
|
12
|
+
const { principal, claims, accessToken, classification } = input;
|
|
13
|
+
// ── ADR-0011 SESSION-FACTS HOT PATH ──────────────────────────────────────────
|
|
14
|
+
// Enter the session-facts ALS scope with THIS session's cached grants around the decide() call.
|
|
15
|
+
// The app-owned `SessionFactsReader` (an ALS-backed reader wired into the decision authority)
|
|
16
|
+
// reads the SAME `SHIELD_SESSION_FACTS_ALS` store inside decide(), so gate 5 gets these facts and
|
|
17
|
+
// can serve the coarse decision from cache (no DB reload) when the cached version is still fresh.
|
|
18
|
+
//
|
|
19
|
+
// CROSS-PRINCIPAL ISOLATION: `als.run(store, cb)` binds `store` to this async context and
|
|
20
|
+
// everything decide() awaits, and ONLY that context. The store is built HERE from THESE claims.
|
|
21
|
+
//
|
|
22
|
+
// FAIL-CLOSED: no projector wired / absent / malformed binding → `claims.cachedFacts` is
|
|
23
|
+
// undefined → the store carries `cachedFacts: null` → gate 5 DB-reloads. The cache is only ever
|
|
24
|
+
// consulted; it never fabricates a permit.
|
|
25
|
+
//
|
|
26
|
+
// RELOAD SIGNAL (security hardening Phase 1C): when gate 5 reloads THIS principal's grants, the
|
|
27
|
+
// framework-built authority reports the reloaded (authoritative) version here.
|
|
28
|
+
//
|
|
29
|
+
// TIME BOUND (ADR-0035): cached facts at or past their `validUntilMs` (the next start or end of
|
|
30
|
+
// a role posting's window — a change no version bump marks) are treated as ABSENT, so gate 5
|
|
31
|
+
// reloads them (and the roles with them, below).
|
|
32
|
+
let reloaded;
|
|
33
|
+
const usableFacts = (0, facts_version_js_1.usableCachedFacts)(claims.cachedFacts, input.nowMs);
|
|
34
|
+
const factsStore = {
|
|
35
|
+
cachedFacts: usableFacts,
|
|
36
|
+
permissionsVersion: usableFacts?.permissionsVersion ?? 0,
|
|
37
|
+
onReload: (principalId, tenantId, grants) => {
|
|
38
|
+
if (principalId === principal.id && tenantId === principal.tenantId) {
|
|
39
|
+
reloaded = grants;
|
|
40
|
+
}
|
|
41
|
+
},
|
|
42
|
+
};
|
|
43
|
+
const decision = await session_facts_als_js_1.SHIELD_SESSION_FACTS_ALS.run(factsStore, () => deps.decisionAuthority.decide(principal, { key: classification.action }, { level: 'object_type', typeKey: classification.typeKey, tenantId: principal.tenantId }, { isAuthenticated: true }));
|
|
44
|
+
// The type-level decision above is on the principal's OWN tenant, which every subtree contains,
|
|
45
|
+
// so it does not depend on the subtree. Hence: decide first, then hand on the re-derived
|
|
46
|
+
// principal.
|
|
47
|
+
//
|
|
48
|
+
// LIVE ROLES (ADR-0035, GAPS #4): the reload also carries the principal's in-effect roles (when
|
|
49
|
+
// the app port reports them). The caller gets them now (role-keyed record rules, list scope,
|
|
50
|
+
// shares, the engine's record checks all read `principal.roleIds`), and the binding is rewritten
|
|
51
|
+
// with the reloaded facts + roles together, so the next requests are served from the cache
|
|
52
|
+
// (GAPS #6) with the same live roles.
|
|
53
|
+
// MANDATORY 2FA (auth capabilities R2.5, AC-9): re-evaluate when the permission version moved
|
|
54
|
+
// past the session's requirement stamp — gate 5 just told us the version (its reload, or the
|
|
55
|
+
// fresh cached facts it served). Unchanged version ⇒ no DB query. A failed evaluation caches
|
|
56
|
+
// nothing, so the next request (or refresh) reloads and retries.
|
|
57
|
+
let enforced = claims;
|
|
58
|
+
let mfaFailed = false;
|
|
59
|
+
const mfa = deps.mfaRequirement;
|
|
60
|
+
if (mfa !== undefined && mfa !== null) {
|
|
61
|
+
try {
|
|
62
|
+
enforced = await mfa.refresh(accessToken ?? '', claims, {
|
|
63
|
+
version: reloaded?.permissionsVersion ?? usableFacts?.permissionsVersion,
|
|
64
|
+
grants: reloaded ?? usableFacts ?? undefined,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
mfaFailed = true;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
let handed = principal;
|
|
72
|
+
let subtreeStale = false;
|
|
73
|
+
if (reloaded !== undefined && !mfaFailed) {
|
|
74
|
+
const liveRoles = (0, session_token_binder_js_1.liveRoleIds)(reloaded);
|
|
75
|
+
const current = liveRoles !== undefined ? { ...claims, roleIds: liveRoles } : claims;
|
|
76
|
+
const rederived = await rederiveSubtreeOnVersionMove(deps, accessToken, current, reloaded.permissionsVersion);
|
|
77
|
+
subtreeStale = rederived === SUBTREE_REDERIVE_FAILED;
|
|
78
|
+
// A subtree re-derive that was due but FAILED (resolver error / empty) keeps the facts
|
|
79
|
+
// uncached, so the next request reloads and retries it (the Phase 1C retry guarantee).
|
|
80
|
+
if (rederived !== SUBTREE_REDERIVE_FAILED) {
|
|
81
|
+
await rebindReloadedGrants(deps, accessToken, claims, reloaded, liveRoles);
|
|
82
|
+
}
|
|
83
|
+
if (rederived !== null && rederived !== SUBTREE_REDERIVE_FAILED) {
|
|
84
|
+
handed = rederived;
|
|
85
|
+
}
|
|
86
|
+
else if (liveRoles !== undefined) {
|
|
87
|
+
const withRoles = (0, request_principal_js_1.principalFromClaims)(current);
|
|
88
|
+
if (withRoles !== null)
|
|
89
|
+
handed = withRoles;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
// G-036 M1 (SPEC §5 run-loop): the version the principal above was derived under, from what
|
|
93
|
+
// gate 5 already reported (no new read). Absent when gate 5 reported none or the subtree
|
|
94
|
+
// re-derive failed (the principal's subtree then belongs to no single version). For a ROOT
|
|
95
|
+
// principal gate 5 loads and checks no grants, so cached facts it never compared with the
|
|
96
|
+
// tenant's version say nothing (SPEC v8): absent.
|
|
97
|
+
const factsVersion = (0, facts_version_js_1.derivedFactsVersion)(principal, reloaded, usableFacts, subtreeStale);
|
|
98
|
+
return { decision, principal: handed, enforced, mfaFailed, factsVersion };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Write gate 5's reloaded grants and the live roles onto the session binding (ADR-0035). Session
|
|
102
|
+
* bindings only: a service-account key has no binding (its roles and scope are read live per
|
|
103
|
+
* request by the key store). Best-effort and conditional (same session, same tenant, fresher
|
|
104
|
+
* facts, `XX`): a miss or a Redis error only means the next request reloads again.
|
|
105
|
+
*/
|
|
106
|
+
async function rebindReloadedGrants(deps, accessToken, claims, grants, liveRoles) {
|
|
107
|
+
if (claims.sessionId === '' || claims.kind === 'service_account')
|
|
108
|
+
return;
|
|
109
|
+
try {
|
|
110
|
+
await deps.tokenBinder.refreshGrants(accessToken, claims.sessionId, claims.tenantId, grants, liveRoles);
|
|
111
|
+
}
|
|
112
|
+
catch {
|
|
113
|
+
// Best-effort: the decision and the handed principal already use the reloaded grants.
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Re-derive the session's scope subtree after gate 5 reloaded facts at `reloadedVersion`
|
|
118
|
+
* (security hardening Phase 1C). Identity bumps a tenant's permission version when a company is
|
|
119
|
+
* created, moved or deleted under it, so a reload at a version newer than the bound subtree's
|
|
120
|
+
* stamp means the subtree may be stale: resolve it again with the SAME resolver login uses,
|
|
121
|
+
* rebind it (token + session entries) and return the principal to hand on.
|
|
122
|
+
*
|
|
123
|
+
* Off the hot path: runs only for a session binding that carries a subtree, with a resolver
|
|
124
|
+
* wired, and a reload NEWER than its stamp (or no stamp yet — once, then stamped). That is the
|
|
125
|
+
* only DB read added (one closure query), and only on a version change.
|
|
126
|
+
*
|
|
127
|
+
* FAIL-CLOSED, NON-WIDENING: a resolver error, a non-array or an EMPTY result →
|
|
128
|
+
* {@link SUBTREE_REDERIVE_FAILED}: the bound subtree stays (never replaced by a guess, never
|
|
129
|
+
* widened), the stamp is not advanced, the reloaded facts are not cached (ADR-0035), and the next
|
|
130
|
+
* request reloads and retries. `null` = no re-derive was due. A failed Redis rebind still returns
|
|
131
|
+
* the fresh principal (the DB answer is authoritative); the next reload retries the rebind.
|
|
132
|
+
*/
|
|
133
|
+
async function rederiveSubtreeOnVersionMove(deps, accessToken, claims, reloadedVersion) {
|
|
134
|
+
const resolver = deps.scopeSubtreeResolver;
|
|
135
|
+
if (resolver === undefined || resolver === null)
|
|
136
|
+
return null;
|
|
137
|
+
// Session bindings only: a service-account key has no binding (its scope is read live per
|
|
138
|
+
// request by the key store) and no session id.
|
|
139
|
+
if (claims.sessionId === '' || claims.kind === 'service_account')
|
|
140
|
+
return null;
|
|
141
|
+
// Only a binding that carries a subtree: an absent one is the self-node fallback (no resolver
|
|
142
|
+
// or a failed login-time resolve) and stays that way until the next login/refresh.
|
|
143
|
+
if (claims.scopeSubtreeNodeIds === undefined || claims.scopeSubtreeNodeIds.length === 0) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const stamp = claims.scopeSubtreeVersion;
|
|
147
|
+
if (stamp !== undefined && reloadedVersion <= stamp)
|
|
148
|
+
return null;
|
|
149
|
+
let subtree;
|
|
150
|
+
try {
|
|
151
|
+
const resolved = await resolver.resolveSubtree(claims.tenantId);
|
|
152
|
+
if (!Array.isArray(resolved) || resolved.length === 0)
|
|
153
|
+
return SUBTREE_REDERIVE_FAILED;
|
|
154
|
+
if (resolved.some((n) => typeof n !== 'string' || n.length === 0)) {
|
|
155
|
+
return SUBTREE_REDERIVE_FAILED;
|
|
156
|
+
}
|
|
157
|
+
subtree = [...resolved];
|
|
158
|
+
}
|
|
159
|
+
catch {
|
|
160
|
+
return SUBTREE_REDERIVE_FAILED;
|
|
161
|
+
}
|
|
162
|
+
await deps.tokenBinder.rederiveScopeSubtree(accessToken, claims.sessionId, claims.tenantId, subtree, reloadedVersion);
|
|
163
|
+
return (0, request_principal_js_1.principalFromClaims)({
|
|
164
|
+
...claims,
|
|
165
|
+
scopeSubtreeNodeIds: subtree,
|
|
166
|
+
scopeSubtreeVersion: reloadedVersion,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
@@ -39,7 +39,7 @@ export type ServiceAccountAction = (typeof SERVICE_ACCOUNT_ACTIONS)[number];
|
|
|
39
39
|
* assistant routes and every agent call, `propose` is reserved for proposals (M3), and
|
|
40
40
|
* `restricted_data` lets a user's run send `restricted` data to an approved model provider.
|
|
41
41
|
*/
|
|
42
|
-
export declare const AGENT_ACTIONS: readonly ["chat", "propose", "restricted_data", "client_data_approve"];
|
|
42
|
+
export declare const AGENT_ACTIONS: readonly ["chat", "propose", "restricted_data", "client_data_approve", "unattended", "unattended_admin"];
|
|
43
43
|
export type AgentAction = (typeof AGENT_ACTIONS)[number];
|
|
44
44
|
/**
|
|
45
45
|
* `agent_audit`'s action vocabulary (agent-activity-audit SPEC v1 §5, §10): `read` only, the key
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-actions.d.ts","sourceRoot":"","sources":["../../src/identity/identity-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAGxD,eAAO,MAAM,UAAU,aAAa,CAAC;AACrC,eAAO,MAAM,gBAAgB,iDAAkD,CAAC;AAChF,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,gBAAgB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE/D;;;;;;GAMG;AACH,eAAO,MAAM,0BAA0B,wCAAyC,CAAC;AACjF,MAAM,MAAM,sBAAsB,GAAG,CAAC,OAAO,0BAA0B,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,4BAA6B,CAAC;AAC/D,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE;;;;;;GAMG;AACH,eAAO,MAAM,uBAAuB,gEAM1B,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,CAAC,MAAM,CAAC,CAAC;AAE5E;;;;;GAKG;AACH,eAAO,MAAM,aAAa,
|
|
1
|
+
{"version":3,"file":"identity-actions.d.ts","sourceRoot":"","sources":["../../src/identity/identity-actions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MA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;AAED;;;GAGG;AACH,wBAAgB,2BAA2B,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAEnF;AAED;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAE1E;AAED;;;;GAIG;AACH,wBAAgB,SAAS,CAAC,GAAG,EAAE,iBAAiB,GAAG,SAAS,MAAM,EAAE,CAEnE;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,CAE9D"}
|
|
@@ -50,6 +50,10 @@ exports.AGENT_ACTIONS = [
|
|
|
50
50
|
// model-provider-client-data SPEC v7 §5 E: approve (or confirm, revoke) sending this company's
|
|
51
51
|
// real data to an external AI provider. Assigned to no role by default.
|
|
52
52
|
'client_data_approve',
|
|
53
|
+
// background-agent-tasks SPEC v4 §3, §10: start and run an unattended (service-account) task, and
|
|
54
|
+
// the per-company switch `PUT /identity/agent/unattended`. Both assigned to no role by default.
|
|
55
|
+
'unattended',
|
|
56
|
+
'unattended_admin',
|
|
53
57
|
];
|
|
54
58
|
/**
|
|
55
59
|
* `agent_audit`'s action vocabulary (agent-activity-audit SPEC v1 §5, §10): `read` only, the key
|
package/dist/internal.d.ts
CHANGED
|
@@ -64,12 +64,28 @@ export type { MfaAdminStatus, MfaStatusBatchSource, MfaStatusSubject, } from './
|
|
|
64
64
|
*/
|
|
65
65
|
export { SHIELD_SESSION_LIVENESS } from './auth/tokens.js';
|
|
66
66
|
export { RedisSessionLiveness, type SessionLiveness, type SessionLivenessState, } from './session/session-liveness.js';
|
|
67
|
+
/**
|
|
68
|
+
* For `@astram/agent` only (background-agent-tasks SPEC v2 §5 B): the per-call principals of a
|
|
69
|
+
* background (session) or unattended (service-account) run, rebuilt by the guard's own code;
|
|
70
|
+
* `null` ⇒ the caller stops (fail closed). `principalFactsVersion` reads the permission version a
|
|
71
|
+
* session principal was derived under (the `requestFactsVersion` rule); `undefined` ⇒ fail closed.
|
|
72
|
+
*/
|
|
73
|
+
export { SHIELD_CALL_PRINCIPALS } from './auth/tokens.js';
|
|
74
|
+
export { GuardCallPrincipals, type CallPrincipals } from './session/call-principals.js';
|
|
75
|
+
export { principalForSession, principalFactsVersion, type SessionClaimsReader, refreshSessionFacts, type SessionFactsRefreshDeps, } from './session/session-principal.js';
|
|
76
|
+
export { principalForServiceAccount, type ApiKeyRecordReader, } from './authentication/service-account-principal.js';
|
|
67
77
|
/**
|
|
68
78
|
* For `@astram/agent` only (SPEC §5 run-loop "Manifest"): the permission version the enforcement
|
|
69
79
|
* guard derived `req.principal` under (gate 5's reload, else its cached facts); `undefined` ⇒ the
|
|
70
80
|
* caller fails closed. Recorded by the guard from what gate 5 reported; no read of its own.
|
|
71
81
|
*/
|
|
72
82
|
export { requestFactsVersion } from './enforcement/global-enforcement.guard.js';
|
|
83
|
+
/**
|
|
84
|
+
* For `@astram/agent` only (background-agent-tasks SPEC v3 §5 B): the version of the `ask_` key the
|
|
85
|
+
* enforcement guard verified for this request (service-account principals only; `undefined`
|
|
86
|
+
* otherwise ⇒ the caller fails closed). The unattended start stores it as the task's key version.
|
|
87
|
+
*/
|
|
88
|
+
export { requestServiceKeyVersion } from './enforcement/global-enforcement.guard.js';
|
|
73
89
|
/**
|
|
74
90
|
* For `@astram/agent` only (capability-outbound-audit SPEC v6 §5 G, QA P2-1): read-only, `true`
|
|
75
91
|
* inside a request that passed the framework middleware (with or without a principal). The audited
|
|
@@ -82,6 +98,13 @@ export { insideRequest } from './request-auth/request-principal-als.js';
|
|
|
82
98
|
* refuses `origin: 'agent'` unless the provenance is the minted object (`forbidden`).
|
|
83
99
|
*/
|
|
84
100
|
export { AGENT_PROVENANCE_ID_MAX, isMintedAgentProvenance, mintAgentProvenance, type AgentProvenance, } from './agent/agent-provenance.js';
|
|
101
|
+
/**
|
|
102
|
+
* For `@astram/agent` (mint) and `@astram/identity` (check) only (background-agent-tasks SPEC v4
|
|
103
|
+
* §5 G): the unforgeable provenance of an unattended (service-account) task's proposal, with the
|
|
104
|
+
* agent's per-kind pending cap. Identity refuses `origin: 'agent_unattended'` unless it is the
|
|
105
|
+
* minted object AND the request principal is a service account (`forbidden`).
|
|
106
|
+
*/
|
|
107
|
+
export { AGENT_UNATTENDED_PENDING_PER_KIND_DEFAULT, AGENT_UNATTENDED_PENDING_PER_KIND_MAX, isMintedAgentUnattendedProvenance, mintAgentUnattendedProvenance, type AgentUnattendedProvenance, } from './agent/agent-provenance.js';
|
|
85
108
|
/**
|
|
86
109
|
* For `@astram/identity` only (schema-change registration SPEC v13 §5): guard's grant-key expander
|
|
87
110
|
* and its explicit-only predicate, so identity's parity test can prove both expanders agree.
|
package/dist/internal.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal.d.ts","sourceRoot":"","sources":["../src/internal.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD;;;;GAIG;AACH,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAC5D,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAClG;;;;;GAKG;AACH,OAAO,EAAE,cAAc,EAAE,MAAM,sCAAsC,CAAC;AACtE,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAClE,YAAY,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACnE;;;GAGG;AACH,OAAO,EAAE,8BAA8B,EAAE,MAAM,kBAAkB,CAAC;AAClE;;;GAGG;AACH,OAAO,EAAE,qCAAqC,EAAE,MAAM,kBAAkB,CAAC;AACzE;;;GAGG;AACH,OAAO,EAAE,yBAAyB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