@fabrika/auth-core 0.9.0-cloudflare.3 → 0.9.0-dev.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/contract-canonical.ts +1 -1
- package/src/contract.ts +3 -5
- package/src/framework-variables.ts +0 -6
- package/src/index.ts +0 -1
- package/src/managed-environment.ts +0 -4
- package/src/ops.ts +222 -0
- package/src/rpc.ts +8 -8
- package/src/token.ts +8 -8
- package/src/types.ts +1 -1
- package/types/src/contract.d.ts +3 -5
- package/types/src/framework-variables.d.ts +1 -6
- package/types/src/index.d.ts +0 -1
- package/types/src/managed-environment.d.ts +1 -1
- package/types/src/ops.d.ts +15 -0
- package/types/src/rpc.d.ts +5 -5
- package/types/src/token.d.ts +7 -7
- package/types/src/types.d.ts +1 -1
- package/src/public-egress.ts +0 -166
- package/types/src/public-egress.d.ts +0 -31
package/package.json
CHANGED
|
@@ -65,7 +65,7 @@ export function canonicalizeArtifact(artifact: ContractArtifact): ContractArtifa
|
|
|
65
65
|
...(reach.actions === undefined ? {} : { actions: sorted(reach.actions) }),
|
|
66
66
|
...(reach.kicks === undefined ? {} : { kicks: sorted(reach.kicks) }),
|
|
67
67
|
...(reach.signs === undefined ? {} : { signs: sorted(reach.signs) }),
|
|
68
|
-
...(reach.egress === undefined ? {} : { egress:
|
|
68
|
+
...(reach.egress === undefined ? {} : { egress: sorted(reach.egress) }),
|
|
69
69
|
})),
|
|
70
70
|
}),
|
|
71
71
|
...(artifact.directories === undefined ? {} : { directories: artifact.directories }),
|
package/src/contract.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import type { Locale } from './locale'
|
|
5
5
|
import type { MailTemplates } from './mail'
|
|
6
|
-
import type { DeclaredEgress } from './public-egress'
|
|
7
6
|
import type { TerminalArtifact } from './terminal'
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -755,11 +754,10 @@ export interface DeclaredReach {
|
|
|
755
754
|
*/
|
|
756
755
|
readonly signs?: readonly string[]
|
|
757
756
|
/**
|
|
758
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted: a credentialed procedure, a webhook or a job.
|
|
759
|
-
*
|
|
760
|
-
* (ADR-0071). Absent unless declared, so the digest stays.
|
|
757
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted: a credentialed procedure, a webhook or a job. Absent
|
|
758
|
+
* unless declared, so the digest stays.
|
|
761
759
|
*/
|
|
762
|
-
readonly egress?:
|
|
760
|
+
readonly egress?: readonly string[]
|
|
763
761
|
/**
|
|
764
762
|
* A public procedure's workload actions, sorted: all its handler holds, through the key Control issues for the
|
|
765
763
|
* endpoint (`contractWorkloads`). Present only on a public procedure's entry, so every other digest stays.
|
|
@@ -18,11 +18,6 @@ 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-0071): 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'
|
|
26
21
|
/** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
|
|
27
22
|
export const FABRIKA_APPLICATION_OBJECT = 'FABRIKA_APPLICATION_OBJECT'
|
|
28
23
|
/** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
|
|
@@ -59,7 +54,6 @@ export const FRAMEWORK_VARIABLE_NAMES = [
|
|
|
59
54
|
FABRIKA_TOKEN_KEYS,
|
|
60
55
|
FABRIKA_APP_ORIGIN,
|
|
61
56
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
62
|
-
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
63
57
|
FABRIKA_APPLICATION_OBJECT,
|
|
64
58
|
FABRIKA_APPLICATION_OBJECTS,
|
|
65
59
|
] as const
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,6 @@ 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,
|
|
7
6
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
8
7
|
FABRIKA_TOKEN_KEYS,
|
|
9
8
|
FRAMEWORK_VARIABLE_PREFIXES,
|
|
@@ -36,7 +35,6 @@ export const MANAGED_VARIABLE_NAMES = [
|
|
|
36
35
|
FABRIKA_APP_ORIGIN,
|
|
37
36
|
FABRIKA_TOKEN_KEYS,
|
|
38
37
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
39
|
-
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
40
38
|
] as const satisfies readonly FrameworkVariableName[]
|
|
41
39
|
|
|
42
40
|
export type ManagedVariableName = (typeof MANAGED_VARIABLE_NAMES)[number]
|
|
@@ -55,8 +53,6 @@ const PUBLIC_VARIABLES: ReadonlySet<string> = new Set<FrameworkVariableName>([
|
|
|
55
53
|
FABRIKA_APP_ORIGIN,
|
|
56
54
|
// SHA-256 of 256-bit random keys: a digest neither is a key nor lets anyone forge one.
|
|
57
55
|
FABRIKA_OPS_KEY_DIGESTS,
|
|
58
|
-
// Host names anyone can look up in DNS.
|
|
59
|
-
FABRIKA_EGRESS_REFUSED_HOSTS,
|
|
60
56
|
])
|
|
61
57
|
|
|
62
58
|
const PLATFORM_URL_VARIABLES: ReadonlySet<string> = new Set(PLATFORM_RECEIVERS.map((receiver) => platformTransportVariables(receiver).url))
|
package/src/ops.ts
CHANGED
|
@@ -1653,6 +1653,228 @@ function loadOrder(tables: readonly DescribedTable[], cycle: ReadonlyMap<string,
|
|
|
1653
1653
|
return order
|
|
1654
1654
|
}
|
|
1655
1655
|
|
|
1656
|
+
/**
|
|
1657
|
+
* The schema `planOpsDump` reads, from the PRAGMAs workerd admits, of every table a dump holds. An `INITIALLY DEFERRED`
|
|
1658
|
+
* clause is read from the table's SQL outside its quotes and comments, and marks every foreign key of its table; the
|
|
1659
|
+
* names a `CHECK` reads come from the same SQL (`checkNamesOf`).
|
|
1660
|
+
*/
|
|
1661
|
+
export function describeOpsDumpSchema(query: OpsDumpSchemaQuery): OpsDumpSchema {
|
|
1662
|
+
const tables: OpsDumpSchemaTable[] = []
|
|
1663
|
+
for (const row of query('PRAGMA table_list')) {
|
|
1664
|
+
const name = schemaText(row['name'])
|
|
1665
|
+
const type = schemaText(row['type'])
|
|
1666
|
+
if (schemaText(row['schema']) !== 'main' || type === 'view' || !dumpedTable(name)) {
|
|
1667
|
+
continue
|
|
1668
|
+
}
|
|
1669
|
+
const virtual = type === 'virtual'
|
|
1670
|
+
const sql = query(`SELECT sql FROM sqlite_schema WHERE type = 'table' AND name = ?`, name)[0]?.['sql']
|
|
1671
|
+
const clauses = typeof sql === 'string' ? unquotedSql(sql) : null
|
|
1672
|
+
tables.push({
|
|
1673
|
+
name,
|
|
1674
|
+
virtual,
|
|
1675
|
+
withoutRowid: schemaFlag(row['wr']),
|
|
1676
|
+
checkNames: typeof sql === 'string' ? checkNamesOf(sql) : null,
|
|
1677
|
+
// A virtual table is refused whatever it holds, and its module may not be loaded to describe it.
|
|
1678
|
+
columns: virtual ? [] : describeColumns(query, name),
|
|
1679
|
+
indexes: virtual ? [] : describeIndexes(query, name),
|
|
1680
|
+
foreignKeys: virtual ? [] : describeForeignKeys(query, name, clauses === null || /\binitially\s+deferred\b/i.test(clauses)),
|
|
1681
|
+
})
|
|
1682
|
+
}
|
|
1683
|
+
return { tables }
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
function describeColumns(query: OpsDumpSchemaQuery, table: string): OpsDumpSchemaColumn[] {
|
|
1687
|
+
return query(`PRAGMA table_xinfo(${sqlLiteral(table)})`).map((row) => {
|
|
1688
|
+
const hidden = schemaInteger(row['hidden'])
|
|
1689
|
+
return {
|
|
1690
|
+
name: schemaText(row['name']),
|
|
1691
|
+
type: schemaText(row['type']),
|
|
1692
|
+
notNull: schemaFlag(row['notnull']),
|
|
1693
|
+
primaryKey: schemaInteger(row['pk']),
|
|
1694
|
+
generated: hidden === 2 || hidden === 3,
|
|
1695
|
+
}
|
|
1696
|
+
})
|
|
1697
|
+
}
|
|
1698
|
+
|
|
1699
|
+
function describeIndexes(query: OpsDumpSchemaQuery, table: string): OpsDumpSchemaIndex[] {
|
|
1700
|
+
return query(`PRAGMA index_list(${sqlLiteral(table)})`).map((row) => {
|
|
1701
|
+
const origin = row['origin']
|
|
1702
|
+
if (origin !== 'c' && origin !== 'u' && origin !== 'pk') {
|
|
1703
|
+
throw new Error('PRAGMA index_list answered an origin SQLite does not write')
|
|
1704
|
+
}
|
|
1705
|
+
const columns = query(`PRAGMA index_xinfo(${sqlLiteral(schemaText(row['name']))})`)
|
|
1706
|
+
.filter((column) => schemaFlag(column['key']))
|
|
1707
|
+
.sort((left, right) => schemaInteger(left['seqno']) - schemaInteger(right['seqno']))
|
|
1708
|
+
.map((column) => typeof column['name'] === 'string' ? column['name'] : null)
|
|
1709
|
+
return { unique: schemaFlag(row['unique']), origin, partial: schemaFlag(row['partial']), columns }
|
|
1710
|
+
})
|
|
1711
|
+
}
|
|
1712
|
+
|
|
1713
|
+
function describeForeignKeys(query: OpsDumpSchemaQuery, table: string, initiallyDeferred: boolean): OpsDumpSchemaForeignKey[] {
|
|
1714
|
+
const keys = new Map<number, { parent: string; rows: { seq: number; from: string; to: string | null }[] }>()
|
|
1715
|
+
for (const row of query(`PRAGMA foreign_key_list(${sqlLiteral(table)})`)) {
|
|
1716
|
+
const id = schemaInteger(row['id'])
|
|
1717
|
+
const to = row['to']
|
|
1718
|
+
const entry = { seq: schemaInteger(row['seq']), from: schemaText(row['from']), to: typeof to === 'string' ? to : null }
|
|
1719
|
+
const key = keys.get(id)
|
|
1720
|
+
if (key === undefined) {
|
|
1721
|
+
keys.set(id, { parent: schemaText(row['table']), rows: [entry] })
|
|
1722
|
+
} else {
|
|
1723
|
+
key.rows.push(entry)
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
return [...keys.entries()].sort(([left], [right]) => left - right).map(([, key]) => {
|
|
1727
|
+
const rows = key.rows.sort((left, right) => left.seq - right.seq)
|
|
1728
|
+
const references = rows.flatMap((row) => row.to === null ? [] : [row.to])
|
|
1729
|
+
if (references.length !== 0 && references.length !== rows.length) {
|
|
1730
|
+
throw new Error('PRAGMA foreign_key_list named the parent columns of a key only in part')
|
|
1731
|
+
}
|
|
1732
|
+
return { parent: key.parent, columns: rows.map((row) => row.from), references: references.length === 0 ? null : references, initiallyDeferred }
|
|
1733
|
+
})
|
|
1734
|
+
}
|
|
1735
|
+
|
|
1736
|
+
type SqlToken =
|
|
1737
|
+
| { readonly kind: 'name'; readonly text: string; readonly quoted: boolean }
|
|
1738
|
+
| { readonly kind: 'open' | 'close' | 'other' }
|
|
1739
|
+
|
|
1740
|
+
const WORD_CHAR = /[A-Za-z0-9_$\u0080-\uffff]/
|
|
1741
|
+
|
|
1742
|
+
/**
|
|
1743
|
+
* The names the `CHECK` clauses of a table's `sql` read: every word and quoted identifier between a `CHECK` keyword's
|
|
1744
|
+
* parentheses, ASCII-lowercase, keywords and numbers included, so it lists at least every column a `CHECK` reads. A
|
|
1745
|
+
* string literal and a comment name nothing; a double-quoted string, which SQLite may read as either, counts as a name.
|
|
1746
|
+
* `null` when the text does not scan (an unclosed quote, comment or parenthesis), which counts as naming every column.
|
|
1747
|
+
*/
|
|
1748
|
+
export function checkNamesOf(sql: string): string[] | null {
|
|
1749
|
+
const tokens = sqlTokens(sql)
|
|
1750
|
+
if (tokens === null) return null
|
|
1751
|
+
const names: string[] = []
|
|
1752
|
+
for (let index = 0; index < tokens.length; index++) {
|
|
1753
|
+
const token = tokens[index]
|
|
1754
|
+
if (token?.kind !== 'name' || token.quoted || asciiLower(token.text) !== 'check' || tokens[index + 1]?.kind !== 'open') continue
|
|
1755
|
+
let depth = 0
|
|
1756
|
+
let end = index + 1
|
|
1757
|
+
for (; end < tokens.length; end++) {
|
|
1758
|
+
const inner = tokens[end]
|
|
1759
|
+
if (inner?.kind === 'open') depth++
|
|
1760
|
+
else if (inner?.kind === 'close' && --depth === 0) break
|
|
1761
|
+
else if (inner?.kind === 'name') names.push(asciiLower(inner.text))
|
|
1762
|
+
}
|
|
1763
|
+
if (end === tokens.length) return null
|
|
1764
|
+
index = end
|
|
1765
|
+
}
|
|
1766
|
+
return names
|
|
1767
|
+
}
|
|
1768
|
+
|
|
1769
|
+
/** `sql` as words, quoted identifiers and parentheses; string literals, comments and whitespace dropped. */
|
|
1770
|
+
function sqlTokens(sql: string): SqlToken[] | null {
|
|
1771
|
+
const tokens: SqlToken[] = []
|
|
1772
|
+
let index = 0
|
|
1773
|
+
while (index < sql.length) {
|
|
1774
|
+
const char = sql.charAt(index)
|
|
1775
|
+
if (sql.startsWith('--', index)) {
|
|
1776
|
+
const end = sql.indexOf('\n', index)
|
|
1777
|
+
index = end < 0 ? sql.length : end + 1
|
|
1778
|
+
} else if (sql.startsWith('/*', index)) {
|
|
1779
|
+
const end = sql.indexOf('*/', index + 2)
|
|
1780
|
+
if (end < 0) return null
|
|
1781
|
+
index = end + 2
|
|
1782
|
+
} else if (char === "'" || char === '"' || char === '`' || char === '[') {
|
|
1783
|
+
const close = char === '[' ? ']' : char
|
|
1784
|
+
let end = index + 1
|
|
1785
|
+
let text = ''
|
|
1786
|
+
for (;;) {
|
|
1787
|
+
const next = sql.indexOf(close, end)
|
|
1788
|
+
if (next < 0) return null
|
|
1789
|
+
text += sql.slice(end, next)
|
|
1790
|
+
if (close !== ']' && sql.charAt(next + 1) === close) {
|
|
1791
|
+
text += close
|
|
1792
|
+
end = next + 2
|
|
1793
|
+
continue
|
|
1794
|
+
}
|
|
1795
|
+
end = next + 1
|
|
1796
|
+
break
|
|
1797
|
+
}
|
|
1798
|
+
if (char !== "'") tokens.push({ kind: 'name', text, quoted: true })
|
|
1799
|
+
index = end
|
|
1800
|
+
} else if (WORD_CHAR.test(char)) {
|
|
1801
|
+
let end = index + 1
|
|
1802
|
+
while (end < sql.length && WORD_CHAR.test(sql.charAt(end))) end++
|
|
1803
|
+
tokens.push({ kind: 'name', text: sql.slice(index, end), quoted: false })
|
|
1804
|
+
index = end
|
|
1805
|
+
} else {
|
|
1806
|
+
if (char === '(') tokens.push({ kind: 'open' })
|
|
1807
|
+
else if (char === ')') tokens.push({ kind: 'close' })
|
|
1808
|
+
else if (!/\s/.test(char)) tokens.push({ kind: 'other' })
|
|
1809
|
+
index++
|
|
1810
|
+
}
|
|
1811
|
+
}
|
|
1812
|
+
return tokens
|
|
1813
|
+
}
|
|
1814
|
+
|
|
1815
|
+
/** `sql` with its string literals, quoted identifiers and comments blanked, so a keyword search finds only clauses. */
|
|
1816
|
+
function unquotedSql(sql: string): string {
|
|
1817
|
+
let out = ''
|
|
1818
|
+
let index = 0
|
|
1819
|
+
while (index < sql.length) {
|
|
1820
|
+
const char = sql.charAt(index)
|
|
1821
|
+
const close = char === "'" ? "'" : char === '"' ? '"' : char === '`' ? '`' : char === '[' ? ']' : null
|
|
1822
|
+
if (close !== null) {
|
|
1823
|
+
let end = index + 1
|
|
1824
|
+
for (;;) {
|
|
1825
|
+
end = sql.indexOf(close, end)
|
|
1826
|
+
if (end < 0 || close === ']' || sql.charAt(end + 1) !== close) break
|
|
1827
|
+
end += 2
|
|
1828
|
+
}
|
|
1829
|
+
index = end < 0 ? sql.length : end + 1
|
|
1830
|
+
out += ' '
|
|
1831
|
+
} else if (sql.startsWith('--', index)) {
|
|
1832
|
+
const end = sql.indexOf('\n', index)
|
|
1833
|
+
index = end < 0 ? sql.length : end + 1
|
|
1834
|
+
out += ' '
|
|
1835
|
+
} else if (sql.startsWith('/*', index)) {
|
|
1836
|
+
const end = sql.indexOf('*/', index + 2)
|
|
1837
|
+
index = end < 0 ? sql.length : end + 2
|
|
1838
|
+
out += ' '
|
|
1839
|
+
} else {
|
|
1840
|
+
out += char
|
|
1841
|
+
index++
|
|
1842
|
+
}
|
|
1843
|
+
}
|
|
1844
|
+
return out
|
|
1845
|
+
}
|
|
1846
|
+
|
|
1847
|
+
/** One statement's rows, as a Durable Object's `sql.exec(...).toArray()` or a `bun:sqlite` query answers them. */
|
|
1848
|
+
export type OpsDumpSchemaQuery = (sql: string, ...bindings: string[]) => readonly Readonly<Record<string, unknown>>[]
|
|
1849
|
+
|
|
1850
|
+
/** Whether a dump holds `name`: no SQLite internal table but `sqlite_sequence`, and none of Cloudflare's `_cf_` ones. */
|
|
1851
|
+
function dumpedTable(name: string): boolean {
|
|
1852
|
+
return !name.startsWith('_cf_') && (!name.startsWith('sqlite_') || name === 'sqlite_sequence')
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
function sqlLiteral(value: string): string {
|
|
1856
|
+
return `'${value.replaceAll("'", "''")}'`
|
|
1857
|
+
}
|
|
1858
|
+
|
|
1859
|
+
// SQLite's own answers: a value of another type is a broken runtime, never input to refuse.
|
|
1860
|
+
function schemaText(value: unknown): string {
|
|
1861
|
+
if (typeof value !== 'string') {
|
|
1862
|
+
throw new Error('SQLite answered a schema name or SQL that is not text')
|
|
1863
|
+
}
|
|
1864
|
+
return value
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
function schemaInteger(value: unknown): number {
|
|
1868
|
+
if (typeof value !== 'number' || !Number.isSafeInteger(value)) {
|
|
1869
|
+
throw new Error('SQLite answered a schema number that is not an integer')
|
|
1870
|
+
}
|
|
1871
|
+
return value
|
|
1872
|
+
}
|
|
1873
|
+
|
|
1874
|
+
function schemaFlag(value: unknown): boolean {
|
|
1875
|
+
return schemaInteger(value) !== 0
|
|
1876
|
+
}
|
|
1877
|
+
|
|
1656
1878
|
/** Whether every deferred column of `table` can hold `NULL` from its part until the link pass, with nothing to violate. */
|
|
1657
1879
|
function takesTemporaryNull(table: OpsDumpSchemaTable, deferred: readonly OpsDumpSchemaColumn[], referenced: ReadonlySet<string>): boolean {
|
|
1658
1880
|
// A `CHECK` answers the same for a `NULL` in a column it does not read; a generated column may read a deferred one.
|
package/src/rpc.ts
CHANGED
|
@@ -10,7 +10,7 @@ import type {
|
|
|
10
10
|
import type { Jwks } from './token'
|
|
11
11
|
import type { PermissionEntry, PrincipalType, Scope } from './types'
|
|
12
12
|
|
|
13
|
-
// ──
|
|
13
|
+
// ── IAM-native session auth (mint a per-app permission token from an SSO session) ──
|
|
14
14
|
//
|
|
15
15
|
// The SDK middleware presents the browser's opaque SSO session cookie; the Worker validates it,
|
|
16
16
|
// resolves the principal's permissions FOR THE CALLING APP, and signs a short-lived per-app
|
|
@@ -33,7 +33,7 @@ export type MintTokenResult =
|
|
|
33
33
|
/** `token_too_large`: the principal holds more than fits in one header; a decided refusal, never a login bounce. */
|
|
34
34
|
| { ok: false; reason: 'no_session' | 'invalid_session' | 'unknown_principal' | 'disabled' | 'token_too_large' }
|
|
35
35
|
|
|
36
|
-
// ──
|
|
36
|
+
// ── IAM-native key auth (mint an access token from an opaque `px_` credential) ──
|
|
37
37
|
//
|
|
38
38
|
// The other front over the same resolve→sign core as `mintToken`: the SDK presents an opaque
|
|
39
39
|
// credential (an API key as a bearer, or a share-link path token) and the Worker resolves its
|
|
@@ -154,8 +154,8 @@ export interface IssueKeyServiceSpec {
|
|
|
154
154
|
export interface IssueKeyInput {
|
|
155
155
|
app: string
|
|
156
156
|
/**
|
|
157
|
-
* The
|
|
158
|
-
* a `px_token` access JWT (verified against
|
|
157
|
+
* The IAM-native credential the ISSUER is resolved from server-side (never self-asserted):
|
|
158
|
+
* a `px_token` access JWT (verified against IAM's signing keys) or a `px_` key. Null = absent.
|
|
159
159
|
*/
|
|
160
160
|
credential: string | null
|
|
161
161
|
requestId: string
|
|
@@ -227,7 +227,7 @@ export interface AuditInput {
|
|
|
227
227
|
|
|
228
228
|
export interface RevokeKeyInput {
|
|
229
229
|
app: string
|
|
230
|
-
/** The
|
|
230
|
+
/** The IAM-native credential the CALLER (authorizer) is resolved from; null = absent. */
|
|
231
231
|
credential: string | null
|
|
232
232
|
requestId: string
|
|
233
233
|
/** The credential id (the `id` returned by `issueKey`), NOT the plaintext `px_` token. */
|
|
@@ -242,7 +242,7 @@ export type RevokeKeyResult =
|
|
|
242
242
|
// ── List principals (the app's people directory) ───────────────────────────────
|
|
243
243
|
//
|
|
244
244
|
// A read-only enumeration of the USER principals who can access an app — its people
|
|
245
|
-
// directory. Apps consume it for things
|
|
245
|
+
// directory. Apps consume it for things IAM isn't the authority on but needs the
|
|
246
246
|
// roster for: an assignee picker, an actor/owner label list. The caller is resolved from
|
|
247
247
|
// the forwarded Access credentials and the listed app is the aud-VERIFIED app — an operator
|
|
248
248
|
// can only enumerate the roster of an app it itself authenticates to (never a self-asserted
|
|
@@ -252,7 +252,7 @@ export type RevokeKeyResult =
|
|
|
252
252
|
export interface ListPrincipalsInput {
|
|
253
253
|
/** Self-asserted caller app id; superseded by the credential's aud on a valid `px_token`. */
|
|
254
254
|
app: string
|
|
255
|
-
/** The
|
|
255
|
+
/** The IAM-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
|
|
256
256
|
credential: string | null
|
|
257
257
|
requestId: string
|
|
258
258
|
}
|
|
@@ -286,7 +286,7 @@ export interface IamRpc {
|
|
|
286
286
|
listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>
|
|
287
287
|
/**
|
|
288
288
|
* Mint a short-lived, per-app permission token from the browser's SSO session — the
|
|
289
|
-
*
|
|
289
|
+
* IAM-native auth path. The SDK middleware calls this only when its cached permission
|
|
290
290
|
* token is missing/near-expiry (≈ once per TTL), NOT per request: every other request verifies
|
|
291
291
|
* the cached token locally against `getJwks`.
|
|
292
292
|
*/
|
package/src/token.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The IAM-issued token contract — the SECOND thing (after `IamRpc`) that must not drift
|
|
3
3
|
* between the Worker and the SDK.
|
|
4
4
|
*
|
|
5
5
|
* Background: today a request is authorized by the Worker resolving a Cloudflare Access JWT on
|
|
6
6
|
* every call over RPC (the CF token carries only identity, so authz needs a round-trip). When
|
|
7
|
-
*
|
|
7
|
+
* IAM issues its OWN token it can embed the already-resolved permission set, and the SDK
|
|
8
8
|
* authorizes LOCALLY — no per-request round-trip. This module is the wire shape of that token:
|
|
9
9
|
*
|
|
10
10
|
* - the Worker BUILDS claims here and signs them (`buildAccessClaims`);
|
|
@@ -47,7 +47,7 @@ export const FABRIKA_COOKIE_PREFIX = '__Host-px_'
|
|
|
47
47
|
* because those origins are potentially trustworthy.
|
|
48
48
|
*/
|
|
49
49
|
export const SESSION_COOKIE = `${FABRIKA_COOKIE_PREFIX}session`
|
|
50
|
-
/** Prefix marking
|
|
50
|
+
/** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
|
|
51
51
|
export const API_KEY_PREFIX = 'px_'
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -56,7 +56,7 @@ export const API_KEY_PREFIX = 'px_'
|
|
|
56
56
|
*/
|
|
57
57
|
export const WORKLOAD_TOKEN_PATH = '/auth/workload/token'
|
|
58
58
|
|
|
59
|
-
/** Signing algorithm
|
|
59
|
+
/** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
|
|
60
60
|
export const TOKEN_ALG = 'ES256'
|
|
61
61
|
/** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
|
|
62
62
|
export const RESOURCE_ACCESS_TOKEN_TYP = 'at+jwt'
|
|
@@ -90,12 +90,12 @@ export const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536
|
|
|
90
90
|
// ── Claim shape (one, no discriminator) ────────────────────────────────────────
|
|
91
91
|
|
|
92
92
|
/**
|
|
93
|
-
* The
|
|
93
|
+
* The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
|
|
94
94
|
* only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
|
|
95
95
|
* credential label otherwise (or null).
|
|
96
96
|
*/
|
|
97
97
|
export interface AccessTokenClaims {
|
|
98
|
-
/** Issuer —
|
|
98
|
+
/** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
|
|
99
99
|
iss: string
|
|
100
100
|
/** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
|
|
101
101
|
aud: string
|
|
@@ -189,7 +189,7 @@ export type TokenAudienceProfile = { kind: 'app'; app: string } | { kind: 'resou
|
|
|
189
189
|
//
|
|
190
190
|
// Transport is the IAM service binding (`getJwks()` RPC), NOT a public HTTPS URL: app↔IAM is
|
|
191
191
|
// RPC over the binding, which never traverses the Access edge — so the SDK reaches the key set
|
|
192
|
-
// even while
|
|
192
|
+
// even while IAM's own hostname is still gated by Cloudflare Access. The Worker also
|
|
193
193
|
// serves the standard `/.well-known/jwks.json`, for when Access is gone. Both emit this shape.
|
|
194
194
|
|
|
195
195
|
/** A published public signing key (EC P-256 / ES256). A jose-compatible JWK subset. */
|
|
@@ -211,7 +211,7 @@ export interface Jwks {
|
|
|
211
211
|
// ── Build (Worker side, pre-sign) ──────────────────────────────────────────────
|
|
212
212
|
|
|
213
213
|
export interface AccessTokenParams {
|
|
214
|
-
/** Issuer (
|
|
214
|
+
/** Issuer (IAM origin). */
|
|
215
215
|
iss: string
|
|
216
216
|
/** App id this token is for (becomes `aud`). */
|
|
217
217
|
app: string
|
package/src/types.ts
CHANGED
|
@@ -147,7 +147,7 @@ export interface AppDelegationDef {
|
|
|
147
147
|
purpose: 'members' | 'creates'
|
|
148
148
|
}
|
|
149
149
|
|
|
150
|
-
/** An app's full authz vocabulary, declared in the app's code, reconciled into
|
|
150
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
|
|
151
151
|
export interface AppSchema {
|
|
152
152
|
scopes: AppScopeDef[]
|
|
153
153
|
actions: AppActionDef[]
|
package/types/src/contract.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Locale } from './locale';
|
|
2
2
|
import type { MailTemplates } from './mail';
|
|
3
|
-
import type { DeclaredEgress } from './public-egress';
|
|
4
3
|
import type { TerminalArtifact } from './terminal';
|
|
5
4
|
/**
|
|
6
5
|
* The artifact format this release writes. A release that changes the artifact raises it, and Control upcasts every
|
|
@@ -695,11 +694,10 @@ export interface DeclaredReach {
|
|
|
695
694
|
*/
|
|
696
695
|
readonly signs?: readonly string[];
|
|
697
696
|
/**
|
|
698
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted: a credentialed procedure, a webhook or a job.
|
|
699
|
-
*
|
|
700
|
-
* (ADR-0071). Absent unless declared, so the digest stays.
|
|
697
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted: a credentialed procedure, a webhook or a job. Absent
|
|
698
|
+
* unless declared, so the digest stays.
|
|
701
699
|
*/
|
|
702
|
-
readonly egress?:
|
|
700
|
+
readonly egress?: readonly string[];
|
|
703
701
|
/**
|
|
704
702
|
* A public procedure's workload actions, sorted: all its handler holds, through the key Control issues for the
|
|
705
703
|
* endpoint (`contractWorkloads`). Present only on a public procedure's entry, so every other digest stays.
|
|
@@ -12,11 +12,6 @@ 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-0071): 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";
|
|
20
15
|
/** The name of the object that serves an environment's ordinary traffic on Cloudflare; `application` without it. */
|
|
21
16
|
export declare const FABRIKA_APPLICATION_OBJECT = "FABRIKA_APPLICATION_OBJECT";
|
|
22
17
|
/** The object names an ops request may target, all in the environment's own namespace (`parseApplicationObjects`). */
|
|
@@ -27,7 +22,7 @@ export declare const FABRIKA_APPLICATION_OBJECTS = "FABRIKA_APPLICATION_OBJECTS"
|
|
|
27
22
|
* application variable or secret under one of them, and so does every provider, for every surface that writes one.
|
|
28
23
|
* A work unit that gives an application a new credential adds its name here.
|
|
29
24
|
*/
|
|
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", "
|
|
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"];
|
|
31
26
|
export type FrameworkVariableName = (typeof FRAMEWORK_VARIABLE_NAMES)[number];
|
|
32
27
|
/**
|
|
33
28
|
* 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"];
|
|
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
|
package/types/src/ops.d.ts
CHANGED
|
@@ -640,3 +640,18 @@ export interface OpsDataRefusal {
|
|
|
640
640
|
readonly table: string | null;
|
|
641
641
|
}
|
|
642
642
|
export declare function parseOpsDataRefusal(body: unknown): OpsDataRefusal | null;
|
|
643
|
+
/**
|
|
644
|
+
* The schema `planOpsDump` reads, from the PRAGMAs workerd admits, of every table a dump holds. An `INITIALLY DEFERRED`
|
|
645
|
+
* clause is read from the table's SQL outside its quotes and comments, and marks every foreign key of its table; the
|
|
646
|
+
* names a `CHECK` reads come from the same SQL (`checkNamesOf`).
|
|
647
|
+
*/
|
|
648
|
+
export declare function describeOpsDumpSchema(query: OpsDumpSchemaQuery): OpsDumpSchema;
|
|
649
|
+
/**
|
|
650
|
+
* The names the `CHECK` clauses of a table's `sql` read: every word and quoted identifier between a `CHECK` keyword's
|
|
651
|
+
* parentheses, ASCII-lowercase, keywords and numbers included, so it lists at least every column a `CHECK` reads. A
|
|
652
|
+
* string literal and a comment name nothing; a double-quoted string, which SQLite may read as either, counts as a name.
|
|
653
|
+
* `null` when the text does not scan (an unclosed quote, comment or parenthesis), which counts as naming every column.
|
|
654
|
+
*/
|
|
655
|
+
export declare function checkNamesOf(sql: string): string[] | null;
|
|
656
|
+
/** One statement's rows, as a Durable Object's `sql.exec(...).toArray()` or a `bun:sqlite` query answers them. */
|
|
657
|
+
export type OpsDumpSchemaQuery = (sql: string, ...bindings: string[]) => readonly Readonly<Record<string, unknown>>[];
|
package/types/src/rpc.d.ts
CHANGED
|
@@ -110,8 +110,8 @@ export interface IssueKeyServiceSpec {
|
|
|
110
110
|
export interface IssueKeyInput {
|
|
111
111
|
app: string;
|
|
112
112
|
/**
|
|
113
|
-
* The
|
|
114
|
-
* a `px_token` access JWT (verified against
|
|
113
|
+
* The IAM-native credential the ISSUER is resolved from server-side (never self-asserted):
|
|
114
|
+
* a `px_token` access JWT (verified against IAM's signing keys) or a `px_` key. Null = absent.
|
|
115
115
|
*/
|
|
116
116
|
credential: string | null;
|
|
117
117
|
requestId: string;
|
|
@@ -185,7 +185,7 @@ export interface AuditInput {
|
|
|
185
185
|
}
|
|
186
186
|
export interface RevokeKeyInput {
|
|
187
187
|
app: string;
|
|
188
|
-
/** The
|
|
188
|
+
/** The IAM-native credential the CALLER (authorizer) is resolved from; null = absent. */
|
|
189
189
|
credential: string | null;
|
|
190
190
|
requestId: string;
|
|
191
191
|
/** The credential id (the `id` returned by `issueKey`), NOT the plaintext `px_` token. */
|
|
@@ -203,7 +203,7 @@ export type RevokeKeyResult =
|
|
|
203
203
|
export interface ListPrincipalsInput {
|
|
204
204
|
/** Self-asserted caller app id; superseded by the credential's aud on a valid `px_token`. */
|
|
205
205
|
app: string;
|
|
206
|
-
/** The
|
|
206
|
+
/** The IAM-native credential the CALLER is resolved from (px_token / px_ key); null = absent. */
|
|
207
207
|
credential: string | null;
|
|
208
208
|
requestId: string;
|
|
209
209
|
}
|
|
@@ -239,7 +239,7 @@ export interface IamRpc {
|
|
|
239
239
|
listOwnDeviceAuthorizations(input: ListOwnDeviceAuthorizationsInput): Promise<ListOwnDeviceAuthorizationsResult>;
|
|
240
240
|
/**
|
|
241
241
|
* Mint a short-lived, per-app permission token from the browser's SSO session — the
|
|
242
|
-
*
|
|
242
|
+
* IAM-native auth path. The SDK middleware calls this only when its cached permission
|
|
243
243
|
* token is missing/near-expiry (≈ once per TTL), NOT per request: every other request verifies
|
|
244
244
|
* the cached token locally against `getJwks`.
|
|
245
245
|
*/
|
package/types/src/token.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The
|
|
2
|
+
* The IAM-issued token contract — the SECOND thing (after `IamRpc`) that must not drift
|
|
3
3
|
* between the Worker and the SDK.
|
|
4
4
|
*
|
|
5
5
|
* Background: today a request is authorized by the Worker resolving a Cloudflare Access JWT on
|
|
6
6
|
* every call over RPC (the CF token carries only identity, so authz needs a round-trip). When
|
|
7
|
-
*
|
|
7
|
+
* IAM issues its OWN token it can embed the already-resolved permission set, and the SDK
|
|
8
8
|
* authorizes LOCALLY — no per-request round-trip. This module is the wire shape of that token:
|
|
9
9
|
*
|
|
10
10
|
* - the Worker BUILDS claims here and signs them (`buildAccessClaims`);
|
|
@@ -38,14 +38,14 @@ export declare const FABRIKA_COOKIE_PREFIX = "__Host-px_";
|
|
|
38
38
|
* because those origins are potentially trustworthy.
|
|
39
39
|
*/
|
|
40
40
|
export declare const SESSION_COOKIE = "__Host-px_session";
|
|
41
|
-
/** Prefix marking
|
|
41
|
+
/** Prefix marking an IAM opaque credential (API key / share link), e.g. `Bearer px_<random>`. */
|
|
42
42
|
export declare const API_KEY_PREFIX = "px_";
|
|
43
43
|
/**
|
|
44
44
|
* Where a job or a webhook exchanges its own `px_` key for an access token at IAM's public origin: `POST` with the key
|
|
45
45
|
* as the bearer and `{ app }` as the body. IAM answers `MintFromKeyResult`, and only for a workload key of that app.
|
|
46
46
|
*/
|
|
47
47
|
export declare const WORKLOAD_TOKEN_PATH = "/auth/workload/token";
|
|
48
|
-
/** Signing algorithm
|
|
48
|
+
/** Signing algorithm IAM issues with and the SDK verifies (ECDSA P-256 — compact, ubiquitous). */
|
|
49
49
|
export declare const TOKEN_ALG = "ES256";
|
|
50
50
|
/** JWT `typ` of an OAuth resource access token (RFC 9068). Native app tokens carry no `typ`. */
|
|
51
51
|
export declare const RESOURCE_ACCESS_TOKEN_TYP = "at+jwt";
|
|
@@ -72,12 +72,12 @@ export declare const MAX_APPLICATION_TOKEN_BYTES = 24576;
|
|
|
72
72
|
/** The request-header limit the platform starts an application's Bun server with (`--max-http-header-size`). */
|
|
73
73
|
export declare const APPLICATION_SERVER_MAX_HEADER_BYTES = 65536;
|
|
74
74
|
/**
|
|
75
|
-
* The
|
|
75
|
+
* The IAM access token. `perms` is always present (matched via `permits`); `ptype` is present
|
|
76
76
|
* only when `sub` is a principal. `label` is the audit actor — the principal's label when bound, the
|
|
77
77
|
* credential label otherwise (or null).
|
|
78
78
|
*/
|
|
79
79
|
export interface AccessTokenClaims {
|
|
80
|
-
/** Issuer —
|
|
80
|
+
/** Issuer — IAM's own origin (e.g. `https://iam.example.com`). */
|
|
81
81
|
iss: string;
|
|
82
82
|
/** The app id this token is scoped to. The SDK REJECTS a token whose `aud` is not its app. */
|
|
83
83
|
aud: string;
|
|
@@ -178,7 +178,7 @@ export interface Jwks {
|
|
|
178
178
|
keys: PublicJwk[];
|
|
179
179
|
}
|
|
180
180
|
export interface AccessTokenParams {
|
|
181
|
-
/** Issuer (
|
|
181
|
+
/** Issuer (IAM origin). */
|
|
182
182
|
iss: string;
|
|
183
183
|
/** App id this token is for (becomes `aud`). */
|
|
184
184
|
app: string;
|
package/types/src/types.d.ts
CHANGED
|
@@ -132,7 +132,7 @@ export interface AppDelegationDef {
|
|
|
132
132
|
dimension: string;
|
|
133
133
|
purpose: 'members' | 'creates';
|
|
134
134
|
}
|
|
135
|
-
/** An app's full authz vocabulary, declared in the app's code, reconciled into
|
|
135
|
+
/** An app's full authz vocabulary, declared in the app's code, reconciled into IAM. */
|
|
136
136
|
export interface AppSchema {
|
|
137
137
|
scopes: AppScopeDef[];
|
|
138
138
|
actions: AppActionDef[];
|
package/src/public-egress.ts
DELETED
|
@@ -1,166 +0,0 @@
|
|
|
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-0071). 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, an IP literal, a name of one label, a name under a refused suffix, or one of
|
|
53
|
-
* `refusedHosts` (normalized names). A host it admits may still resolve to a private address, which only a runtime that
|
|
54
|
-
* 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
|
-
const host = normalizedHost(url.hostname)
|
|
60
|
-
if (host.startsWith('[') || IPV4.test(host)) return `${host} is an IP address, not a public host name`
|
|
61
|
-
if (!host.includes('.')) return `${host} is a name of one label, as an internal service or a local machine has`
|
|
62
|
-
if (host.split('.').some((label) => label === '')) return `${host} has an empty label`
|
|
63
|
-
const suffix = PUBLIC_EGRESS_REFUSED_SUFFIXES.find((refused) => host === refused || host.endsWith(`.${refused}`))
|
|
64
|
-
if (suffix !== undefined) return `${host} is under .${suffix}, which names no public website`
|
|
65
|
-
if (refusedHosts.has(host)) return `${host} is a host of this installation`
|
|
66
|
-
return null
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Whether `address` (an IPv4 or IPv6 address, as a resolver answers it) is a public unicast address: not private,
|
|
71
|
-
* loopback, link-local (which holds the cloud metadata address 169.254.169.254), shared, multicast, reserved,
|
|
72
|
-
* documentation, or an IPv6 form that embeds or tunnels an IPv4 address it cannot vouch for. A text that is no address
|
|
73
|
-
* is not public.
|
|
74
|
-
*/
|
|
75
|
-
export function isPublicAddress(address: string): boolean {
|
|
76
|
-
const v4 = ipv4Octets(address)
|
|
77
|
-
if (v4 !== null) return isPublicIpv4(v4)
|
|
78
|
-
const words = ipv6Words(address)
|
|
79
|
-
if (words === null) return false
|
|
80
|
-
const [w0 = 0, w1 = 0, w2 = 0, w3 = 0, w4 = 0, w5 = 0, w6 = 0, w7 = 0] = words
|
|
81
|
-
// ::ffff:a.b.c.d, an IPv4 address in IPv6 form, is that IPv4 address.
|
|
82
|
-
if (w0 === 0 && w1 === 0 && w2 === 0 && w3 === 0 && w4 === 0 && w5 === 0xffff) {
|
|
83
|
-
return isPublicIpv4([w6 >> 8, w6 & 0xff, w7 >> 8, w7 & 0xff])
|
|
84
|
-
}
|
|
85
|
-
// Only global unicast (2000::/3) is public; every other block is local, multicast, reserved or a translation prefix.
|
|
86
|
-
if ((w0 & 0xe000) !== 0x2000) return false
|
|
87
|
-
// 2001::/32 Teredo, 2001:10::/28 ORCHID, 2001:20::/28 ORCHIDv2, 2001:db8::/32 documentation, 2002::/16 6to4.
|
|
88
|
-
if (w0 === 0x2001 && (w1 === 0 || (w1 & 0xfff0) === 0x10 || (w1 & 0xfff0) === 0x20 || w1 === 0x0db8)) return false
|
|
89
|
-
if (w0 === 0x2002) return false
|
|
90
|
-
// 3fff::/20 documentation (RFC 9637).
|
|
91
|
-
if (w0 === 0x3fff && (w1 & 0xf000) === 0) return false
|
|
92
|
-
return true
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/** The non-public IPv4 blocks, each as its network (a 32-bit number) and its prefix length. */
|
|
96
|
-
const IPV4_REFUSED: readonly (readonly [number, number])[] = [
|
|
97
|
-
[0x00000000, 8], // 0.0.0.0/8 this network
|
|
98
|
-
[0x0a000000, 8], // 10.0.0.0/8 private
|
|
99
|
-
[0x64400000, 10], // 100.64.0.0/10 shared address space
|
|
100
|
-
[0x7f000000, 8], // 127.0.0.0/8 loopback
|
|
101
|
-
[0xa9fe0000, 16], // 169.254.0.0/16 link-local, the cloud metadata address
|
|
102
|
-
[0xac100000, 12], // 172.16.0.0/12 private
|
|
103
|
-
[0xc0000000, 24], // 192.0.0.0/24 IETF protocol assignments
|
|
104
|
-
[0xc0000200, 24], // 192.0.2.0/24 documentation
|
|
105
|
-
[0xc0586300, 24], // 192.88.99.0/24 6to4 relay anycast
|
|
106
|
-
[0xc0a80000, 16], // 192.168.0.0/16 private
|
|
107
|
-
[0xc6120000, 15], // 198.18.0.0/15 benchmarking
|
|
108
|
-
[0xc6336400, 24], // 198.51.100.0/24 documentation
|
|
109
|
-
[0xcb007100, 24], // 203.0.113.0/24 documentation
|
|
110
|
-
[0xe0000000, 4], // 224.0.0.0/4 multicast
|
|
111
|
-
[0xf0000000, 4], // 240.0.0.0/4 reserved, broadcast
|
|
112
|
-
]
|
|
113
|
-
|
|
114
|
-
function isPublicIpv4(octets: readonly number[]): boolean {
|
|
115
|
-
const [a = 0, b = 0, c = 0, d = 0] = octets
|
|
116
|
-
const value = ((a << 24) >>> 0) + (b << 16) + (c << 8) + d
|
|
117
|
-
return !IPV4_REFUSED.some(([network, prefix]) => {
|
|
118
|
-
const mask = prefix === 0 ? 0 : (0xffffffff << (32 - prefix)) >>> 0
|
|
119
|
-
return ((value & mask) >>> 0) === network
|
|
120
|
-
})
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function ipv4Octets(text: string): number[] | null {
|
|
124
|
-
if (!IPV4.test(text)) return null
|
|
125
|
-
const octets = text.split('.').map((part) => Number.parseInt(part, 10))
|
|
126
|
-
return octets.every((octet) => octet >= 0 && octet <= 255) ? octets : null
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const HEX_WORD = /^[0-9a-f]{1,4}$/i
|
|
130
|
-
|
|
131
|
-
/** The eight 16-bit words of an IPv6 address (brackets and a zone allowed, an embedded IPv4 tail too), or `null`. */
|
|
132
|
-
function ipv6Words(text: string): number[] | null {
|
|
133
|
-
let rest = text.startsWith('[') && text.endsWith(']') ? text.slice(1, -1) : text
|
|
134
|
-
const zone = rest.indexOf('%')
|
|
135
|
-
if (zone !== -1) rest = rest.slice(0, zone)
|
|
136
|
-
if (!rest.includes(':')) return null
|
|
137
|
-
const tailAt = rest.lastIndexOf(':')
|
|
138
|
-
const tail = ipv4Octets(rest.slice(tailAt + 1))
|
|
139
|
-
const embedded: number[] = []
|
|
140
|
-
if (tail !== null) {
|
|
141
|
-
const [a = 0, b = 0, c = 0, d = 0] = tail
|
|
142
|
-
embedded.push((a << 8) | b, (c << 8) | d)
|
|
143
|
-
rest = rest.slice(0, tailAt + 1) + '0'
|
|
144
|
-
}
|
|
145
|
-
const halves = rest.split('::')
|
|
146
|
-
if (halves.length > 2) return null
|
|
147
|
-
const parse = (half: string | undefined): number[] | null => {
|
|
148
|
-
if (half === undefined || half === '') return []
|
|
149
|
-
const parts = half.split(':')
|
|
150
|
-
if (!parts.every((part) => HEX_WORD.test(part))) return null
|
|
151
|
-
return parts.map((part) => Number.parseInt(part, 16))
|
|
152
|
-
}
|
|
153
|
-
const head = parse(halves[0])
|
|
154
|
-
const back = parse(halves[1])
|
|
155
|
-
if (head === null || back === null) return null
|
|
156
|
-
if (tail !== null) {
|
|
157
|
-
// The placeholder word stands for the two words of the IPv4 tail.
|
|
158
|
-
const last = halves.length === 2 ? back : head
|
|
159
|
-
last.pop()
|
|
160
|
-
last.push(...embedded)
|
|
161
|
-
}
|
|
162
|
-
const missing = 8 - head.length - back.length
|
|
163
|
-
if (halves.length === 1) return missing === 0 ? head : null
|
|
164
|
-
if (missing < 1) return null
|
|
165
|
-
return [...head, ...Array.from({ length: missing }, () => 0), ...back]
|
|
166
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
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, an IP literal, a name of one label, a name under a refused suffix, or one of
|
|
21
|
-
* `refusedHosts` (normalized names). A host it admits may still resolve to a private address, which only a runtime that
|
|
22
|
-
* 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;
|