@fabrika/auth-core 0.9.0-dev.4 → 0.9.0-dev.40
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/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 +212 -12
- package/src/dev-environment.ts +6 -0
- package/src/egress.ts +97 -0
- package/src/endpoint-digest.ts +22 -2
- package/src/framework-release.ts +72 -0
- package/src/framework-variables.ts +23 -0
- package/src/iam-mail.ts +354 -0
- package/src/index.ts +10 -0
- package/src/locale.ts +13 -1
- package/src/managed-environment.ts +147 -0
- package/src/membership.ts +12 -4
- package/src/oauth.ts +11 -0
- package/src/ops.ts +1933 -0
- package/src/permissions.ts +42 -0
- package/src/public-egress.ts +168 -0
- package/src/requirement.ts +5 -2
- package/src/rpc.ts +8 -8
- package/src/scope-values.ts +123 -0
- package/src/sha256.ts +52 -14
- package/src/terminal.ts +105 -0
- package/src/token.ts +170 -19
- package/src/types.ts +68 -2
- package/src/wire.ts +7 -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 +197 -11
- package/types/src/dev-environment.d.ts +5 -0
- package/types/src/egress.d.ts +27 -0
- package/types/src/endpoint-digest.d.ts +5 -0
- package/types/src/framework-release.d.ts +25 -0
- package/types/src/framework-variables.d.ts +12 -1
- package/types/src/iam-mail.d.ts +92 -0
- package/types/src/index.d.ts +10 -0
- package/types/src/locale.d.ts +11 -1
- package/types/src/managed-environment.d.ts +32 -0
- package/types/src/membership.d.ts +8 -3
- package/types/src/oauth.d.ts +7 -0
- package/types/src/ops.d.ts +657 -0
- package/types/src/permissions.d.ts +12 -0
- package/types/src/public-egress.d.ts +31 -0
- package/types/src/requirement.d.ts +2 -2
- package/types/src/rpc.d.ts +5 -5
- package/types/src/scope-values.d.ts +61 -0
- package/types/src/sha256.d.ts +10 -0
- package/types/src/terminal.d.ts +72 -0
- package/types/src/token.d.ts +69 -12
- package/types/src/types.d.ts +47 -2
- package/types/src/wire.d.ts +6 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { KeyGrant } from './rpc';
|
|
1
2
|
import type { PermissionEntry, Scope } from './types';
|
|
2
3
|
/**
|
|
3
4
|
* Wildcard action matching. The pattern is one of:
|
|
@@ -16,6 +17,11 @@ import type { PermissionEntry, Scope } from './types';
|
|
|
16
17
|
* matchAction('project.*', 'projects.read') === false
|
|
17
18
|
*/
|
|
18
19
|
export declare function matchAction(pattern: string, action: string): boolean;
|
|
20
|
+
/**
|
|
21
|
+
* `entries` with each identical action, scope and source once, the first kept in order: how IAM resolves a principal's
|
|
22
|
+
* permissions, so two roles granting one action at one scope put one entry into the token.
|
|
23
|
+
*/
|
|
24
|
+
export declare function uniquePermissions(entries: readonly PermissionEntry[]): PermissionEntry[];
|
|
19
25
|
/**
|
|
20
26
|
* Does `entries` grant `action` at the given scope? Mirrors `can()` semantics exactly:
|
|
21
27
|
* - scope === undefined → scope-less: ONLY entries with scope === null satisfy (global perms only).
|
|
@@ -48,3 +54,9 @@ export declare function scopedValues(entries: PermissionEntry[], action: string,
|
|
|
48
54
|
* - otherwise → invalid.
|
|
49
55
|
*/
|
|
50
56
|
export declare function isActionAllowed(pattern: string, catalog: readonly string[]): boolean;
|
|
57
|
+
/**
|
|
58
|
+
* Intersect live permissions with a ceiling: an OAuth scope's grants, or a terminal's patterns for an application. The
|
|
59
|
+
* ceiling never adds anything: each result is the narrower action and the narrower scope of one held entry and one
|
|
60
|
+
* ceiling entry that overlap, so a held `*` under a ceiling `a.read` yields `a.read`.
|
|
61
|
+
*/
|
|
62
|
+
export declare function narrowPermissions(live: readonly PermissionEntry[], ceiling: readonly KeyGrant[]): PermissionEntry[];
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** The declared form of public egress: every public host, over HTTPS or HTTP, on its default port. */
|
|
2
|
+
export declare const PUBLIC_EGRESS = "public";
|
|
3
|
+
export type PublicEgress = typeof PUBLIC_EGRESS;
|
|
4
|
+
/** What a site declares in `egress`: its exact HTTPS origins, sorted, or every public host (a cron job only). */
|
|
5
|
+
export type DeclaredEgress = readonly string[] | PublicEgress;
|
|
6
|
+
/**
|
|
7
|
+
* The name suffixes public egress refuses, each with every name under it: local and special-use names (RFC 6761,
|
|
8
|
+
* RFC 6762, RFC 8375, RFC 9476), the names private networks conventionally use (`.internal` holds Google's metadata
|
|
9
|
+
* host and Control's own `operations.internal`), and the platform subdomains an installation is served on beside its
|
|
10
|
+
* own domains: Cloudflare's `workers.dev`, where its Workers have their default routes, and Zerops' `zerops.app`, where
|
|
11
|
+
* its proxies, Control and IAM have their subdomains (a namespace proxy's `proxy-…-8080.<region>.zerops.app`), with the
|
|
12
|
+
* `zerops` suffix of a Zerops project's private network. Control knows no list of those subdomains, so every one is
|
|
13
|
+
* refused, another installation's too.
|
|
14
|
+
*/
|
|
15
|
+
export declare const PUBLIC_EGRESS_REFUSED_SUFFIXES: readonly ["localhost", "local", "internal", "intranet", "lan", "home", "corp", "private", "arpa", "test", "invalid", "example", "onion", "alt", "zerops", "zerops.app", "workers.dev"];
|
|
16
|
+
/** A host name without its trailing dots, lowercased: the form every comparison here uses. */
|
|
17
|
+
export declare function normalizedHost(hostname: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* Why public egress refuses `url`, or `null` when the URL alone admits it: a scheme other than `https:` and `http:`, a
|
|
20
|
+
* port other than the scheme's default, credentials in the URL, an IP literal, a name of one label, a name under a
|
|
21
|
+
* refused suffix, or one of `refusedHosts` (normalized names). A host it admits may still resolve to a private address,
|
|
22
|
+
* which only a runtime that resolves names refuses.
|
|
23
|
+
*/
|
|
24
|
+
export declare function publicEgressRefusal(url: URL, refusedHosts?: ReadonlySet<string>): string | null;
|
|
25
|
+
/**
|
|
26
|
+
* Whether `address` (an IPv4 or IPv6 address, as a resolver answers it) is a public unicast address: not private,
|
|
27
|
+
* loopback, link-local (which holds the cloud metadata address 169.254.169.254), shared, multicast, reserved,
|
|
28
|
+
* documentation, or an IPv6 form that embeds or tunnels an IPv4 address it cannot vouch for. A text that is no address
|
|
29
|
+
* is not public.
|
|
30
|
+
*/
|
|
31
|
+
export declare function isPublicAddress(address: string): boolean;
|
|
@@ -6,8 +6,8 @@ import type { PermissionEntry } from './types';
|
|
|
6
6
|
* Whether a token's permissions meet an endpoint's requirement. This is authorization, not a gate: it reads only the
|
|
7
7
|
* token. `member` is any permission of this application; an action is that action in some scope, global included.
|
|
8
8
|
* The access form narrows it to one scope afterwards, against the application's own data. The `app` form is the
|
|
9
|
-
* action held as a global grant, so an entry scoped to any value does not meet it
|
|
10
|
-
* one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
9
|
+
* action held as a global grant, so an entry scoped to any value does not meet it; `anyOf` is one of its actions held so.
|
|
10
|
+
* Several capabilities need every one of their actions. `authenticated`, which only an installation row carries, needs no permission.
|
|
11
11
|
*/
|
|
12
12
|
export declare function satisfies(requirement: EndpointRequirement | AuthenticatedRequirement, perms: readonly PermissionEntry[]): boolean;
|
|
13
13
|
/**
|
package/types/src/rpc.d.ts
CHANGED
|
@@ -110,8 +110,8 @@ export interface IssueKeyServiceSpec {
|
|
|
110
110
|
export interface IssueKeyInput {
|
|
111
111
|
app: string;
|
|
112
112
|
/**
|
|
113
|
-
* The
|
|
114
|
-
* a `px_token` access JWT (verified against
|
|
113
|
+
* The IAM-native credential the ISSUER is resolved from server-side (never self-asserted):
|
|
114
|
+
* a `px_token` access JWT (verified against IAM's signing keys) or a `px_` key. Null = absent.
|
|
115
115
|
*/
|
|
116
116
|
credential: string | null;
|
|
117
117
|
requestId: string;
|
|
@@ -185,7 +185,7 @@ export interface AuditInput {
|
|
|
185
185
|
}
|
|
186
186
|
export interface RevokeKeyInput {
|
|
187
187
|
app: string;
|
|
188
|
-
/** The
|
|
188
|
+
/** The IAM-native credential the CALLER (authorizer) is resolved from; null = absent. */
|
|
189
189
|
credential: string | null;
|
|
190
190
|
requestId: string;
|
|
191
191
|
/** The credential id (the `id` returned by `issueKey`), NOT the plaintext `px_` token. */
|
|
@@ -203,7 +203,7 @@ export type RevokeKeyResult =
|
|
|
203
203
|
export interface ListPrincipalsInput {
|
|
204
204
|
/** Self-asserted caller app id; superseded by the credential's aud on a valid `px_token`. */
|
|
205
205
|
app: string;
|
|
206
|
-
/** The
|
|
206
|
+
/** The IAM-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
|
|
207
207
|
credential: string | null;
|
|
208
208
|
requestId: string;
|
|
209
209
|
}
|
|
@@ -239,7 +239,7 @@ export interface IamRpc {
|
|
|
239
239
|
listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>;
|
|
240
240
|
/**
|
|
241
241
|
* Mint a short-lived, per-app permission token from the browser's SSO session — the
|
|
242
|
-
*
|
|
242
|
+
* IAM-native auth path. The SDK middleware calls this only when its cached permission
|
|
243
243
|
* token is missing/near-expiry (≈ once per TTL), NOT per request: every other request verifies
|
|
244
244
|
* the cached token locally against `getJwks`.
|
|
245
245
|
*/
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { OutputShape, SchemaShape } from './contract';
|
|
2
|
+
/** One value a dimension lists, with the text the console shows beside it. */
|
|
3
|
+
export interface DimensionValue {
|
|
4
|
+
readonly value: string;
|
|
5
|
+
readonly label?: string;
|
|
6
|
+
}
|
|
7
|
+
/** The most values a dimension lists. */
|
|
8
|
+
export declare const MAX_DIMENSION_VALUES = 500;
|
|
9
|
+
/** The longest label of a listed value. */
|
|
10
|
+
export declare const MAX_DIMENSION_VALUE_LABEL_LENGTH = 120;
|
|
11
|
+
/**
|
|
12
|
+
* Why `values` is not a dimension's list, or `null`: at least one and at most `MAX_DIMENSION_VALUES` values, each a
|
|
13
|
+
* non-empty value no longer than a scope value IAM takes, listed once, with a non-empty label when it has one.
|
|
14
|
+
*/
|
|
15
|
+
export declare function dimensionValuesProblem(values: readonly DimensionValue[]): string | null;
|
|
16
|
+
/**
|
|
17
|
+
* Where IAM asks the application for a dimension's values (ADR-0085 §4): the procedure's endpoint id, its path on the
|
|
18
|
+
* application's origin and the action its requirement names. IAM calls it as the administrator, through the proxy.
|
|
19
|
+
*/
|
|
20
|
+
export interface DimensionValueSource {
|
|
21
|
+
readonly endpoint: string;
|
|
22
|
+
readonly path: string;
|
|
23
|
+
readonly action: string;
|
|
24
|
+
}
|
|
25
|
+
/** How long IAM waits for a value source's whole answer before the console falls back. */
|
|
26
|
+
export declare const SCOPE_VALUE_SOURCE_TIMEOUT_MS = 3000;
|
|
27
|
+
/** The largest answer IAM reads from a value source. */
|
|
28
|
+
export declare const MAX_SCOPE_VALUE_SOURCE_BYTES: number;
|
|
29
|
+
/** The row of a value-source procedure, as far as its rule reads it. */
|
|
30
|
+
interface ValueSourceRow {
|
|
31
|
+
readonly id: string;
|
|
32
|
+
readonly kind: string;
|
|
33
|
+
readonly method: string;
|
|
34
|
+
readonly callers: readonly string[];
|
|
35
|
+
readonly requirement: {
|
|
36
|
+
readonly kind: string;
|
|
37
|
+
readonly action?: string;
|
|
38
|
+
readonly access?: {
|
|
39
|
+
readonly form: string;
|
|
40
|
+
readonly dimension?: string;
|
|
41
|
+
};
|
|
42
|
+
} | null;
|
|
43
|
+
readonly input: SchemaShape | null;
|
|
44
|
+
readonly output: OutputShape | null;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Why `row` cannot be `dimension`'s value source, or null: a person's `POST` query without input, requiring an action
|
|
48
|
+
* `over` that dimension other than its `members.manage` (`managedBy`), whose output is
|
|
49
|
+
* `{ values: [{ value: string, label?: string }] }`. The proxy decides the call from the row like any other; the
|
|
50
|
+
* requirement's action is what IAM's key for the call carries, and a row of `members.manage` would carry a membership
|
|
51
|
+
* delegation into a call the administrator only reads with.
|
|
52
|
+
*/
|
|
53
|
+
export declare function valueSourceProblem(row: ValueSourceRow, dimension: string, managedBy: string | null): string | null;
|
|
54
|
+
/** The output shape `{ values: [{ value: string, label?: string }] }`, strings with any checks. */
|
|
55
|
+
export declare function isDimensionValuesShape(shape: OutputShape): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* The values a source answered, or null when the answer is not `{ values }` of at most `MAX_DIMENSION_VALUES` values
|
|
58
|
+
* `dimensionValuesProblem` admits. An answer is the application's word: the console shows it, IAM decides nothing by it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function parseDimensionValues(result: unknown): DimensionValue[] | null;
|
|
61
|
+
export {};
|
package/types/src/sha256.d.ts
CHANGED
|
@@ -1,2 +1,12 @@
|
|
|
1
1
|
/** The SHA-256 of `text`'s UTF-8 bytes, as 64 lower-case hex digits. */
|
|
2
2
|
export declare function sha256Hex(text: string): string;
|
|
3
|
+
/**
|
|
4
|
+
* SHA-256 over text fed in pieces, so a digest of a large serialization never needs the whole text in memory. Each
|
|
5
|
+
* piece is whole text: a surrogate pair split across two pieces encodes as two replacement characters.
|
|
6
|
+
*/
|
|
7
|
+
export declare class Sha256 {
|
|
8
|
+
#private;
|
|
9
|
+
update(text: string): this;
|
|
10
|
+
/** The digest of everything fed so far; the hash takes no piece after it. */
|
|
11
|
+
hex(): string;
|
|
12
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import type { MembershipCaller } from './membership';
|
|
2
|
+
/** The terminal declaration of a contract: the page on the application's own origin that identifies a person. */
|
|
3
|
+
export interface TerminalArtifact {
|
|
4
|
+
readonly identify: string;
|
|
5
|
+
}
|
|
6
|
+
/** The longest identification path a contract declares. */
|
|
7
|
+
export declare const MAX_TERMINAL_IDENTIFY_PATH_LENGTH = 200;
|
|
8
|
+
/** The query parameter IAM appends to the identification page: the identification's id. */
|
|
9
|
+
export declare const IDENTIFICATION_QUERY_PARAMETER = "identification";
|
|
10
|
+
/**
|
|
11
|
+
* Why `path` is not an identification page, or `null`: an absolute, canonical path on the application's own origin,
|
|
12
|
+
* with no query or fragment (IAM appends its own) and outside the platform's `/__fabrika`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function terminalIdentifyProblem(path: string): string | null;
|
|
15
|
+
/** Every identification operation carries the caller's verified credential: a public procedure's workload token. */
|
|
16
|
+
export type TerminalCaller = MembershipCaller;
|
|
17
|
+
/**
|
|
18
|
+
* Why IAM refused. `not_found` is an identification that is unknown, expired, consumed, cancelled, of another
|
|
19
|
+
* application, or whose terminal no longer lists the application: alike, so an id reveals nothing. `invalid_principal`
|
|
20
|
+
* is a principal that cannot sign in on a terminal: unknown, disabled, not a person, or external (ADR-0051).
|
|
21
|
+
*/
|
|
22
|
+
export type TerminalFailure = {
|
|
23
|
+
ok: false;
|
|
24
|
+
reason: 'missing_token' | 'invalid_token' | 'not_allowed' | 'not_found' | 'invalid_principal';
|
|
25
|
+
};
|
|
26
|
+
export type TerminalFailureReason = TerminalFailure['reason'];
|
|
27
|
+
/** The terminal an identification was opened on, as the token's `terminal` claim names it. */
|
|
28
|
+
export interface IdentificationTerminal {
|
|
29
|
+
id: string;
|
|
30
|
+
label: string;
|
|
31
|
+
}
|
|
32
|
+
/** Read an open identification: the id is the `identification` query parameter of the identification page. */
|
|
33
|
+
export interface InspectIdentificationInput extends TerminalCaller {
|
|
34
|
+
id: string;
|
|
35
|
+
}
|
|
36
|
+
/** `expiresAt` is unix seconds. The application keys its throttle of guesses on `terminal.id`. */
|
|
37
|
+
export type InspectIdentificationResult = {
|
|
38
|
+
ok: true;
|
|
39
|
+
terminal: IdentificationTerminal;
|
|
40
|
+
expiresAt: number;
|
|
41
|
+
} | TerminalFailure;
|
|
42
|
+
/**
|
|
43
|
+
* The application's word that `principalId` stands at the identification's terminal. IAM consumes the identification
|
|
44
|
+
* (single use), signs the person in under the terminal's ceiling, and answers the URL the browser goes to next: IAM's
|
|
45
|
+
* completion of the identification, which issues the handoff code only to the terminal's own browser. The application
|
|
46
|
+
* never holds a code.
|
|
47
|
+
*/
|
|
48
|
+
export interface AssertIdentityInput extends TerminalCaller {
|
|
49
|
+
id: string;
|
|
50
|
+
principalId: string;
|
|
51
|
+
}
|
|
52
|
+
export type AssertIdentityResult = {
|
|
53
|
+
ok: true;
|
|
54
|
+
completionUrl: string;
|
|
55
|
+
} | TerminalFailure;
|
|
56
|
+
/** End an identification the person abandoned. Repeating it, or cancelling a consumed one, answers `not_found`. */
|
|
57
|
+
export interface CancelIdentificationInput extends TerminalCaller {
|
|
58
|
+
id: string;
|
|
59
|
+
}
|
|
60
|
+
export type CancelIdentificationResult = {
|
|
61
|
+
ok: true;
|
|
62
|
+
} | TerminalFailure;
|
|
63
|
+
/**
|
|
64
|
+
* The identification operations IAM serves an application: on the membership transport (`/membership/<method>`) and
|
|
65
|
+
* on its application entrypoint. A SEPARATE interface from `IamMembershipRpc`, so a transport that predates terminals
|
|
66
|
+
* still satisfies that one.
|
|
67
|
+
*/
|
|
68
|
+
export interface IamTerminalRpc {
|
|
69
|
+
inspectIdentification(input: InspectIdentificationInput): Promise<InspectIdentificationResult>;
|
|
70
|
+
assertIdentity(input: AssertIdentityInput): Promise<AssertIdentityResult>;
|
|
71
|
+
cancelIdentification(input: CancelIdentificationInput): Promise<CancelIdentificationResult>;
|
|
72
|
+
}
|
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`);
|
|
@@ -38,14 +38,14 @@ export declare const FABRIKA_COOKIE_PREFIX = "__Host-px_";
|
|
|
38
38
|
* because those origins are potentially trustworthy.
|
|
39
39
|
*/
|
|
40
40
|
export declare const SESSION_COOKIE = "__Host-px_session";
|
|
41
|
-
/** Prefix marking
|
|
41
|
+
/** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
|
|
42
42
|
export declare const API_KEY_PREFIX = "px_";
|
|
43
43
|
/**
|
|
44
44
|
* 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
45
|
* as the bearer and `{ app }` as the body. IAM answers `MintFromKeyResult`, and only for a workload key of that app.
|
|
46
46
|
*/
|
|
47
47
|
export declare const WORKLOAD_TOKEN_PATH = "/auth/workload/token";
|
|
48
|
-
/** Signing algorithm
|
|
48
|
+
/** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
|
|
49
49
|
export declare const TOKEN_ALG = "ES256";
|
|
50
50
|
/** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
|
|
51
51
|
export declare const RESOURCE_ACCESS_TOKEN_TYP = "at+jwt";
|
|
@@ -57,19 +57,27 @@ export declare const DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
|
57
57
|
*/
|
|
58
58
|
export declare const TOKEN_REFRESH_SKEW_SECONDS = 30;
|
|
59
59
|
/**
|
|
60
|
-
* The largest access token IAM signs, in bytes (a JWT is ASCII)
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
60
|
+
* The largest access token IAM signs, in bytes (a JWT is ASCII), except an application token below. A client sends
|
|
61
|
+
* such a token itself (an OAuth access token, a console bearer), so it crosses Caddy's `forward_auth` into the proxy's
|
|
62
|
+
* auth service and reaches installation services, which run on Bun with its default: a request's headers at most
|
|
63
|
+
* 16 KiB in total. 8 KiB leaves the rest for the request's own headers and cookies.
|
|
64
64
|
*/
|
|
65
65
|
export declare const MAX_ACCESS_TOKEN_BYTES = 8192;
|
|
66
66
|
/**
|
|
67
|
-
* The
|
|
67
|
+
* The largest token IAM mints for the proxy to inject toward a contract application, in bytes. No client sends it; on
|
|
68
|
+
* that hop it travels twice (`X-Fabrika-Token`, and `Authorization` on a bearer request), so two copies and 16 KiB of
|
|
69
|
+
* the request's own headers fit the header limit the platform starts the application's Bun with.
|
|
70
|
+
*/
|
|
71
|
+
export declare const MAX_APPLICATION_TOKEN_BYTES = 24576;
|
|
72
|
+
/** The request-header limit the platform starts an application's Bun server with (`--max-http-header-size`). */
|
|
73
|
+
export declare const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536;
|
|
74
|
+
/**
|
|
75
|
+
* The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
|
|
68
76
|
* only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
|
|
69
77
|
* credential label otherwise (or null).
|
|
70
78
|
*/
|
|
71
79
|
export interface AccessTokenClaims {
|
|
72
|
-
/** Issuer —
|
|
80
|
+
/** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
|
|
73
81
|
iss: string;
|
|
74
82
|
/** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
|
|
75
83
|
aud: string;
|
|
@@ -79,7 +87,10 @@ export interface AccessTokenClaims {
|
|
|
79
87
|
iat: number;
|
|
80
88
|
/** Expiry (unix seconds). */
|
|
81
89
|
exp: number;
|
|
82
|
-
/**
|
|
90
|
+
/**
|
|
91
|
+
* Resolved/effective permissions; `can(action, scope?)` = `permits(perms, action, scope)`. On the wire a compact token
|
|
92
|
+
* carries its global grants in `gperms` (`AccessTokenPayload`); the parser reads them back into this list.
|
|
93
|
+
*/
|
|
83
94
|
perms: PermissionEntry[];
|
|
84
95
|
/** Present only when the token is bound to a principal (`sub` is that principal). */
|
|
85
96
|
ptype?: TokenPrincipalType;
|
|
@@ -101,11 +112,26 @@ export interface AccessTokenClaims {
|
|
|
101
112
|
* key carries what the key's own grants narrow, so a check that resolves the person's permissions requires this.
|
|
102
113
|
*/
|
|
103
114
|
session?: true;
|
|
115
|
+
/**
|
|
116
|
+
* Present only on a session token of a person an application asserted at an enrolled terminal (ADR-0067), and
|
|
117
|
+
* always together with `terminal`.
|
|
118
|
+
*/
|
|
119
|
+
amr?: TerminalAuthenticationMethod;
|
|
120
|
+
/** The terminal the person is signed in on; present exactly when `amr` is. */
|
|
121
|
+
terminal?: TerminalTokenClaims;
|
|
104
122
|
/** Present only on an OAuth resource token (`aud` is then a resource URI, not an app id). */
|
|
105
123
|
oauth?: OAuthTokenClaims;
|
|
106
124
|
/** Present only on a share-link token, which has no `ptype`: `sub` is then the link key's id. */
|
|
107
125
|
link?: LinkTokenClaims;
|
|
108
126
|
}
|
|
127
|
+
/** The `amr` value of a session an application asserted at a terminal. */
|
|
128
|
+
export declare const TERMINAL_AUTHENTICATION_METHOD = "terminal_assertion";
|
|
129
|
+
export type TerminalAuthenticationMethod = typeof TERMINAL_AUTHENTICATION_METHOD;
|
|
130
|
+
/** The terminal a person's session was asserted on: its principal id and the label an administrator gave it. */
|
|
131
|
+
export interface TerminalTokenClaims {
|
|
132
|
+
id: string;
|
|
133
|
+
label: string;
|
|
134
|
+
}
|
|
109
135
|
/** What a share-link token adds: the link mount that issued the key and the chain the key is bound to. */
|
|
110
136
|
export interface LinkTokenClaims {
|
|
111
137
|
mount: string;
|
|
@@ -130,6 +156,11 @@ export interface OAuthTokenClaims {
|
|
|
130
156
|
grantId: string;
|
|
131
157
|
/** Unique token id, fresh on every mint. */
|
|
132
158
|
tokenId: string;
|
|
159
|
+
/**
|
|
160
|
+
* The keys of the roles the person holds at an external application that declares roles; absent on every other
|
|
161
|
+
* token. The application decides what each role allows; IAM grants it and names it here.
|
|
162
|
+
*/
|
|
163
|
+
roles?: string[];
|
|
133
164
|
}
|
|
134
165
|
/** Which tokens a verifier accepts: native app tokens, or OAuth tokens minted for one resource of one app. */
|
|
135
166
|
export type TokenAudienceProfile = {
|
|
@@ -155,7 +186,7 @@ export interface Jwks {
|
|
|
155
186
|
keys: PublicJwk[];
|
|
156
187
|
}
|
|
157
188
|
export interface AccessTokenParams {
|
|
158
|
-
/** Issuer (
|
|
189
|
+
/** Issuer (IAM origin). */
|
|
159
190
|
iss: string;
|
|
160
191
|
/** App id this token is for (becomes `aud`). */
|
|
161
192
|
app: string;
|
|
@@ -171,6 +202,8 @@ export interface AccessTokenParams {
|
|
|
171
202
|
email?: string;
|
|
172
203
|
/** Minted from a signed-in session; refused on a token without `type` or of a workload. */
|
|
173
204
|
session?: true;
|
|
205
|
+
/** The terminal of a person's session asserted on one; sets `amr` too, and requires a user `type` and `session`. */
|
|
206
|
+
terminal?: TerminalTokenClaims;
|
|
174
207
|
permissions: PermissionEntry[];
|
|
175
208
|
issuedAt: number;
|
|
176
209
|
expiresAt: number;
|
|
@@ -190,6 +223,10 @@ export interface ResourceAccessTokenParams {
|
|
|
190
223
|
scopes: string[];
|
|
191
224
|
grantId: string;
|
|
192
225
|
tokenId: string;
|
|
226
|
+
/** The person's normalized mailbox; an identity resource's token carries it. */
|
|
227
|
+
email?: string;
|
|
228
|
+
/** The roles the person holds at an external application that declares roles (`OAuthTokenClaims.roles`). */
|
|
229
|
+
roles?: string[];
|
|
193
230
|
}
|
|
194
231
|
/**
|
|
195
232
|
* Assemble an OAuth resource access token. Always a user principal. The wire carries the standard
|
|
@@ -199,6 +236,26 @@ export interface ResourceAccessTokenParams {
|
|
|
199
236
|
export declare function buildResourceAccessClaims(params: ResourceAccessTokenParams): Record<string, unknown>;
|
|
200
237
|
/** A token is accepted only by the profile it was minted for: an app token never passes as a resource token, and vice versa. */
|
|
201
238
|
export declare function matchesTokenAudience(claims: AccessTokenClaims, profile: TokenAudienceProfile): boolean;
|
|
239
|
+
/**
|
|
240
|
+
* How an access token's claims travel. `entries` writes every permission into `perms`. `compact` writes each global
|
|
241
|
+
* grant (scope null, source `grant`) into `gperms` as its bare action name and the rest into `perms`; it is a third of
|
|
242
|
+
* the size for a person holding a few hundred actions. `parseAccessClaims` reads both into the same `perms`.
|
|
243
|
+
*/
|
|
244
|
+
export type AccessTokenLayout = 'entries' | 'compact';
|
|
245
|
+
/** The signed payload: the claims, with the global grants of the compact layout in `gperms`. */
|
|
246
|
+
export interface AccessTokenPayload extends AccessTokenClaims {
|
|
247
|
+
/** The compact layout's global grants, by action name; absent in the entries layout and when there are none. */
|
|
248
|
+
gperms?: string[];
|
|
249
|
+
}
|
|
250
|
+
/** The payload that carries `claims` in `layout`. */
|
|
251
|
+
export declare function accessTokenPayload(claims: AccessTokenClaims, layout: AccessTokenLayout): AccessTokenPayload;
|
|
252
|
+
/**
|
|
253
|
+
* Sign `claims` in the entries layout, or in the compact one when the entries layout is above `bound` bytes; the caller
|
|
254
|
+
* refuses a result still above it. A reader older than `gperms` reads a compact token without its global grants, which
|
|
255
|
+
* denies more and never allows more, and receives one only where the entries layout would have been refused anyway, so
|
|
256
|
+
* a platform release never changes a token an older framework release or a pinned proxy reads (ADR-0062).
|
|
257
|
+
*/
|
|
258
|
+
export declare function signAccessClaims(claims: AccessTokenClaims, bound: number, sign: (payload: AccessTokenPayload) => Promise<string>): Promise<string>;
|
|
202
259
|
/** Assemble the claim object for an access token. Pure — the caller signs the result. */
|
|
203
260
|
export declare function buildAccessClaims(params: AccessTokenParams): AccessTokenClaims;
|
|
204
261
|
/**
|
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
|
|
@@ -22,8 +23,9 @@ export declare function isWorkloadKind(value: unknown): value is WorkloadKind;
|
|
|
22
23
|
* - 'grant' — explicit `grants` row
|
|
23
24
|
* - 'bootstrap' — IAM_BOOTSTRAP_ADMINS env match (resolution-time only)
|
|
24
25
|
* - `group:${groupRef}` — IdP group → role mapping (the `<org>/<team>` ref)
|
|
26
|
+
* - 'terminal' — a grant of the terminal a person is signed in on (ADR-0067)
|
|
25
27
|
*/
|
|
26
|
-
export type PermissionSource = 'grant' | 'bootstrap' | `group:${string}`;
|
|
28
|
+
export type PermissionSource = 'grant' | 'bootstrap' | 'terminal' | `group:${string}`;
|
|
27
29
|
/**
|
|
28
30
|
* A flat, app-owned scope coordinate — one dimension (`type`) and an opaque value.
|
|
29
31
|
* Dimensions are INDEPENDENT: there is NO hierarchy/containment between them.
|
|
@@ -33,6 +35,34 @@ export interface Scope {
|
|
|
33
35
|
type: string;
|
|
34
36
|
value: string;
|
|
35
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
40
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
41
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
42
|
+
*/
|
|
43
|
+
export declare const RELATION_SCOPE_TYPE = "~rel";
|
|
44
|
+
/**
|
|
45
|
+
* The pseudo-scope of a relation entry held inside one node: `{ type: '~relin', value: '<relation>:<dimension>:<node>' }`
|
|
46
|
+
* means the action is held where a row names the principal in that relation, on rows that lie inside `node` of
|
|
47
|
+
* `dimension`. IAM gives it a grant at that node of a role with `via`. Its own type, never `~rel`: a release that reads
|
|
48
|
+
* `~rel` as "the relation anywhere" ignores this one and reaches less.
|
|
49
|
+
*/
|
|
50
|
+
export declare const RELATION_INSIDE_SCOPE_TYPE = "~relin";
|
|
51
|
+
/** A relation held inside one node of a dimension, as a `~relin` entry names it. */
|
|
52
|
+
export interface RelationInside {
|
|
53
|
+
readonly relation: string;
|
|
54
|
+
readonly dimension: string;
|
|
55
|
+
readonly node: string;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* The `~relin` scope of `relation` inside `node` of `dimension`. A relation or dimension name never holds `:` (the
|
|
59
|
+
* contract's names do not), so the node, last, is read back verbatim, colons included; a name that holds one is refused.
|
|
60
|
+
*/
|
|
61
|
+
export declare function relationInsideScope(inside: RelationInside): Scope;
|
|
62
|
+
/** The relation, dimension and node of a `~relin` scope, or null for any other scope or a malformed value. */
|
|
63
|
+
export declare function parseRelationInside(scope: Scope): RelationInside | null;
|
|
64
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
65
|
+
export declare function isReservedScopeType(type: string): boolean;
|
|
36
66
|
export interface PermissionEntry {
|
|
37
67
|
action: string;
|
|
38
68
|
/** null = global / all scopes */
|
|
@@ -69,6 +99,13 @@ export interface RoleDef {
|
|
|
69
99
|
};
|
|
70
100
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
71
101
|
external?: true;
|
|
102
|
+
/**
|
|
103
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
104
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation. A
|
|
105
|
+
* grant at a node carries `~relin` instead (`relationInsideScope`): the relation holds only inside that node. Only an
|
|
106
|
+
* internal role declares it.
|
|
107
|
+
*/
|
|
108
|
+
via?: Record<string, string[]>;
|
|
72
109
|
}
|
|
73
110
|
/**
|
|
74
111
|
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|
|
@@ -96,6 +133,10 @@ export interface AppScopeDef {
|
|
|
96
133
|
* answers a lookup only for one of them, held on the directory's value. Absent, no endpoint looks one up.
|
|
97
134
|
*/
|
|
98
135
|
lookups?: string[];
|
|
136
|
+
/** The values the console offers for a grant in this dimension (ADR-0085); absent, it takes free text. */
|
|
137
|
+
values?: DimensionValue[];
|
|
138
|
+
/** The procedure IAM asks for this dimension's values as the administrator (ADR-0085 §4); absent, only `values` count. */
|
|
139
|
+
valueSource?: DimensionValueSource;
|
|
99
140
|
}
|
|
100
141
|
/**
|
|
101
142
|
* The role keys IAM defines itself for every app. A built-in wins over an app role of the same key at
|
|
@@ -131,7 +172,7 @@ export interface AppDelegationDef {
|
|
|
131
172
|
dimension: string;
|
|
132
173
|
purpose: 'members' | 'creates';
|
|
133
174
|
}
|
|
134
|
-
/** An app's full authz vocabulary, declared in the app's code, reconciled into
|
|
175
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
|
|
135
176
|
export interface AppSchema {
|
|
136
177
|
scopes: AppScopeDef[];
|
|
137
178
|
actions: AppActionDef[];
|
|
@@ -165,6 +206,10 @@ export interface AppSchema {
|
|
|
165
206
|
};
|
|
166
207
|
/** `labels`: a holder of the app's `members.list` also sees each member's label. Absent, labels stay with `members.manage`. */
|
|
167
208
|
directory?: 'labels';
|
|
209
|
+
/** The app's identification page for a person at an enrolled terminal (ADR-0067); absent, no terminal lists it. */
|
|
210
|
+
terminal?: {
|
|
211
|
+
identify: string;
|
|
212
|
+
};
|
|
168
213
|
}
|
|
169
214
|
/**
|
|
170
215
|
* 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
|
@@ -51,6 +51,12 @@ export declare const FABRIKA_PROXY_SECRET = "FABRIKA_PROXY_SECRET";
|
|
|
51
51
|
* the name carries a digest of the id rather than the id.
|
|
52
52
|
*/
|
|
53
53
|
export declare function proxySecretVariable(id: string): string;
|
|
54
|
+
/**
|
|
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 request-id header; IAM keys every request without
|
|
57
|
+
* it on one shared client bucket.
|
|
58
|
+
*/
|
|
59
|
+
export declare const IAM_PROXY_SECRET_VARIABLE = "FABRIKA_INSTALLATION_PROXY_SECRET_IAM";
|
|
54
60
|
/**
|
|
55
61
|
* Every `X-Fabrika-*` name a proxy hop carries to an application. Caddy's first step and the Cloudflare proxy Worker
|
|
56
62
|
* delete each of them from the client's request before anything else, then set only what the decision asserts. A new
|