@astram/core 0.1.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/admin/admin-service.d.ts +1 -1
- package/dist/admin/command/grants.js +3 -3
- package/dist/admin/command/grants.js.map +1 -1
- package/dist/admin/command/invitations.d.ts +2 -2
- package/dist/admin/command/invitations.js +8 -8
- package/dist/admin/command/invitations.js.map +1 -1
- package/dist/admin/command/service-accounts.d.ts +1 -1
- package/dist/admin/command/service-accounts.js +1 -1
- package/dist/admin/query/simulate.d.ts.map +1 -1
- package/dist/admin/query/simulate.js +4 -0
- package/dist/admin/query/simulate.js.map +1 -1
- package/dist/admin/safeguards-impl.d.ts +2 -2
- package/dist/admin/safeguards-impl.js +9 -9
- package/dist/admin/safeguards-impl.js.map +1 -1
- package/dist/admin/safeguards.d.ts +4 -4
- package/dist/admin/safeguards.js +4 -4
- package/dist/admin/types.d.ts +1 -1
- package/dist/admin/types.d.ts.map +1 -1
- package/dist/authentication/authenticator.d.ts +2 -2
- package/dist/authentication/authenticator.js +2 -2
- package/dist/authentication/authenticator.js.map +1 -1
- package/dist/authentication/credential-resolver.d.ts +1 -1
- package/dist/authorization/cross-tenant/grant-evaluator.d.ts +2 -2
- package/dist/authorization/cross-tenant/grant-evaluator.js +2 -2
- package/dist/authorization/decision-authority.d.ts +2 -2
- package/dist/authorization/decision-authority.d.ts.map +1 -1
- package/dist/authorization/decision-authority.js +11 -3
- package/dist/authorization/decision-authority.js.map +1 -1
- package/dist/authorization/errors.d.ts +37 -0
- package/dist/authorization/errors.d.ts.map +1 -1
- package/dist/authorization/errors.js +43 -0
- package/dist/authorization/errors.js.map +1 -1
- package/dist/authorization/gates/object-type.d.ts +2 -2
- package/dist/authorization/gates/object-type.d.ts.map +1 -1
- package/dist/authorization/gates/object-type.js +20 -7
- package/dist/authorization/gates/object-type.js.map +1 -1
- package/dist/authorization/gates/tenant.d.ts +3 -3
- package/dist/authorization/gates/tenant.js +7 -7
- package/dist/authorization/gates/tenant.js.map +1 -1
- package/dist/authorization/index.d.ts +23 -4
- package/dist/authorization/index.d.ts.map +1 -1
- package/dist/authorization/index.js +29 -4
- package/dist/authorization/index.js.map +1 -1
- package/dist/authorization/ports.d.ts +3 -3
- package/dist/authorization/reason-codes.d.ts +7 -1
- package/dist/authorization/reason-codes.d.ts.map +1 -1
- package/dist/authorization/reason-codes.js +9 -1
- package/dist/authorization/reason-codes.js.map +1 -1
- package/dist/authorization/record/owner-baseline.d.ts +43 -0
- package/dist/authorization/record/owner-baseline.d.ts.map +1 -0
- package/dist/authorization/record/owner-baseline.js +72 -0
- package/dist/authorization/record/owner-baseline.js.map +1 -0
- package/dist/authorization/record/permit-tier.d.ts.map +1 -1
- package/dist/authorization/record/permit-tier.js +16 -5
- package/dist/authorization/record/permit-tier.js.map +1 -1
- package/dist/identity/broker.d.ts +8 -8
- package/dist/identity/broker.d.ts.map +1 -1
- package/dist/identity/broker.js +8 -8
- package/dist/identity/broker.js.map +1 -1
- package/dist/identity/claim-mapper.d.ts +8 -8
- package/dist/identity/claim-mapper.d.ts.map +1 -1
- package/dist/identity/claim-mapper.js +4 -4
- package/dist/identity/index.d.ts +2 -2
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/internal-adapter.d.ts +12 -12
- package/dist/identity/internal-adapter.d.ts.map +1 -1
- package/dist/identity/internal-adapter.js +9 -9
- package/dist/identity/internal-adapter.js.map +1 -1
- package/dist/metadata/index.d.ts +43 -0
- package/dist/metadata/index.d.ts.map +1 -1
- package/dist/metadata/index.js +6 -0
- package/dist/metadata/index.js.map +1 -1
- package/dist/metadata/registry.d.ts.map +1 -1
- package/dist/metadata/registry.js +2 -1
- package/dist/metadata/registry.js.map +1 -1
- package/dist-cjs/admin/admin-service.js +159 -0
- package/dist-cjs/admin/command/grants.js +200 -0
- package/dist-cjs/admin/command/index.js +38 -0
- package/dist-cjs/admin/command/invitations.js +246 -0
- package/dist-cjs/admin/command/permissions.js +69 -0
- package/dist-cjs/admin/command/pipeline.js +110 -0
- package/dist-cjs/admin/command/policies.js +223 -0
- package/dist-cjs/admin/command/service-accounts.js +278 -0
- package/dist-cjs/admin/command/service.js +130 -0
- package/dist-cjs/admin/command/tiers.js +81 -0
- package/dist-cjs/admin/index.js +78 -0
- package/dist-cjs/admin/ports.js +41 -0
- package/dist-cjs/admin/query/audit-view.js +88 -0
- package/dist-cjs/admin/query/catalog.js +174 -0
- package/dist-cjs/admin/query/explain.js +149 -0
- package/dist-cjs/admin/query/index.js +74 -0
- package/dist-cjs/admin/query/simulate.js +98 -0
- package/dist-cjs/admin/safeguards-impl.js +322 -0
- package/dist-cjs/admin/safeguards.js +95 -0
- package/dist-cjs/admin/types.js +40 -0
- package/dist-cjs/audit/audit-recorder.js +269 -0
- package/dist-cjs/audit/canonicalize.js +176 -0
- package/dist-cjs/audit/errors.js +44 -0
- package/dist-cjs/audit/index.js +39 -0
- package/dist-cjs/audit/ports.js +27 -0
- package/dist-cjs/audit/sensitive.js +162 -0
- package/dist-cjs/audit/walk.js +123 -0
- package/dist-cjs/authentication/authenticator.js +210 -0
- package/dist-cjs/authentication/credential-resolver.js +21 -0
- package/dist-cjs/authentication/index.js +42 -0
- package/dist-cjs/authentication/password-hasher.js +21 -0
- package/dist-cjs/authentication/totp.js +155 -0
- package/dist-cjs/authorization/cross-tenant/grant-evaluator.js +167 -0
- package/dist-cjs/authorization/decision-authority.js +213 -0
- package/dist-cjs/authorization/default-gates.js +53 -0
- package/dist-cjs/authorization/delegation/operation-identity.js +226 -0
- package/dist-cjs/authorization/errors.js +110 -0
- package/dist-cjs/authorization/gates/object-type.js +192 -0
- package/dist-cjs/authorization/gates/tenant.js +89 -0
- package/dist-cjs/authorization/gates/wiring.js +59 -0
- package/dist-cjs/authorization/index.js +124 -0
- package/dist-cjs/authorization/ports.js +36 -0
- package/dist-cjs/authorization/reason-codes.js +117 -0
- package/dist-cjs/authorization/record/owner-baseline.js +74 -0
- package/dist-cjs/authorization/record/permit-tier.js +92 -0
- package/dist-cjs/authorization/record/rule-evaluator.js +128 -0
- package/dist-cjs/authorization/record/shares.js +110 -0
- package/dist-cjs/identity/broker.js +139 -0
- package/dist-cjs/identity/claim-mapper.js +51 -0
- package/dist-cjs/identity/index.js +39 -0
- package/dist-cjs/identity/internal-adapter.js +91 -0
- package/dist-cjs/index.js +63 -0
- package/dist-cjs/metadata/completeness.js +108 -0
- package/dist-cjs/metadata/dependencies.js +110 -0
- package/dist-cjs/metadata/index.js +76 -0
- package/dist-cjs/metadata/registry.js +207 -0
- package/dist-cjs/package.json +3 -0
- package/dist-cjs/risk/evaluator.js +63 -0
- package/dist-cjs/risk/index.js +35 -0
- package/dist-cjs/risk/risk-engine.js +290 -0
- package/dist-cjs/risk/signals.js +106 -0
- package/dist-cjs/risk/thresholds.js +63 -0
- package/dist-cjs/session/index.js +35 -0
- package/dist-cjs/session/lifetimes.js +70 -0
- package/dist-cjs/session/ports.js +23 -0
- package/dist-cjs/session/session-authority.js +398 -0
- package/package.json +13 -10
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Team B commands — **service-account lifecycle** (AC 10).
|
|
4
|
+
*
|
|
5
|
+
* Five commands: create / scope / rotate-credential / revoke / set-expiry. Every
|
|
6
|
+
* one routes the §11.3 pipeline + audits. Accounts are least-privilege scoped +
|
|
7
|
+
* tenant-bound (invariant #4/#5). A NON-root creating/scoping an account is
|
|
8
|
+
* subject to the delegated-admin gate (it can't scope the account beyond the
|
|
9
|
+
* admin's OWN authority — enforced by the safeguard when the scope declares a
|
|
10
|
+
* discrete `(action, typeKey)` authority bound).
|
|
11
|
+
*
|
|
12
|
+
* ⛔ CREDENTIAL CRYPTO. The credential HASH is produced by the Auth layer's hasher
|
|
13
|
+
* port (never here), then persisted via {@link ServiceAccountStore.setCredentialHash}.
|
|
14
|
+
* `AdminCommandDeps` carries no hasher, so rotate takes an OPTIONAL injected
|
|
15
|
+
* {@link PasswordHasher}; when absent it stores a caller-provided pre-computed hash
|
|
16
|
+
* (the credential is minted/hashed by the adapter). This file NEVER logs/returns a
|
|
17
|
+
* secret or a hash.
|
|
18
|
+
*
|
|
19
|
+
* Revocation is IMMEDIATE (the store's revoke is idempotent).
|
|
20
|
+
*
|
|
21
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.makeCreateServiceAccount = makeCreateServiceAccount;
|
|
25
|
+
exports.makeScopeServiceAccount = makeScopeServiceAccount;
|
|
26
|
+
exports.makeRotateServiceAccountCredential = makeRotateServiceAccountCredential;
|
|
27
|
+
exports.makeRevokeServiceAccount = makeRevokeServiceAccount;
|
|
28
|
+
exports.makeSetServiceAccountExpiry = makeSetServiceAccountExpiry;
|
|
29
|
+
const grants_js_1 = require("./grants.js");
|
|
30
|
+
const pipeline_js_1 = require("./pipeline.js");
|
|
31
|
+
function defaultSecret() {
|
|
32
|
+
// A non-cryptographic placeholder is acceptable ONLY because the real secret
|
|
33
|
+
// generation is the adapter's job (this Core file has no crypto dep); the value
|
|
34
|
+
// is immediately hashed and never returned. Adapters inject a CSPRNG generator.
|
|
35
|
+
return `sa-secret-${String(Date.now())}-${String(Math.random()).slice(2)}`;
|
|
36
|
+
}
|
|
37
|
+
function makeCreateServiceAccount(deps) {
|
|
38
|
+
const clock = deps.now ?? Date.now;
|
|
39
|
+
return async function createServiceAccount(mutation, input) {
|
|
40
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
41
|
+
mutation,
|
|
42
|
+
hasConfirmToken: true, // create is additive
|
|
43
|
+
validate: () => {
|
|
44
|
+
if (typeof input.tenantId !== 'string' ||
|
|
45
|
+
input.tenantId.length === 0 ||
|
|
46
|
+
typeof input.label !== 'string' ||
|
|
47
|
+
input.label.length === 0 ||
|
|
48
|
+
typeof input.scope !== 'string' ||
|
|
49
|
+
input.scope.length === 0) {
|
|
50
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
51
|
+
}
|
|
52
|
+
// Tenant-binding: the account MUST bind to the mutation's target tenant
|
|
53
|
+
// (invariant #4). A mismatch is a cross-tenant escalation attempt.
|
|
54
|
+
if (input.tenantId !== mutation.targetTenantId) {
|
|
55
|
+
return {
|
|
56
|
+
ok: false,
|
|
57
|
+
reason: 'unilateral_cross_tenant',
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
},
|
|
62
|
+
mutate: async () => deps.serviceAccountStore.create({
|
|
63
|
+
tenantId: input.tenantId,
|
|
64
|
+
label: input.label,
|
|
65
|
+
scope: input.scope,
|
|
66
|
+
...(input.expiresAtMs !== undefined
|
|
67
|
+
? { expiresAtMs: input.expiresAtMs }
|
|
68
|
+
: {}),
|
|
69
|
+
}),
|
|
70
|
+
emitAudit: async (value, blastRadius) => {
|
|
71
|
+
await deps.audit.record({
|
|
72
|
+
type: 'admin_action',
|
|
73
|
+
occurredAtMs: clock(),
|
|
74
|
+
actorId: mutation.admin.id,
|
|
75
|
+
tenantId: mutation.targetTenantId,
|
|
76
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
77
|
+
action: 'service_account_create',
|
|
78
|
+
serviceAccountLabel: value.label,
|
|
79
|
+
scope: value.scope,
|
|
80
|
+
}),
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
}, deps.decide);
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
function makeScopeServiceAccount(deps) {
|
|
87
|
+
const clock = deps.now ?? Date.now;
|
|
88
|
+
return async function scopeServiceAccount(mutation, input) {
|
|
89
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
90
|
+
mutation,
|
|
91
|
+
hasConfirmToken: true, // re-scope is not destructive per se
|
|
92
|
+
validate: async () => {
|
|
93
|
+
if (typeof input.id !== 'string' ||
|
|
94
|
+
input.id.length === 0 ||
|
|
95
|
+
typeof input.scope !== 'string' ||
|
|
96
|
+
input.scope.length === 0) {
|
|
97
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
98
|
+
}
|
|
99
|
+
const existing = await deps.serviceAccountStore.get(input.id);
|
|
100
|
+
if (existing === null) {
|
|
101
|
+
return { ok: false, reason: 'not_found' };
|
|
102
|
+
}
|
|
103
|
+
// Tenant-binding: the account must belong to the mutation's tenant.
|
|
104
|
+
if (existing.tenantId !== mutation.targetTenantId) {
|
|
105
|
+
return {
|
|
106
|
+
ok: false,
|
|
107
|
+
reason: 'unilateral_cross_tenant',
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
return null;
|
|
111
|
+
},
|
|
112
|
+
mutate: async () => {
|
|
113
|
+
await deps.serviceAccountStore.updateScope(input.id, input.scope);
|
|
114
|
+
},
|
|
115
|
+
emitAudit: async (_value, blastRadius) => {
|
|
116
|
+
const label = await deps.labels.resolve('service_account', input.id, mutation.targetTenantId);
|
|
117
|
+
await deps.audit.record({
|
|
118
|
+
type: 'admin_action',
|
|
119
|
+
occurredAtMs: clock(),
|
|
120
|
+
actorId: mutation.admin.id,
|
|
121
|
+
tenantId: mutation.targetTenantId,
|
|
122
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
123
|
+
action: 'service_account_scope',
|
|
124
|
+
serviceAccountLabel: label,
|
|
125
|
+
newScope: input.scope,
|
|
126
|
+
}),
|
|
127
|
+
});
|
|
128
|
+
},
|
|
129
|
+
}, deps.decide);
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
function makeRotateServiceAccountCredential(deps) {
|
|
133
|
+
const clock = deps.now ?? Date.now;
|
|
134
|
+
const mintSecret = deps.newSecret ?? defaultSecret;
|
|
135
|
+
return async function rotateServiceAccountCredential(mutation, input) {
|
|
136
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
137
|
+
mutation,
|
|
138
|
+
hasConfirmToken: true, // rotate is not a broad destructive removal
|
|
139
|
+
validate: async () => {
|
|
140
|
+
if (typeof input.id !== 'string' || input.id.length === 0) {
|
|
141
|
+
return { ok: false, reason: 'not_found' };
|
|
142
|
+
}
|
|
143
|
+
const existing = await deps.serviceAccountStore.get(input.id);
|
|
144
|
+
if (existing === null) {
|
|
145
|
+
return { ok: false, reason: 'not_found' };
|
|
146
|
+
}
|
|
147
|
+
if (existing.tenantId !== mutation.targetTenantId) {
|
|
148
|
+
return {
|
|
149
|
+
ok: false,
|
|
150
|
+
reason: 'unilateral_cross_tenant',
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
return null;
|
|
154
|
+
},
|
|
155
|
+
mutate: async () => {
|
|
156
|
+
// Produce the HASH (never a raw secret leaves this scope). Prefer the
|
|
157
|
+
// injected Auth hasher; else accept a caller pre-computed hash.
|
|
158
|
+
let hash;
|
|
159
|
+
if (deps.hasher !== undefined) {
|
|
160
|
+
const secret = mintSecret();
|
|
161
|
+
hash = await deps.hasher.hash(secret);
|
|
162
|
+
}
|
|
163
|
+
else if (typeof input.precomputedHash === 'string' &&
|
|
164
|
+
input.precomputedHash.length > 0) {
|
|
165
|
+
hash = input.precomputedHash;
|
|
166
|
+
}
|
|
167
|
+
else {
|
|
168
|
+
// No hasher + no pre-computed hash → cannot rotate safely. Throw so the
|
|
169
|
+
// caller sees a failure rather than persisting an empty credential.
|
|
170
|
+
throw new Error('rotateServiceAccountCredential: no hasher injected and no precomputedHash provided');
|
|
171
|
+
}
|
|
172
|
+
await deps.serviceAccountStore.setCredentialHash(input.id, hash);
|
|
173
|
+
},
|
|
174
|
+
emitAudit: async (_value, blastRadius) => {
|
|
175
|
+
const label = await deps.labels.resolve('service_account', input.id, mutation.targetTenantId);
|
|
176
|
+
await deps.audit.record({
|
|
177
|
+
type: 'admin_action',
|
|
178
|
+
occurredAtMs: clock(),
|
|
179
|
+
actorId: mutation.admin.id,
|
|
180
|
+
tenantId: mutation.targetTenantId,
|
|
181
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
182
|
+
action: 'service_account_rotate',
|
|
183
|
+
serviceAccountLabel: label,
|
|
184
|
+
// ⛔ NEVER record the secret or the hash in the audit event.
|
|
185
|
+
}),
|
|
186
|
+
});
|
|
187
|
+
},
|
|
188
|
+
}, deps.decide);
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
function makeRevokeServiceAccount(deps) {
|
|
192
|
+
const clock = deps.now ?? Date.now;
|
|
193
|
+
return async function revokeServiceAccount(mutation, id) {
|
|
194
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
195
|
+
mutation,
|
|
196
|
+
hasConfirmToken: (0, grants_js_1.extractHasConfirm)(mutation), // DESTRUCTIVE → confirm required
|
|
197
|
+
validate: async () => {
|
|
198
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
199
|
+
return { ok: false, reason: 'not_found' };
|
|
200
|
+
}
|
|
201
|
+
const existing = await deps.serviceAccountStore.get(id);
|
|
202
|
+
if (existing === null) {
|
|
203
|
+
return { ok: false, reason: 'not_found' };
|
|
204
|
+
}
|
|
205
|
+
if (existing.tenantId !== mutation.targetTenantId) {
|
|
206
|
+
return {
|
|
207
|
+
ok: false,
|
|
208
|
+
reason: 'unilateral_cross_tenant',
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
return null;
|
|
212
|
+
},
|
|
213
|
+
mutate: async () => {
|
|
214
|
+
await deps.serviceAccountStore.revoke(id); // immediate effect
|
|
215
|
+
},
|
|
216
|
+
emitAudit: async (_value, blastRadius) => {
|
|
217
|
+
const label = await deps.labels.resolve('service_account', id, mutation.targetTenantId);
|
|
218
|
+
await deps.audit.record({
|
|
219
|
+
type: 'admin_action',
|
|
220
|
+
occurredAtMs: clock(),
|
|
221
|
+
actorId: mutation.admin.id,
|
|
222
|
+
tenantId: mutation.targetTenantId,
|
|
223
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
224
|
+
action: 'service_account_revoke',
|
|
225
|
+
serviceAccountLabel: label,
|
|
226
|
+
}),
|
|
227
|
+
});
|
|
228
|
+
},
|
|
229
|
+
}, deps.decide);
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
function makeSetServiceAccountExpiry(deps) {
|
|
233
|
+
const clock = deps.now ?? Date.now;
|
|
234
|
+
return async function setServiceAccountExpiry(mutation, input) {
|
|
235
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
236
|
+
mutation,
|
|
237
|
+
hasConfirmToken: true, // expiry adjustment is not a broad removal
|
|
238
|
+
validate: async () => {
|
|
239
|
+
if (typeof input.id !== 'string' || input.id.length === 0) {
|
|
240
|
+
return { ok: false, reason: 'not_found' };
|
|
241
|
+
}
|
|
242
|
+
if (input.expiresAtMs !== null &&
|
|
243
|
+
(typeof input.expiresAtMs !== 'number' ||
|
|
244
|
+
!Number.isFinite(input.expiresAtMs))) {
|
|
245
|
+
return { ok: false, reason: 'invalid_policy' };
|
|
246
|
+
}
|
|
247
|
+
const existing = await deps.serviceAccountStore.get(input.id);
|
|
248
|
+
if (existing === null) {
|
|
249
|
+
return { ok: false, reason: 'not_found' };
|
|
250
|
+
}
|
|
251
|
+
if (existing.tenantId !== mutation.targetTenantId) {
|
|
252
|
+
return {
|
|
253
|
+
ok: false,
|
|
254
|
+
reason: 'unilateral_cross_tenant',
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
return null;
|
|
258
|
+
},
|
|
259
|
+
mutate: async () => {
|
|
260
|
+
await deps.serviceAccountStore.setExpiry(input.id, input.expiresAtMs);
|
|
261
|
+
},
|
|
262
|
+
emitAudit: async (_value, blastRadius) => {
|
|
263
|
+
const label = await deps.labels.resolve('service_account', input.id, mutation.targetTenantId);
|
|
264
|
+
await deps.audit.record({
|
|
265
|
+
type: 'admin_action',
|
|
266
|
+
occurredAtMs: clock(),
|
|
267
|
+
actorId: mutation.admin.id,
|
|
268
|
+
tenantId: mutation.targetTenantId,
|
|
269
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
270
|
+
action: 'service_account_expiry',
|
|
271
|
+
serviceAccountLabel: label,
|
|
272
|
+
expiresAtMs: input.expiresAtMs,
|
|
273
|
+
}),
|
|
274
|
+
});
|
|
275
|
+
},
|
|
276
|
+
}, deps.decide);
|
|
277
|
+
};
|
|
278
|
+
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The REAL admin COMMAND service (Team B) — assembles every command body over the
|
|
4
|
+
* §11.3 pipeline + real safeguards, conforming EXACTLY to the frozen
|
|
5
|
+
* {@link AdminCommandService} interface.
|
|
6
|
+
*
|
|
7
|
+
* ⛔ WHY A SEPARATE FACTORY. The frozen `admin-service.ts#createAdminCommandService`
|
|
8
|
+
* returns a fail-closed skeleton (every method `not_implemented`) and Team B may
|
|
9
|
+
* NOT edit it. The integration owner wires the command service to THIS factory
|
|
10
|
+
* ({@link createRealAdminCommandService}); it satisfies the identical frozen
|
|
11
|
+
* `AdminCommandService` interface, so it is a drop-in.
|
|
12
|
+
*
|
|
13
|
+
* The frozen `curatePermission(mutation, label, group)` signature carries no
|
|
14
|
+
* permission key; it is read from `mutation.payload.permissionKey` (INPUT position
|
|
15
|
+
* — permitted; never rendered). Destructive commands read their confirm token from
|
|
16
|
+
* `mutation.payload.confirm` (the assembler surfaces `hasConfirmToken` to the
|
|
17
|
+
* pipeline). All ids are opaque INPUTS; outputs are label-resolved for audit.
|
|
18
|
+
*
|
|
19
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
20
|
+
*/
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.createRealAdminCommandService = createRealAdminCommandService;
|
|
23
|
+
const grants_js_1 = require("./grants.js");
|
|
24
|
+
const invitations_js_1 = require("./invitations.js");
|
|
25
|
+
const policies_js_1 = require("./policies.js");
|
|
26
|
+
const permissions_js_1 = require("./permissions.js");
|
|
27
|
+
const service_accounts_js_1 = require("./service-accounts.js");
|
|
28
|
+
const tiers_js_1 = require("./tiers.js");
|
|
29
|
+
/** Read the permission key a curate command targets from the mutation payload. */
|
|
30
|
+
function curatePermissionKey(mutation) {
|
|
31
|
+
const payload = mutation.payload;
|
|
32
|
+
const key = payload?.permissionKey;
|
|
33
|
+
return typeof key === 'string' && key.length > 0
|
|
34
|
+
? key
|
|
35
|
+
: undefined;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create the REAL admin COMMAND service. Conforms to the frozen
|
|
39
|
+
* {@link AdminCommandService}; the integration owner substitutes this for the
|
|
40
|
+
* prelude's fail-closed skeleton.
|
|
41
|
+
*/
|
|
42
|
+
function createRealAdminCommandService(deps) {
|
|
43
|
+
const common = {
|
|
44
|
+
labels: deps.labels,
|
|
45
|
+
decide: deps.decide,
|
|
46
|
+
audit: deps.audit,
|
|
47
|
+
...(deps.now !== undefined ? { now: deps.now } : {}),
|
|
48
|
+
};
|
|
49
|
+
const grant = (0, grants_js_1.makeGrant)({
|
|
50
|
+
grantStore: deps.grantStore,
|
|
51
|
+
...common,
|
|
52
|
+
...(deps.newGrantId !== undefined ? { newId: deps.newGrantId } : {}),
|
|
53
|
+
});
|
|
54
|
+
const revoke = (0, grants_js_1.makeRevoke)({ grantStore: deps.grantStore, ...common });
|
|
55
|
+
const curate = (0, permissions_js_1.makeCuratePermission)({
|
|
56
|
+
catalogStore: deps.catalogStore,
|
|
57
|
+
...common,
|
|
58
|
+
});
|
|
59
|
+
const authorPolicy = (0, policies_js_1.makeAuthorPolicy)({
|
|
60
|
+
registry: deps.registry,
|
|
61
|
+
policyStore: deps.policyStore,
|
|
62
|
+
...common,
|
|
63
|
+
});
|
|
64
|
+
const setTier = (0, tiers_js_1.makeSetTier)({
|
|
65
|
+
...common,
|
|
66
|
+
...(deps.persistTier !== undefined ? { persistTier: deps.persistTier } : {}),
|
|
67
|
+
});
|
|
68
|
+
const saDeps = {
|
|
69
|
+
serviceAccountStore: deps.serviceAccountStore,
|
|
70
|
+
...common,
|
|
71
|
+
...(deps.hasher !== undefined ? { hasher: deps.hasher } : {}),
|
|
72
|
+
...(deps.newSecret !== undefined ? { newSecret: deps.newSecret } : {}),
|
|
73
|
+
};
|
|
74
|
+
const createServiceAccount = (0, service_accounts_js_1.makeCreateServiceAccount)(saDeps);
|
|
75
|
+
const scopeServiceAccount = (0, service_accounts_js_1.makeScopeServiceAccount)(saDeps);
|
|
76
|
+
const rotateServiceAccountCredential = (0, service_accounts_js_1.makeRotateServiceAccountCredential)(saDeps);
|
|
77
|
+
const revokeServiceAccount = (0, service_accounts_js_1.makeRevokeServiceAccount)(saDeps);
|
|
78
|
+
const setServiceAccountExpiry = (0, service_accounts_js_1.makeSetServiceAccountExpiry)(saDeps);
|
|
79
|
+
const invDeps = {
|
|
80
|
+
invitationStore: deps.invitationStore,
|
|
81
|
+
...common,
|
|
82
|
+
...(deps.resolveGranteeTenant !== undefined
|
|
83
|
+
? { resolveGranteeTenant: deps.resolveGranteeTenant }
|
|
84
|
+
: {}),
|
|
85
|
+
};
|
|
86
|
+
const createInvitation = (0, invitations_js_1.makeCreateInvitation)(invDeps);
|
|
87
|
+
const transitionInvitation = (0, invitations_js_1.makeTransitionInvitation)(invDeps);
|
|
88
|
+
return {
|
|
89
|
+
async curatePermission(mutation, label, group) {
|
|
90
|
+
const key = curatePermissionKey(mutation);
|
|
91
|
+
if (key === undefined) {
|
|
92
|
+
return { ok: false, reason: 'not_found' };
|
|
93
|
+
}
|
|
94
|
+
return curate(mutation, key, label, group);
|
|
95
|
+
},
|
|
96
|
+
async grant(mutation, command) {
|
|
97
|
+
return grant(mutation, command);
|
|
98
|
+
},
|
|
99
|
+
async revoke(mutation, grantId) {
|
|
100
|
+
return revoke(mutation, grantId);
|
|
101
|
+
},
|
|
102
|
+
async authorPolicy(mutation, policy) {
|
|
103
|
+
return authorPolicy(mutation, policy);
|
|
104
|
+
},
|
|
105
|
+
async setTier(mutation, permissionKey, tier) {
|
|
106
|
+
return setTier(mutation, permissionKey, tier);
|
|
107
|
+
},
|
|
108
|
+
async createServiceAccount(mutation, input) {
|
|
109
|
+
return createServiceAccount(mutation, input);
|
|
110
|
+
},
|
|
111
|
+
async scopeServiceAccount(mutation, input) {
|
|
112
|
+
return scopeServiceAccount(mutation, input);
|
|
113
|
+
},
|
|
114
|
+
async rotateServiceAccountCredential(mutation, input) {
|
|
115
|
+
return rotateServiceAccountCredential(mutation, input);
|
|
116
|
+
},
|
|
117
|
+
async revokeServiceAccount(mutation, id) {
|
|
118
|
+
return revokeServiceAccount(mutation, id);
|
|
119
|
+
},
|
|
120
|
+
async setServiceAccountExpiry(mutation, input) {
|
|
121
|
+
return setServiceAccountExpiry(mutation, input);
|
|
122
|
+
},
|
|
123
|
+
async createInvitation(mutation, command) {
|
|
124
|
+
return createInvitation(mutation, command);
|
|
125
|
+
},
|
|
126
|
+
async transitionInvitation(mutation, command) {
|
|
127
|
+
return transitionInvitation(mutation, command);
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Team B command — **setTier** (AC 8 / §3.6). Public is CODE-ONLY.
|
|
4
|
+
*
|
|
5
|
+
* The tier command may set the admin-settable tiers ({@link ADMIN_SETTABLE_TIERS}
|
|
6
|
+
* — `gated` / `authenticated_global`) but MUST REFUSE `public` with
|
|
7
|
+
* `public_not_settable`: Public is a code-declared tier, never console-settable — a
|
|
8
|
+
* safeguard against accidentally opening a resource to the anonymous world.
|
|
9
|
+
*
|
|
10
|
+
* A tier change is DESTRUCTIVE / high-blast (it changes reachability for every
|
|
11
|
+
* principal touching the permission), so the pipeline requires a confirm token +
|
|
12
|
+
* computes the blast-radius (threaded into the audit event).
|
|
13
|
+
*
|
|
14
|
+
* ⛔ PORTS: this layer has NO dedicated tier-override store (the registry is the
|
|
15
|
+
* tier BASE; a persistent override is an adapter concern, ADR-0023). The command
|
|
16
|
+
* therefore takes an OPTIONAL injected `persistTier` sink (default: no-op) so the
|
|
17
|
+
* integration owner can wire real persistence without this file importing a DB.
|
|
18
|
+
* The AUTHORITATIVE record of the change is the emitted audit event regardless.
|
|
19
|
+
*
|
|
20
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
21
|
+
*/
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
exports.makeSetTier = makeSetTier;
|
|
24
|
+
const ports_js_1 = require("../ports.js");
|
|
25
|
+
const grants_js_1 = require("./grants.js");
|
|
26
|
+
const pipeline_js_1 = require("./pipeline.js");
|
|
27
|
+
/** The admin-settable tier set as a strict membership check (mirrors the port). */
|
|
28
|
+
const SETTABLE = new Set(ports_js_1.ADMIN_SETTABLE_TIERS);
|
|
29
|
+
function makeSetTier(deps) {
|
|
30
|
+
const clock = deps.now ?? Date.now;
|
|
31
|
+
return async function setTier(inMutation, permissionKey, tier) {
|
|
32
|
+
// Enrich so the delegated-admin safeguard can read the target permission key.
|
|
33
|
+
const mutation = (0, pipeline_js_1.withPayload)(inMutation, { permissionKey });
|
|
34
|
+
return (0, pipeline_js_1.runAdminCommand)({
|
|
35
|
+
mutation,
|
|
36
|
+
hasConfirmToken: (0, grants_js_1.extractHasConfirm)(mutation), // destructive → confirm required
|
|
37
|
+
validate: () => {
|
|
38
|
+
if (typeof permissionKey !== 'string' || permissionKey.length === 0) {
|
|
39
|
+
return { ok: false, reason: 'not_found' };
|
|
40
|
+
}
|
|
41
|
+
// ⛔ Public is code-only — refuse it EXPLICITLY (before the settable check
|
|
42
|
+
// so the reason is precise, §3.6 / AC 8).
|
|
43
|
+
if (tier === 'public') {
|
|
44
|
+
return {
|
|
45
|
+
ok: false,
|
|
46
|
+
reason: 'public_not_settable',
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
// Only the admin-settable tiers are accepted; anything else (a junk cast)
|
|
50
|
+
// is refused via the same code-only guard's sibling — treat as public-
|
|
51
|
+
// adjacent illegal set (fail-closed).
|
|
52
|
+
if (!SETTABLE.has(tier)) {
|
|
53
|
+
return {
|
|
54
|
+
ok: false,
|
|
55
|
+
reason: 'public_not_settable',
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
},
|
|
60
|
+
mutate: async () => {
|
|
61
|
+
if (deps.persistTier !== undefined) {
|
|
62
|
+
await deps.persistTier(permissionKey, tier, mutation.targetTenantId);
|
|
63
|
+
}
|
|
64
|
+
},
|
|
65
|
+
emitAudit: async (_value, blastRadius) => {
|
|
66
|
+
const permissionLabel = await deps.labels.resolve('permission', permissionKey, mutation.targetTenantId);
|
|
67
|
+
await deps.audit.record({
|
|
68
|
+
type: 'admin_action',
|
|
69
|
+
occurredAtMs: clock(),
|
|
70
|
+
actorId: mutation.admin.id,
|
|
71
|
+
tenantId: mutation.targetTenantId,
|
|
72
|
+
attributes: (0, pipeline_js_1.buildAuditAttributes)(mutation, blastRadius, {
|
|
73
|
+
action: 'set_tier',
|
|
74
|
+
permissionLabel,
|
|
75
|
+
tier,
|
|
76
|
+
}),
|
|
77
|
+
});
|
|
78
|
+
},
|
|
79
|
+
}, deps.decide);
|
|
80
|
+
};
|
|
81
|
+
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Engine seam: **Admin Console** (Layer 10) — the administration experience over
|
|
4
|
+
* the security Core.
|
|
5
|
+
*
|
|
6
|
+
* Manage the human-readable permission catalog, grants, guided record-access
|
|
7
|
+
* policies, access tiers, service accounts, and cross-tenant invitations, and
|
|
8
|
+
* review audit — all in human-readable terms (never routes/ids, ADR-0012). Plus
|
|
9
|
+
* effective-access explain/simulate. Every administrative capability is subject to
|
|
10
|
+
* the §11.3 safeguards (delegated-administration, blast-radius, confirm-and-audit).
|
|
11
|
+
*
|
|
12
|
+
* This is a NEW top-level Core module (sibling to authorization/audit); it touches
|
|
13
|
+
* NO frozen prior-layer seam. The PRELUDE freezes the ports, the shared query +
|
|
14
|
+
* command types, the safeguard SIGNATURES (fail-closed defaults), and the
|
|
15
|
+
* query/command service factories + the §11.3 command pipeline order; the three
|
|
16
|
+
* parallel teams fill the engine bodies:
|
|
17
|
+
* - Team A → the QUERY engine (catalog / explain / simulate / audit viewer).
|
|
18
|
+
* - Team B → the COMMAND engine + the `./safeguards.ts` bodies.
|
|
19
|
+
* - Team C → the React console over the SDK admin surface.
|
|
20
|
+
*
|
|
21
|
+
* ⛔ NON-NEGOTIABLES: ONE decision path (simulate + delegated-admin REUSE
|
|
22
|
+
* `decide()`, ADR-0001); fail-closed defaults everywhere; no raw ids out (the
|
|
23
|
+
* `LabelResolver` chokepoint, ADR-0012); guided builder only (no raw expressions);
|
|
24
|
+
* blast-radius + confirm + audit on destructive commands (§11.3); Public is
|
|
25
|
+
* code-only (the tier command refuses it).
|
|
26
|
+
*
|
|
27
|
+
* APPEND-ONLY re-exports (mirrors the identity/session/authorization/audit
|
|
28
|
+
* barrels). ADR-0003: framework-agnostic — zero-dep Core.
|
|
29
|
+
*/
|
|
30
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
31
|
+
if (k2 === undefined) k2 = k;
|
|
32
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
33
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
34
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
35
|
+
}
|
|
36
|
+
Object.defineProperty(o, k2, desc);
|
|
37
|
+
}) : (function(o, m, k, k2) {
|
|
38
|
+
if (k2 === undefined) k2 = k;
|
|
39
|
+
o[k2] = m[k];
|
|
40
|
+
}));
|
|
41
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
42
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
// The injected admin PORTs (curation / grant / policy / invitation / service-account
|
|
46
|
+
// stores + the audit reader + the id→label chokepoint) + their input shapes:
|
|
47
|
+
__exportStar(require("./ports.js"), exports);
|
|
48
|
+
// The shared query + command TYPES (catalog view, explain, simulate, guided
|
|
49
|
+
// policy, blast-radius, confirm token, invitation state machine, service account,
|
|
50
|
+
// command result + deny reasons):
|
|
51
|
+
__exportStar(require("./types.js"), exports);
|
|
52
|
+
// The §11.3 SAFEGUARD signatures + fail-closed defaults (Team B implements bodies):
|
|
53
|
+
__exportStar(require("./safeguards.js"), exports);
|
|
54
|
+
// The query/command service factories + interfaces + the §11.3 command pipeline
|
|
55
|
+
// order (the seam Teams A/B fill method-by-method):
|
|
56
|
+
__exportStar(require("./admin-service.js"), exports);
|
|
57
|
+
// ---------------------------------------------------------------------------
|
|
58
|
+
// INTEGRATION APPEND (Layer-10 integration owner) — surface the REAL engine
|
|
59
|
+
// bodies on the package barrel. Everything ABOVE this line is the frozen
|
|
60
|
+
// prelude seam (types + fail-closed factories) and is UNCHANGED. The frozen
|
|
61
|
+
// `createAdminQueryService` / `createAdminCommandService` remain the typed
|
|
62
|
+
// fail-closed DEFAULT; the SANCTIONED entry points a consumer wires are the
|
|
63
|
+
// REAL composers re-exported here:
|
|
64
|
+
// - Team A query engine → `composeAdminQueryService(deps)` (query/index.js)
|
|
65
|
+
// - Team B command engine → `createRealAdminCommandService(deps)` (command/index.js)
|
|
66
|
+
// - Team B real safeguards → `checkDelegatedAdminImpl` / `computeBlastRadiusImpl`
|
|
67
|
+
// / `requiresConfirmImpl` (safeguards-impl.js) — the REAL §11.3 safeguards
|
|
68
|
+
// that the real command pipeline (`runAdminCommand`) uses, NEVER the frozen
|
|
69
|
+
// deny-stub `runCommandPipeline`.
|
|
70
|
+
// ---------------------------------------------------------------------------
|
|
71
|
+
// Team A — the REAL query engine (catalog / explain / simulate / audit view) +
|
|
72
|
+
// `composeAdminQueryService`:
|
|
73
|
+
__exportStar(require("./query/index.js"), exports);
|
|
74
|
+
// Team B — the REAL §11.3 safeguard implementations (replace the fail-closed stubs):
|
|
75
|
+
__exportStar(require("./safeguards-impl.js"), exports);
|
|
76
|
+
// Team B — the command engine (real service factory + builders + validators + the
|
|
77
|
+
// real §11.3 pipeline runner `runAdminCommand`):
|
|
78
|
+
__exportStar(require("./command/index.js"), exports);
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* The Admin Console engine **PORTS** — the framework-agnostic contracts the admin
|
|
4
|
+
* query/command engines (`./admin-service.ts`) use to reach the curation overlay,
|
|
5
|
+
* grants, policies, cross-tenant invitations, service accounts, the audit read
|
|
6
|
+
* side, and id→label resolution, WITHOUT the engine ever knowing which DB / cache
|
|
7
|
+
* / directory backs them (Layer 10).
|
|
8
|
+
*
|
|
9
|
+
* ADR-0003 (zero-dep Core): every concrete adapter (MariaDB stores, an IdP-backed
|
|
10
|
+
* label directory, the audit read model) is a real runtime dependency and CANNOT
|
|
11
|
+
* live here. The Core defines only these interfaces; `@astram/guard` ships the
|
|
12
|
+
* concretes and INJECTS them into `createAdminQueryService(...)` /
|
|
13
|
+
* `createAdminCommandService(...)`. This keeps `@astram/core` at ZERO runtime
|
|
14
|
+
* dependencies (the load-bearing invariant) while the substrate stays swappable.
|
|
15
|
+
*
|
|
16
|
+
* ⛔ DATA-ABSENCE vs TRANSIENT-UNAVAILABLE (mirrors session/audit ports). A port
|
|
17
|
+
* returning `null` / `[]` means "the store answered: no such data" — a NORMAL
|
|
18
|
+
* miss the engine handles as an ordinary empty result. A port that genuinely
|
|
19
|
+
* CANNOT answer (DB down / timeout) MUST **throw** so the engine fails CLOSED
|
|
20
|
+
* (ADR-0016) — it must NEVER conflate "down" with "absent" (that would fail open
|
|
21
|
+
* or misreport an empty catalog). Each method below documents its absence value.
|
|
22
|
+
*
|
|
23
|
+
* ⛔ NO RAW IDENTIFIERS reach the UI. The {@link LabelResolver} port is the
|
|
24
|
+
* id→label chokepoint (ADR-0012 / §13.4). Stores traffic in opaque ids for
|
|
25
|
+
* correlation; the query engine resolves every user-facing id to a label via
|
|
26
|
+
* {@link LabelResolver} before it leaves the Core.
|
|
27
|
+
*
|
|
28
|
+
* ADR-0003: framework-agnostic — no framework / HTTP / DB / node imports.
|
|
29
|
+
*/
|
|
30
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
+
exports.ADMIN_SETTABLE_TIERS = void 0;
|
|
32
|
+
/**
|
|
33
|
+
* The default access tier the tier-set command is permitted to assign. Exported
|
|
34
|
+
* for Team B's tier command + the safeguards: the console may set `gated` or
|
|
35
|
+
* `authenticated_global`, but MUST refuse `public` (Public is code-only, §3.6 /
|
|
36
|
+
* AC 8). This names the admin-settable subset so the refusal can't drift.
|
|
37
|
+
*/
|
|
38
|
+
exports.ADMIN_SETTABLE_TIERS = [
|
|
39
|
+
'gated',
|
|
40
|
+
'authenticated_global',
|
|
41
|
+
];
|