@fabrika/auth-core 0.9.0-dev.5 → 0.9.0-dev.50
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/package.json +3 -2
- package/src/agent.ts +89 -0
- package/src/canonical-path.ts +18 -0
- package/src/client-address.ts +74 -0
- package/src/contract-canonical.ts +168 -2
- package/src/contract-encoding.ts +181 -0
- package/src/contract.ts +220 -17
- package/src/egress.ts +97 -0
- package/src/endpoint-digest.ts +22 -2
- package/src/framework-release.ts +70 -0
- package/src/framework-variables.ts +14 -0
- package/src/iam-mail.ts +354 -0
- package/src/index.ts +7 -0
- package/src/installation-endpoint.ts +3 -2
- package/src/locale.ts +13 -1
- package/src/managed-environment.ts +11 -0
- package/src/membership.ts +12 -4
- package/src/oauth.ts +19 -0
- package/src/ops.ts +487 -16
- package/src/permissions.ts +42 -0
- package/src/public-egress.ts +168 -0
- package/src/requirement.ts +12 -4
- package/src/rpc.ts +137 -9
- package/src/scope-values.ts +123 -0
- package/src/sha256.ts +52 -14
- package/src/token.ts +195 -14
- package/src/types.ts +72 -1
- package/src/wire.ts +2 -1
- package/types/src/agent.d.ts +37 -0
- package/types/src/canonical-path.d.ts +6 -0
- package/types/src/client-address.d.ts +7 -0
- package/types/src/contract-canonical.d.ts +11 -1
- package/types/src/contract-encoding.d.ts +18 -0
- package/types/src/contract.d.ts +205 -16
- package/types/src/egress.d.ts +27 -0
- package/types/src/endpoint-digest.d.ts +5 -0
- package/types/src/framework-release.d.ts +23 -0
- package/types/src/framework-variables.d.ts +6 -1
- package/types/src/iam-mail.d.ts +92 -0
- package/types/src/index.d.ts +7 -0
- package/types/src/installation-endpoint.d.ts +3 -2
- package/types/src/locale.d.ts +11 -1
- package/types/src/managed-environment.d.ts +1 -1
- package/types/src/membership.d.ts +8 -3
- package/types/src/oauth.d.ts +11 -0
- package/types/src/ops.d.ts +133 -8
- package/types/src/permissions.d.ts +12 -0
- package/types/src/public-egress.d.ts +31 -0
- package/types/src/requirement.d.ts +5 -4
- package/types/src/rpc.d.ts +113 -6
- package/types/src/scope-values.d.ts +61 -0
- package/types/src/sha256.d.ts +10 -0
- package/types/src/token.d.ts +70 -8
- package/types/src/types.d.ts +48 -1
- package/types/src/wire.d.ts +2 -1
package/types/src/token.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The IAM-issued token contract — the SECOND thing (after `IamRpc`) that must not drift
|
|
3
3
|
* between the Worker and the SDK.
|
|
4
4
|
*
|
|
5
5
|
* Background: today a request is authorized by the Worker resolving a Cloudflare Access JWT on
|
|
6
6
|
* every call over RPC (the CF token carries only identity, so authz needs a round-trip). When
|
|
7
|
-
*
|
|
7
|
+
* IAM issues its OWN token it can embed the already-resolved permission set, and the SDK
|
|
8
8
|
* authorizes LOCALLY — no per-request round-trip. This module is the wire shape of that token:
|
|
9
9
|
*
|
|
10
10
|
* - the Worker BUILDS claims here and signs them (`buildAccessClaims`);
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
*
|
|
22
22
|
* Pure: no jose, no I/O. Signing/verifying (key material) stays in the packages that own it.
|
|
23
23
|
*/
|
|
24
|
+
import { AGENT_CLIENT_ID, type AgentScope } from './agent';
|
|
24
25
|
import type { ResolvedPrincipal } from './rpc';
|
|
25
26
|
import { type PermissionEntry, type Scope, type TokenPrincipalType } from './types';
|
|
26
27
|
/** Namespace reserved for browser credentials owned by IAM and the Fabrika proxy. */
|
|
@@ -38,14 +39,14 @@ export declare const FABRIKA_COOKIE_PREFIX = "__Host-px_";
|
|
|
38
39
|
* because those origins are potentially trustworthy.
|
|
39
40
|
*/
|
|
40
41
|
export declare const SESSION_COOKIE = "__Host-px_session";
|
|
41
|
-
/** Prefix marking
|
|
42
|
+
/** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
|
|
42
43
|
export declare const API_KEY_PREFIX = "px_";
|
|
43
44
|
/**
|
|
44
45
|
* Where a job or a webhook exchanges its own `px_` key for an access token at IAM's public origin: `POST` with the key
|
|
45
46
|
* as the bearer and `{ app }` as the body. IAM answers `MintFromKeyResult`, and only for a workload key of that app.
|
|
46
47
|
*/
|
|
47
48
|
export declare const WORKLOAD_TOKEN_PATH = "/auth/workload/token";
|
|
48
|
-
/** Signing algorithm
|
|
49
|
+
/** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
|
|
49
50
|
export declare const TOKEN_ALG = "ES256";
|
|
50
51
|
/** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
|
|
51
52
|
export declare const RESOURCE_ACCESS_TOKEN_TYP = "at+jwt";
|
|
@@ -72,12 +73,12 @@ export declare const MAX_APPLICATION_TOKEN_BYTES = 24576;
|
|
|
72
73
|
/** The request-header limit the platform starts an application's Bun server with (`--max-http-header-size`). */
|
|
73
74
|
export declare const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536;
|
|
74
75
|
/**
|
|
75
|
-
* The
|
|
76
|
+
* The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
|
|
76
77
|
* only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
|
|
77
78
|
* credential label otherwise (or null).
|
|
78
79
|
*/
|
|
79
80
|
export interface AccessTokenClaims {
|
|
80
|
-
/** Issuer —
|
|
81
|
+
/** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
|
|
81
82
|
iss: string;
|
|
82
83
|
/** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
|
|
83
84
|
aud: string;
|
|
@@ -87,7 +88,10 @@ export interface AccessTokenClaims {
|
|
|
87
88
|
iat: number;
|
|
88
89
|
/** Expiry (unix seconds). */
|
|
89
90
|
exp: number;
|
|
90
|
-
/**
|
|
91
|
+
/**
|
|
92
|
+
* Resolved/effective permissions; `can(action, scope?)` = `permits(perms, action, scope)`. On the wire a compact token
|
|
93
|
+
* carries its global grants in `gperms` (`AccessTokenPayload`); the parser reads them back into this list.
|
|
94
|
+
*/
|
|
91
95
|
perms: PermissionEntry[];
|
|
92
96
|
/** Present only when the token is bound to a principal (`sub` is that principal). */
|
|
93
97
|
ptype?: TokenPrincipalType;
|
|
@@ -116,11 +120,35 @@ export interface AccessTokenClaims {
|
|
|
116
120
|
amr?: TerminalAuthenticationMethod;
|
|
117
121
|
/** The terminal the person is signed in on; present exactly when `amr` is. */
|
|
118
122
|
terminal?: TerminalTokenClaims;
|
|
123
|
+
/**
|
|
124
|
+
* Present only on a person's application token the proxy exchanged an agent's device grant for (ADR-0090), never on a
|
|
125
|
+
* session's: the agent acts as the person, under the grant's scope.
|
|
126
|
+
*/
|
|
127
|
+
act?: AgentActClaims;
|
|
119
128
|
/** Present only on an OAuth resource token (`aud` is then a resource URI, not an app id). */
|
|
120
129
|
oauth?: OAuthTokenClaims;
|
|
121
130
|
/** Present only on a share-link token, which has no `ptype`: `sub` is then the link key's id. */
|
|
122
131
|
link?: LinkTokenClaims;
|
|
123
132
|
}
|
|
133
|
+
/**
|
|
134
|
+
* The agent a person's application token acts for: the device client, the grant the person approved, its parsed scope
|
|
135
|
+
* (ADR-0090 §2) and the label the agent gave itself, when it gave one.
|
|
136
|
+
*/
|
|
137
|
+
export interface AgentActClaims {
|
|
138
|
+
sub: typeof AGENT_CLIENT_ID;
|
|
139
|
+
grant: string;
|
|
140
|
+
scope: AgentScope;
|
|
141
|
+
label?: string;
|
|
142
|
+
}
|
|
143
|
+
/** `AgentActClaims` as the token carries them: the scope as its scope token (`agentScopeToken`). */
|
|
144
|
+
export interface AgentActPayload {
|
|
145
|
+
sub: typeof AGENT_CLIENT_ID;
|
|
146
|
+
grant: string;
|
|
147
|
+
scope: string;
|
|
148
|
+
label?: string;
|
|
149
|
+
}
|
|
150
|
+
/** The longest grant id and agent label an `act` claim carries. */
|
|
151
|
+
export declare const MAX_AGENT_ACT_FIELD_LENGTH = 64;
|
|
124
152
|
/** The `amr` value of a session an application asserted at a terminal. */
|
|
125
153
|
export declare const TERMINAL_AUTHENTICATION_METHOD = "terminal_assertion";
|
|
126
154
|
export type TerminalAuthenticationMethod = typeof TERMINAL_AUTHENTICATION_METHOD;
|
|
@@ -153,6 +181,11 @@ export interface OAuthTokenClaims {
|
|
|
153
181
|
grantId: string;
|
|
154
182
|
/** Unique token id, fresh on every mint. */
|
|
155
183
|
tokenId: string;
|
|
184
|
+
/**
|
|
185
|
+
* The keys of the roles the person holds at an external application that declares roles; absent on every other
|
|
186
|
+
* token. The application decides what each role allows; IAM grants it and names it here.
|
|
187
|
+
*/
|
|
188
|
+
roles?: string[];
|
|
156
189
|
}
|
|
157
190
|
/** Which tokens a verifier accepts: native app tokens, or OAuth tokens minted for one resource of one app. */
|
|
158
191
|
export type TokenAudienceProfile = {
|
|
@@ -178,7 +211,7 @@ export interface Jwks {
|
|
|
178
211
|
keys: PublicJwk[];
|
|
179
212
|
}
|
|
180
213
|
export interface AccessTokenParams {
|
|
181
|
-
/** Issuer (
|
|
214
|
+
/** Issuer (IAM origin). */
|
|
182
215
|
iss: string;
|
|
183
216
|
/** App id this token is for (becomes `aud`). */
|
|
184
217
|
app: string;
|
|
@@ -196,6 +229,8 @@ export interface AccessTokenParams {
|
|
|
196
229
|
session?: true;
|
|
197
230
|
/** The terminal of a person's session asserted on one; sets `amr` too, and requires a user `type` and `session`. */
|
|
198
231
|
terminal?: TerminalTokenClaims;
|
|
232
|
+
/** The agent a person's exchanged token acts for; requires a user `type`, no `session` and no `terminal`. */
|
|
233
|
+
act?: AgentActClaims;
|
|
199
234
|
permissions: PermissionEntry[];
|
|
200
235
|
issuedAt: number;
|
|
201
236
|
expiresAt: number;
|
|
@@ -215,6 +250,10 @@ export interface ResourceAccessTokenParams {
|
|
|
215
250
|
scopes: string[];
|
|
216
251
|
grantId: string;
|
|
217
252
|
tokenId: string;
|
|
253
|
+
/** The person's normalized mailbox; an identity resource's token carries it. */
|
|
254
|
+
email?: string;
|
|
255
|
+
/** The roles the person holds at an external application that declares roles (`OAuthTokenClaims.roles`). */
|
|
256
|
+
roles?: string[];
|
|
218
257
|
}
|
|
219
258
|
/**
|
|
220
259
|
* Assemble an OAuth resource access token. Always a user principal. The wire carries the standard
|
|
@@ -224,6 +263,27 @@ export interface ResourceAccessTokenParams {
|
|
|
224
263
|
export declare function buildResourceAccessClaims(params: ResourceAccessTokenParams): Record<string, unknown>;
|
|
225
264
|
/** A token is accepted only by the profile it was minted for: an app token never passes as a resource token, and vice versa. */
|
|
226
265
|
export declare function matchesTokenAudience(claims: AccessTokenClaims, profile: TokenAudienceProfile): boolean;
|
|
266
|
+
/**
|
|
267
|
+
* How an access token's claims travel. `entries` writes every permission into `perms`. `compact` writes each global
|
|
268
|
+
* grant (scope null, source `grant`) into `gperms` as its bare action name and the rest into `perms`; it is a third of
|
|
269
|
+
* the size for a person holding a few hundred actions. `parseAccessClaims` reads both into the same `perms`.
|
|
270
|
+
*/
|
|
271
|
+
export type AccessTokenLayout = 'entries' | 'compact';
|
|
272
|
+
/** The signed payload: the claims, with the global grants of the compact layout in `gperms`. */
|
|
273
|
+
export interface AccessTokenPayload extends Omit<AccessTokenClaims, 'act'> {
|
|
274
|
+
act?: AgentActPayload;
|
|
275
|
+
/** The compact layout's global grants, by action name; absent in the entries layout and when there are none. */
|
|
276
|
+
gperms?: string[];
|
|
277
|
+
}
|
|
278
|
+
/** The payload that carries `claims` in `layout`. */
|
|
279
|
+
export declare function accessTokenPayload(claims: AccessTokenClaims, layout: AccessTokenLayout): AccessTokenPayload;
|
|
280
|
+
/**
|
|
281
|
+
* Sign `claims` in the entries layout, or in the compact one when the entries layout is above `bound` bytes; the caller
|
|
282
|
+
* refuses a result still above it. A reader older than `gperms` reads a compact token without its global grants, which
|
|
283
|
+
* denies more and never allows more, and receives one only where the entries layout would have been refused anyway, so
|
|
284
|
+
* a platform release never changes a token an older framework release or a pinned proxy reads (ADR-0062).
|
|
285
|
+
*/
|
|
286
|
+
export declare function signAccessClaims(claims: AccessTokenClaims, bound: number, sign: (payload: AccessTokenPayload) => Promise<string>): Promise<string>;
|
|
227
287
|
/** Assemble the claim object for an access token. Pure — the caller signs the result. */
|
|
228
288
|
export declare function buildAccessClaims(params: AccessTokenParams): AccessTokenClaims;
|
|
229
289
|
/**
|
|
@@ -232,6 +292,8 @@ export declare function buildAccessClaims(params: AccessTokenParams): AccessToke
|
|
|
232
292
|
* the SDK reads them without an `as` cast. Returns null on any malformed claim shape.
|
|
233
293
|
*/
|
|
234
294
|
export declare function parseAccessClaims(payload: unknown): AccessTokenClaims | null;
|
|
295
|
+
/** The name an agent gives itself (`agent_label`): not blank, at most 64 characters, no control character. */
|
|
296
|
+
export declare function isAgentLabel(value: string): boolean;
|
|
235
297
|
/**
|
|
236
298
|
* Map a verified PRINCIPAL-bound access token into the `ResolvedPrincipal` the existing
|
|
237
299
|
* `AuthContext` consumes. Returns null for an anonymous token (no `ptype`) and for a workload token,
|
package/types/src/types.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Locale } from './locale';
|
|
2
2
|
import type { MailTemplates } from './mail';
|
|
3
|
+
import type { DimensionValue, DimensionValueSource } from './scope-values';
|
|
3
4
|
export type PrincipalType = 'user' | 'service';
|
|
4
5
|
/**
|
|
5
6
|
* Whether a person belongs to the organization (ADR-0051). An `external` principal holds only grants of a role its
|
|
@@ -34,6 +35,36 @@ export interface Scope {
|
|
|
34
35
|
type: string;
|
|
35
36
|
value: string;
|
|
36
37
|
}
|
|
38
|
+
/** A dimension's name as a contract declares it; also the dimension of a scope an agent's grant is narrowed to. */
|
|
39
|
+
export declare const DIMENSION_NAME: RegExp;
|
|
40
|
+
/**
|
|
41
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
42
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
43
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
44
|
+
*/
|
|
45
|
+
export declare const RELATION_SCOPE_TYPE = "~rel";
|
|
46
|
+
/**
|
|
47
|
+
* The pseudo-scope of a relation entry held inside one node: `{ type: '~relin', value: '<relation>:<dimension>:<node>' }`
|
|
48
|
+
* means the action is held where a row names the principal in that relation, on rows that lie inside `node` of
|
|
49
|
+
* `dimension`. IAM gives it a grant at that node of a role with `via`. Its own type, never `~rel`: a release that reads
|
|
50
|
+
* `~rel` as "the relation anywhere" ignores this one and reaches less.
|
|
51
|
+
*/
|
|
52
|
+
export declare const RELATION_INSIDE_SCOPE_TYPE = "~relin";
|
|
53
|
+
/** A relation held inside one node of a dimension, as a `~relin` entry names it. */
|
|
54
|
+
export interface RelationInside {
|
|
55
|
+
readonly relation: string;
|
|
56
|
+
readonly dimension: string;
|
|
57
|
+
readonly node: string;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* The `~relin` scope of `relation` inside `node` of `dimension`. A relation or dimension name never holds `:` (the
|
|
61
|
+
* contract's names do not), so the node, last, is read back verbatim, colons included; a name that holds one is refused.
|
|
62
|
+
*/
|
|
63
|
+
export declare function relationInsideScope(inside: RelationInside): Scope;
|
|
64
|
+
/** The relation, dimension and node of a `~relin` scope, or null for any other scope or a malformed value. */
|
|
65
|
+
export declare function parseRelationInside(scope: Scope): RelationInside | null;
|
|
66
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
67
|
+
export declare function isReservedScopeType(type: string): boolean;
|
|
37
68
|
export interface PermissionEntry {
|
|
38
69
|
action: string;
|
|
39
70
|
/** null = global / all scopes */
|
|
@@ -70,6 +101,13 @@ export interface RoleDef {
|
|
|
70
101
|
};
|
|
71
102
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
72
103
|
external?: true;
|
|
104
|
+
/**
|
|
105
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
106
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation. A
|
|
107
|
+
* grant at a node carries `~relin` instead (`relationInsideScope`): the relation holds only inside that node. Only an
|
|
108
|
+
* internal role declares it.
|
|
109
|
+
*/
|
|
110
|
+
via?: Record<string, string[]>;
|
|
73
111
|
}
|
|
74
112
|
/**
|
|
75
113
|
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|
|
@@ -97,6 +135,10 @@ export interface AppScopeDef {
|
|
|
97
135
|
* answers a lookup only for one of them, held on the directory's value. Absent, no endpoint looks one up.
|
|
98
136
|
*/
|
|
99
137
|
lookups?: string[];
|
|
138
|
+
/** The values the console offers for a grant in this dimension (ADR-0085); absent, it takes free text. */
|
|
139
|
+
values?: DimensionValue[];
|
|
140
|
+
/** The procedure IAM asks for this dimension's values as the administrator (ADR-0085 §4); absent, only `values` count. */
|
|
141
|
+
valueSource?: DimensionValueSource;
|
|
100
142
|
}
|
|
101
143
|
/**
|
|
102
144
|
* The role keys IAM defines itself for every app. A built-in wins over an app role of the same key at
|
|
@@ -132,7 +174,7 @@ export interface AppDelegationDef {
|
|
|
132
174
|
dimension: string;
|
|
133
175
|
purpose: 'members' | 'creates';
|
|
134
176
|
}
|
|
135
|
-
/** An app's full authz vocabulary, declared in the app's code, reconciled into
|
|
177
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
|
|
136
178
|
export interface AppSchema {
|
|
137
179
|
scopes: AppScopeDef[];
|
|
138
180
|
actions: AppActionDef[];
|
|
@@ -170,6 +212,11 @@ export interface AppSchema {
|
|
|
170
212
|
terminal?: {
|
|
171
213
|
identify: string;
|
|
172
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* A group of the contract admits the caller `agent` (ADR-0090): the environment's origin is then an OAuth resource of
|
|
217
|
+
* the agent client. Absent or false, IAM serves the environment to no agent.
|
|
218
|
+
*/
|
|
219
|
+
agentCallers?: boolean;
|
|
173
220
|
}
|
|
174
221
|
/**
|
|
175
222
|
* A job, a webhook or a public procedure (`public`, named by its endpoint id) of a contract application, or a consuming
|
package/types/src/wire.d.ts
CHANGED
|
@@ -53,7 +53,8 @@ export declare const FABRIKA_PROXY_SECRET = "FABRIKA_PROXY_SECRET";
|
|
|
53
53
|
export declare function proxySecretVariable(id: string): string;
|
|
54
54
|
/**
|
|
55
55
|
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
56
|
-
* and IAM hold it under this one name. It proves only who wrote IAM's
|
|
56
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
57
|
+
* it on one shared client bucket.
|
|
57
58
|
*/
|
|
58
59
|
export declare const IAM_PROXY_SECRET_VARIABLE = "FABRIKA_INSTALLATION_PROXY_SECRET_IAM";
|
|
59
60
|
/**
|