@fabrika/auth-core 0.9.0-dev.11 → 0.9.0-dev.13
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 +2 -2
- package/src/canonical-path.ts +18 -0
- package/src/client-address.ts +74 -0
- package/src/contract-canonical.ts +109 -0
- package/src/contract.ts +133 -7
- package/src/egress.ts +97 -0
- package/src/index.ts +2 -0
- package/src/types.ts +18 -0
- package/src/wire.ts +2 -1
- 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 +6 -1
- package/types/src/contract.d.ts +121 -6
- package/types/src/egress.d.ts +27 -0
- package/types/src/index.d.ts +2 -0
- package/types/src/types.d.ts +14 -0
- package/types/src/wire.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/auth-core",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"typecheck": "
|
|
26
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
27
27
|
"test": "bun test"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/canonical-path.ts
CHANGED
|
@@ -50,6 +50,24 @@ export function rawRequestTarget(url: string): RequestTarget {
|
|
|
50
50
|
return target.pathname === '' ? { pathname: '/', search: target.search } : target
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path of that origin: the one rule for a
|
|
55
|
+
* redirect or return target that must stay on its own origin. A leading `//` or any `\` would make a browser read a
|
|
56
|
+
* host from it, and a browser strips a tab or newline before parsing, so no control character is admitted.
|
|
57
|
+
*/
|
|
58
|
+
export function sameOriginTarget(origin: string, path: string): string | null {
|
|
59
|
+
if (!path.startsWith('/') || path.startsWith('//') || path.includes('\\') || [...path].some(isControl)) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
const target = new URL(path, origin)
|
|
63
|
+
return target.origin === origin ? target.toString() : null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isControl(character: string): boolean {
|
|
67
|
+
const code = character.charCodeAt(0)
|
|
68
|
+
return code < 0x20 || code === 0x7f
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
/** A segment one reader decodes and another refuses would route differently, so a malformed escape is refused. */
|
|
54
72
|
function isDecodable(segment: string): boolean {
|
|
55
73
|
try {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// The client a per-client abuse bucket counts, derived from the address an ingress wrote. IAM and the application
|
|
2
|
+
// runtime both key on it, so one client is one bucket on either side.
|
|
3
|
+
|
|
4
|
+
/** Longest header value read; an IPv6 address with a zone id fits with room to spare. */
|
|
5
|
+
const MAX_ADDRESS_LENGTH = 64
|
|
6
|
+
|
|
7
|
+
const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/
|
|
8
|
+
const HEXTET = /^[0-9a-f]{1,4}$/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The eight groups of an IPv6 address, or `null`. An embedded IPv4 tail (`::ffff:192.0.2.1`) counts as two groups,
|
|
12
|
+
* and a zone id (`%eth0`) is dropped.
|
|
13
|
+
*/
|
|
14
|
+
function ipv6Groups(text: string): number[] | null {
|
|
15
|
+
const address = text.split('%')[0] ?? ''
|
|
16
|
+
const halves = address.split('::')
|
|
17
|
+
if (halves.length > 2) {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
const groupsOf = (half: string): number[] | null => {
|
|
21
|
+
if (half === '') {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
const groups: number[] = []
|
|
25
|
+
const parts = half.split(':')
|
|
26
|
+
for (const [index, part] of parts.entries()) {
|
|
27
|
+
if (index === parts.length - 1 && IPV4.test(part)) {
|
|
28
|
+
const [a = 0, b = 0, c = 0, d = 0] = part.split('.').map(Number)
|
|
29
|
+
groups.push(a * 256 + b, c * 256 + d)
|
|
30
|
+
} else if (HEXTET.test(part)) {
|
|
31
|
+
groups.push(Number.parseInt(part, 16))
|
|
32
|
+
} else {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return groups
|
|
37
|
+
}
|
|
38
|
+
const head = groupsOf(halves[0] ?? '')
|
|
39
|
+
const tail = halves.length === 2 ? groupsOf(halves[1] ?? '') : []
|
|
40
|
+
if (head === null || tail === null) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (halves.length === 1) {
|
|
44
|
+
return head.length === 8 ? head : null
|
|
45
|
+
}
|
|
46
|
+
const missing = 8 - head.length - tail.length
|
|
47
|
+
return missing < 1 ? null : [...head, ...Array.from({ length: missing }, () => 0), ...tail]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The client a client-address header value counts as: an IPv4 address, or an IPv6 address's /64 (one subscriber's
|
|
52
|
+
* prefix, of which it may hold every address); an IPv4-mapped IPv6 address counts as its IPv4 address. Only the first
|
|
53
|
+
* value counts, so a caller that appends a second copy cannot change the key. `null` when the value is absent or no
|
|
54
|
+
* IP address.
|
|
55
|
+
*/
|
|
56
|
+
export function clientAddressKey(header: string | null): string | null {
|
|
57
|
+
const value = (header ?? '').split(',')[0]?.trim().toLowerCase() ?? ''
|
|
58
|
+
if (value === '' || value.length > MAX_ADDRESS_LENGTH) {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
if (IPV4.test(value)) {
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
const groups = ipv6Groups(value.startsWith('[') && value.endsWith(']') ? value.slice(1, -1) : value)
|
|
65
|
+
if (groups === null) {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
const mapped = groups.slice(0, 5).every((group) => group === 0) && groups[5] === 0xffff
|
|
69
|
+
if (mapped) {
|
|
70
|
+
const [high = 0, low = 0] = groups.slice(6)
|
|
71
|
+
return [high >> 8, high & 0xff, low >> 8, low & 0xff].join('.')
|
|
72
|
+
}
|
|
73
|
+
return `${groups.slice(0, 4).map((group) => group.toString(16)).join(':')}::/64`
|
|
74
|
+
}
|
|
@@ -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,
|
|
@@ -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,109 @@ 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.confers === undefined ? {} : { confers: mapValues(table.confers, canonicalConfers) }),
|
|
165
|
+
...(table.reveals === undefined ? {} : { reveals: mapValues(table.reveals, canonicalReveals) }),
|
|
166
|
+
...(table.memberReveals === undefined ? {} : { memberReveals: mapValues(table.memberReveals, canonicalMemberReveals) }),
|
|
154
167
|
}
|
|
155
168
|
}
|
|
156
169
|
|
|
170
|
+
function canonicalConfers(confers: ConfersArtifact): ConfersArtifact {
|
|
171
|
+
return confers.when === undefined ? confers : { ...confers, when: canonicalCondition(confers.when) }
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function canonicalReveals(reveals: RevealsArtifact): RevealsArtifact {
|
|
175
|
+
return {
|
|
176
|
+
...reveals,
|
|
177
|
+
actions: sorted(reveals.actions),
|
|
178
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function canonicalMemberReveals(reveals: MemberRevealsArtifact): MemberRevealsArtifact {
|
|
183
|
+
return {
|
|
184
|
+
...reveals,
|
|
185
|
+
actions: sorted(reveals.actions),
|
|
186
|
+
...(reveals.when === undefined ? {} : { when: canonicalCondition(reveals.when) }),
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* A condition with its connectives' operands and its `in` / `notIn` lists sorted by their canonical JSON: AND and OR
|
|
192
|
+
* commute and a list is a set, so neither order changes which rows it admits.
|
|
193
|
+
*/
|
|
194
|
+
export function canonicalCondition(condition: ConditionArtifact): ConditionArtifact {
|
|
195
|
+
if ('allOf' in condition && isConditionList(condition.allOf)) {
|
|
196
|
+
return { allOf: sortedConditions(condition.allOf) }
|
|
197
|
+
}
|
|
198
|
+
if ('anyOf' in condition && isConditionList(condition.anyOf)) {
|
|
199
|
+
return { anyOf: sortedConditions(condition.anyOf) }
|
|
200
|
+
}
|
|
201
|
+
if ('not' in condition && isCondition(condition.not)) {
|
|
202
|
+
return { not: canonicalCondition(condition.not) }
|
|
203
|
+
}
|
|
204
|
+
const rows = canonicalRows(condition)
|
|
205
|
+
if (rows !== undefined) return rows
|
|
206
|
+
const tests: Record<string, ColumnTestArtifact | RowsTestArtifact> = {}
|
|
207
|
+
for (const [path, test] of Object.entries(condition)) {
|
|
208
|
+
const after = isCondition(test) ? canonicalRows(test) : undefined
|
|
209
|
+
if (after !== undefined) {
|
|
210
|
+
tests[path] = after
|
|
211
|
+
continue
|
|
212
|
+
}
|
|
213
|
+
// A parsed artifact holds nothing else here; dropping an unknown test would widen what the condition admits.
|
|
214
|
+
if (!isColumnTest(test)) throw new Error(`the condition test of ${path} is not a column test`)
|
|
215
|
+
tests[path] = canonicalTest(test)
|
|
216
|
+
}
|
|
217
|
+
return tests
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** `some` or `none` with its condition canonical, or `undefined` for any other form: one beside another key is no rows test. */
|
|
221
|
+
function canonicalRows(condition: object): RowsTestArtifact | undefined {
|
|
222
|
+
if (Object.keys(condition).length !== 1) return undefined
|
|
223
|
+
if ('some' in condition && isConditionRecord(condition.some)) {
|
|
224
|
+
return { some: mapValues(condition.some, canonicalCondition) }
|
|
225
|
+
}
|
|
226
|
+
if ('none' in condition && isConditionRecord(condition.none)) {
|
|
227
|
+
return { none: mapValues(condition.none, canonicalCondition) }
|
|
228
|
+
}
|
|
229
|
+
return undefined
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
function canonicalTest(test: ColumnTestArtifact): ColumnTestArtifact {
|
|
233
|
+
return {
|
|
234
|
+
...test,
|
|
235
|
+
...(test.in === undefined ? {} : { in: sortedLiterals(test.in) }),
|
|
236
|
+
...(test.notIn === undefined ? {} : { notIn: sortedLiterals(test.notIn) }),
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
function sortedConditions(conditions: readonly ConditionArtifact[]): ConditionArtifact[] {
|
|
241
|
+
return conditions.map(canonicalCondition).sort((a, b) => compare(canonicalJson(a), canonicalJson(b)))
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
function sortedLiterals(values: readonly ConditionLiteralArtifact[]): ConditionLiteralArtifact[] {
|
|
245
|
+
return [...values].sort((a, b) => compare(JSON.stringify(a), JSON.stringify(b)))
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isCondition(value: unknown): value is ConditionArtifact {
|
|
249
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function isConditionRecord(value: unknown): value is Readonly<Record<string, ConditionArtifact>> {
|
|
253
|
+
return isCondition(value) && Object.values(value).every(isCondition)
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function isConditionList(value: unknown): value is readonly ConditionArtifact[] {
|
|
257
|
+
return Array.isArray(value) && value.every(isCondition)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const COLUMN_TEST_OPERATORS: ReadonlySet<string> = new Set(['eq', 'notEq', 'in', 'notIn', 'isNull', 'lt', 'lte', 'gt', 'gte'])
|
|
261
|
+
|
|
262
|
+
function isColumnTest(value: unknown): value is ColumnTestArtifact {
|
|
263
|
+
return isCondition(value) && Object.keys(value).every((operator) => COLUMN_TEST_OPERATORS.has(operator))
|
|
264
|
+
}
|
|
265
|
+
|
|
157
266
|
function canonicalizeEndpoint(row: EndpointRow): EndpointRow {
|
|
158
267
|
const shared = {
|
|
159
268
|
admission: row.admission === null ? null : canonicalAdmission(row.admission),
|
package/src/contract.ts
CHANGED
|
@@ -24,10 +24,15 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
24
24
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
25
25
|
readonly actions: Readonly<Record<string, string>>
|
|
26
26
|
readonly roles: Readonly<Record<string, RoleArtifact>>
|
|
27
|
+
/**
|
|
28
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
29
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
30
|
+
*/
|
|
31
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>
|
|
27
32
|
readonly mounts: Readonly<Record<string, MountArtifact>>
|
|
28
33
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>
|
|
29
34
|
/**
|
|
30
|
-
* The file kinds (`c.files({ types, maxBytes, scan? })`): classes of stored files a table's file column holds. A kind
|
|
35
|
+
* The file kinds (`c.files({ types, maxBytes, scan?, inline? })`): classes of stored files a table's file column holds. A kind
|
|
31
36
|
* has no owner and no endpoint; the table that holds a file is its authority. Absent unless declared, so the digest stays.
|
|
32
37
|
*/
|
|
33
38
|
readonly fileKinds?: Readonly<Record<string, FileKindArtifact>>
|
|
@@ -189,7 +194,8 @@ interface EndpointRowBase {
|
|
|
189
194
|
readonly crossOrigin?: CrossOriginForm
|
|
190
195
|
/**
|
|
191
196
|
* `file`: the procedure answers a stored file (an output `file('<kind>')`), so the proxy and the application give every
|
|
192
|
-
* answer of it, a denial included, ADR-0022's file treatment.
|
|
197
|
+
* answer of it, a denial included, ADR-0022's file treatment. `inline-file`: the same, for a kind declared `inline:
|
|
198
|
+
* true`, whose XML documents are shown too. Absent otherwise, so every other row keeps its digest.
|
|
193
199
|
*/
|
|
194
200
|
readonly response?: EndpointResponse
|
|
195
201
|
/**
|
|
@@ -209,8 +215,8 @@ interface EndpointRowBase {
|
|
|
209
215
|
/** What the proxy does with an anonymous request's `Authorization` on a row that names it: forward it to the application. */
|
|
210
216
|
export type EndpointAuthorization = 'forward'
|
|
211
217
|
|
|
212
|
-
/** The answer profile of a row that answers a stored file. */
|
|
213
|
-
export type EndpointResponse = 'file'
|
|
218
|
+
/** The answer profile of a row that answers a stored file: `inline-file` also shows the XML documents a machine reads. */
|
|
219
|
+
export type EndpointResponse = 'file' | 'inline-file'
|
|
214
220
|
|
|
215
221
|
/** A cacheable row's lifetime: `maxAgeSeconds`, or `immutable`, a year, for an input that names an immutable value. */
|
|
216
222
|
export type EndpointCache = { readonly maxAgeSeconds: number } | 'immutable'
|
|
@@ -223,7 +229,7 @@ export const FILE_RESPONSE_KINDS: readonly EndpointKind[] = ['query', 'mutation'
|
|
|
223
229
|
|
|
224
230
|
/** Whether every answer of a row gets the file treatment: a collection's download, or a procedure that answers a file. */
|
|
225
231
|
export function answersFile(row: { readonly kind: string; readonly response?: EndpointResponse }): boolean {
|
|
226
|
-
return row.kind === 'download' || row.response
|
|
232
|
+
return row.kind === 'download' || row.response !== undefined
|
|
227
233
|
}
|
|
228
234
|
|
|
229
235
|
/** How an endpoint admits another origin: from the environment's list, or (a form or a public procedure) from any origin. */
|
|
@@ -343,6 +349,29 @@ export function isFileShape(shape: OutputShape): shape is FileShape {
|
|
|
343
349
|
return shape.type === 'file'
|
|
344
350
|
}
|
|
345
351
|
|
|
352
|
+
/** The kinds of the files a schema holds, anywhere in it, each once per place it appears. */
|
|
353
|
+
export function fileKindsIn(shape: SchemaShape): readonly string[] {
|
|
354
|
+
switch (shape.type) {
|
|
355
|
+
case 'file':
|
|
356
|
+
return [shape.kind]
|
|
357
|
+
case 'array':
|
|
358
|
+
return fileKindsIn(shape.items)
|
|
359
|
+
case 'tuple':
|
|
360
|
+
return [...shape.items.flatMap(fileKindsIn), ...(shape.rest === null ? [] : fileKindsIn(shape.rest))]
|
|
361
|
+
case 'record':
|
|
362
|
+
return fileKindsIn(shape.value)
|
|
363
|
+
case 'object':
|
|
364
|
+
return Object.values(shape.fields).flatMap(fileKindsIn)
|
|
365
|
+
case 'optional':
|
|
366
|
+
case 'nullable':
|
|
367
|
+
return fileKindsIn(shape.inner)
|
|
368
|
+
case 'union':
|
|
369
|
+
return shape.options.flatMap(fileKindsIn)
|
|
370
|
+
default:
|
|
371
|
+
return []
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
346
375
|
/**
|
|
347
376
|
* What a procedure answers: a JSON value of a schema, a file of rows (`attachment()` of `@fabrika/app/contract`), or a
|
|
348
377
|
* redirect (`redirect()`).
|
|
@@ -460,6 +489,16 @@ export interface RoleArtifact {
|
|
|
460
489
|
readonly member: { readonly scope: string; readonly assignableBy: readonly string[] } | null
|
|
461
490
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
462
491
|
readonly external?: true
|
|
492
|
+
/**
|
|
493
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
494
|
+
* Absent unless declared, so digests stay.
|
|
495
|
+
*/
|
|
496
|
+
readonly via?: Readonly<Record<string, readonly string[]>>
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
500
|
+
export interface RelationArtifact {
|
|
501
|
+
readonly dimension: string
|
|
463
502
|
}
|
|
464
503
|
|
|
465
504
|
// ── Mounts and companions ───────────────────────────────────────────────────────────────────────
|
|
@@ -674,6 +713,11 @@ export interface FileKindArtifact {
|
|
|
674
713
|
readonly maxBytes: number
|
|
675
714
|
/** Present when every file of the kind waits `quarantined` for a clean malware verdict before it is served. */
|
|
676
715
|
readonly scan?: true
|
|
716
|
+
/**
|
|
717
|
+
* Present when its files are shown rather than downloaded: every type is an inert image or an XML document a machine
|
|
718
|
+
* reads, and a row answering it is `response: 'inline-file'`. Absent otherwise, so every other kind keeps its digest.
|
|
719
|
+
*/
|
|
720
|
+
readonly inline?: true
|
|
677
721
|
}
|
|
678
722
|
|
|
679
723
|
export interface JobArtifact {
|
|
@@ -754,8 +798,8 @@ export interface DeclaredReach {
|
|
|
754
798
|
*/
|
|
755
799
|
readonly signs?: readonly string[]
|
|
756
800
|
/**
|
|
757
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted
|
|
758
|
-
* unless declared, so the digest stays.
|
|
801
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
802
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Absent unless declared, so the digest stays.
|
|
759
803
|
*/
|
|
760
804
|
readonly egress?: readonly string[]
|
|
761
805
|
/**
|
|
@@ -832,6 +876,88 @@ export interface TablePolicyArtifact {
|
|
|
832
876
|
* actions are the file's authority. Absent unless declared, so the digest stays.
|
|
833
877
|
*/
|
|
834
878
|
readonly files?: Readonly<Record<string, string>>
|
|
879
|
+
/**
|
|
880
|
+
* A view (ADR-0072): read like its scope's tables, written by nothing, its containment stated by its SQL alone.
|
|
881
|
+
* Absent for a table, so the digest stays.
|
|
882
|
+
*/
|
|
883
|
+
readonly view?: true
|
|
884
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
885
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>
|
|
886
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
887
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>
|
|
888
|
+
/**
|
|
889
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
890
|
+
* A reader that ignores it reaches less, never more.
|
|
891
|
+
*/
|
|
892
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>
|
|
893
|
+
/**
|
|
894
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
895
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
896
|
+
*/
|
|
897
|
+
readonly readThrough?: Readonly<Record<string, string>>
|
|
898
|
+
/**
|
|
899
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
900
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
901
|
+
*/
|
|
902
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
/** A row reveals its node in `to` for `actions` to a grant of them at the row's own node, while `when` admits the row. */
|
|
906
|
+
export interface MemberRevealsArtifact {
|
|
907
|
+
readonly to: string
|
|
908
|
+
readonly actions: readonly string[]
|
|
909
|
+
readonly when?: ConditionArtifact
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
913
|
+
export interface RevealsArtifact {
|
|
914
|
+
readonly to: string
|
|
915
|
+
readonly actions: readonly string[]
|
|
916
|
+
readonly when?: ConditionArtifact
|
|
917
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
918
|
+
readonly assign?: { readonly self: boolean }
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
922
|
+
export interface ConfersArtifact {
|
|
923
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
924
|
+
readonly principal: string
|
|
925
|
+
readonly node: string
|
|
926
|
+
readonly expires: string | null
|
|
927
|
+
readonly when?: ConditionArtifact
|
|
928
|
+
readonly assign: { readonly maxDays: number | null; readonly self: boolean } | null
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
933
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
934
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
935
|
+
*/
|
|
936
|
+
export type ConditionArtifact =
|
|
937
|
+
| { readonly allOf: readonly ConditionArtifact[] }
|
|
938
|
+
| { readonly anyOf: readonly ConditionArtifact[] }
|
|
939
|
+
| { readonly not: ConditionArtifact }
|
|
940
|
+
| RowsTestArtifact
|
|
941
|
+
| { readonly [path: string]: ColumnTestArtifact | RowsTestArtifact }
|
|
942
|
+
|
|
943
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
944
|
+
export type RowsTestArtifact =
|
|
945
|
+
| { readonly some: Readonly<Record<string, ConditionArtifact>> }
|
|
946
|
+
| { readonly none: Readonly<Record<string, ConditionArtifact>> }
|
|
947
|
+
|
|
948
|
+
export type ConditionLiteralArtifact = string | number | boolean
|
|
949
|
+
|
|
950
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
951
|
+
export interface ColumnTestArtifact {
|
|
952
|
+
readonly eq?: ConditionLiteralArtifact
|
|
953
|
+
readonly notEq?: ConditionLiteralArtifact
|
|
954
|
+
readonly in?: readonly ConditionLiteralArtifact[]
|
|
955
|
+
readonly notIn?: readonly ConditionLiteralArtifact[]
|
|
956
|
+
readonly isNull?: boolean
|
|
957
|
+
readonly lt?: ConditionLiteralArtifact | { readonly now: true }
|
|
958
|
+
readonly lte?: ConditionLiteralArtifact | { readonly now: true }
|
|
959
|
+
readonly gt?: ConditionLiteralArtifact | { readonly now: true }
|
|
960
|
+
readonly gte?: ConditionLiteralArtifact | { readonly now: true }
|
|
835
961
|
}
|
|
836
962
|
|
|
837
963
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
package/src/egress.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// What a site's `egress` entry is, and which request URL it admits: the one rule the contract build, the artifact parser,
|
|
2
|
+
// the runtime guard on `fetch`, the checker and the approval diff share (ADR-0012 §15). An entry is an exact `https`
|
|
3
|
+
// origin or a pattern `https://*.<domain>[:port]` whose `*` stands for exactly one DNS label.
|
|
4
|
+
|
|
5
|
+
/** One parsed `egress` entry. `port` is `''` for the default port, as `URL.port` spells it. */
|
|
6
|
+
export type EgressEntry =
|
|
7
|
+
| { readonly kind: 'origin'; readonly origin: string; readonly host: string; readonly port: string }
|
|
8
|
+
| { readonly kind: 'pattern'; readonly pattern: string; readonly domain: string; readonly port: string }
|
|
9
|
+
|
|
10
|
+
export type EgressEntryParse = { readonly ok: true; readonly entry: EgressEntry } | { readonly ok: false; readonly problem: string }
|
|
11
|
+
|
|
12
|
+
/** What every pattern starts with: the scheme and the one wildcard label. */
|
|
13
|
+
const EGRESS_WILDCARD_PREFIX = 'https://*.'
|
|
14
|
+
|
|
15
|
+
const HOSTNAME = /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/
|
|
16
|
+
const NUMERIC_LABEL = /^[0-9]+$/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `value` as an `egress` entry, or why it is none. Each entry is written canonically (lower case, punycode, no default
|
|
20
|
+
* port, no trailing dot, no path), so an artifact names one entry one way; a problem names the canonical spelling when
|
|
21
|
+
* there is one.
|
|
22
|
+
*/
|
|
23
|
+
export function parseEgressEntry(value: string): EgressEntryParse {
|
|
24
|
+
return value.startsWith(EGRESS_WILDCARD_PREFIX) ? parsePattern(value) : parseOrigin(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseOrigin(value: string): EgressEntryParse {
|
|
28
|
+
const url = urlOf(value)
|
|
29
|
+
if (url === null || url.protocol !== 'https:') return refused('is not an https origin')
|
|
30
|
+
if (url.hostname.endsWith('.')) return refused(canonicalProblem(url, `https://${url.host.replace(/\.(?=:|$)/, '')}`))
|
|
31
|
+
if (!HOSTNAME.test(url.hostname)) {
|
|
32
|
+
return refused(url.hostname.includes('*') ? 'puts a wildcard elsewhere than one leading label' : 'is not an https origin with a literal host')
|
|
33
|
+
}
|
|
34
|
+
if (url.origin !== value) return refused(canonicalProblem(url, url.origin))
|
|
35
|
+
return { ok: true, entry: { kind: 'origin', origin: value, host: url.hostname, port: url.port } }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parsePattern(value: string): EgressEntryParse {
|
|
39
|
+
const rest = value.slice(EGRESS_WILDCARD_PREFIX.length)
|
|
40
|
+
const url = urlOf(`https://${rest}`)
|
|
41
|
+
if (url === null) return refused('is not an https origin pattern')
|
|
42
|
+
if (url.hostname.includes('*')) return refused('has more than one wildcard label (allowed: one leading *.)')
|
|
43
|
+
if (url.hostname.endsWith('.')) return refused(canonicalProblem(url, `${EGRESS_WILDCARD_PREFIX}${url.host.replace(/\.(?=:|$)/, '')}`))
|
|
44
|
+
if (!HOSTNAME.test(url.hostname)) return refused('is not an https origin pattern with a literal domain')
|
|
45
|
+
const labels = url.hostname.split('.')
|
|
46
|
+
if (NUMERIC_LABEL.test(labels.at(-1) ?? '')) return refused('puts its wildcard on an IP address (allowed: a domain name)')
|
|
47
|
+
if (isPublicSuffix(labels)) {
|
|
48
|
+
return refused(`puts its wildcard on the public suffix '${url.hostname}' (allowed: a domain of your own, as in 'https://*.example.com')`)
|
|
49
|
+
}
|
|
50
|
+
if (url.origin !== `https://${rest}`) return refused(canonicalProblem(url, `${EGRESS_WILDCARD_PREFIX}${url.host}`))
|
|
51
|
+
return { ok: true, entry: { kind: 'pattern', pattern: value, domain: url.hostname, port: url.port } }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether `labels` name a public suffix by this rule, which stands in for the public suffix list (the platform ships no
|
|
56
|
+
* copy of it): one label (`com`), or two labels under a two-letter country code whose first has at
|
|
57
|
+
* most three characters (`co.uk`, `com.au`, `ne.jp`). A suffix this rule cannot tell, such as a longer second-level
|
|
58
|
+
* label or a shared hosting domain, is the approver's to judge: the diff shows every pattern as a wider grant.
|
|
59
|
+
*/
|
|
60
|
+
function isPublicSuffix(labels: readonly string[]): boolean {
|
|
61
|
+
if (labels.length < 2) return true
|
|
62
|
+
const top = labels.at(-1) ?? ''
|
|
63
|
+
const second = labels.at(-2) ?? ''
|
|
64
|
+
return labels.length === 2 && /^[a-z]{2}$/.test(top) && second.length <= 3
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether `url` is a request an entry of `entries` admits: its host and port, a trailing dot of the host aside. */
|
|
68
|
+
export function egressAdmits(entries: readonly EgressEntry[], url: URL): boolean {
|
|
69
|
+
if (url.protocol !== 'https:') return false
|
|
70
|
+
const host = url.hostname.endsWith('.') ? url.hostname.slice(0, -1) : url.hostname
|
|
71
|
+
return entries.some((entry) => entry.port === url.port && (entry.kind === 'origin' ? entry.host === host : isOneLabelUnder(host, entry.domain)))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `host` is exactly one non-empty label followed by `.<domain>`, so `evil-example.com` is not under `example.com`. */
|
|
75
|
+
function isOneLabelUnder(host: string, domain: string): boolean {
|
|
76
|
+
const suffix = `.${domain}`
|
|
77
|
+
if (!host.endsWith(suffix)) return false
|
|
78
|
+
const label = host.slice(0, -suffix.length)
|
|
79
|
+
return label.length > 0 && !label.includes('.')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function canonicalProblem(url: URL, canonical: string): string {
|
|
83
|
+
const bare = url.pathname === '/' && url.search === '' && url.hash === '' && url.username === '' && url.password === ''
|
|
84
|
+
return bare ? `is not written canonically (write it as '${canonical}')` : 'carries a path, query or credentials (allowed: an origin only)'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function refused(problem: string): EgressEntryParse {
|
|
88
|
+
return { ok: false, problem }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function urlOf(value: string): URL | null {
|
|
92
|
+
try {
|
|
93
|
+
return new URL(value)
|
|
94
|
+
} catch {
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// @fabrika/auth-core — pure logic, types, and wire names shared across auth components and apps.
|
|
2
2
|
export * from './app-environment'
|
|
3
3
|
export * from './canonical-path'
|
|
4
|
+
export * from './client-address'
|
|
4
5
|
export * from './contract'
|
|
5
6
|
export * from './contract-canonical'
|
|
6
7
|
export * from './dev-environment'
|
|
7
8
|
export * from './device'
|
|
9
|
+
export * from './egress'
|
|
8
10
|
export * from './endpoint-digest'
|
|
9
11
|
export * from './endpoints'
|
|
10
12
|
export * from './environment'
|
package/src/types.ts
CHANGED
|
@@ -45,6 +45,18 @@ 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
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
56
|
+
export function isReservedScopeType(type: string): boolean {
|
|
57
|
+
return type.startsWith('~')
|
|
58
|
+
}
|
|
59
|
+
|
|
48
60
|
export interface PermissionEntry {
|
|
49
61
|
action: string
|
|
50
62
|
/** null = global / all scopes */
|
|
@@ -80,6 +92,12 @@ export interface RoleDef {
|
|
|
80
92
|
member?: { scope: string; assignableBy?: string[] }
|
|
81
93
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
82
94
|
external?: true
|
|
95
|
+
/**
|
|
96
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
97
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation.
|
|
98
|
+
* Only an application-wide internal role declares it.
|
|
99
|
+
*/
|
|
100
|
+
via?: Record<string, string[]>
|
|
83
101
|
}
|
|
84
102
|
|
|
85
103
|
/**
|
package/src/wire.ts
CHANGED
|
@@ -65,7 +65,8 @@ export function proxySecretVariable(id: string): string {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
68
|
-
* and IAM hold it under this one name. It proves only who wrote IAM's
|
|
68
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
69
|
+
* it on one shared client bucket.
|
|
69
70
|
*/
|
|
70
71
|
export const IAM_PROXY_SECRET_VARIABLE = 'FABRIKA_INSTALLATION_PROXY_SECRET_IAM'
|
|
71
72
|
|
|
@@ -18,3 +18,9 @@ export declare function splitRequestTarget(target: string): RequestTarget;
|
|
|
18
18
|
* the string because `new URL()` resolves dot segments and so hides the very paths that must be refused.
|
|
19
19
|
*/
|
|
20
20
|
export declare function rawRequestTarget(url: string): RequestTarget;
|
|
21
|
+
/**
|
|
22
|
+
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path of that origin: the one rule for a
|
|
23
|
+
* redirect or return target that must stay on its own origin. A leading `//` or any `\` would make a browser read a
|
|
24
|
+
* host from it, and a browser strips a tab or newline before parsing, so no control character is admitted.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sameOriginTarget(origin: string, path: string): string | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client a client-address header value counts as: an IPv4 address, or an IPv6 address's /64 (one subscriber's
|
|
3
|
+
* prefix, of which it may hold every address); an IPv4-mapped IPv6 address counts as its IPv4 address. Only the first
|
|
4
|
+
* value counts, so a caller that appends a second copy cannot change the key. `null` when the value is absent or no
|
|
5
|
+
* IP address.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clientAddressKey(header: string | null): string | null;
|
|
@@ -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
|
@@ -19,10 +19,15 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
19
19
|
/** Action → description. Exact actions only; the artifact holds no wildcard. */
|
|
20
20
|
readonly actions: Readonly<Record<string, string>>;
|
|
21
21
|
readonly roles: Readonly<Record<string, RoleArtifact>>;
|
|
22
|
+
/**
|
|
23
|
+
* The relations a table's rows confer (`relations: { owner: { dimension: 'project' } }`): a role's `via` holds its
|
|
24
|
+
* actions where a row names the caller. Absent unless declared, so the digest stays.
|
|
25
|
+
*/
|
|
26
|
+
readonly relations?: Readonly<Record<string, RelationArtifact>>;
|
|
22
27
|
readonly mounts: Readonly<Record<string, MountArtifact>>;
|
|
23
28
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>;
|
|
24
29
|
/**
|
|
25
|
-
* The file kinds (`c.files({ types, maxBytes, scan? })`): classes of stored files a table's file column holds. A kind
|
|
30
|
+
* The file kinds (`c.files({ types, maxBytes, scan?, inline? })`): classes of stored files a table's file column holds. A kind
|
|
26
31
|
* has no owner and no endpoint; the table that holds a file is its authority. Absent unless declared, so the digest stays.
|
|
27
32
|
*/
|
|
28
33
|
readonly fileKinds?: Readonly<Record<string, FileKindArtifact>>;
|
|
@@ -174,7 +179,8 @@ interface EndpointRowBase {
|
|
|
174
179
|
readonly crossOrigin?: CrossOriginForm;
|
|
175
180
|
/**
|
|
176
181
|
* `file`: the procedure answers a stored file (an output `file('<kind>')`), so the proxy and the application give every
|
|
177
|
-
* answer of it, a denial included, ADR-0022's file treatment.
|
|
182
|
+
* answer of it, a denial included, ADR-0022's file treatment. `inline-file`: the same, for a kind declared `inline:
|
|
183
|
+
* true`, whose XML documents are shown too. Absent otherwise, so every other row keeps its digest.
|
|
178
184
|
*/
|
|
179
185
|
readonly response?: EndpointResponse;
|
|
180
186
|
/**
|
|
@@ -192,8 +198,8 @@ interface EndpointRowBase {
|
|
|
192
198
|
}
|
|
193
199
|
/** What the proxy does with an anonymous request's `Authorization` on a row that names it: forward it to the application. */
|
|
194
200
|
export type EndpointAuthorization = 'forward';
|
|
195
|
-
/** The answer profile of a row that answers a stored file. */
|
|
196
|
-
export type EndpointResponse = 'file';
|
|
201
|
+
/** The answer profile of a row that answers a stored file: `inline-file` also shows the XML documents a machine reads. */
|
|
202
|
+
export type EndpointResponse = 'file' | 'inline-file';
|
|
197
203
|
/** A cacheable row's lifetime: `maxAgeSeconds`, or `immutable`, a year, for an input that names an immutable value. */
|
|
198
204
|
export type EndpointCache = {
|
|
199
205
|
readonly maxAgeSeconds: number;
|
|
@@ -332,6 +338,8 @@ export interface FileShape {
|
|
|
332
338
|
readonly kind: string;
|
|
333
339
|
}
|
|
334
340
|
export declare function isFileShape(shape: OutputShape): shape is FileShape;
|
|
341
|
+
/** The kinds of the files a schema holds, anywhere in it, each once per place it appears. */
|
|
342
|
+
export declare function fileKindsIn(shape: SchemaShape): readonly string[];
|
|
335
343
|
/**
|
|
336
344
|
* What a procedure answers: a JSON value of a schema, a file of rows (`attachment()` of `@fabrika/app/contract`), or a
|
|
337
345
|
* redirect (`redirect()`).
|
|
@@ -433,6 +441,15 @@ export interface RoleArtifact {
|
|
|
433
441
|
} | null;
|
|
434
442
|
/** An external principal may hold this membership role (ADR-0051). Absent unless declared, so digests stay. */
|
|
435
443
|
readonly external?: true;
|
|
444
|
+
/**
|
|
445
|
+
* Relation → actions the holder of a global grant of this role holds at each node a relation row names them at.
|
|
446
|
+
* Absent unless declared, so digests stay.
|
|
447
|
+
*/
|
|
448
|
+
readonly via?: Readonly<Record<string, readonly string[]>>;
|
|
449
|
+
}
|
|
450
|
+
/** A relation of the vocabulary: the dimension whose nodes its rows name. */
|
|
451
|
+
export interface RelationArtifact {
|
|
452
|
+
readonly dimension: string;
|
|
436
453
|
}
|
|
437
454
|
export type MountArtifact = RpcMountArtifact | LinkMountArtifact | SpaMountArtifact | HealthMountArtifact | FormMountArtifact | WebhookMountArtifact;
|
|
438
455
|
export interface RpcMountArtifact {
|
|
@@ -621,6 +638,11 @@ export interface FileKindArtifact {
|
|
|
621
638
|
readonly maxBytes: number;
|
|
622
639
|
/** Present when every file of the kind waits `quarantined` for a clean malware verdict before it is served. */
|
|
623
640
|
readonly scan?: true;
|
|
641
|
+
/**
|
|
642
|
+
* Present when its files are shown rather than downloaded: every type is an inert image or an XML document a machine
|
|
643
|
+
* reads, and a row answering it is `response: 'inline-file'`. Absent otherwise, so every other kind keeps its digest.
|
|
644
|
+
*/
|
|
645
|
+
readonly inline?: true;
|
|
624
646
|
}
|
|
625
647
|
export interface JobArtifact {
|
|
626
648
|
readonly schedule: string;
|
|
@@ -694,8 +716,8 @@ export interface DeclaredReach {
|
|
|
694
716
|
*/
|
|
695
717
|
readonly signs?: readonly string[];
|
|
696
718
|
/**
|
|
697
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted
|
|
698
|
-
* unless declared, so the digest stays.
|
|
719
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
720
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Absent unless declared, so the digest stays.
|
|
699
721
|
*/
|
|
700
722
|
readonly egress?: readonly string[];
|
|
701
723
|
/**
|
|
@@ -764,6 +786,99 @@ export interface TablePolicyArtifact {
|
|
|
764
786
|
* actions are the file's authority. Absent unless declared, so the digest stays.
|
|
765
787
|
*/
|
|
766
788
|
readonly files?: Readonly<Record<string, string>>;
|
|
789
|
+
/**
|
|
790
|
+
* A view (ADR-0072): read like its scope's tables, written by nothing, its containment stated by its SQL alone.
|
|
791
|
+
* Absent for a table, so the digest stays.
|
|
792
|
+
*/
|
|
793
|
+
readonly view?: true;
|
|
794
|
+
/** Relation → how a row of this table confers it. Absent unless declared, so the digest stays. */
|
|
795
|
+
readonly confers?: Readonly<Record<string, ConfersArtifact>>;
|
|
796
|
+
/** Action → the condition a row must meet for it, narrowing what any grant of it reaches. Absent unless declared. */
|
|
797
|
+
readonly when?: Readonly<Record<string, ConditionArtifact>>;
|
|
798
|
+
/**
|
|
799
|
+
* Relation of the table's own dimension → the ancestor its rows reveal. Absent unless declared, so the digest stays.
|
|
800
|
+
* A reader that ignores it reaches less, never more.
|
|
801
|
+
*/
|
|
802
|
+
readonly reveals?: Readonly<Record<string, RevealsArtifact>>;
|
|
803
|
+
/**
|
|
804
|
+
* Dimension outside the chain → the column a `Within`'s read reaches a row through. Absent unless declared, so the
|
|
805
|
+
* digest stays. A reader that ignores it reaches less, never more.
|
|
806
|
+
*/
|
|
807
|
+
readonly readThrough?: Readonly<Record<string, string>>;
|
|
808
|
+
/**
|
|
809
|
+
* The table's own dimension → the ancestor its rows reveal to a grant at their node, for a `Within`'s reads. Absent
|
|
810
|
+
* unless declared, so the digest stays. A reader that ignores it reaches less, never more.
|
|
811
|
+
*/
|
|
812
|
+
readonly memberReveals?: Readonly<Record<string, MemberRevealsArtifact>>;
|
|
813
|
+
}
|
|
814
|
+
/** A row reveals its node in `to` for `actions` to a grant of them at the row's own node, while `when` admits the row. */
|
|
815
|
+
export interface MemberRevealsArtifact {
|
|
816
|
+
readonly to: string;
|
|
817
|
+
readonly actions: readonly string[];
|
|
818
|
+
readonly when?: ConditionArtifact;
|
|
819
|
+
}
|
|
820
|
+
/** A row the relation reaches reveals its node in `to` for `actions`, while `when` admits the row. */
|
|
821
|
+
export interface RevealsArtifact {
|
|
822
|
+
readonly to: string;
|
|
823
|
+
readonly actions: readonly string[];
|
|
824
|
+
readonly when?: ConditionArtifact;
|
|
825
|
+
/** On a reveal matched through `readThrough`: an insert delegates, and `self` lets it name a node its writer holds. */
|
|
826
|
+
readonly assign?: {
|
|
827
|
+
readonly self: boolean;
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/** A row names `principal` at the node in `node`, until `expires`, while `when` admits it; `assign` bounds its writer. */
|
|
831
|
+
export interface ConfersArtifact {
|
|
832
|
+
/** The column that holds the principal, or `<column>.<principal column>` through one foreign key of the table. */
|
|
833
|
+
readonly principal: string;
|
|
834
|
+
readonly node: string;
|
|
835
|
+
readonly expires: string | null;
|
|
836
|
+
readonly when?: ConditionArtifact;
|
|
837
|
+
readonly assign: {
|
|
838
|
+
readonly maxDays: number | null;
|
|
839
|
+
readonly self: boolean;
|
|
840
|
+
} | null;
|
|
841
|
+
}
|
|
842
|
+
/**
|
|
843
|
+
* A structured row condition: connectives, `{ '<column or fk_column.column>': test }` with every test holding, or
|
|
844
|
+
* `some` / `none` of the rows of one table whose foreign key names the row, also at the end of a path
|
|
845
|
+
* (`{ '<fk_column>': { some: … } }`). Each form is absent from a condition that does not use it, so its digest stays.
|
|
846
|
+
*/
|
|
847
|
+
export type ConditionArtifact = {
|
|
848
|
+
readonly allOf: readonly ConditionArtifact[];
|
|
849
|
+
} | {
|
|
850
|
+
readonly anyOf: readonly ConditionArtifact[];
|
|
851
|
+
} | {
|
|
852
|
+
readonly not: ConditionArtifact;
|
|
853
|
+
} | RowsTestArtifact | {
|
|
854
|
+
readonly [path: string]: ColumnTestArtifact | RowsTestArtifact;
|
|
855
|
+
};
|
|
856
|
+
/** `some` or `none` of the rows of one table whose foreign key names the row. */
|
|
857
|
+
export type RowsTestArtifact = {
|
|
858
|
+
readonly some: Readonly<Record<string, ConditionArtifact>>;
|
|
859
|
+
} | {
|
|
860
|
+
readonly none: Readonly<Record<string, ConditionArtifact>>;
|
|
861
|
+
};
|
|
862
|
+
export type ConditionLiteralArtifact = string | number | boolean;
|
|
863
|
+
/** One operator of a column test; `{ now: true }` compares a timestamp with the statement's clock. */
|
|
864
|
+
export interface ColumnTestArtifact {
|
|
865
|
+
readonly eq?: ConditionLiteralArtifact;
|
|
866
|
+
readonly notEq?: ConditionLiteralArtifact;
|
|
867
|
+
readonly in?: readonly ConditionLiteralArtifact[];
|
|
868
|
+
readonly notIn?: readonly ConditionLiteralArtifact[];
|
|
869
|
+
readonly isNull?: boolean;
|
|
870
|
+
readonly lt?: ConditionLiteralArtifact | {
|
|
871
|
+
readonly now: true;
|
|
872
|
+
};
|
|
873
|
+
readonly lte?: ConditionLiteralArtifact | {
|
|
874
|
+
readonly now: true;
|
|
875
|
+
};
|
|
876
|
+
readonly gt?: ConditionLiteralArtifact | {
|
|
877
|
+
readonly now: true;
|
|
878
|
+
};
|
|
879
|
+
readonly gte?: ConditionLiteralArtifact | {
|
|
880
|
+
readonly now: true;
|
|
881
|
+
};
|
|
767
882
|
}
|
|
768
883
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
|
769
884
|
export interface ColumnPolicyArtifact {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One parsed `egress` entry. `port` is `''` for the default port, as `URL.port` spells it. */
|
|
2
|
+
export type EgressEntry = {
|
|
3
|
+
readonly kind: 'origin';
|
|
4
|
+
readonly origin: string;
|
|
5
|
+
readonly host: string;
|
|
6
|
+
readonly port: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'pattern';
|
|
9
|
+
readonly pattern: string;
|
|
10
|
+
readonly domain: string;
|
|
11
|
+
readonly port: string;
|
|
12
|
+
};
|
|
13
|
+
export type EgressEntryParse = {
|
|
14
|
+
readonly ok: true;
|
|
15
|
+
readonly entry: EgressEntry;
|
|
16
|
+
} | {
|
|
17
|
+
readonly ok: false;
|
|
18
|
+
readonly problem: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* `value` as an `egress` entry, or why it is none. Each entry is written canonically (lower case, punycode, no default
|
|
22
|
+
* port, no trailing dot, no path), so an artifact names one entry one way; a problem names the canonical spelling when
|
|
23
|
+
* there is one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseEgressEntry(value: string): EgressEntryParse;
|
|
26
|
+
/** Whether `url` is a request an entry of `entries` admits: its host and port, a trailing dot of the host aside. */
|
|
27
|
+
export declare function egressAdmits(entries: readonly EgressEntry[], url: URL): boolean;
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from './app-environment';
|
|
2
2
|
export * from './canonical-path';
|
|
3
|
+
export * from './client-address';
|
|
3
4
|
export * from './contract';
|
|
4
5
|
export * from './contract-canonical';
|
|
5
6
|
export * from './dev-environment';
|
|
6
7
|
export * from './device';
|
|
8
|
+
export * from './egress';
|
|
7
9
|
export * from './endpoint-digest';
|
|
8
10
|
export * from './endpoints';
|
|
9
11
|
export * from './environment';
|
package/types/src/types.d.ts
CHANGED
|
@@ -34,6 +34,14 @@ 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
|
+
/** A scope type no dimension, grant or key may name: IAM derives a `~` entry itself and never stores one. */
|
|
44
|
+
export declare function isReservedScopeType(type: string): boolean;
|
|
37
45
|
export interface PermissionEntry {
|
|
38
46
|
action: string;
|
|
39
47
|
/** null = global / all scopes */
|
|
@@ -70,6 +78,12 @@ export interface RoleDef {
|
|
|
70
78
|
};
|
|
71
79
|
/** An external principal may hold this membership role (ADR-0051). Only a membership role may declare it. */
|
|
72
80
|
external?: true;
|
|
81
|
+
/**
|
|
82
|
+
* Relation → exact actions. A GLOBAL grant of this role also carries `{ action, scope: { type: '~rel', value:
|
|
83
|
+
* relation } }`: the application holds the action where one of its rows names the principal in that relation.
|
|
84
|
+
* Only an application-wide internal role declares it.
|
|
85
|
+
*/
|
|
86
|
+
via?: Record<string, string[]>;
|
|
73
87
|
}
|
|
74
88
|
/**
|
|
75
89
|
* One scope dimension an app exposes. IAM evaluates every value as a flat scope; `in` only tells IAM
|
package/types/src/wire.d.ts
CHANGED
|
@@ -53,7 +53,8 @@ export declare const FABRIKA_PROXY_SECRET = "FABRIKA_PROXY_SECRET";
|
|
|
53
53
|
export declare function proxySecretVariable(id: string): string;
|
|
54
54
|
/**
|
|
55
55
|
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
56
|
-
* and IAM hold it under this one name. It proves only who wrote IAM's
|
|
56
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
57
|
+
* it on one shared client bucket.
|
|
57
58
|
*/
|
|
58
59
|
export declare const IAM_PROXY_SECRET_VARIABLE = "FABRIKA_INSTALLATION_PROXY_SECRET_IAM";
|
|
59
60
|
/**
|