@fabrika/auth-core 0.8.2 → 0.9.0-cloudflare.2
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 +4 -3
- package/src/contract-canonical.ts +2 -1
- package/src/contract.ts +11 -3
- package/src/dev-environment.ts +45 -0
- package/src/framework-release.ts +2 -0
- package/src/framework-variables.ts +20 -2
- package/src/index.ts +6 -0
- package/src/managed-environment.ts +140 -0
- package/src/ops.ts +497 -0
- package/src/public-egress.ts +166 -0
- package/src/terminal.ts +105 -0
- package/src/token.ts +65 -5
- package/src/types.ts +4 -1
- package/types/src/app-environment.d.ts +24 -0
- package/types/src/canonical-path.d.ts +20 -0
- package/types/src/contract-canonical.d.ts +19 -0
- package/types/src/contract.d.ts +802 -0
- package/types/src/dev-environment.d.ts +37 -0
- package/types/src/device.d.ts +144 -0
- package/types/src/endpoint-digest.d.ts +58 -0
- package/types/src/endpoints.d.ts +65 -0
- package/types/src/environment.d.ts +58 -0
- package/types/src/framework-release.d.ts +2 -0
- package/types/src/framework-variables.d.ts +91 -0
- package/types/src/index.d.ts +29 -0
- package/types/src/installation-endpoint.d.ts +46 -0
- package/types/src/json.d.ts +13 -0
- package/types/src/locale.d.ts +14 -0
- package/types/src/mail.d.ts +67 -0
- package/types/src/managed-environment.d.ts +32 -0
- package/types/src/membership.d.ts +318 -0
- package/types/src/oauth.d.ts +7 -0
- package/types/src/ops.d.ts +181 -0
- package/types/src/path-segment.d.ts +5 -0
- package/types/src/permissions.d.ts +50 -0
- package/types/src/public-egress.d.ts +31 -0
- package/types/src/requirement.d.ts +24 -0
- package/types/src/rpc.d.ts +283 -0
- package/types/src/sha256.d.ts +2 -0
- package/types/src/terminal.d.ts +72 -0
- package/types/src/token.d.ts +240 -0
- package/types/src/types.d.ts +196 -0
- package/types/src/wire.d.ts +65 -0
- package/types/src/workloads.d.ts +25 -0
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import type { Locale } from './locale';
|
|
2
|
+
import type { MailTemplates } from './mail';
|
|
3
|
+
export type PrincipalType = 'user' | 'service';
|
|
4
|
+
/**
|
|
5
|
+
* Whether a person belongs to the organization (ADR-0051). An `external` principal holds only grants of a role its
|
|
6
|
+
* application declares `external`; a service is always `internal`.
|
|
7
|
+
*/
|
|
8
|
+
export type PrincipalAffiliation = 'internal' | 'external';
|
|
9
|
+
/**
|
|
10
|
+
* The principal kind of a workload credential (ADR-0022 "Principal kinds"): a contract job, a webhook, a public
|
|
11
|
+
* procedure (named by its endpoint id), or the connector of a consuming application. IAM stores a workload principal as
|
|
12
|
+
* a `service` row and mints its key with this kind, so a workload key is never a `machine` caller.
|
|
13
|
+
*/
|
|
14
|
+
export type WorkloadKind = 'job' | 'webhook' | 'public' | 'app';
|
|
15
|
+
export declare const WORKLOAD_KINDS: readonly ["job", "webhook", "public", "app"];
|
|
16
|
+
/** The principal kind a token carries in `ptype`: a stored principal type, or a workload kind. */
|
|
17
|
+
export type TokenPrincipalType = PrincipalType | WorkloadKind;
|
|
18
|
+
export declare function isWorkloadKind(value: unknown): value is WorkloadKind;
|
|
19
|
+
/**
|
|
20
|
+
* Where a resolved permission entry came from. Used for debuggability in the admin UI
|
|
21
|
+
* ("why does this user have this permission?"); `can()`/`scopedTo()` ignore it.
|
|
22
|
+
* - 'grant' — explicit `grants` row
|
|
23
|
+
* - 'bootstrap' — IAM_BOOTSTRAP_ADMINS env match (resolution-time only)
|
|
24
|
+
* - `group:${groupRef}` — IdP group → role mapping (the `<org>/<team>` ref)
|
|
25
|
+
* - 'terminal' — a grant of the terminal a person is signed in on (ADR-0067)
|
|
26
|
+
*/
|
|
27
|
+
export type PermissionSource = 'grant' | 'bootstrap' | 'terminal' | `group:${string}`;
|
|
28
|
+
/**
|
|
29
|
+
* A flat, app-owned scope coordinate — one dimension (`type`) and an opaque value.
|
|
30
|
+
* Dimensions are INDEPENDENT: there is NO hierarchy/containment between them.
|
|
31
|
+
* `value` is an opaque app-owned string; core never validates it.
|
|
32
|
+
*/
|
|
33
|
+
export interface Scope {
|
|
34
|
+
type: string;
|
|
35
|
+
value: string;
|
|
36
|
+
}
|
|
37
|
+
export interface PermissionEntry {
|
|
38
|
+
action: string;
|
|
39
|
+
/** null = global / all scopes */
|
|
40
|
+
scope: Scope | null;
|
|
41
|
+
source: PermissionSource;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Domain event apps emit. Only the app knows what changed.
|
|
45
|
+
*
|
|
46
|
+
* IMPORTANT: `diff`/`metadata` may carry sensitive values (settings can hold secrets).
|
|
47
|
+
* The app MUST redact secret material before passing them — audit storage is verbatim
|
|
48
|
+
* and long-lived; the IAM Worker stores what it receives as-is.
|
|
49
|
+
*/
|
|
50
|
+
export interface DomainEvent {
|
|
51
|
+
action: string;
|
|
52
|
+
resourceType: string;
|
|
53
|
+
resourceId?: string;
|
|
54
|
+
diff?: unknown;
|
|
55
|
+
metadata?: unknown;
|
|
56
|
+
}
|
|
57
|
+
export interface RoleDef {
|
|
58
|
+
name: string;
|
|
59
|
+
description?: string;
|
|
60
|
+
permissions: string[];
|
|
61
|
+
/**
|
|
62
|
+
* A membership role is granted only in a value of `scope`, never globally. `assignableBy` names the
|
|
63
|
+
* roles whose holders may assign it there: a membership role of the same scope, held there, or an
|
|
64
|
+
* application-wide role (one with no `member`), held there or globally. Absent, only an IAM
|
|
65
|
+
* administrator assigns it.
|
|
66
|
+
*/
|
|
67
|
+
member?: {
|
|
68
|
+
scope: string;
|
|
69
|
+
assignableBy?: string[];
|
|
70
|
+
};
|
|
71
|
+
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
72
|
+
external?: true;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|
|
76
|
+
* which dimension a share link's containment chain names next.
|
|
77
|
+
*/
|
|
78
|
+
export interface AppScopeDef {
|
|
79
|
+
type: string;
|
|
80
|
+
label?: string;
|
|
81
|
+
/** The dimension that contains every value of this one (`note` is in `workspace`). */
|
|
82
|
+
in?: string;
|
|
83
|
+
/** The membership role IAM grants the caller in a value it creates for them (`createScope`). */
|
|
84
|
+
creator?: string;
|
|
85
|
+
/** The action that manages the members of a value, and the one that lists them. */
|
|
86
|
+
members?: {
|
|
87
|
+
manage: string;
|
|
88
|
+
list: string;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* `labels`: a holder of `members.list` also sees each member's label (a user's spelling of its address). Absent, the
|
|
92
|
+
* labels stay with `members.manage`.
|
|
93
|
+
*/
|
|
94
|
+
directory?: 'labels';
|
|
95
|
+
/**
|
|
96
|
+
* The actions of the endpoints on, in or below this dimension that look up one of its members (`findMember`). IAM
|
|
97
|
+
* answers a lookup only for one of them, held on the directory's value. Absent, no endpoint looks one up.
|
|
98
|
+
*/
|
|
99
|
+
lookups?: string[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The role keys IAM defines itself for every app. A built-in wins over an app role of the same key at
|
|
103
|
+
* resolution, so a membership role, and any role of a contract application, may not use one.
|
|
104
|
+
*/
|
|
105
|
+
declare const BUILTIN_ROLE_KEY_LITERALS: readonly ["admin"];
|
|
106
|
+
/** A role key IAM defines itself, as a type: `defineVocabulary` refuses a role of that name. */
|
|
107
|
+
export type BuiltinRoleKey = (typeof BUILTIN_ROLE_KEY_LITERALS)[number];
|
|
108
|
+
export declare const BUILTIN_ROLE_KEYS: readonly string[];
|
|
109
|
+
/** One action in an app's catalog (used for validation + admin UI discovery). */
|
|
110
|
+
export interface AppActionDef {
|
|
111
|
+
action: string;
|
|
112
|
+
description?: string;
|
|
113
|
+
}
|
|
114
|
+
/** A share-link mount: what a link key of the mount carries and who may issue one. */
|
|
115
|
+
export interface AppLinkMountDef {
|
|
116
|
+
/** The dimension of the object a link is bound to. */
|
|
117
|
+
dimension: string;
|
|
118
|
+
/** Exact actions frozen into every key, on the bound object. */
|
|
119
|
+
grants: string[];
|
|
120
|
+
/** The action the issuer must hold on the object or a value containing it. */
|
|
121
|
+
issuedBy: string;
|
|
122
|
+
/** The longest a link of the mount may live, in days. */
|
|
123
|
+
maxDays: number;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* An endpoint whose request may spend the caller's membership authority. IAM issues a delegation grant
|
|
127
|
+
* only for one of these: `members` for an endpoint whose action is the dimension's `members.manage`,
|
|
128
|
+
* `creates` for one that creates a value of the dimension.
|
|
129
|
+
*/
|
|
130
|
+
export interface AppDelegationDef {
|
|
131
|
+
action: string;
|
|
132
|
+
dimension: string;
|
|
133
|
+
purpose: 'members' | 'creates';
|
|
134
|
+
}
|
|
135
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into Propustka. */
|
|
136
|
+
export interface AppSchema {
|
|
137
|
+
scopes: AppScopeDef[];
|
|
138
|
+
actions: AppActionDef[];
|
|
139
|
+
/** role_key -> def; these are origin='app' roles. */
|
|
140
|
+
roles: Record<string, RoleDef>;
|
|
141
|
+
/** Compiled from a contract (`schemaFromContract`): IAM then refuses every wildcard action written for the app. */
|
|
142
|
+
contract?: boolean;
|
|
143
|
+
/** Link mount id -> its definition. Removing a mount revokes its keys. */
|
|
144
|
+
links?: Record<string, AppLinkMountDef>;
|
|
145
|
+
/** Endpoint id -> what the endpoint may spend through a delegation grant. */
|
|
146
|
+
delegations?: Record<string, AppDelegationDef>;
|
|
147
|
+
/**
|
|
148
|
+
* The workloads of a contract application and their exact actions. A workload key resolves to these actions, app-wide,
|
|
149
|
+
* and to nothing once its workload is no longer declared; removing one revokes its keys.
|
|
150
|
+
*/
|
|
151
|
+
workloads?: AppWorkloadDef[];
|
|
152
|
+
/** The language IAM speaks to the app's people; absent, IAM's default. */
|
|
153
|
+
locale?: Locale;
|
|
154
|
+
/** The name IAM shows on its pages and e-mails for the app; absent, a wording without a name. */
|
|
155
|
+
displayName?: string;
|
|
156
|
+
/** The app's wording of IAM's e-mails, by message and language; absent, IAM's own. */
|
|
157
|
+
mail?: MailTemplates;
|
|
158
|
+
/**
|
|
159
|
+
* The application's own people, every holder of one of its roles. A holder of `manage`, globally at the app, grants and
|
|
160
|
+
* revokes the app's global roles in IAM's console within its own actions; a holder of `list`, globally, reads the
|
|
161
|
+
* directory (`listAppMembers`). Absent, only an IAM administrator grants them and nobody lists them.
|
|
162
|
+
*/
|
|
163
|
+
members?: {
|
|
164
|
+
manage: string;
|
|
165
|
+
list: string;
|
|
166
|
+
};
|
|
167
|
+
/** `labels`: a holder of the app's `members.list` also sees each member's label. Absent, labels stay with `members.manage`. */
|
|
168
|
+
directory?: 'labels';
|
|
169
|
+
/** The app's identification page for a person at an enrolled terminal (ADR-0067); absent, no terminal lists it. */
|
|
170
|
+
terminal?: {
|
|
171
|
+
identify: string;
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
/**
|
|
175
|
+
* A job, a webhook or a public procedure (`public`, named by its endpoint id) of a contract application, or a consuming
|
|
176
|
+
* application of its exports (`app`, named by that application's id): the actions its credential carries.
|
|
177
|
+
*/
|
|
178
|
+
export interface AppWorkloadDef {
|
|
179
|
+
kind: WorkloadKind;
|
|
180
|
+
name: string;
|
|
181
|
+
actions: string[];
|
|
182
|
+
/**
|
|
183
|
+
* A job only: the link mount whose links it may issue (`issueLink`) and revoke, its own only. Its actions hold the
|
|
184
|
+
* mount's `issuedBy` and every grant, app-wide, so the job issues for any object of the mount's dimension.
|
|
185
|
+
*/
|
|
186
|
+
issues?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* App-aware role lookup. The worker layers a built-in cross-app source (admin) over a
|
|
190
|
+
* per-app DB source. `app` is the calling app id; null = cross-app/built-in only.
|
|
191
|
+
*/
|
|
192
|
+
export interface RoleSource {
|
|
193
|
+
getRole(app: string | null, key: string): RoleDef | undefined;
|
|
194
|
+
listRoles(app: string | null): Record<string, RoleDef>;
|
|
195
|
+
}
|
|
196
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/** Header carrying the proxy-verified access token to the upstream app. */
|
|
2
|
+
export declare const PROXY_TOKEN_HEADER = "X-Fabrika-Token";
|
|
3
|
+
/**
|
|
4
|
+
* Header carrying the CLIENT COORDINATE the enforcement point observed — the only address an inner
|
|
5
|
+
* hop may key an abuse limit on.
|
|
6
|
+
*
|
|
7
|
+
* Owned exactly like `PROXY_TOKEN_HEADER`: the edge deletes a caller-supplied one and writes its own,
|
|
8
|
+
* so an upstream reading it is reading the edge and never the caller. It is deliberately NOT
|
|
9
|
+
* `X-Forwarded-For` — that name means "whatever the chain appended", and a value whose
|
|
10
|
+
* trustworthiness depends on where you are standing is exactly the key backlog 21 and 49 twice
|
|
11
|
+
* refused to build on ([sprint](../../../docs/archive/sprint-2026-08-05-auth-track-closeout.md)).
|
|
12
|
+
*
|
|
13
|
+
* Where a composition cannot observe the client the header is simply ABSENT, and the upstream then
|
|
14
|
+
* has no per-client bucket — today's behaviour — rather than a spoofable one.
|
|
15
|
+
*/
|
|
16
|
+
export declare const CLIENT_ADDRESS_HEADER = "X-Fabrika-Client-Ip";
|
|
17
|
+
/**
|
|
18
|
+
* The other names a client address travels under, deleted at ingress so `CLIENT_ADDRESS_HEADER` is the
|
|
19
|
+
* only one an upstream can read.
|
|
20
|
+
*
|
|
21
|
+
* Two reasons, and both matter. `X-Forwarded-For` is caller-writable on BOTH compositions — Caddy
|
|
22
|
+
* keeps a client-supplied prefix once the peer is trusted, and Cloudflare appends to whatever the
|
|
23
|
+
* caller sent — so a downstream reading it reads the caller. `CF-Connecting-IP` is genuinely
|
|
24
|
+
* trustworthy on Cloudflare's edge and a caller's invention anywhere else, which is worse: an app that
|
|
25
|
+
* reads it works on one cloud and silently keys on a forgery on the other. Deleting both leaves one
|
|
26
|
+
* header with one meaning everywhere, supplied only by the enforcement point.
|
|
27
|
+
*/
|
|
28
|
+
export declare const UNTRUSTED_FORWARD_HEADERS: readonly string[];
|
|
29
|
+
/**
|
|
30
|
+
* Header carrying the endpoint the proxy selected and the digest of the rules it applied, `<id>@<digest>`
|
|
31
|
+
* (`formatEndpointHeader`). Set by the proxy on every allowed request to a contract application, after the strip of
|
|
32
|
+
* a client's own; the application serves only that endpoint and answers 503 when its digest differs.
|
|
33
|
+
*/
|
|
34
|
+
export declare const ENDPOINT_HEADER = "X-Fabrika-Endpoint";
|
|
35
|
+
/**
|
|
36
|
+
* Header carrying the single-use delegation grant the proxy obtained from IAM for a membership or scope-creating
|
|
37
|
+
* endpoint (ADR-0022 rule 6). The framework forwards it to IAM; nothing else reads it.
|
|
38
|
+
*/
|
|
39
|
+
export declare const DELEGATION_HEADER = "X-Fabrika-Delegation";
|
|
40
|
+
/**
|
|
41
|
+
* Header carrying the proxy secret of one application environment (ADR-0022 rule 5), on Zerops only: a namespace is
|
|
42
|
+
* one private network, so the application refuses a request that does not prove it came through the proxy. On
|
|
43
|
+
* Cloudflare the service binding is the authenticated hop and this header is never set.
|
|
44
|
+
*/
|
|
45
|
+
export declare const PROXY_SECRET_HEADER = "X-Fabrika-Proxy-Secret";
|
|
46
|
+
/** The application's framework variable holding the secret its proxy sends in `PROXY_SECRET_HEADER`. */
|
|
47
|
+
export declare const FABRIKA_PROXY_SECRET = "FABRIKA_PROXY_SECRET";
|
|
48
|
+
/**
|
|
49
|
+
* The proxy service's variable holding the secret of application environment `id` (`<app>@<env>`). One proxy fronts
|
|
50
|
+
* every application of a namespace, so each secret needs its own name; an environment name may hold any character, so
|
|
51
|
+
* the name carries a digest of the id rather than the id.
|
|
52
|
+
*/
|
|
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 client-address and request-id headers.
|
|
57
|
+
*/
|
|
58
|
+
export declare const IAM_PROXY_SECRET_VARIABLE = "FABRIKA_INSTALLATION_PROXY_SECRET_IAM";
|
|
59
|
+
/**
|
|
60
|
+
* Every `X-Fabrika-*` name a proxy hop carries to an application. Caddy's first step and the Cloudflare proxy Worker
|
|
61
|
+
* delete each of them from the client's request before anything else, then set only what the decision asserts. A new
|
|
62
|
+
* header the proxy sets joins this list in the same change. The Operations upload headers are not hop headers: a
|
|
63
|
+
* client sends them to Operations through the platform proxy, so the proxy must let them pass.
|
|
64
|
+
*/
|
|
65
|
+
export declare const FABRIKA_HOP_HEADERS: readonly string[];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ContractArtifact } from './contract';
|
|
2
|
+
import type { OwnWorkloadKind } from './framework-variables';
|
|
3
|
+
/** A job or webhook name of a contract. */
|
|
4
|
+
export declare const WORKLOAD_NAME: RegExp;
|
|
5
|
+
/**
|
|
6
|
+
* A public procedure's workload name: its full endpoint id, `<mount>.<group>.<procedure>`, so one group mounted twice
|
|
7
|
+
* holds two workloads and never merges their authority.
|
|
8
|
+
*/
|
|
9
|
+
export declare const PUBLIC_WORKLOAD_NAME: RegExp;
|
|
10
|
+
/** IAM stores the name in the principal's external id, and the token carries it. */
|
|
11
|
+
export declare const MAX_PUBLIC_WORKLOAD_NAME_LENGTH = 128;
|
|
12
|
+
/** Whether `name` names a workload of an application's own `kind`. */
|
|
13
|
+
export declare function isOwnWorkloadName(kind: OwnWorkloadKind, name: string): boolean;
|
|
14
|
+
/** One workload the contract declares: what IAM stores, what its key is named after and what its token carries. */
|
|
15
|
+
export interface ContractWorkload {
|
|
16
|
+
readonly kind: OwnWorkloadKind;
|
|
17
|
+
readonly name: string;
|
|
18
|
+
/** The workload's declared actions, sorted. */
|
|
19
|
+
readonly actions: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Every workload of `artifact`: its jobs, its webhooks, and each endpoint whose declared reach names `actions` — a public
|
|
23
|
+
* procedure, which runs as its own workload.
|
|
24
|
+
*/
|
|
25
|
+
export declare function contractWorkloads(artifact: Pick<ContractArtifact, 'jobs' | 'mounts' | 'declared'>): readonly ContractWorkload[];
|