@stigmer/server 3.14.1 → 3.15.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/boot/compose.d.ts +8 -1
- package/dist/boot/compose.d.ts.map +1 -1
- package/dist/boot/compose.js +98 -12
- package/dist/boot/compose.js.map +1 -1
- package/dist/domain/apikey/verifier.d.ts +8 -1
- package/dist/domain/apikey/verifier.d.ts.map +1 -1
- package/dist/domain/apikey/verifier.js +14 -2
- package/dist/domain/apikey/verifier.js.map +1 -1
- package/dist/domain/identityaccount/constants.d.ts +66 -0
- package/dist/domain/identityaccount/constants.d.ts.map +1 -0
- package/dist/domain/identityaccount/constants.js +153 -0
- package/dist/domain/identityaccount/constants.js.map +1 -0
- package/dist/domain/identityaccount/controller.d.ts +34 -0
- package/dist/domain/identityaccount/controller.d.ts.map +1 -0
- package/dist/domain/identityaccount/controller.js +342 -0
- package/dist/domain/identityaccount/controller.js.map +1 -0
- package/dist/domain/identityaccount/operator.d.ts +14 -0
- package/dist/domain/identityaccount/operator.d.ts.map +1 -0
- package/dist/domain/identityaccount/operator.js +67 -0
- package/dist/domain/identityaccount/operator.js.map +1 -0
- package/dist/domain/identityaccount/provisioning.d.ts +52 -0
- package/dist/domain/identityaccount/provisioning.d.ts.map +1 -0
- package/dist/domain/identityaccount/provisioning.js +114 -0
- package/dist/domain/identityaccount/provisioning.js.map +1 -0
- package/dist/domain/identityaccount/resolve.d.ts +36 -0
- package/dist/domain/identityaccount/resolve.d.ts.map +1 -0
- package/dist/domain/identityaccount/resolve.js +12 -0
- package/dist/domain/identityaccount/resolve.js.map +1 -0
- package/dist/domain/identityaccount/resource-store.d.ts +4 -0
- package/dist/domain/identityaccount/resource-store.d.ts.map +1 -0
- package/dist/domain/identityaccount/resource-store.js +131 -0
- package/dist/domain/identityaccount/resource-store.js.map +1 -0
- package/dist/domain/identityaccount/steps.d.ts +79 -0
- package/dist/domain/identityaccount/steps.d.ts.map +1 -0
- package/dist/domain/identityaccount/steps.js +291 -0
- package/dist/domain/identityaccount/steps.js.map +1 -0
- package/dist/domain/identityaccount/store-contract.d.ts +22 -0
- package/dist/domain/identityaccount/store-contract.d.ts.map +1 -0
- package/dist/domain/identityaccount/store-contract.js +307 -0
- package/dist/domain/identityaccount/store-contract.js.map +1 -0
- package/dist/domain/identityaccount/store.d.ts +66 -0
- package/dist/domain/identityaccount/store.d.ts.map +1 -0
- package/dist/domain/identityaccount/store.js +13 -0
- package/dist/domain/identityaccount/store.js.map +1 -0
- package/dist/extensions/drivers.d.ts +26 -0
- package/dist/extensions/drivers.d.ts.map +1 -1
- package/dist/extensions/gate-slots.d.ts +16 -1
- package/dist/extensions/gate-slots.d.ts.map +1 -1
- package/dist/extensions/gate-slots.js +1 -0
- package/dist/extensions/gate-slots.js.map +1 -1
- package/dist/extensions/identity-federation.d.ts +36 -0
- package/dist/extensions/identity-federation.d.ts.map +1 -0
- package/dist/extensions/identity-federation.js +2 -0
- package/dist/extensions/identity-federation.js.map +1 -0
- package/dist/extensions/registry.d.ts +18 -1
- package/dist/extensions/registry.d.ts.map +1 -1
- package/dist/extensions/registry.js +20 -0
- package/dist/extensions/registry.js.map +1 -1
- package/dist/identity/oidc-discovery.d.ts +36 -0
- package/dist/identity/oidc-discovery.d.ts.map +1 -0
- package/dist/identity/oidc-discovery.js +60 -0
- package/dist/identity/oidc-discovery.js.map +1 -0
- package/dist/identity/oidc-userinfo.d.ts +30 -0
- package/dist/identity/oidc-userinfo.d.ts.map +1 -0
- package/dist/identity/oidc-userinfo.js +28 -0
- package/dist/identity/oidc-userinfo.js.map +1 -0
- package/dist/identity/oidc-verifier.d.ts +6 -0
- package/dist/identity/oidc-verifier.d.ts.map +1 -1
- package/dist/identity/oidc-verifier.js +35 -34
- package/dist/identity/oidc-verifier.js.map +1 -1
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/pipeline/interceptors/auth.d.ts +10 -0
- package/dist/pipeline/interceptors/auth.d.ts.map +1 -1
- package/dist/pipeline/interceptors/auth.js +9 -1
- package/dist/pipeline/interceptors/auth.js.map +1 -1
- package/package.json +4 -4
- package/src/boot/__tests__/auth-enabled-composition.test.ts +226 -2
- package/src/boot/compose.ts +118 -13
- package/src/domain/apikey/__tests__/verifier.test.ts +146 -22
- package/src/domain/apikey/verifier.ts +24 -2
- package/src/domain/identityaccount/__tests__/constants.test.ts +155 -0
- package/src/domain/identityaccount/__tests__/identityaccount.test.ts +484 -0
- package/src/domain/identityaccount/__tests__/operator.test.ts +180 -0
- package/src/domain/identityaccount/__tests__/provisioning.test.ts +281 -0
- package/src/domain/identityaccount/__tests__/resolve.test.ts +114 -0
- package/src/domain/identityaccount/__tests__/resource-store.test.ts +216 -0
- package/src/domain/identityaccount/__tests__/support.ts +58 -0
- package/src/domain/identityaccount/constants.ts +178 -0
- package/src/domain/identityaccount/controller.ts +667 -0
- package/src/domain/identityaccount/operator.ts +94 -0
- package/src/domain/identityaccount/provisioning.ts +182 -0
- package/src/domain/identityaccount/resolve.ts +52 -0
- package/src/domain/identityaccount/resource-store.ts +157 -0
- package/src/domain/identityaccount/steps.ts +377 -0
- package/src/domain/identityaccount/store-contract.ts +471 -0
- package/src/domain/identityaccount/store.ts +70 -0
- package/src/extensions/__tests__/identity-account-composed.test.ts +803 -0
- package/src/extensions/__tests__/identity-account-points.test.ts +129 -0
- package/src/extensions/__tests__/registry.test.ts +4 -0
- package/src/extensions/__tests__/tier-truthfulness.test.ts +299 -0
- package/src/extensions/drivers.ts +26 -0
- package/src/extensions/gate-slots.ts +16 -0
- package/src/extensions/identity-federation.ts +58 -0
- package/src/extensions/registry.ts +44 -1
- package/src/identity/__tests__/oidc-discovery.test.ts +122 -0
- package/src/identity/__tests__/oidc-userinfo.test.ts +103 -0
- package/src/identity/__tests__/oidc-verifier.test.ts +173 -3
- package/src/identity/oidc-discovery.ts +84 -0
- package/src/identity/oidc-userinfo.ts +64 -0
- package/src/identity/oidc-verifier.ts +42 -45
- package/src/index.ts +19 -0
- package/src/pipeline/interceptors/auth.ts +13 -1
- package/src/pipeline/steps/__tests__/authorize-annotation-completeness.test.ts +184 -0
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Identity-account domain constants (20260911.11, T01_1_review.md A1, A2,
|
|
3
|
+
* A7): the derived account id, the one function that turns a caller into
|
|
4
|
+
* an issuer subject, and the byte-pinned wire copy.
|
|
5
|
+
*
|
|
6
|
+
* The derived id (A1). A direct account's id is a pure function of its
|
|
7
|
+
* subject: `ida_` + the top 130 bits of sha256(idp_id) as 26 lowercase
|
|
8
|
+
* Crockford-base32 characters. The shape is indistinguishable from a
|
|
9
|
+
* minted `{prefix}_{ulid}`, so nothing downstream learns a second id
|
|
10
|
+
* grammar, and the PRIMARY KEY becomes the one home of "one account per
|
|
11
|
+
* subject": the generic store has no secondary uniqueness and its save is
|
|
12
|
+
* an upsert (`store/sqlite/store.ts`), so a lookup-then-insert on a scan
|
|
13
|
+
* could never close the first-login race. Two replicas deriving the same
|
|
14
|
+
* id converge by primary key with no migration and no second copy of any
|
|
15
|
+
* field. The hash is one-way, so an issuer subject never leaks into the
|
|
16
|
+
* `created_by.id` stamps that ride on every resource. The golden vectors in
|
|
17
|
+
* __tests__/constants.test.ts are wire-adjacent contract: a change here
|
|
18
|
+
* re-addresses every direct account open source ever created.
|
|
19
|
+
*
|
|
20
|
+
* `idpIdOf` (A2) is the ONE place a CallerIdentity becomes a subject. An
|
|
21
|
+
* issuer-vouched token is read for its `sub` (already verified at
|
|
22
|
+
* position 1, so this is a read of trusted state, never a verification);
|
|
23
|
+
* a caller with no issuer and no token is the trusted-local operator,
|
|
24
|
+
* whose subject is `local|<identityId>`. It deliberately knows nothing
|
|
25
|
+
* about API keys: every verifier resolves its stamp to the account when
|
|
26
|
+
* one exists (A6), so a credential's shape is the verifier's business.
|
|
27
|
+
*
|
|
28
|
+
* The copy moved from the cloud's iam/account/handlers.ts as-is: the CLI,
|
|
29
|
+
* console and SDK show these sentences verbatim, so they are contract.
|
|
30
|
+
*/
|
|
31
|
+
import { createHash } from "node:crypto";
|
|
32
|
+
|
|
33
|
+
import type { CallerIdentity } from "../../extensions/identity.js";
|
|
34
|
+
|
|
35
|
+
/** The kind's id prefix (kind_meta `identity_account.id_prefix`). */
|
|
36
|
+
export const ACCOUNT_ID_PREFIX = "ida";
|
|
37
|
+
|
|
38
|
+
/** Crockford base32, lowercased — the alphabet every minted ULID id uses. */
|
|
39
|
+
const CROCKFORD_ALPHABET = "0123456789abcdefghjkmnpqrstvwxyz";
|
|
40
|
+
const DERIVED_ID_CHARS = 26;
|
|
41
|
+
const DERIVED_ID_BITS = BigInt(DERIVED_ID_CHARS * 5);
|
|
42
|
+
const SHA256_BITS = 256n;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The derived account id of a direct account with subject `idpId`. Pure,
|
|
46
|
+
* total over non-empty input; an empty subject has no principal and so
|
|
47
|
+
* no address — refused, never hashed.
|
|
48
|
+
*/
|
|
49
|
+
export function accountIdFor(idpId: string): string {
|
|
50
|
+
if (idpId === "") {
|
|
51
|
+
throw new Error("idp_id must not be empty");
|
|
52
|
+
}
|
|
53
|
+
const digest = createHash("sha256").update(idpId, "utf8").digest();
|
|
54
|
+
let bits = 0n;
|
|
55
|
+
for (const byte of digest) {
|
|
56
|
+
bits = (bits << 8n) | BigInt(byte);
|
|
57
|
+
}
|
|
58
|
+
let top = bits >> (SHA256_BITS - DERIVED_ID_BITS);
|
|
59
|
+
let encoded = "";
|
|
60
|
+
for (let i = 0; i < DERIVED_ID_CHARS; i++) {
|
|
61
|
+
encoded = CROCKFORD_ALPHABET[Number(top & 31n)] + encoded;
|
|
62
|
+
top >>= 5n;
|
|
63
|
+
}
|
|
64
|
+
return `${ACCOUNT_ID_PREFIX}_${encoded}`;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The subject namespace of the trusted-local posture. An OIDC subject is
|
|
69
|
+
* `<connection>|<id>` by Auth0 convention; `local|` claims the same shape
|
|
70
|
+
* for the one principal no issuer vouches for, so the derived ids of a
|
|
71
|
+
* local operator and an OIDC user can never collide by construction.
|
|
72
|
+
*/
|
|
73
|
+
export const LOCAL_IDP_ID_PREFIX = "local|";
|
|
74
|
+
|
|
75
|
+
/** `local|<identityId>` — the trusted-local operator's subject. */
|
|
76
|
+
export function localIdpIdFor(identityId: string): string {
|
|
77
|
+
return `${LOCAL_IDP_ID_PREFIX}${identityId}`;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The issuer subject a caller stands for:
|
|
82
|
+
* - a caller with no issuer and no token is the trusted-local operator
|
|
83
|
+
* (`local|<identityId>`; identityId is the operator's email or
|
|
84
|
+
* "system" — pipeline/interceptors/auth.ts trustedLocalIdentity);
|
|
85
|
+
* - a token-bearing caller is its JWT `sub`, read from the raw token
|
|
86
|
+
* the verifier already proved; `""` when the token carries no
|
|
87
|
+
* readable subject (an opaque credential under an issuer), which
|
|
88
|
+
* the provisionMyAccount handler maps to the UNAUTHENTICATED arm.
|
|
89
|
+
*/
|
|
90
|
+
export function idpIdOf(caller: CallerIdentity): string {
|
|
91
|
+
if (caller.issuer === "" && caller.rawToken === "") {
|
|
92
|
+
return localIdpIdFor(caller.identityId);
|
|
93
|
+
}
|
|
94
|
+
return jwtSubjectOf(caller.rawToken);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The cloud's jwtSubjectOf verbatim: the payload segment decoded, `sub`
|
|
99
|
+
* when it is a string. Not a verification — the chain's position 1 did
|
|
100
|
+
* that; this only reads a claim from trusted state.
|
|
101
|
+
*/
|
|
102
|
+
function jwtSubjectOf(rawToken: string): string {
|
|
103
|
+
const segments = rawToken.split(".");
|
|
104
|
+
if (segments.length !== 3) {
|
|
105
|
+
return "";
|
|
106
|
+
}
|
|
107
|
+
try {
|
|
108
|
+
const payload = JSON.parse(
|
|
109
|
+
Buffer.from(segments[1] ?? "", "base64url").toString("utf8"),
|
|
110
|
+
) as { sub?: unknown };
|
|
111
|
+
return typeof payload.sub === "string" ? payload.sub : "";
|
|
112
|
+
} catch {
|
|
113
|
+
return "";
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Auth0's client-credentials subject shape (`<client_id>@clients`) — the
|
|
119
|
+
* cloud's IsMachineAccountVerifier rule, the one input to
|
|
120
|
+
* `is_machine_account`.
|
|
121
|
+
*/
|
|
122
|
+
export const MACHINE_ACCOUNT_SUFFIX = "@clients";
|
|
123
|
+
|
|
124
|
+
export function isMachineSubject(idpId: string): boolean {
|
|
125
|
+
return idpId.endsWith(MACHINE_ACCOUNT_SUFFIX);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// ---------------------------------------------------------------------------
|
|
129
|
+
// Byte-pinned copy (the cloud handlers' sentences, moved as-is).
|
|
130
|
+
// ---------------------------------------------------------------------------
|
|
131
|
+
|
|
132
|
+
/** whoAmI for a caller with no account (NOT_FOUND). */
|
|
133
|
+
export const ACCOUNT_NOT_FOUND_FOR_CALLER_MESSAGE =
|
|
134
|
+
"Identity account not found for the authenticated user";
|
|
135
|
+
|
|
136
|
+
/** provisionMyAccount for a caller whose credential names no subject (UNAUTHENTICATED). */
|
|
137
|
+
export const NO_IDP_ID_MESSAGE =
|
|
138
|
+
"Cannot provision account: no IDP ID in authentication context";
|
|
139
|
+
|
|
140
|
+
/** provisionMyAccount when the issuer's userinfo cannot be read (UNAVAILABLE); the cause follows. */
|
|
141
|
+
export const USERINFO_UNAVAILABLE_PREFIX =
|
|
142
|
+
"Failed to fetch user profile from identity provider: ";
|
|
143
|
+
|
|
144
|
+
/** get / getByEmail / getByIdpId / getActorInfo / update / delete on a missing account (NOT_FOUND). */
|
|
145
|
+
export function accountNotFoundMessage(handle: string): string {
|
|
146
|
+
return `Identity account not found: ${handle}`;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* The cloud#393 gate's refusal (PERMISSION_DENIED): the create RPC admits
|
|
151
|
+
* the platform's own pipelines only — machine-class callers and
|
|
152
|
+
* server-composed (in-process) requests (T01_1_review.md A7).
|
|
153
|
+
*/
|
|
154
|
+
export const CREATE_IS_INTERNAL_MESSAGE =
|
|
155
|
+
"this RPC is internal to the platform";
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* The reason a composition with no IdentityFederation unit refuses the four
|
|
159
|
+
* federation RPCs (UNIMPLEMENTED). The sentence a person can act on; the
|
|
160
|
+
* method-naming prefix is the organization directory's absent-method shape
|
|
161
|
+
* so clients matching on "is not implemented" keep working.
|
|
162
|
+
*/
|
|
163
|
+
export const FEDERATION_UNIMPLEMENTED_REASON =
|
|
164
|
+
"federated identity accounts are served by the Enterprise and Cloud editions";
|
|
165
|
+
|
|
166
|
+
export function federationUnimplementedMessage(method: string): string {
|
|
167
|
+
return `${method} is not implemented: ${FEDERATION_UNIMPLEMENTED_REASON}`;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* update with a changed spec.idp_id (FAILED_PRECONDITION; the schedule
|
|
172
|
+
* domain's immutability shape, T01_1_review.md A1). The subject IS the
|
|
173
|
+
* identity; a client that sends a different one has a bug it should hear
|
|
174
|
+
* about, never a silent preserve.
|
|
175
|
+
*/
|
|
176
|
+
export function idpIdImmutableMessage(existingIdpId: string): string {
|
|
177
|
+
return `spec.idp_id is immutable (account subject is '${existingIdpId}') — create a new account for a different subject`;
|
|
178
|
+
}
|