@fabrika/auth-core 0.9.0-dev.12 → 0.9.0-dev.14
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 +1 -1
- package/src/contract-canonical.ts +113 -1
- package/src/contract.ts +130 -2
- package/src/framework-variables.ts +6 -0
- package/src/index.ts +1 -0
- package/src/managed-environment.ts +4 -0
- package/src/public-egress.ts +168 -0
- package/src/types.ts +58 -0
- package/types/src/contract-canonical.d.ts +6 -1
- package/types/src/contract.d.ts +141 -2
- package/types/src/framework-variables.d.ts +6 -1
- package/types/src/index.d.ts +1 -0
- package/types/src/managed-environment.d.ts +1 -1
- package/types/src/public-egress.d.ts +31 -0
- package/types/src/types.d.ts +35 -0
package/package.json
CHANGED
|
@@ -4,12 +4,19 @@
|
|
|
4
4
|
import type {
|
|
5
5
|
BodyAdmission,
|
|
6
6
|
Caller,
|
|
7
|
+
ColumnTestArtifact,
|
|
8
|
+
ConditionArtifact,
|
|
9
|
+
ConditionLiteralArtifact,
|
|
10
|
+
ConfersArtifact,
|
|
7
11
|
ContractArtifact,
|
|
8
12
|
CspSource,
|
|
9
13
|
EndpointRow,
|
|
14
|
+
MemberRevealsArtifact,
|
|
10
15
|
MountArtifact,
|
|
11
16
|
OutputShape,
|
|
17
|
+
RevealsArtifact,
|
|
12
18
|
RoleArtifact,
|
|
19
|
+
RowsTestArtifact,
|
|
13
20
|
SchemaShape,
|
|
14
21
|
TableActionArtifact,
|
|
15
22
|
TablePolicyArtifact,
|
|
@@ -27,6 +34,7 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
27
34
|
dimensions: artifact.dimensions,
|
|
28
35
|
actions: artifact.actions,
|
|
29
36
|
roles: mapValues(artifact.roles, canonicalRole),
|
|
37
|
+
...(artifact.relations === undefined ? {} : { relations: artifact.relations }),
|
|
30
38
|
mounts: mapValues(artifact.mounts, canonicalMount),
|
|
31
39
|
files: mapValues(artifact.files, (collection) => ({
|
|
32
40
|
...collection,
|
|
@@ -65,7 +73,7 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
65
73
|
...(reach.actions === undefined ? {} : { actions: sorted(reach.actions) }),
|
|
66
74
|
...(reach.kicks === undefined ? {} : { kicks: sorted(reach.kicks) }),
|
|
67
75
|
...(reach.signs === undefined ? {} : { signs: sorted(reach.signs) }),
|
|
68
|
-
...(reach.egress === undefined ? {} : { egress: sorted(reach.egress) }),
|
|
76
|
+
...(reach.egress === undefined ? {} : { egress: typeof reach.egress === 'string' ? reach.egress : sorted(reach.egress) }),
|
|
69
77
|
})),
|
|
70
78
|
}),
|
|
71
79
|
...(artifact.directories === undefined ? {} : { directories: artifact.directories }),
|
|
@@ -101,6 +109,7 @@ function canonicalRole(role: RoleArtifact): RoleArtifact {
|
|
|
101
109
|
grants: sorted(role.grants),
|
|
102
110
|
member: role.member === null ? null : { scope: role.member.scope, assignableBy: sorted(role.member.assignableBy) },
|
|
103
111
|
...(role.external === true ? { external: true } : {}),
|
|
112
|
+
...(role.via === undefined ? {} : { via: mapValues(role.via, sorted) }),
|
|
104
113
|
}
|
|
105
114
|
}
|
|
106
115
|
|
|
@@ -151,9 +160,112 @@ function canonicalTable(table: TablePolicyArtifact): TablePolicyArtifact {
|
|
|
151
160
|
scope: table.scope.mode === 'child' ? { ...table.scope, inherit: sorted(table.scope.inherit) } : table.scope,
|
|
152
161
|
insert: sorted(table.insert),
|
|
153
162
|
update: sorted(table.update),
|
|
163
|
+
...(table.when === undefined ? {} : { when: mapValues(table.when, canonicalCondition) }),
|
|
164
|
+
...(table.relationWhen === undefined
|
|
165
|
+
? {}
|
|
166
|
+
: { relationWhen: mapValues(table.relationWhen, (conditions) => mapValues(conditions, canonicalCondition)) }),
|
|
167
|
+
...(table.confers === undefined ? {} : { confers: mapValues(table.confers, canonicalConfers) }),
|
|
168
|
+
...(table.reveals === undefined ? {} : { reveals: mapValues(table.reveals, canonicalReveals) }),
|
|
169
|
+
...(table.memberReveals === undefined ? {} : { memberReveals: mapValues(table.memberReveals, canonicalMemberReveals) }),
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function canonicalConfers(confers: ConfersArtifact): ConfersArtifact {
|
|
174
|
+
return confers.when === undefined ? confers : { ...confers, when: canonicalCondition(confers.when) }
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function canonicalReveals(reveals: RevealsArtifact): RevealsArtifact {
|
|
178
|
+
return {
|
|
179
|
+
...reveals,
|
|
180
|
+
actions: sorted(reveals.actions),
|
|
181
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
function canonicalMemberReveals(reveals: MemberRevealsArtifact): MemberRevealsArtifact {
|
|
186
|
+
return {
|
|
187
|
+
...reveals,
|
|
188
|
+
actions: sorted(reveals.actions),
|
|
189
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/**
|
|
194
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
195
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
196
|
+
*/
|
|
197
|
+
export function canonicalCondition(condition: ConditionArtifact): ConditionArtifact {
|
|
198
|
+
if ('allOf' in condition && isConditionList(condition.allOf)) {
|
|
199
|
+
return { allOf: sortedConditions(condition.allOf) }
|
|
200
|
+
}
|
|
201
|
+
if ('anyOf' in condition && isConditionList(condition.anyOf)) {
|
|
202
|
+
return { anyOf: sortedConditions(condition.anyOf) }
|
|
203
|
+
}
|
|
204
|
+
if ('not' in condition && isCondition(condition.not)) {
|
|
205
|
+
return { not: canonicalCondition(condition.not) }
|
|
206
|
+
}
|
|
207
|
+
const rows = canonicalRows(condition)
|
|
208
|
+
if (rows !== undefined) return rows
|
|
209
|
+
const tests: Record<string, ColumnTestArtifact | RowsTestArtifact> = {}
|
|
210
|
+
for (const [path, test] of Object.entries(condition)) {
|
|
211
|
+
const after = isCondition(test) ? canonicalRows(test) : undefined
|
|
212
|
+
if (after !== undefined) {
|
|
213
|
+
tests[path] = after
|
|
214
|
+
continue
|
|
215
|
+
}
|
|
216
|
+
// A parsed artifact holds nothing else here; dropping an unknown test would widen what the condition admits.
|
|
217
|
+
if (!isColumnTest(test)) throw new Error(`the condition test of ${path} is not a column test`)
|
|
218
|
+
tests[path] = canonicalTest(test)
|
|
219
|
+
}
|
|
220
|
+
return tests
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** `some` or `none` with its condition canonical, or `undefined` for any other form: one beside another key is no rows test. */
|
|
224
|
+
function canonicalRows(condition: object): RowsTestArtifact | undefined {
|
|
225
|
+
if (Object.keys(condition).length !== 1) return undefined
|
|
226
|
+
if ('some' in condition && isConditionRecord(condition.some)) {
|
|
227
|
+
return { some: mapValues(condition.some, canonicalCondition) }
|
|
228
|
+
}
|
|
229
|
+
if ('none' in condition && isConditionRecord(condition.none)) {
|
|
230
|
+
return { none: mapValues(condition.none, canonicalCondition) }
|
|
231
|
+
}
|
|
232
|
+
return undefined
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function canonicalTest(test: ColumnTestArtifact): ColumnTestArtifact {
|
|
236
|
+
return {
|
|
237
|
+
...test,
|
|
238
|
+
...(test.in === undefined ? {} : { in: sortedLiterals(test.in) }),
|
|
239
|
+
...(test.notIn === undefined ? {} : { notIn: sortedLiterals(test.notIn) }),
|
|
154
240
|
}
|
|
155
241
|
}
|
|
156
242
|
|
|
243
|
+
function sortedConditions(conditions: readonly ConditionArtifact[]): ConditionArtifact[] {
|
|
244
|
+
return conditions.map(canonicalCondition).sort((a, b) => compare(canonicalJson(a), canonicalJson(b)))
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
function sortedLiterals(values: readonly ConditionLiteralArtifact[]): ConditionLiteralArtifact[] {
|
|
248
|
+
return [...values].sort((a, b) => compare(JSON.stringify(a), JSON.stringify(b)))
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function isCondition(value: unknown): value is ConditionArtifact {
|
|
252
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
function isConditionRecord(value: unknown): value is Readonly<Record<string, ConditionArtifact>> {
|
|
256
|
+
return isCondition(value) && Object.values(value).every(isCondition)
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
function isConditionList(value: unknown): value is readonly ConditionArtifact[] {
|
|
260
|
+
return Array.isArray(value) && value.every(isCondition)
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const COLUMN_TEST_OPERATORS: ReadonlySet<string> = new Set(['eq', 'notEq', 'in', 'notIn', 'isNull', 'lt', 'lte', 'gt', 'gte'])
|
|
264
|
+
|
|
265
|
+
function isColumnTest(value: unknown): value is ColumnTestArtifact {
|
|
266
|
+
return isCondition(value) && Object.keys(value).every((operator) => COLUMN_TEST_OPERATORS.has(operator))
|
|
267
|
+
}
|
|
268
|
+
|
|
157
269
|
function canonicalizeEndpoint(row: EndpointRow): EndpointRow {
|
|
158
270
|
const shared = {
|
|
159
271
|
admission: row.admission === null ? null : canonicalAdmission(row.admission),
|
package/src/contract.ts
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Locale } from './locale'
|
|
5
5
|
import type { MailTemplates } from './mail'
|
|
6
|
+
import type { DeclaredEgress } from './public-egress'
|
|
6
7
|
import type { TerminalArtifact } from './terminal'
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -24,6 +25,11 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
24
25
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
25
26
|
readonly actions: Readonly<Record<string, string>>
|
|
26
27
|
readonly roles: Readonly<Record<string, RoleArtifact>>
|
|
28
|
+
/**
|
|
29
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
30
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
31
|
+
*/
|
|
32
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>
|
|
27
33
|
readonly mounts: Readonly<Record<string, MountArtifact>>
|
|
28
34
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>
|
|
29
35
|
/**
|
|
@@ -484,6 +490,16 @@ export interface RoleArtifact {
|
|
|
484
490
|
readonly member: { readonly scope: string; readonly assignableBy: readonly string[] } | null
|
|
485
491
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
486
492
|
readonly external?: true
|
|
493
|
+
/**
|
|
494
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
495
|
+
* Absent unless declared, so digests stay.
|
|
496
|
+
*/
|
|
497
|
+
readonly via?: Readonly<Record<string, readonly string[]>>
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
501
|
+
export interface RelationArtifact {
|
|
502
|
+
readonly dimension: string
|
|
487
503
|
}
|
|
488
504
|
|
|
489
505
|
// ── Mounts and companions ───────────────────────────────────────────────────────────────────────
|
|
@@ -784,9 +800,11 @@ export interface DeclaredReach {
|
|
|
784
800
|
readonly signs?: readonly string[]
|
|
785
801
|
/**
|
|
786
802
|
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
787
|
-
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job.
|
|
803
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Or `'public'` (a cron job only): every public
|
|
804
|
+
* host over HTTPS or HTTP, never the installation or a private network (ADR-0075). Absent unless declared, so the
|
|
805
|
+
* digest stays.
|
|
788
806
|
*/
|
|
789
|
-
readonly egress?:
|
|
807
|
+
readonly egress?: DeclaredEgress
|
|
790
808
|
/**
|
|
791
809
|
* A public procedure's workload actions, sorted: all its handler holds, through the key Control issues for the
|
|
792
810
|
* endpoint (`contractWorkloads`). Present only on a public procedure's entry, so every other digest stays.
|
|
@@ -866,6 +884,116 @@ export interface TablePolicyArtifact {
|
|
|
866
884
|
* Absent for a table, so the digest stays.
|
|
867
885
|
*/
|
|
868
886
|
readonly view?: true
|
|
887
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
888
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>
|
|
889
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
890
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>
|
|
891
|
+
/**
|
|
892
|
+
* Relation → action → the condition a row the relation reaches must meet for it; it narrows that relation's reach only.
|
|
893
|
+
* Absent unless declared, so the digest stays. A reader that ignores it reaches more: Control refuses to publish it to
|
|
894
|
+
* an application pinned below the release that enforces it.
|
|
895
|
+
*/
|
|
896
|
+
readonly relationWhen?: Readonly<Record<string, Readonly<Record<string, ConditionArtifact>>>>
|
|
897
|
+
/**
|
|
898
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
899
|
+
* A reader that ignores it reaches less, never more.
|
|
900
|
+
*/
|
|
901
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>
|
|
902
|
+
/**
|
|
903
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
904
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
905
|
+
*/
|
|
906
|
+
readonly readThrough?: Readonly<Record<string, string>>
|
|
907
|
+
/**
|
|
908
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
|
|
909
|
+
* path's column must hold each at the node it names. Absent unless declared, so the digest stays. A reader that
|
|
910
|
+
* ignores it reaches less, never more.
|
|
911
|
+
*/
|
|
912
|
+
readonly writeThrough?: Readonly<Record<string, readonly string[]>>
|
|
913
|
+
/**
|
|
914
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
915
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
916
|
+
*/
|
|
917
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>
|
|
918
|
+
/**
|
|
919
|
+
* Relation → the access view that lists the rows it reaches (ADR-0076). Absent unless declared, so the digest stays.
|
|
920
|
+
* A reader that ignores it reaches less, never more.
|
|
921
|
+
*/
|
|
922
|
+
readonly access?: Readonly<Record<string, AccessArtifact>>
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/** An access view: its `row` column names the table's key; `principal` is compared to the caller, `member` to its nodes. */
|
|
926
|
+
export interface AccessArtifact {
|
|
927
|
+
readonly view: string
|
|
928
|
+
readonly row: string
|
|
929
|
+
readonly principal: string | null
|
|
930
|
+
readonly member: string | null
|
|
931
|
+
}
|
|
932
|
+
|
|
933
|
+
/**
|
|
934
|
+
* A row reveals its node in `to` for `actions` to a grant of them at the row's own node, or at the node its path to the
|
|
935
|
+
* key's dimension names, while `when` admits the row.
|
|
936
|
+
*/
|
|
937
|
+
export interface MemberRevealsArtifact {
|
|
938
|
+
readonly to: string
|
|
939
|
+
readonly actions: readonly string[]
|
|
940
|
+
readonly when?: ConditionArtifact
|
|
941
|
+
/**
|
|
942
|
+
* Through a path, on a table with an insert: the writer picks the node, and `self` lets it pick one where it holds a
|
|
943
|
+
* grant the reveal counts. Absent otherwise; only a reader that refuses a path's key reads it.
|
|
944
|
+
*/
|
|
945
|
+
readonly assign?: { readonly self: boolean }
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
949
|
+
export interface RevealsArtifact {
|
|
950
|
+
readonly to: string
|
|
951
|
+
readonly actions: readonly string[]
|
|
952
|
+
readonly when?: ConditionArtifact
|
|
953
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
954
|
+
readonly assign?: { readonly self: boolean }
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
958
|
+
export interface ConfersArtifact {
|
|
959
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
960
|
+
readonly principal: string
|
|
961
|
+
readonly node: string
|
|
962
|
+
readonly expires: string | null
|
|
963
|
+
readonly when?: ConditionArtifact
|
|
964
|
+
readonly assign: { readonly maxDays: number | null; readonly self: boolean } | null
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
/**
|
|
968
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
969
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
970
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
971
|
+
*/
|
|
972
|
+
export type ConditionArtifact =
|
|
973
|
+
| { readonly allOf: readonly ConditionArtifact[] }
|
|
974
|
+
| { readonly anyOf: readonly ConditionArtifact[] }
|
|
975
|
+
| { readonly not: ConditionArtifact }
|
|
976
|
+
| RowsTestArtifact
|
|
977
|
+
| { readonly [path: string]: ColumnTestArtifact | RowsTestArtifact }
|
|
978
|
+
|
|
979
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
980
|
+
export type RowsTestArtifact =
|
|
981
|
+
| { readonly some: Readonly<Record<string, ConditionArtifact>> }
|
|
982
|
+
| { readonly none: Readonly<Record<string, ConditionArtifact>> }
|
|
983
|
+
|
|
984
|
+
export type ConditionLiteralArtifact = string | number | boolean
|
|
985
|
+
|
|
986
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
987
|
+
export interface ColumnTestArtifact {
|
|
988
|
+
readonly eq?: ConditionLiteralArtifact
|
|
989
|
+
readonly notEq?: ConditionLiteralArtifact
|
|
990
|
+
readonly in?: readonly ConditionLiteralArtifact[]
|
|
991
|
+
readonly notIn?: readonly ConditionLiteralArtifact[]
|
|
992
|
+
readonly isNull?: boolean
|
|
993
|
+
readonly lt?: ConditionLiteralArtifact | { readonly now: true }
|
|
994
|
+
readonly lte?: ConditionLiteralArtifact | { readonly now: true }
|
|
995
|
+
readonly gt?: ConditionLiteralArtifact | { readonly now: true }
|
|
996
|
+
readonly gte?: ConditionLiteralArtifact | { readonly now: true }
|
|
869
997
|
}
|
|
870
998
|
|
|
871
999
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
|
@@ -18,6 +18,11 @@ export const FABRIKA_TOKEN_KEYS = 'FABRIKA_TOKEN_KEYS'
|
|
|
18
18
|
export const FABRIKA_APP_ORIGIN = 'FABRIKA_APP_ORIGIN'
|
|
19
19
|
/** The digests of the environment's ops keys, which the object checks Control's key against (`parseOpsKeyDigests`, ADR-0069). */
|
|
20
20
|
export const FABRIKA_OPS_KEY_DIGESTS = 'FABRIKA_OPS_KEY_DIGESTS'
|
|
21
|
+
/**
|
|
22
|
+
* The installation's own hosts, which a cron job's public egress refuses (ADR-0075): Control's, IAM's, Operations' and
|
|
23
|
+
* every application environment's domain, normalized and joined by `,`. Written only for a contract with such a job.
|
|
24
|
+
*/
|
|
25
|
+
export const FABRIKA_EGRESS_REFUSED_HOSTS = 'FABRIKA_EGRESS_REFUSED_HOSTS'
|
|
21
26
|
/** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
|
|
22
27
|
export const FABRIKA_APPLICATION_OBJECT = 'FABRIKA_APPLICATION_OBJECT'
|
|
23
28
|
/** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
|
|
@@ -54,6 +59,7 @@ export const FRAMEWORK_VARIABLE_NAMES = [
|
|
|
54
59
|
FABRIKA_TOKEN_KEYS,
|
|
55
60
|
FABRIKA_APP_ORIGIN,
|
|
56
61
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
62
|
+
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
57
63
|
FABRIKA_APPLICATION_OBJECT,
|
|
58
64
|
FABRIKA_APPLICATION_OBJECTS,
|
|
59
65
|
] as const
|
package/src/index.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { FABRIKA_CONTRACT_DIGEST } from './endpoint-digest'
|
|
|
3
3
|
import { FABRIKA_IAM_ISSUER } from './environment'
|
|
4
4
|
import {
|
|
5
5
|
FABRIKA_APP_ORIGIN,
|
|
6
|
+
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
6
7
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
7
8
|
FABRIKA_TOKEN_KEYS,
|
|
8
9
|
FRAMEWORK_VARIABLE_PREFIXES,
|
|
@@ -35,6 +36,7 @@ export const MANAGED_VARIABLE_NAMES = [
|
|
|
35
36
|
FABRIKA_APP_ORIGIN,
|
|
36
37
|
FABRIKA_TOKEN_KEYS,
|
|
37
38
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
39
|
+
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
38
40
|
] as const satisfies readonly FrameworkVariableName[]
|
|
39
41
|
|
|
40
42
|
export type ManagedVariableName = (typeof MANAGED_VARIABLE_NAMES)[number]
|
|
@@ -53,6 +55,8 @@ const PUBLIC_VARIABLES: ReadonlySet<string> = new Set<FrameworkVariableName>([
|
|
|
53
55
|
FABRIKA_APP_ORIGIN,
|
|
54
56
|
// SHA-256 of 256-bit random keys: a digest neither is a key nor lets anyone forge one.
|
|
55
57
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
58
|
+
// Host names anyone can look up in DNS.
|
|
59
|
+
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
56
60
|
])
|
|
57
61
|
|
|
58
62
|
const PLATFORM_URL_VARIABLES: ReadonlySet<string> = new Set(PLATFORM_RECEIVERS.map((receiver) => platformTransportVariables(receiver).url))
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// `egress: 'public'`: a cron job that calls the websites its operators name (a crawler, an auditor, a link checker)
|
|
2
|
+
// reaches any public host over HTTPS or HTTP, and never the installation or a private network (ADR-0075). These are the
|
|
3
|
+
// rules a URL alone decides, which the runtime guard and the checker share. The guard adds the installation's own hosts
|
|
4
|
+
// and, where the runtime exposes name resolution, the addresses a name resolves to.
|
|
5
|
+
|
|
6
|
+
/** The declared form of public egress: every public host, over HTTPS or HTTP, on its default port. */
|
|
7
|
+
export const PUBLIC_EGRESS = 'public'
|
|
8
|
+
|
|
9
|
+
export type PublicEgress = typeof PUBLIC_EGRESS
|
|
10
|
+
|
|
11
|
+
/** What a site declares in `egress`: its exact HTTPS origins, sorted, or every public host (a cron job only). */
|
|
12
|
+
export type DeclaredEgress = readonly string[] | PublicEgress
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* The name suffixes public egress refuses, each with every name under it: local and special-use names (RFC 6761,
|
|
16
|
+
* RFC 6762, RFC 8375, RFC 9476), the names private networks conventionally use (`.internal` holds Google's metadata
|
|
17
|
+
* host and Control's own `operations.internal`), and the platform subdomains an installation is served on beside its
|
|
18
|
+
* own domains: Cloudflare's `workers.dev`, where its Workers have their default routes, and Zerops' `zerops.app`, where
|
|
19
|
+
* its proxies, Control and IAM have their subdomains (a namespace proxy's `proxy-…-8080.<region>.zerops.app`), with the
|
|
20
|
+
* `zerops` suffix of a Zerops project's private network. Control knows no list of those subdomains, so every one is
|
|
21
|
+
* refused, another installation's too.
|
|
22
|
+
*/
|
|
23
|
+
export const PUBLIC_EGRESS_REFUSED_SUFFIXES = [
|
|
24
|
+
'localhost',
|
|
25
|
+
'local',
|
|
26
|
+
'internal',
|
|
27
|
+
'intranet',
|
|
28
|
+
'lan',
|
|
29
|
+
'home',
|
|
30
|
+
'corp',
|
|
31
|
+
'private',
|
|
32
|
+
'arpa',
|
|
33
|
+
'test',
|
|
34
|
+
'invalid',
|
|
35
|
+
'example',
|
|
36
|
+
'onion',
|
|
37
|
+
'alt',
|
|
38
|
+
'zerops',
|
|
39
|
+
'zerops.app',
|
|
40
|
+
'workers.dev',
|
|
41
|
+
] as const
|
|
42
|
+
|
|
43
|
+
/** A host name without its trailing dots, lowercased: the form every comparison here uses. */
|
|
44
|
+
export function normalizedHost(hostname: string): string {
|
|
45
|
+
return hostname.toLowerCase().replace(/\.+$/, '')
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const IPV4 = /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Why public egress refuses `url`, or `null` when the URL alone admits it: a scheme other than `https:` and `http:`, a
|
|
52
|
+
* port other than the scheme's default, credentials in the URL, an IP literal, a name of one label, a name under a
|
|
53
|
+
* refused suffix, or one of `refusedHosts` (normalized names). A host it admits may still resolve to a private address,
|
|
54
|
+
* which only a runtime that resolves names refuses.
|
|
55
|
+
*/
|
|
56
|
+
export function publicEgressRefusal(url: URL, refusedHosts: ReadonlySet<string> = new Set()): string | null {
|
|
57
|
+
if (url.protocol !== 'https:' && url.protocol !== 'http:') return `${url.protocol} is not https: or http:`
|
|
58
|
+
if (url.port !== '') return `port ${url.port} is not the default port of ${url.protocol}`
|
|
59
|
+
if (url.username !== '' || url.password !== '') return 'the URL carries credentials, which a public request never sends'
|
|
60
|
+
const host = normalizedHost(url.hostname)
|
|
61
|
+
if (host.startsWith('[') || IPV4.test(host)) return `${host} is an IP address, not a public host name`
|
|
62
|
+
if (!host.includes('.')) return `${host} is a name of one label, as an internal service or a local machine has`
|
|
63
|
+
if (host.split('.').some((label) => label === '')) return `${host} has an empty label`
|
|
64
|
+
const suffix = PUBLIC_EGRESS_REFUSED_SUFFIXES.find((refused) => host === refused || host.endsWith(`.${refused}`))
|
|
65
|
+
if (suffix !== undefined) return `${host} is under .${suffix}, which names no public website`
|
|
66
|
+
if (refusedHosts.has(host)) return `${host} is a host of this installation`
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Whether `address` (an IPv4 or IPv6 address, as a resolver answers it) is a public unicast address: not private,
|
|
72
|
+
* loopback, link-local (which holds the cloud metadata address 169.254.169.254), shared, multicast, reserved,
|
|
73
|
+
* documentation, or an IPv6 form that embeds or tunnels an IPv4 address it cannot vouch for. A text that is no address
|
|
74
|
+
* is not public.
|
|
75
|
+
*/
|
|
76
|
+
export function isPublicAddress(address: string): boolean {
|
|
77
|
+
const v4 = ipv4Octets(address)
|
|
78
|
+
if (v4 !== null) return isPublicIpv4(v4)
|
|
79
|
+
const words = ipv6Words(address)
|
|
80
|
+
if (words === null) return false
|
|
81
|
+
const [w0 = 0, w1 = 0, w2 = 0, w3 = 0, w4 = 0, w5 = 0, w6 = 0, w7 = 0] = words
|
|
82
|
+
// ::ffff:a.b.c.d, an IPv4 address in IPv6 form, is that IPv4 address.
|
|
83
|
+
if (w0 === 0 && w1 === 0 && w2 === 0 && w3 === 0 && w4 === 0 && w5 === 0xffff) {
|
|
84
|
+
return isPublicIpv4([w6 >> 8, w6 & 0xff, w7 >> 8, w7 & 0xff])
|
|
85
|
+
}
|
|
86
|
+
// Only global unicast (2000::/3) is public; every other block is local, multicast, reserved or a translation prefix.
|
|
87
|
+
if ((w0 & 0xe000) !== 0x2000) return false
|
|
88
|
+
// 2001::/32 Teredo, 2001:10::/28 ORCHID, 2001:20::/28 ORCHIDv2, 2001:db8::/32 documentation, 2002::/16 6to4.
|
|
89
|
+
if (w0 === 0x2001 && (w1 === 0 || (w1 & 0xfff0) === 0x10 || (w1 & 0xfff0) === 0x20 || w1 === 0x0db8)) return false
|
|
90
|
+
if (w0 === 0x2002) return false
|
|
91
|
+
// 3fff::/20 documentation (RFC 9637).
|
|
92
|
+
if (w0 === 0x3fff && (w1 & 0xf000) === 0) return false
|
|
93
|
+
return true
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** The non-public IPv4 blocks, each as its network (a 32-bit number) and its prefix length. */
|
|
97
|
+
const IPV4_REFUSED: readonly (readonly [number, number])[] = [
|
|
98
|
+
[0x00000000, 8], // 0.0.0.0/8 this network
|
|
99
|
+
[0x0a000000, 8], // 10.0.0.0/8 private
|
|
100
|
+
[0x64400000, 10], // 100.64.0.0/10 shared address space
|
|
101
|
+
[0x7f000000, 8], // 127.0.0.0/8 loopback
|
|
102
|
+
[0xa9fe0000, 16], // 169.254.0.0/16 link-local, the cloud metadata address
|
|
103
|
+
[0xa83f8110, 32], // 168.63.129.16 Azure's host endpoint (metadata, DNS), a public address answered inside the VM
|
|
104
|
+
[0xac100000, 12], // 172.16.0.0/12 private
|
|
105
|
+
[0xc0000000, 24], // 192.0.0.0/24 IETF protocol assignments
|
|
106
|
+
[0xc0000200, 24], // 192.0.2.0/24 documentation
|
|
107
|
+
[0xc0586300, 24], // 192.88.99.0/24 6to4 relay anycast
|
|
108
|
+
[0xc0a80000, 16], // 192.168.0.0/16 private
|
|
109
|
+
[0xc6120000, 15], // 198.18.0.0/15 benchmarking
|
|
110
|
+
[0xc6336400, 24], // 198.51.100.0/24 documentation
|
|
111
|
+
[0xcb007100, 24], // 203.0.113.0/24 documentation
|
|
112
|
+
[0xe0000000, 4], // 224.0.0.0/4 multicast
|
|
113
|
+
[0xf0000000, 4], // 240.0.0.0/4 reserved, broadcast
|
|
114
|
+
]
|
|
115
|
+
|
|
116
|
+
function isPublicIpv4(octets: readonly number[]): boolean {
|
|
117
|
+
const [a = 0, b = 0, c = 0, d = 0] = octets
|
|
118
|
+
const value = ((a << 24) >>> 0) + (b << 16) + (c << 8) + d
|
|
119
|
+
return !IPV4_REFUSED.some(([network, prefix]) => {
|
|
120
|
+
const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0
|
|
121
|
+
return ((value & mask) >>> 0) === network
|
|
122
|
+
})
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
function ipv4Octets(text: string): number[] | null {
|
|
126
|
+
if (!IPV4.test(text)) return null
|
|
127
|
+
const octets = text.split('.').map((part) => Number.parseInt(part, 10))
|
|
128
|
+
return octets.every((octet) => octet >= 0 && octet <= 255) ? octets : null
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
const HEX_WORD = /^[0-9a-f]{1,4}$/i
|
|
132
|
+
|
|
133
|
+
/** The eight 16-bit words of an IPv6 address (brackets and a zone allowed, an embedded IPv4 tail too), or `null`. */
|
|
134
|
+
function ipv6Words(text: string): number[] | null {
|
|
135
|
+
let rest = text.startsWith('[') && text.endsWith(']') ? text.slice(1, -1) : text
|
|
136
|
+
const zone = rest.indexOf('%')
|
|
137
|
+
if (zone !== -1) rest = rest.slice(0, zone)
|
|
138
|
+
if (!rest.includes(':')) return null
|
|
139
|
+
const tailAt = rest.lastIndexOf(':')
|
|
140
|
+
const tail = ipv4Octets(rest.slice(tailAt + 1))
|
|
141
|
+
const embedded: number[] = []
|
|
142
|
+
if (tail !== null) {
|
|
143
|
+
const [a = 0, b = 0, c = 0, d = 0] = tail
|
|
144
|
+
embedded.push((a << 8) | b, (c << 8) | d)
|
|
145
|
+
rest = rest.slice(0, tailAt + 1) + '0'
|
|
146
|
+
}
|
|
147
|
+
const halves = rest.split('::')
|
|
148
|
+
if (halves.length > 2) return null
|
|
149
|
+
const parse = (half: string | undefined): number[] | null => {
|
|
150
|
+
if (half === undefined || half === '') return []
|
|
151
|
+
const parts = half.split(':')
|
|
152
|
+
if (!parts.every((part) => HEX_WORD.test(part))) return null
|
|
153
|
+
return parts.map((part) => Number.parseInt(part, 16))
|
|
154
|
+
}
|
|
155
|
+
const head = parse(halves[0])
|
|
156
|
+
const back = parse(halves[1])
|
|
157
|
+
if (head === null || back === null) return null
|
|
158
|
+
if (tail !== null) {
|
|
159
|
+
// The placeholder word stands for the two words of the IPv4 tail.
|
|
160
|
+
const last = halves.length === 2 ? back : head
|
|
161
|
+
last.pop()
|
|
162
|
+
last.push(...embedded)
|
|
163
|
+
}
|
|
164
|
+
const missing = 8 - head.length - back.length
|
|
165
|
+
if (halves.length === 1) return missing === 0 ? head : null
|
|
166
|
+
if (missing < 1) return null
|
|
167
|
+
return [...head, ...Array.from({ length: missing }, () => 0), ...back]
|
|
168
|
+
}
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,57 @@ export interface Scope {
|
|
|
45
45
|
value: string
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
/**
|
|
49
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
50
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
51
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
52
|
+
*/
|
|
53
|
+
export const RELATION_SCOPE_TYPE = '~rel'
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The pseudo-scope of a relation entry held inside one node: `{ type: '~relin', value: '<relation>:<dimension>:<node>' }`
|
|
57
|
+
* means the action is held where a row names the principal in that relation, on rows that lie inside `node` of
|
|
58
|
+
* `dimension`. IAM gives it a grant at that node of a role with `via`. Its own type, never `~rel`: a release that reads
|
|
59
|
+
* `~rel` as "the relation anywhere" ignores this one and reaches less.
|
|
60
|
+
*/
|
|
61
|
+
export const RELATION_INSIDE_SCOPE_TYPE = '~relin'
|
|
62
|
+
|
|
63
|
+
/** A relation held inside one node of a dimension, as a `~relin` entry names it. */
|
|
64
|
+
export interface RelationInside {
|
|
65
|
+
readonly relation: string
|
|
66
|
+
readonly dimension: string
|
|
67
|
+
readonly node: string
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The `~relin` scope of `relation` inside `node` of `dimension`. A relation or dimension name never holds `:` (the
|
|
72
|
+
* contract's names do not), so the node, last, is read back verbatim, colons included; a name that holds one is refused.
|
|
73
|
+
*/
|
|
74
|
+
export function relationInsideScope(inside: RelationInside): Scope {
|
|
75
|
+
if (inside.relation === '' || inside.dimension === '' || inside.relation.includes(':') || inside.dimension.includes(':')) {
|
|
76
|
+
throw new Error('a relation held inside a node names a relation and a dimension without ":"')
|
|
77
|
+
}
|
|
78
|
+
return { type: RELATION_INSIDE_SCOPE_TYPE, value: `${inside.relation}:${inside.dimension}:${inside.node}` }
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The relation, dimension and node of a `~relin` scope, or null for any other scope or a malformed value. */
|
|
82
|
+
export function parseRelationInside(scope: Scope): RelationInside | null {
|
|
83
|
+
if (scope.type !== RELATION_INSIDE_SCOPE_TYPE) {
|
|
84
|
+
return null
|
|
85
|
+
}
|
|
86
|
+
const first = scope.value.indexOf(':')
|
|
87
|
+
const second = first === -1 ? -1 : scope.value.indexOf(':', first + 1)
|
|
88
|
+
if (first <= 0 || second <= first + 1 || second === scope.value.length - 1) {
|
|
89
|
+
return null
|
|
90
|
+
}
|
|
91
|
+
return { relation: scope.value.slice(0, first), dimension: scope.value.slice(first + 1, second), node: scope.value.slice(second + 1) }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
95
|
+
export function isReservedScopeType(type: string): boolean {
|
|
96
|
+
return type.startsWith('~')
|
|
97
|
+
}
|
|
98
|
+
|
|
48
99
|
export interface PermissionEntry {
|
|
49
100
|
action: string
|
|
50
101
|
/** null = global / all scopes */
|
|
@@ -80,6 +131,13 @@ export interface RoleDef {
|
|
|
80
131
|
member?: { scope: string; assignableBy?: string[] }
|
|
81
132
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
82
133
|
external?: true
|
|
134
|
+
/**
|
|
135
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
136
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation. A
|
|
137
|
+
* grant at a node carries `~relin` instead (`relationInsideScope`): the relation holds only inside that node. Only an
|
|
138
|
+
* internal role declares it.
|
|
139
|
+
*/
|
|
140
|
+
via?: Record<string, string[]>
|
|
83
141
|
}
|
|
84
142
|
|
|
85
143
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BodyAdmission, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
1
|
+
import type { BodyAdmission, ConditionArtifact, ContractArtifact, OutputShape, SchemaShape, TableActionArtifact } from './contract';
|
|
2
2
|
/**
|
|
3
3
|
* The artifact with every array whose order carries no meaning sorted: endpoints by id, and every list of names.
|
|
4
4
|
* Tuple items and union options keep their order, because it changes what a schema admits. Object keys are left
|
|
@@ -11,6 +11,11 @@ export declare function canonicalArtifactJson(artifact: ContractArtifact): strin
|
|
|
11
11
|
export declare function canonicalJson(value: unknown): string;
|
|
12
12
|
/** Each action of one table operation, `[]` for none: how a reader of the artifact reads `actions.read` and the others. */
|
|
13
13
|
export declare function tableActions(actions: TableActionArtifact | null): readonly string[];
|
|
14
|
+
/**
|
|
15
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
16
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
17
|
+
*/
|
|
18
|
+
export declare function canonicalCondition(condition: ConditionArtifact): ConditionArtifact;
|
|
14
19
|
/** A body admission with its content types sorted. */
|
|
15
20
|
export declare function canonicalAdmission(admission: BodyAdmission): BodyAdmission;
|
|
16
21
|
/** An output shape: an attachment keeps its column order, which is the file's; each column's shape is canonical. */
|
package/types/src/contract.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Locale } from './locale';
|
|
2
2
|
import type { MailTemplates } from './mail';
|
|
3
|
+
import type { DeclaredEgress } from './public-egress';
|
|
3
4
|
import type { TerminalArtifact } from './terminal';
|
|
4
5
|
/**
|
|
5
6
|
* The artifact format this release writes. A release that changes the artifact raises it, and Control upcasts every
|
|
@@ -19,6 +20,11 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
19
20
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
20
21
|
readonly actions: Readonly<Record<string, string>>;
|
|
21
22
|
readonly roles: Readonly<Record<string, RoleArtifact>>;
|
|
23
|
+
/**
|
|
24
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
25
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
26
|
+
*/
|
|
27
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>;
|
|
22
28
|
readonly mounts: Readonly<Record<string, MountArtifact>>;
|
|
23
29
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>;
|
|
24
30
|
/**
|
|
@@ -436,6 +442,15 @@ export interface RoleArtifact {
|
|
|
436
442
|
} | null;
|
|
437
443
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
438
444
|
readonly external?: true;
|
|
445
|
+
/**
|
|
446
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
447
|
+
* Absent unless declared, so digests stay.
|
|
448
|
+
*/
|
|
449
|
+
readonly via?: Readonly<Record<string, readonly string[]>>;
|
|
450
|
+
}
|
|
451
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
452
|
+
export interface RelationArtifact {
|
|
453
|
+
readonly dimension: string;
|
|
439
454
|
}
|
|
440
455
|
export type MountArtifact = RpcMountArtifact | LinkMountArtifact | SpaMountArtifact | HealthMountArtifact | FormMountArtifact | WebhookMountArtifact;
|
|
441
456
|
export interface RpcMountArtifact {
|
|
@@ -703,9 +718,11 @@ export interface DeclaredReach {
|
|
|
703
718
|
readonly signs?: readonly string[];
|
|
704
719
|
/**
|
|
705
720
|
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
706
|
-
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job.
|
|
721
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Or `'public'` (a cron job only): every public
|
|
722
|
+
* host over HTTPS or HTTP, never the installation or a private network (ADR-0075). Absent unless declared, so the
|
|
723
|
+
* digest stays.
|
|
707
724
|
*/
|
|
708
|
-
readonly egress?:
|
|
725
|
+
readonly egress?: DeclaredEgress;
|
|
709
726
|
/**
|
|
710
727
|
* A public procedure's workload actions, sorted: all its handler holds, through the key Control issues for the
|
|
711
728
|
* endpoint (`contractWorkloads`). Present only on a public procedure's entry, so every other digest stays.
|
|
@@ -777,6 +794,128 @@ export interface TablePolicyArtifact {
|
|
|
777
794
|
* Absent for a table, so the digest stays.
|
|
778
795
|
*/
|
|
779
796
|
readonly view?: true;
|
|
797
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
798
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>;
|
|
799
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
800
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>;
|
|
801
|
+
/**
|
|
802
|
+
* Relation → action → the condition a row the relation reaches must meet for it; it narrows that relation's reach only.
|
|
803
|
+
* Absent unless declared, so the digest stays. A reader that ignores it reaches more: Control refuses to publish it to
|
|
804
|
+
* an application pinned below the release that enforces it.
|
|
805
|
+
*/
|
|
806
|
+
readonly relationWhen?: Readonly<Record<string, Readonly<Record<string, ConditionArtifact>>>>;
|
|
807
|
+
/**
|
|
808
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
809
|
+
* A reader that ignores it reaches less, never more.
|
|
810
|
+
*/
|
|
811
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>;
|
|
812
|
+
/**
|
|
813
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
814
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
815
|
+
*/
|
|
816
|
+
readonly readThrough?: Readonly<Record<string, string>>;
|
|
817
|
+
/**
|
|
818
|
+
* Dimension of `readThrough` → the actions a `Ref` held through that path holds, writes included; whoever inserts the
|
|
819
|
+
* path's column must hold each at the node it names. Absent unless declared, so the digest stays. A reader that
|
|
820
|
+
* ignores it reaches less, never more.
|
|
821
|
+
*/
|
|
822
|
+
readonly writeThrough?: Readonly<Record<string, readonly string[]>>;
|
|
823
|
+
/**
|
|
824
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
825
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
826
|
+
*/
|
|
827
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>;
|
|
828
|
+
/**
|
|
829
|
+
* Relation → the access view that lists the rows it reaches (ADR-0076). Absent unless declared, so the digest stays.
|
|
830
|
+
* A reader that ignores it reaches less, never more.
|
|
831
|
+
*/
|
|
832
|
+
readonly access?: Readonly<Record<string, AccessArtifact>>;
|
|
833
|
+
}
|
|
834
|
+
/** An access view: its `row` column names the table's key; `principal` is compared to the caller, `member` to its nodes. */
|
|
835
|
+
export interface AccessArtifact {
|
|
836
|
+
readonly view: string;
|
|
837
|
+
readonly row: string;
|
|
838
|
+
readonly principal: string | null;
|
|
839
|
+
readonly member: string | null;
|
|
840
|
+
}
|
|
841
|
+
/**
|
|
842
|
+
* A row reveals its node in `to` for `actions` to a grant of them at the row's own node, or at the node its path to the
|
|
843
|
+
* key's dimension names, while `when` admits the row.
|
|
844
|
+
*/
|
|
845
|
+
export interface MemberRevealsArtifact {
|
|
846
|
+
readonly to: string;
|
|
847
|
+
readonly actions: readonly string[];
|
|
848
|
+
readonly when?: ConditionArtifact;
|
|
849
|
+
/**
|
|
850
|
+
* Through a path, on a table with an insert: the writer picks the node, and `self` lets it pick one where it holds a
|
|
851
|
+
* grant the reveal counts. Absent otherwise; only a reader that refuses a path's key reads it.
|
|
852
|
+
*/
|
|
853
|
+
readonly assign?: {
|
|
854
|
+
readonly self: boolean;
|
|
855
|
+
};
|
|
856
|
+
}
|
|
857
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
858
|
+
export interface RevealsArtifact {
|
|
859
|
+
readonly to: string;
|
|
860
|
+
readonly actions: readonly string[];
|
|
861
|
+
readonly when?: ConditionArtifact;
|
|
862
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
863
|
+
readonly assign?: {
|
|
864
|
+
readonly self: boolean;
|
|
865
|
+
};
|
|
866
|
+
}
|
|
867
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
868
|
+
export interface ConfersArtifact {
|
|
869
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
870
|
+
readonly principal: string;
|
|
871
|
+
readonly node: string;
|
|
872
|
+
readonly expires: string | null;
|
|
873
|
+
readonly when?: ConditionArtifact;
|
|
874
|
+
readonly assign: {
|
|
875
|
+
readonly maxDays: number | null;
|
|
876
|
+
readonly self: boolean;
|
|
877
|
+
} | null;
|
|
878
|
+
}
|
|
879
|
+
/**
|
|
880
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
881
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
882
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
883
|
+
*/
|
|
884
|
+
export type ConditionArtifact = {
|
|
885
|
+
readonly allOf: readonly ConditionArtifact[];
|
|
886
|
+
} | {
|
|
887
|
+
readonly anyOf: readonly ConditionArtifact[];
|
|
888
|
+
} | {
|
|
889
|
+
readonly not: ConditionArtifact;
|
|
890
|
+
} | RowsTestArtifact | {
|
|
891
|
+
readonly [path: string]: ColumnTestArtifact | RowsTestArtifact;
|
|
892
|
+
};
|
|
893
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
894
|
+
export type RowsTestArtifact = {
|
|
895
|
+
readonly some: Readonly<Record<string, ConditionArtifact>>;
|
|
896
|
+
} | {
|
|
897
|
+
readonly none: Readonly<Record<string, ConditionArtifact>>;
|
|
898
|
+
};
|
|
899
|
+
export type ConditionLiteralArtifact = string | number | boolean;
|
|
900
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
901
|
+
export interface ColumnTestArtifact {
|
|
902
|
+
readonly eq?: ConditionLiteralArtifact;
|
|
903
|
+
readonly notEq?: ConditionLiteralArtifact;
|
|
904
|
+
readonly in?: readonly ConditionLiteralArtifact[];
|
|
905
|
+
readonly notIn?: readonly ConditionLiteralArtifact[];
|
|
906
|
+
readonly isNull?: boolean;
|
|
907
|
+
readonly lt?: ConditionLiteralArtifact | {
|
|
908
|
+
readonly now: true;
|
|
909
|
+
};
|
|
910
|
+
readonly lte?: ConditionLiteralArtifact | {
|
|
911
|
+
readonly now: true;
|
|
912
|
+
};
|
|
913
|
+
readonly gt?: ConditionLiteralArtifact | {
|
|
914
|
+
readonly now: true;
|
|
915
|
+
};
|
|
916
|
+
readonly gte?: ConditionLiteralArtifact | {
|
|
917
|
+
readonly now: true;
|
|
918
|
+
};
|
|
780
919
|
}
|
|
781
920
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
|
782
921
|
export interface ColumnPolicyArtifact {
|
|
@@ -12,6 +12,11 @@ export declare const FABRIKA_TOKEN_KEYS = "FABRIKA_TOKEN_KEYS";
|
|
|
12
12
|
export declare const FABRIKA_APP_ORIGIN = "FABRIKA_APP_ORIGIN";
|
|
13
13
|
/** The digests of the environment's ops keys, which the object checks Control's key against (`parseOpsKeyDigests`, ADR-0069). */
|
|
14
14
|
export declare const FABRIKA_OPS_KEY_DIGESTS = "FABRIKA_OPS_KEY_DIGESTS";
|
|
15
|
+
/**
|
|
16
|
+
* The installation's own hosts, which a cron job's public egress refuses (ADR-0075): Control's, IAM's, Operations' and
|
|
17
|
+
* every application environment's domain, normalized and joined by `,`. Written only for a contract with such a job.
|
|
18
|
+
*/
|
|
19
|
+
export declare const FABRIKA_EGRESS_REFUSED_HOSTS = "FABRIKA_EGRESS_REFUSED_HOSTS";
|
|
15
20
|
/** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
|
|
16
21
|
export declare const FABRIKA_APPLICATION_OBJECT = "FABRIKA_APPLICATION_OBJECT";
|
|
17
22
|
/** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
|
|
@@ -22,7 +27,7 @@ export declare const FABRIKA_APPLICATION_OBJECTS = "FABRIKA_APPLICATION_OBJECTS"
|
|
|
22
27
|
* application variable or secret under one of them, and so does every provider, for every surface that writes one.
|
|
23
28
|
* A work unit that gives an application a new credential adds its name here.
|
|
24
29
|
*/
|
|
25
|
-
export declare const FRAMEWORK_VARIABLE_NAMES: readonly ["FABRIKA_RELEASE", "FABRIKA_CONTRACT_DIGEST", "FABRIKA_IAM_ISSUER", "FABRIKA_IAM_APP_ID", "FABRIKA_OPERATIONS_DSN", "FABRIKA_APP_ID", "FABRIKA_ENVIRONMENT", "FABRIKA_SERVICE_KEY", "FABRIKA_APP_DATABASE_URL", "FABRIKA_APP_RUNTIME_DATABASE_URL", "FABRIKA_APP_DATABASE_CONNECTIONS", "FABRIKA_APP_STORAGE_ENDPOINT", "FABRIKA_APP_STORAGE_BUCKET", "FABRIKA_APP_STORAGE_ACCESS_KEY_ID", "FABRIKA_APP_STORAGE_SECRET_ACCESS_KEY", "FABRIKA_STORAGE_PROVENANCE", "FABRIKA_PROXY_SECRET", "FABRIKA_IAM_RPC_URL", "FABRIKA_IAM_RPC_KEY", "FABRIKA_SOURCE_MAP_UPLOAD", "FABRIKA_SOURCE_MAP_UPLOAD_KEY", "FABRIKA_TOKEN_KEYS", "FABRIKA_APP_ORIGIN", "FABRIKA_OPS_KEY_DIGESTS", "FABRIKA_APPLICATION_OBJECT", "FABRIKA_APPLICATION_OBJECTS"];
|
|
30
|
+
export declare const FRAMEWORK_VARIABLE_NAMES: readonly ["FABRIKA_RELEASE", "FABRIKA_CONTRACT_DIGEST", "FABRIKA_IAM_ISSUER", "FABRIKA_IAM_APP_ID", "FABRIKA_OPERATIONS_DSN", "FABRIKA_APP_ID", "FABRIKA_ENVIRONMENT", "FABRIKA_SERVICE_KEY", "FABRIKA_APP_DATABASE_URL", "FABRIKA_APP_RUNTIME_DATABASE_URL", "FABRIKA_APP_DATABASE_CONNECTIONS", "FABRIKA_APP_STORAGE_ENDPOINT", "FABRIKA_APP_STORAGE_BUCKET", "FABRIKA_APP_STORAGE_ACCESS_KEY_ID", "FABRIKA_APP_STORAGE_SECRET_ACCESS_KEY", "FABRIKA_STORAGE_PROVENANCE", "FABRIKA_PROXY_SECRET", "FABRIKA_IAM_RPC_URL", "FABRIKA_IAM_RPC_KEY", "FABRIKA_SOURCE_MAP_UPLOAD", "FABRIKA_SOURCE_MAP_UPLOAD_KEY", "FABRIKA_TOKEN_KEYS", "FABRIKA_APP_ORIGIN", "FABRIKA_OPS_KEY_DIGESTS", "FABRIKA_EGRESS_REFUSED_HOSTS", "FABRIKA_APPLICATION_OBJECT", "FABRIKA_APPLICATION_OBJECTS"];
|
|
26
31
|
export type FrameworkVariableName = (typeof FRAMEWORK_VARIABLE_NAMES)[number];
|
|
27
32
|
/**
|
|
28
33
|
* The name families only the platform writes: one variable per job, webhook or public procedure, named after it
|
package/types/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* The framework names Control hands every deploy, each with a value or `null` (the deploy removes it). Beside them, a
|
|
3
3
|
* deploy carries the families of `FRAMEWORK_VARIABLE_PREFIXES`, one variable per workload, import or receiver.
|
|
4
4
|
*/
|
|
5
|
-
export declare const MANAGED_VARIABLE_NAMES: readonly ["FABRIKA_RELEASE", "FABRIKA_OPERATIONS_DSN", "FABRIKA_IAM_ISSUER", "FABRIKA_IAM_APP_ID", "FABRIKA_APP_ID", "FABRIKA_ENVIRONMENT", "FABRIKA_SERVICE_KEY", "FABRIKA_PROXY_SECRET", "FABRIKA_IAM_RPC_URL", "FABRIKA_IAM_RPC_KEY", "FABRIKA_APP_ORIGIN", "FABRIKA_TOKEN_KEYS", "FABRIKA_OPS_KEY_DIGESTS"];
|
|
5
|
+
export declare const MANAGED_VARIABLE_NAMES: readonly ["FABRIKA_RELEASE", "FABRIKA_OPERATIONS_DSN", "FABRIKA_IAM_ISSUER", "FABRIKA_IAM_APP_ID", "FABRIKA_APP_ID", "FABRIKA_ENVIRONMENT", "FABRIKA_SERVICE_KEY", "FABRIKA_PROXY_SECRET", "FABRIKA_IAM_RPC_URL", "FABRIKA_IAM_RPC_KEY", "FABRIKA_APP_ORIGIN", "FABRIKA_TOKEN_KEYS", "FABRIKA_OPS_KEY_DIGESTS", "FABRIKA_EGRESS_REFUSED_HOSTS"];
|
|
6
6
|
export type ManagedVariableName = (typeof MANAGED_VARIABLE_NAMES)[number];
|
|
7
7
|
/**
|
|
8
8
|
* Whether a managed variable carries a credential, so a provider writes it as a secret and never reads it back. Fail
|
|
@@ -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;
|
package/types/src/types.d.ts
CHANGED
|
@@ -34,6 +34,34 @@ export interface Scope {
|
|
|
34
34
|
type: string;
|
|
35
35
|
value: string;
|
|
36
36
|
}
|
|
37
|
+
/**
|
|
38
|
+
* The pseudo-scope of a relation entry: `{ type: '~rel', value: <relation> }` means the action is held where a row of
|
|
39
|
+
* the application names the principal in that relation. No dimension may start with `~`, so no reader that compares
|
|
40
|
+
* scopes by `(type, value)` mistakes one for a dimension value, and none resolves it but the framework.
|
|
41
|
+
*/
|
|
42
|
+
export declare const RELATION_SCOPE_TYPE = "~rel";
|
|
43
|
+
/**
|
|
44
|
+
* The pseudo-scope of a relation entry held inside one node: `{ type: '~relin', value: '<relation>:<dimension>:<node>' }`
|
|
45
|
+
* means the action is held where a row names the principal in that relation, on rows that lie inside `node` of
|
|
46
|
+
* `dimension`. IAM gives it a grant at that node of a role with `via`. Its own type, never `~rel`: a release that reads
|
|
47
|
+
* `~rel` as "the relation anywhere" ignores this one and reaches less.
|
|
48
|
+
*/
|
|
49
|
+
export declare const RELATION_INSIDE_SCOPE_TYPE = "~relin";
|
|
50
|
+
/** A relation held inside one node of a dimension, as a `~relin` entry names it. */
|
|
51
|
+
export interface RelationInside {
|
|
52
|
+
readonly relation: string;
|
|
53
|
+
readonly dimension: string;
|
|
54
|
+
readonly node: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* The `~relin` scope of `relation` inside `node` of `dimension`. A relation or dimension name never holds `:` (the
|
|
58
|
+
* contract's names do not), so the node, last, is read back verbatim, colons included; a name that holds one is refused.
|
|
59
|
+
*/
|
|
60
|
+
export declare function relationInsideScope(inside: RelationInside): Scope;
|
|
61
|
+
/** The relation, dimension and node of a `~relin` scope, or null for any other scope or a malformed value. */
|
|
62
|
+
export declare function parseRelationInside(scope: Scope): RelationInside | null;
|
|
63
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
64
|
+
export declare function isReservedScopeType(type: string): boolean;
|
|
37
65
|
export interface PermissionEntry {
|
|
38
66
|
action: string;
|
|
39
67
|
/** null = global / all scopes */
|
|
@@ -70,6 +98,13 @@ export interface RoleDef {
|
|
|
70
98
|
};
|
|
71
99
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
72
100
|
external?: true;
|
|
101
|
+
/**
|
|
102
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
103
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation. A
|
|
104
|
+
* grant at a node carries `~relin` instead (`relationInsideScope`): the relation holds only inside that node. Only an
|
|
105
|
+
* internal role declares it.
|
|
106
|
+
*/
|
|
107
|
+
via?: Record<string, string[]>;
|
|
73
108
|
}
|
|
74
109
|
/**
|
|
75
110
|
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|