@fabrika/auth-core 0.9.0-dev.1 → 0.9.0-dev.10

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.
Files changed (44) hide show
  1. package/package.json +4 -3
  2. package/src/contract-canonical.ts +1 -0
  3. package/src/contract.ts +6 -0
  4. package/src/dev-environment.ts +6 -0
  5. package/src/framework-release.ts +2 -0
  6. package/src/framework-variables.ts +9 -0
  7. package/src/index.ts +4 -0
  8. package/src/managed-environment.ts +136 -0
  9. package/src/ops.ts +1933 -0
  10. package/src/rpc.ts +8 -8
  11. package/src/terminal.ts +105 -0
  12. package/src/token.ts +73 -13
  13. package/src/types.ts +5 -2
  14. package/src/wire.ts +6 -0
  15. package/types/src/app-environment.d.ts +24 -0
  16. package/types/src/canonical-path.d.ts +20 -0
  17. package/types/src/contract-canonical.d.ts +19 -0
  18. package/types/src/contract.d.ts +800 -0
  19. package/types/src/dev-environment.d.ts +37 -0
  20. package/types/src/device.d.ts +144 -0
  21. package/types/src/endpoint-digest.d.ts +58 -0
  22. package/types/src/endpoints.d.ts +65 -0
  23. package/types/src/environment.d.ts +58 -0
  24. package/types/src/framework-release.d.ts +2 -0
  25. package/types/src/framework-variables.d.ts +86 -0
  26. package/types/src/index.d.ts +28 -0
  27. package/types/src/installation-endpoint.d.ts +46 -0
  28. package/types/src/json.d.ts +13 -0
  29. package/types/src/locale.d.ts +14 -0
  30. package/types/src/mail.d.ts +67 -0
  31. package/types/src/managed-environment.d.ts +32 -0
  32. package/types/src/membership.d.ts +318 -0
  33. package/types/src/oauth.d.ts +7 -0
  34. package/types/src/ops.d.ts +657 -0
  35. package/types/src/path-segment.d.ts +5 -0
  36. package/types/src/permissions.d.ts +50 -0
  37. package/types/src/requirement.d.ts +24 -0
  38. package/types/src/rpc.d.ts +283 -0
  39. package/types/src/sha256.d.ts +2 -0
  40. package/types/src/terminal.d.ts +72 -0
  41. package/types/src/token.d.ts +240 -0
  42. package/types/src/types.d.ts +196 -0
  43. package/types/src/wire.d.ts +65 -0
  44. package/types/src/workloads.d.ts +25 -0
package/src/rpc.ts CHANGED
@@ -10,7 +10,7 @@ import type {
10
10
  import type { Jwks } from './token'
11
11
  import type { PermissionEntry, PrincipalType, Scope } from './types'
12
12
 
13
- // ── propustka-native session auth (mint a per-app permission token from an SSO session) ──
13
+ // ── IAM-native session auth (mint a per-app permission token from an SSO session) ──
14
14
  //
15
15
  // The SDK middleware presents the browser's opaque SSO session cookie; the Worker validates it,
16
16
  // resolves the principal's permissions FOR THE CALLING APP, and signs a short-lived per-app
@@ -33,7 +33,7 @@ export type MintTokenResult =
33
33
  /** `token_too_large`: the principal holds more than fits in one header; a decided refusal, never a login bounce. */
34
34
  | { ok: false; reason: 'no_session' | 'invalid_session' | 'unknown_principal' | 'disabled' | 'token_too_large' }
35
35
 
36
- // ── propustka-native key auth (mint an access token from an opaque `px_` credential) ──
36
+ // ── IAM-native key auth (mint an access token from an opaque `px_` credential) ──
37
37
  //
38
38
  // The other front over the same resolve→sign core as `mintToken`: the SDK presents an opaque
39
39
  // credential (an API key as a bearer, or a share-link path token) and the Worker resolves its
@@ -154,8 +154,8 @@ export interface IssueKeyServiceSpec {
154
154
  export interface IssueKeyInput {
155
155
  app: string
156
156
  /**
157
- * The propustka-native credential the ISSUER is resolved from server-side (never self-asserted):
158
- * a `px_token` access JWT (verified against propustka's signing keys) or a `px_` key. Null = absent.
157
+ * The IAM-native credential the ISSUER is resolved from server-side (never self-asserted):
158
+ * a `px_token` access JWT (verified against IAM's signing keys) or a `px_` key. Null = absent.
159
159
  */
160
160
  credential: string | null
161
161
  requestId: string
@@ -227,7 +227,7 @@ export interface AuditInput {
227
227
 
228
228
  export interface RevokeKeyInput {
229
229
  app: string
230
- /** The propustka-native credential the CALLER (authorizer) is resolved from; null = absent. */
230
+ /** The IAM-native credential the CALLER (authorizer) is resolved from; null = absent. */
231
231
  credential: string | null
232
232
  requestId: string
233
233
  /** The credential id (the `id` returned by `issueKey`), NOT the plaintext `px_` token. */
@@ -242,7 +242,7 @@ export type RevokeKeyResult =
242
242
  // ── List principals (the app's people directory) ───────────────────────────────
243
243
  //
244
244
  // A read-only enumeration of the USER principals who can access an app — its people
245
- // directory. Apps consume it for things propustka isn't the authority on but needs the
245
+ // directory. Apps consume it for things IAM isn't the authority on but needs the
246
246
  // roster for: an assignee picker, an actor/owner label list. The caller is resolved from
247
247
  // the forwarded Access credentials and the listed app is the aud-VERIFIED app — an operator
248
248
  // can only enumerate the roster of an app it itself authenticates to (never a self-asserted
@@ -252,7 +252,7 @@ export type RevokeKeyResult =
252
252
  export interface ListPrincipalsInput {
253
253
  /** Self-asserted caller app id; superseded by the credential's aud on a valid `px_token`. */
254
254
  app: string
255
- /** The propustka-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
255
+ /** The IAM-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
256
256
  credential: string | null
257
257
  requestId: string
258
258
  }
@@ -286,7 +286,7 @@ export interface IamRpc {
286
286
  listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>
287
287
  /**
288
288
  * Mint a short-lived, per-app permission token from the browser's SSO session — the
289
- * propustka-native auth path. The SDK middleware calls this only when its cached permission
289
+ * IAM-native auth path. The SDK middleware calls this only when its cached permission
290
290
  * token is missing/near-expiry (≈ once per TTL), NOT per request: every other request verifies
291
291
  * the cached token locally against `getJwks`.
292
292
  */
@@ -0,0 +1,105 @@
1
+ // What an application declares and calls to sign a person in on an enrolled terminal (ADR-0067): its identification
2
+ // page, and the identification operations a handler asks IAM for. IAM takes the asserting application from the
3
+ // verified transport, never from the input: over `/membership/*` the application's membership transport key pins it, and
4
+ // over a Workers binding the `props` the deployer wrote on the application's `IAM` binding pin it. The credential must
5
+ // also verify for that application, but its audience alone proves nothing.
6
+
7
+ import { isCanonicalPath } from './canonical-path'
8
+ import type { MembershipCaller } from './membership'
9
+
10
+ /** The terminal declaration of a contract: the page on the application's own origin that identifies a person. */
11
+ export interface TerminalArtifact {
12
+ readonly identify: string
13
+ }
14
+
15
+ /** The longest identification path a contract declares. */
16
+ export const MAX_TERMINAL_IDENTIFY_PATH_LENGTH = 200
17
+
18
+ /** The query parameter IAM appends to the identification page: the identification's id. */
19
+ export const IDENTIFICATION_QUERY_PARAMETER = 'identification'
20
+
21
+ /** The path prefix the platform owns on every application host. */
22
+ const PLATFORM_PATH = '/__fabrika'
23
+
24
+ /**
25
+ * Why `path` is not an identification page, or `null`: an absolute, canonical path on the application's own origin,
26
+ * with no query or fragment (IAM appends its own) and outside the platform's `/__fabrika`.
27
+ */
28
+ export function terminalIdentifyProblem(path: string): string | null {
29
+ if (path.length === 0 || path.length > MAX_TERMINAL_IDENTIFY_PATH_LENGTH) {
30
+ return `is 1 to ${MAX_TERMINAL_IDENTIFY_PATH_LENGTH} characters`
31
+ }
32
+ if (!path.startsWith('/') || path.startsWith('//')) {
33
+ return "is not an absolute path on the application's own origin (write it as '/identify')"
34
+ }
35
+ if (/[?#\s\p{Cc}]/u.test(path)) {
36
+ return 'carries a query, a fragment, whitespace or a control character; IAM appends the query itself'
37
+ }
38
+ if (!isCanonicalPath(path)) {
39
+ return 'is not a canonical path: no empty, `.` or `..` segment, no `\\` and no encoded separator'
40
+ }
41
+ if (path === PLATFORM_PATH || path.startsWith(`${PLATFORM_PATH}/`)) {
42
+ return `lies under ${PLATFORM_PATH}, which the platform owns`
43
+ }
44
+ return null
45
+ }
46
+
47
+ /** Every identification operation carries the caller's verified credential: a public procedure's workload token. */
48
+ export type TerminalCaller = MembershipCaller
49
+
50
+ /**
51
+ * Why IAM refused. `not_found` is an identification that is unknown, expired, consumed, cancelled, of another
52
+ * application, or whose terminal no longer lists the application: alike, so an id reveals nothing. `invalid_principal`
53
+ * is a principal that cannot sign in on a terminal: unknown, disabled, not a person, or external (ADR-0051).
54
+ */
55
+ export type TerminalFailure = {
56
+ ok: false
57
+ reason: 'missing_token' | 'invalid_token' | 'not_allowed' | 'not_found' | 'invalid_principal'
58
+ }
59
+
60
+ export type TerminalFailureReason = TerminalFailure['reason']
61
+
62
+ /** The terminal an identification was opened on, as the token's `terminal` claim names it. */
63
+ export interface IdentificationTerminal {
64
+ id: string
65
+ label: string
66
+ }
67
+
68
+ /** Read an open identification: the id is the `identification` query parameter of the identification page. */
69
+ export interface InspectIdentificationInput extends TerminalCaller {
70
+ id: string
71
+ }
72
+
73
+ /** `expiresAt` is unix seconds. The application keys its throttle of guesses on `terminal.id`. */
74
+ export type InspectIdentificationResult = { ok: true; terminal: IdentificationTerminal; expiresAt: number } | TerminalFailure
75
+
76
+ /**
77
+ * The application's word that `principalId` stands at the identification's terminal. IAM consumes the identification
78
+ * (single use), signs the person in under the terminal's ceiling, and answers the URL the browser goes to next: IAM's
79
+ * completion of the identification, which issues the handoff code only to the terminal's own browser. The application
80
+ * never holds a code.
81
+ */
82
+ export interface AssertIdentityInput extends TerminalCaller {
83
+ id: string
84
+ principalId: string
85
+ }
86
+
87
+ export type AssertIdentityResult = { ok: true; completionUrl: string } | TerminalFailure
88
+
89
+ /** End an identification the person abandoned. Repeating it, or cancelling a consumed one, answers `not_found`. */
90
+ export interface CancelIdentificationInput extends TerminalCaller {
91
+ id: string
92
+ }
93
+
94
+ export type CancelIdentificationResult = { ok: true } | TerminalFailure
95
+
96
+ /**
97
+ * The identification operations IAM serves an application: on the membership transport (`/membership/<method>`) and
98
+ * on its application entrypoint. A SEPARATE interface from `IamMembershipRpc`, so a transport that predates terminals
99
+ * still satisfies that one.
100
+ */
101
+ export interface IamTerminalRpc {
102
+ inspectIdentification(input: InspectIdentificationInput): Promise<InspectIdentificationResult>
103
+ assertIdentity(input: AssertIdentityInput): Promise<AssertIdentityResult>
104
+ cancelIdentification(input: CancelIdentificationInput): Promise<CancelIdentificationResult>
105
+ }
package/src/token.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  /**
2
- * The propustka-issued token contract — the SECOND thing (after `IamRpc`) that must not drift
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
- * propustka issues its OWN token it can embed the already-resolved permission set, and the SDK
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`);
@@ -47,7 +47,7 @@ export const FABRIKA_COOKIE_PREFIX = '__Host-px_'
47
47
  * because those origins are potentially trustworthy.
48
48
  */
49
49
  export const SESSION_COOKIE = `${FABRIKA_COOKIE_PREFIX}session`
50
- /** Prefix marking a propustka opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
50
+ /** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
51
51
  export const API_KEY_PREFIX = 'px_'
52
52
 
53
53
  /**
@@ -56,7 +56,7 @@ export const API_KEY_PREFIX = 'px_'
56
56
  */
57
57
  export const WORKLOAD_TOKEN_PATH = '/auth/workload/token'
58
58
 
59
- /** Signing algorithm propustka issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
59
+ /** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
60
60
  export const TOKEN_ALG = 'ES256'
61
61
  /** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
62
62
  export const RESOURCE_ACCESS_TOKEN_TYP = 'at+jwt'
@@ -70,22 +70,32 @@ export const DEFAULT_TOKEN_TTL_SECONDS = 300
70
70
  export const TOKEN_REFRESH_SKEW_SECONDS = 30
71
71
 
72
72
  /**
73
- * The largest access token IAM signs, in bytes (a JWT is ASCII). The proxy forwards it as one header,
74
- * and Bun's server, the application's runtime on Zerops, refuses a request whose headers exceed 16 KiB
75
- * in total; 8 KiB leaves the rest for the request's own headers and cookies. Caddy (1 MiB) and
76
- * Cloudflare (128 KiB) allow more.
73
+ * The largest access token IAM signs, in bytes (a JWT is ASCII), except an application token below. A client sends
74
+ * such a token itself (an OAuth access token, a console bearer), so it crosses Caddy's `forward_auth` into the proxy's
75
+ * auth service and reaches installation services, which run on Bun with its default: a request's headers at most
76
+ * 16 KiB in total. 8 KiB leaves the rest for the request's own headers and cookies.
77
77
  */
78
78
  export const MAX_ACCESS_TOKEN_BYTES = 8192
79
79
 
80
+ /**
81
+ * The largest token IAM mints for the proxy to inject toward a contract application, in bytes. No client sends it; on
82
+ * that hop it travels twice (`X-Fabrika-Token`, and `Authorization` on a bearer request), so two copies and 16 KiB of
83
+ * the request's own headers fit the header limit the platform starts the application's Bun with.
84
+ */
85
+ export const MAX_APPLICATION_TOKEN_BYTES = 24576
86
+
87
+ /** The request-header limit the platform starts an application's Bun server with (`--max-http-header-size`). */
88
+ export const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536
89
+
80
90
  // ── Claim shape (one, no discriminator) ────────────────────────────────────────
81
91
 
82
92
  /**
83
- * The propustka access token. `perms` is always present (matched via `permits`); `ptype` is present
93
+ * The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
84
94
  * only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
85
95
  * credential label otherwise (or null).
86
96
  */
87
97
  export interface AccessTokenClaims {
88
- /** Issuer — propustka's own origin (e.g. `https://propustka.example.com`). */
98
+ /** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
89
99
  iss: string
90
100
  /** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
91
101
  aud: string
@@ -117,12 +127,29 @@ export interface AccessTokenClaims {
117
127
  * key carries what the key's own grants narrow, so a check that resolves the person's permissions requires this.
118
128
  */
119
129
  session?: true
130
+ /**
131
+ * Present only on a session token of a person an application asserted at an enrolled terminal (ADR-0067), and
132
+ * always together with `terminal`.
133
+ */
134
+ amr?: TerminalAuthenticationMethod
135
+ /** The terminal the person is signed in on; present exactly when `amr` is. */
136
+ terminal?: TerminalTokenClaims
120
137
  /** Present only on an OAuth resource token (`aud` is then a resource URI, not an app id). */
121
138
  oauth?: OAuthTokenClaims
122
139
  /** Present only on a share-link token, which has no `ptype`: `sub` is then the link key's id. */
123
140
  link?: LinkTokenClaims
124
141
  }
125
142
 
143
+ /** The `amr` value of a session an application asserted at a terminal. */
144
+ export const TERMINAL_AUTHENTICATION_METHOD = 'terminal_assertion'
145
+ export type TerminalAuthenticationMethod = typeof TERMINAL_AUTHENTICATION_METHOD
146
+
147
+ /** The terminal a person's session was asserted on: its principal id and the label an administrator gave it. */
148
+ export interface TerminalTokenClaims {
149
+ id: string
150
+ label: string
151
+ }
152
+
126
153
  /** What a share-link token adds: the link mount that issued the key and the chain the key is bound to. */
127
154
  export interface LinkTokenClaims {
128
155
  mount: string
@@ -162,7 +189,7 @@ export type TokenAudienceProfile = { kind: 'app'; app: string } | { kind: 'resou
162
189
  //
163
190
  // Transport is the IAM service binding (`getJwks()` RPC), NOT a public HTTPS URL: app↔IAM is
164
191
  // RPC over the binding, which never traverses the Access edge — so the SDK reaches the key set
165
- // even while propustka's own hostname is still gated by Cloudflare Access. The Worker also
192
+ // even while IAM's own hostname is still gated by Cloudflare Access. The Worker also
166
193
  // serves the standard `/.well-known/jwks.json`, for when Access is gone. Both emit this shape.
167
194
 
168
195
  /** A published public signing key (EC P-256 / ES256). A jose-compatible JWK subset. */
@@ -184,7 +211,7 @@ export interface Jwks {
184
211
  // ── Build (Worker side, pre-sign) ──────────────────────────────────────────────
185
212
 
186
213
  export interface AccessTokenParams {
187
- /** Issuer (propustka origin). */
214
+ /** Issuer (IAM origin). */
188
215
  iss: string
189
216
  /** App id this token is for (becomes `aud`). */
190
217
  app: string
@@ -200,6 +227,8 @@ export interface AccessTokenParams {
200
227
  email?: string
201
228
  /** Minted from a signed-in session; refused on a token without `type` or of a workload. */
202
229
  session?: true
230
+ /** The terminal of a person's session asserted on one; sets `amr` too, and requires a user `type` and `session`. */
231
+ terminal?: TerminalTokenClaims
203
232
  permissions: PermissionEntry[]
204
233
  issuedAt: number
205
234
  expiresAt: number
@@ -284,6 +313,13 @@ export function buildAccessClaims(params: AccessTokenParams): AccessTokenClaims
284
313
  if (params.type === undefined || isWorkloadKind(params.type)) throw new Error("Only a person's or a service's token is minted from a session")
285
314
  claims.session = params.session
286
315
  }
316
+ if (params.terminal !== undefined) {
317
+ if (params.type !== 'user' || params.session !== true || !isTerminalClaims(params.terminal)) {
318
+ throw new Error("Only a person's session token names a terminal, and only by a non-empty id and label")
319
+ }
320
+ claims.amr = TERMINAL_AUTHENTICATION_METHOD
321
+ claims.terminal = { id: params.terminal.id, label: params.terminal.label }
322
+ }
287
323
  if (params.link !== undefined) {
288
324
  if (params.type !== undefined) throw new Error('A share-link token has no principal type')
289
325
  claims.link = { mount: params.link.mount, chain: params.link.chain.map((scope) => ({ type: scope.type, value: scope.value })) }
@@ -333,6 +369,10 @@ export function parseAccessClaims(payload: unknown): AccessTokenClaims | null {
333
369
  if (session !== undefined && (session !== true || ptype === null || isWorkloadKind(ptype) || oauth !== null)) {
334
370
  return null
335
371
  }
372
+ const terminal = parseTerminalClaims(prop(payload, 'amr'), prop(payload, 'terminal'))
373
+ if (terminal === undefined || (terminal !== null && (ptype !== 'user' || session !== true || oauth !== null))) {
374
+ return null
375
+ }
336
376
  const claims: AccessTokenClaims = { iss, aud, sub, iat, exp, perms, label }
337
377
  if (ptype !== null) {
338
378
  claims.ptype = ptype
@@ -346,6 +386,10 @@ export function parseAccessClaims(payload: unknown): AccessTokenClaims | null {
346
386
  if (session === true) {
347
387
  claims.session = true
348
388
  }
389
+ if (terminal !== null) {
390
+ claims.amr = TERMINAL_AUTHENTICATION_METHOD
391
+ claims.terminal = terminal
392
+ }
349
393
  if (oauth !== null) {
350
394
  claims.oauth = oauth
351
395
  }
@@ -379,6 +423,22 @@ function parseEmail(value: unknown, ptype: TokenPrincipalType | null): string |
379
423
  return ptype === 'user' && typeof value === 'string' && isNormalizedMailbox(value) ? value : undefined
380
424
  }
381
425
 
426
+ /** Both absent → null; `amr` naming the terminal method beside a well-formed `terminal` → it; anything else → undefined. */
427
+ function parseTerminalClaims(amr: unknown, value: unknown): TerminalTokenClaims | null | undefined {
428
+ if (amr === undefined && value === undefined) {
429
+ return null
430
+ }
431
+ if (amr !== TERMINAL_AUTHENTICATION_METHOD) {
432
+ return undefined
433
+ }
434
+ const terminal = { id: stringField(value, 'id'), label: stringField(value, 'label') }
435
+ return isTerminalClaims(terminal) ? { id: terminal.id, label: terminal.label } : undefined
436
+ }
437
+
438
+ function isTerminalClaims(value: { id: string | undefined; label: string | undefined }): value is TerminalTokenClaims {
439
+ return value.id !== undefined && value.id !== '' && value.label !== undefined && value.label !== ''
440
+ }
441
+
382
442
  /** Absent → null; a mount and a non-empty chain → the claims; anything else → undefined. */
383
443
  function parseLinkClaims(value: unknown): LinkTokenClaims | null | undefined {
384
444
  if (value === undefined) {
@@ -470,7 +530,7 @@ function parseScope(value: unknown): Scope | null | undefined {
470
530
 
471
531
  /** Validate `source` against the union — our own token, but read without `as`. */
472
532
  function parseSource(value: unknown): PermissionSource | null {
473
- if (value === 'grant' || value === 'bootstrap') {
533
+ if (value === 'grant' || value === 'bootstrap' || value === 'terminal') {
474
534
  return value
475
535
  }
476
536
  if (typeof value === 'string' && value.startsWith('group:')) {
package/src/types.ts CHANGED
@@ -31,8 +31,9 @@ export function isWorkloadKind(value: unknown): value is WorkloadKind {
31
31
  * - 'grant' — explicit `grants` row
32
32
  * - 'bootstrap' — IAM_BOOTSTRAP_ADMINS env match (resolution-time only)
33
33
  * - `group:${groupRef}` — IdP group → role mapping (the `<org>/<team>` ref)
34
+ * - 'terminal' — a grant of the terminal a person is signed in on (ADR-0067)
34
35
  */
35
- export type PermissionSource = 'grant' | 'bootstrap' | `group:${string}`
36
+ export type PermissionSource = 'grant' | 'bootstrap' | 'terminal' | `group:${string}`
36
37
 
37
38
  /**
38
39
  * A flat, app-owned scope coordinate — one dimension (`type`) and an opaque value.
@@ -146,7 +147,7 @@ export interface AppDelegationDef {
146
147
  purpose: 'members' | 'creates'
147
148
  }
148
149
 
149
- /** An app's full authz vocabulary, declared in the app's code, reconciled into Propustka. */
150
+ /** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
150
151
  export interface AppSchema {
151
152
  scopes: AppScopeDef[]
152
153
  actions: AppActionDef[]
@@ -177,6 +178,8 @@ export interface AppSchema {
177
178
  members?: { manage: string; list: string }
178
179
  /** `labels`: a holder of the app's `members.list` also sees each member's label. Absent, labels stay with `members.manage`. */
179
180
  directory?: 'labels'
181
+ /** The app's identification page for a person at an enrolled terminal (ADR-0067); absent, no terminal lists it. */
182
+ terminal?: { identify: string }
180
183
  }
181
184
 
182
185
  /**
package/src/wire.ts CHANGED
@@ -63,6 +63,12 @@ export function proxySecretVariable(id: string): string {
63
63
  return `${FABRIKA_PROXY_SECRET}_${sha256Hex(id).slice(0, 32).toUpperCase()}`
64
64
  }
65
65
 
66
+ /**
67
+ * The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
68
+ * and IAM hold it under this one name. It proves only who wrote IAM's client-address and request-id headers.
69
+ */
70
+ export const IAM_PROXY_SECRET_VARIABLE = 'FABRIKA_INSTALLATION_PROXY_SECRET_IAM'
71
+
66
72
  /**
67
73
  * Every `X-Fabrika-*` name a proxy hop carries to an application. Caddy's first step and the Cloudflare proxy Worker
68
74
  * delete each of them from the client's request before anything else, then set only what the decision asserts. A new
@@ -0,0 +1,24 @@
1
+ /**
2
+ * The IAM application id of one environment of an application: `<app>@<env>`, for example `notes@prod`
3
+ * ([ADR-0022](../../../docs/decisions/0022-the-proxy-is-the-only-enforcement-point.md) rule 6). Schemas,
4
+ * roles, grants, keys and return origins are registered under it, so a staging key is refused at production.
5
+ * The installation's own services keep a plain id without `@` — the platform audiences IAM registers.
6
+ */
7
+ /**
8
+ * The one name the IAM application id travels under, from the control plane to the application that
9
+ * verifies a token's `aud` against it. Platform-owned like `FABRIKA_IAM_ISSUER`: every deploy writes it,
10
+ * and an application that declares it for itself is refused.
11
+ */
12
+ export declare const FABRIKA_IAM_APP_ID = "FABRIKA_IAM_APP_ID";
13
+ /** Separates the application from the environment. Reserved: neither part may contain it. */
14
+ export declare const APP_ENVIRONMENT_SEPARATOR = "@";
15
+ export interface AppEnvironment {
16
+ readonly app: string;
17
+ readonly env: string;
18
+ }
19
+ /** True when `value` can be one part of an application id: non-empty and without the separator. */
20
+ export declare function isAppEnvironmentPart(value: string): boolean;
21
+ /** Build `<app>@<env>`. Throws when either part is empty or contains `@`, because the id would not parse back. */
22
+ export declare function appEnvironmentId(app: string, env: string): string;
23
+ /** The parts of `<app>@<env>`, or null for any other string — a platform audience or a malformed id. */
24
+ export declare function parseAppEnvironmentId(id: string): AppEnvironment | null;
@@ -0,0 +1,20 @@
1
+ /** A request target split into its raw pathname and its query (with the leading `?`, or empty). */
2
+ export interface RequestTarget {
3
+ readonly pathname: string;
4
+ readonly search: string;
5
+ }
6
+ /**
7
+ * A raw pathname is canonical when it starts with `/` and has no empty segment, no `.` or `..` (also
8
+ * encoded), no encoded `/` or `\`, no literal `\` and no malformed percent escape. Each refused form is one
9
+ * some hop rewrites or rejects, so the gate matcher and the application would otherwise read different
10
+ * paths. A trailing `/` is allowed and significant: every matcher compares it literally, so `/a/` and `/a`
11
+ * are different paths.
12
+ */
13
+ export declare function isCanonicalPath(pathname: string): boolean;
14
+ /** Split an origin-form request target (`/path?query`) at its first `?`. */
15
+ export declare function splitRequestTarget(target: string): RequestTarget;
16
+ /**
17
+ * The path and query of an absolute URL string exactly as written, without the fragment. Read it from
18
+ * the string because `new URL()` resolves dot segments and so hides the very paths that must be refused.
19
+ */
20
+ export declare function rawRequestTarget(url: string): RequestTarget;
@@ -0,0 +1,19 @@
1
+ import type { BodyAdmission, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
2
+ /**
3
+ * The artifact with every array whose order carries no meaning sorted: endpoints by id, and every list of names.
4
+ * Tuple items and union options keep their order, because it changes what a schema admits. Object keys are left
5
+ * as they are; `canonicalArtifactJson` sorts them.
6
+ */
7
+ export declare function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifact;
8
+ /** The canonical artifact as JSON with every object's keys sorted: the bytes a digest of the artifact is taken over. */
9
+ export declare function canonicalArtifactJson(artifact: ContractArtifact): string;
10
+ /** JSON with every object's keys sorted. Arrays keep their order; canonicalize them first. */
11
+ export declare function canonicalJson(value: unknown): string;
12
+ /** Each action of one table operation, `[]` for none: how a reader of the artifact reads `actions.read` and the others. */
13
+ export declare function tableActions(actions: TableActionArtifact | null): readonly string[];
14
+ /** A body admission with its content types sorted. */
15
+ export declare function canonicalAdmission(admission: BodyAdmission): BodyAdmission;
16
+ /** An output shape: an attachment keeps its column order, which is the file's; each column's shape is canonical. */
17
+ export declare function canonicalOutput(shape: OutputShape): OutputShape;
18
+ /** A schema shape with its enum values sorted; tuple items and union options keep their order. */
19
+ export declare function canonicalShape(shape: SchemaShape): SchemaShape;