@fabrika/provider-cloudflare 0.5.2 → 0.5.4
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 +10 -10
- package/src/command.ts +27 -1
- package/src/control.ts +17 -0
- package/src/installation/scaffold.ts +1 -1
- package/src/installation/templates/platform.yml +1 -1
- package/src/provider.ts +3 -0
- package/src/proxy-worker.ts +14 -1
- package/src/proxy.ts +12 -1
- package/src/runner-protocol.ts +3 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/provider-cloudflare",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -42,15 +42,15 @@
|
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
44
|
"zod": "^3.25.76",
|
|
45
|
-
"@fabrika/app": "0.5.
|
|
46
|
-
"@fabrika/auth": "0.5.
|
|
47
|
-
"@fabrika/auth-core": "0.5.
|
|
48
|
-
"@fabrika/check": "0.5.
|
|
49
|
-
"@fabrika/email": "0.5.
|
|
50
|
-
"@fabrika/iam-contract": "0.5.
|
|
51
|
-
"@fabrika/installation-init": "0.5.
|
|
52
|
-
"@fabrika/proxy-core": "0.5.
|
|
53
|
-
"@fabrika/provider-contract": "0.5.
|
|
45
|
+
"@fabrika/app": "0.5.4",
|
|
46
|
+
"@fabrika/auth": "0.5.4",
|
|
47
|
+
"@fabrika/auth-core": "0.5.4",
|
|
48
|
+
"@fabrika/check": "0.5.4",
|
|
49
|
+
"@fabrika/email": "0.5.4",
|
|
50
|
+
"@fabrika/iam-contract": "0.5.4",
|
|
51
|
+
"@fabrika/installation-init": "0.5.4",
|
|
52
|
+
"@fabrika/proxy-core": "0.5.4",
|
|
53
|
+
"@fabrika/provider-contract": "0.5.4",
|
|
54
54
|
"oblaka-iac": "^0.0.18"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/command.ts
CHANGED
|
@@ -4,7 +4,13 @@ import { z } from 'zod'
|
|
|
4
4
|
import type { CloudflareAppConfig } from './authoring'
|
|
5
5
|
import { loadCloudflareConfig } from './collaborators'
|
|
6
6
|
import { type CloudflareDeployResult, createCloudflareDeployer, type PlatformIamTarget } from './provider'
|
|
7
|
-
import {
|
|
7
|
+
import {
|
|
8
|
+
APPROVED_ACCESS_FILE_ENV,
|
|
9
|
+
CROSS_ORIGINS_ENV,
|
|
10
|
+
INSTALLATION_APPS_ENV,
|
|
11
|
+
type RunnerApprovedAccess,
|
|
12
|
+
runnerApprovedAccessSchema,
|
|
13
|
+
} from './runner-protocol'
|
|
8
14
|
|
|
9
15
|
const requiredEnvironmentValue = (name: string): string => {
|
|
10
16
|
const value = environmentValue(name)
|
|
@@ -47,6 +53,24 @@ export const parseReturnOrigins = (raw: string | undefined): readonly string[] |
|
|
|
47
53
|
}
|
|
48
54
|
|
|
49
55
|
const installationAppsSchema = z.array(z.string())
|
|
56
|
+
const crossOriginsSchema = z.array(z.string())
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Decode `FABRIKA_CROSS_ORIGINS`, the environment's cross-origin list as the runner writes it. Undefined when absent or
|
|
60
|
+
* empty; anything malformed fails the deploy, and the proxy manifest's own parser judges each origin.
|
|
61
|
+
*/
|
|
62
|
+
export const parseCrossOrigins = (raw: string | undefined): readonly string[] | undefined => {
|
|
63
|
+
if (raw === undefined || raw === '') return undefined
|
|
64
|
+
let decoded: unknown
|
|
65
|
+
try {
|
|
66
|
+
decoded = JSON.parse(raw)
|
|
67
|
+
} catch {
|
|
68
|
+
throw new Error(`${CROSS_ORIGINS_ENV} is not a JSON array`)
|
|
69
|
+
}
|
|
70
|
+
const origins = crossOriginsSchema.safeParse(decoded)
|
|
71
|
+
if (!origins.success) throw new Error(`${CROSS_ORIGINS_ENV} is not a JSON array of strings`)
|
|
72
|
+
return origins.data.length === 0 ? undefined : origins.data
|
|
73
|
+
}
|
|
50
74
|
|
|
51
75
|
/**
|
|
52
76
|
* Decode `FABRIKA_INSTALLATION_APPS`, the Cloudflare deployments Control registered, as the runner writes it.
|
|
@@ -130,10 +154,12 @@ export const deployCloudflareConfig = async (options: CloudflareCommandDeployOpt
|
|
|
130
154
|
const domain = environmentValue('FABRIKA_CONTROL_DOMAIN')
|
|
131
155
|
const returnOrigins = parseReturnOrigins(environmentValue('FABRIKA_IAM_RETURN_ORIGINS'))
|
|
132
156
|
const installationApps = parseInstallationApps(environmentValue(INSTALLATION_APPS_ENV))
|
|
157
|
+
const crossOrigins = parseCrossOrigins(environmentValue(CROSS_ORIGINS_ENV))
|
|
133
158
|
return deploy({
|
|
134
159
|
appId: loaded.config.id,
|
|
135
160
|
env: options.env,
|
|
136
161
|
...(domain === undefined ? {} : { domain }),
|
|
162
|
+
...(crossOrigins === undefined ? {} : { crossOrigins }),
|
|
137
163
|
...(returnOrigins === undefined ? {} : { returnOrigins }),
|
|
138
164
|
...(installationApps === undefined ? {} : { installationApps }),
|
|
139
165
|
...approved,
|
package/src/control.ts
CHANGED
|
@@ -25,6 +25,7 @@ import type {
|
|
|
25
25
|
SchemaReconciler,
|
|
26
26
|
} from '@fabrika/provider-contract'
|
|
27
27
|
import { abortableWait, decodeEnvelope, isLeaseLoss, ProviderInvocationAbort } from '@fabrika/provider-contract'
|
|
28
|
+
import { isCrossOrigin, MAX_CROSS_ORIGINS } from '@fabrika/proxy-core/headers'
|
|
28
29
|
import { isProxyHost } from '@fabrika/proxy-core/manifest'
|
|
29
30
|
import { z } from 'zod'
|
|
30
31
|
import { cloudflareArtifactCodec } from './codec'
|
|
@@ -66,6 +67,8 @@ export interface CloudflareRunnerJob {
|
|
|
66
67
|
readonly configPath?: string
|
|
67
68
|
readonly stateNamespace?: string
|
|
68
69
|
readonly domain?: string
|
|
70
|
+
/** The environment's cross-origin list from Control's registry (ADR-0022); the proxy Worker's manifest entry lists it. */
|
|
71
|
+
readonly crossOrigins?: readonly string[]
|
|
69
72
|
/** Every origin IAM may hand this app a session at, projected by the control plane (ADR-0022). */
|
|
70
73
|
readonly returnOrigins?: readonly string[]
|
|
71
74
|
/** `<app>@<env>` of every Cloudflare deployment in Control's registry; the deploy refuses another application's names. */
|
|
@@ -155,6 +158,7 @@ export const cloudflareRunnerJobSchema = z.object({
|
|
|
155
158
|
configPath: z.string().refine(isContainedPath).optional(),
|
|
156
159
|
stateNamespace: z.string().min(1).optional(),
|
|
157
160
|
domain: z.string().refine((value) => isProxyHost(value.toLowerCase())).optional(),
|
|
161
|
+
crossOrigins: z.array(z.string().refine(isCrossOrigin)).max(MAX_CROSS_ORIGINS).optional(),
|
|
158
162
|
returnOrigins: z.array(z.string().min(1)).optional(),
|
|
159
163
|
installationApps: z.array(z.string().refine((id) => !hasUnsafeChars(id) && parseAppEnvironmentId(id) !== null)).optional(),
|
|
160
164
|
approvedAccess: runnerApprovedAccessSchema.optional(),
|
|
@@ -172,8 +176,18 @@ export const cloudflareRunnerJobSchema = z.object({
|
|
|
172
176
|
runId: z.string().min(1),
|
|
173
177
|
}).optional(),
|
|
174
178
|
}).refine((job) => job.dryRun === true || isCanonicalCommit(job.ref))
|
|
179
|
+
.refine((job) => crossOriginsFit(job.crossOrigins ?? [], job.domain))
|
|
175
180
|
.refine((job) => job.dryRun === true || job.approvedAccess !== undefined)
|
|
176
181
|
|
|
182
|
+
/**
|
|
183
|
+
* Each origin once, never the environment's own domain: the rule the proxy manifest parser applies to the entry. A
|
|
184
|
+
* refinement also runs over an origin its element check refused, so the host is read only from a valid one.
|
|
185
|
+
*/
|
|
186
|
+
function crossOriginsFit(origins: readonly string[], domain: string | undefined): boolean {
|
|
187
|
+
const host = domain?.toLowerCase()
|
|
188
|
+
return new Set(origins).size === origins.length && origins.every((origin) => isCrossOrigin(origin) && new URL(origin).hostname !== host)
|
|
189
|
+
}
|
|
190
|
+
|
|
177
191
|
export interface CloudflareCloneSource {
|
|
178
192
|
readonly repoUrl: string
|
|
179
193
|
}
|
|
@@ -316,6 +330,9 @@ const buildJob = async (options: CloudflareControlOptions, input: ProviderDeploy
|
|
|
316
330
|
configPath: artifact.configPath,
|
|
317
331
|
...(storedTarget.stateNamespace === undefined ? {} : { stateNamespace: storedTarget.stateNamespace }),
|
|
318
332
|
...(input.environment.domain === undefined ? {} : { domain: input.environment.domain }),
|
|
333
|
+
...(input.environment.crossOrigins === undefined || input.environment.crossOrigins.length === 0
|
|
334
|
+
? {}
|
|
335
|
+
: { crossOrigins: input.environment.crossOrigins }),
|
|
319
336
|
...(input.returnOrigins === undefined ? {} : { returnOrigins: input.returnOrigins }),
|
|
320
337
|
...(installationApps === undefined ? {} : { installationApps }),
|
|
321
338
|
...(approvedAccess === undefined ? {} : { approvedAccess }),
|
|
@@ -27,7 +27,7 @@ const LEGACY_REF_FILES = ['vozka.ref', 'propustka.ref']
|
|
|
27
27
|
export { INITIAL_SCAFFOLD_COMMIT_MESSAGE, REFRESH_SCAFFOLD_COMMIT_MESSAGE }
|
|
28
28
|
|
|
29
29
|
export interface ScaffoldInput {
|
|
30
|
-
/** The base repo, e.g. `
|
|
30
|
+
/** The base repo, e.g. `acme/fabrika-platform`. */
|
|
31
31
|
repo: string
|
|
32
32
|
/** The account label (positional `init` arg) — substituted into the templates + the env/summary names. */
|
|
33
33
|
account: string
|
|
@@ -17,7 +17,7 @@ on:
|
|
|
17
17
|
retire_legacy_propustka_worker:
|
|
18
18
|
description: >-
|
|
19
19
|
Name of a LEGACY propustka Worker to delete BEFORE Stage 1 (one-off migration off an old
|
|
20
|
-
deploy — e.g. a CF-Access-era
|
|
20
|
+
deploy — e.g. a CF-Access-era `<env>-propustka-worker`). Deleting it releases its Custom
|
|
21
21
|
Domain so the new env-prod propustka can claim it. Empty = skip (the normal case).
|
|
22
22
|
type: string
|
|
23
23
|
default: ''
|
package/src/provider.ts
CHANGED
|
@@ -172,6 +172,7 @@ const platformProxied = (authored: Worker, contract: ContractArtifact, run: Clou
|
|
|
172
172
|
appId: appEnvironmentId(run.appId, run.env),
|
|
173
173
|
appHost: run.domain ?? 'localhost',
|
|
174
174
|
...(run.domain === undefined ? {} : { domain: run.domain }),
|
|
175
|
+
...(run.crossOrigins === undefined ? {} : { crossOrigins: run.crossOrigins }),
|
|
175
176
|
endpoints: contractProxyTable(contract),
|
|
176
177
|
...operationsOrigin(run.managedEnvironment),
|
|
177
178
|
iamUrl: run.managedEnvironment[FABRIKA_IAM_ISSUER] ?? '',
|
|
@@ -414,6 +415,8 @@ export interface CloudflareDeployRun {
|
|
|
414
415
|
readonly appId: string
|
|
415
416
|
readonly env: string
|
|
416
417
|
readonly domain?: string
|
|
418
|
+
/** The environment's cross-origin list from Control's registry (ADR-0022); the proxy Worker's manifest entry lists it. */
|
|
419
|
+
readonly crossOrigins?: readonly string[]
|
|
417
420
|
/** Every origin IAM may hand this environment a session at, registered under `<app>@<env>`. */
|
|
418
421
|
readonly returnOrigins?: readonly string[]
|
|
419
422
|
readonly cwd: string
|
package/src/proxy-worker.ts
CHANGED
|
@@ -13,6 +13,7 @@ import {
|
|
|
13
13
|
FORWARDED_URI_HEADER,
|
|
14
14
|
MemoryTokenCache,
|
|
15
15
|
OAUTH_METADATA_VERIFY_PATH,
|
|
16
|
+
PREFLIGHT_HEADER,
|
|
16
17
|
PROXY_TOKEN_HEADER,
|
|
17
18
|
REQUEST_ID_HEADER,
|
|
18
19
|
stripFabrikaCookies,
|
|
@@ -21,8 +22,10 @@ import {
|
|
|
21
22
|
import {
|
|
22
23
|
appFileTreatment,
|
|
23
24
|
appHeaderPolicy,
|
|
25
|
+
applyCrossOriginHeaders,
|
|
24
26
|
applyFileTreatment,
|
|
25
27
|
applyHeaderPolicy,
|
|
28
|
+
crossOriginHeaders,
|
|
26
29
|
type HeaderPolicy,
|
|
27
30
|
withResponseHeaders,
|
|
28
31
|
} from '@fabrika/proxy-core/headers'
|
|
@@ -154,6 +157,8 @@ function proxyHandler(env: CloudflareProxyEnv, manifest: ProxyManifest, verify:
|
|
|
154
157
|
}),
|
|
155
158
|
)
|
|
156
159
|
if (!verification.ok || isMetadata) return verification
|
|
160
|
+
// An admitted preflight: the decision's 2xx is the whole answer, and the application never sees the request.
|
|
161
|
+
if (verification.headers.get(PREFLIGHT_HEADER) === '1') return withResponseHeaders(verification, (headers) => headers.delete(PREFLIGHT_HEADER))
|
|
157
162
|
|
|
158
163
|
if (app === null) return new Response('not found', { status: 404 })
|
|
159
164
|
const treatment = answerHeaders.get(app.id)
|
|
@@ -183,10 +188,18 @@ function proxyHandler(env: CloudflareProxyEnv, manifest: ProxyManifest, verify:
|
|
|
183
188
|
// Nothing of the error is answered or logged: it can carry the upstream request, a token header included.
|
|
184
189
|
answer = new Response('bad gateway', { status: 502, headers: { 'content-type': 'text/plain; charset=utf-8', 'cache-control': 'no-store' } })
|
|
185
190
|
}
|
|
186
|
-
|
|
191
|
+
if (treatment === undefined) return answer
|
|
192
|
+
// The treatment deleted the application's own `Access-Control-*`; only the origin the decision admitted is set.
|
|
193
|
+
const allowOrigin = verification.headers.get(ALLOW_ORIGIN_HEADER)
|
|
194
|
+
return withResponseHeaders(answer, (headers) => {
|
|
195
|
+
treatment(verification.headers.get(ENDPOINT_HEADER))(headers)
|
|
196
|
+
if (allowOrigin !== null) applyCrossOriginHeaders(headers, crossOriginHeaders(allowOrigin))
|
|
197
|
+
})
|
|
187
198
|
}
|
|
188
199
|
}
|
|
189
200
|
|
|
201
|
+
const ALLOW_ORIGIN_HEADER = 'Access-Control-Allow-Origin'
|
|
202
|
+
|
|
190
203
|
/**
|
|
191
204
|
* What a contract application's answer is given, replacing whatever the application set (ADR-0022): the file
|
|
192
205
|
* treatment for the download endpoint the decision asserted, the policy otherwise. The decision's own answers carry
|
package/src/proxy.ts
CHANGED
|
@@ -29,6 +29,8 @@ interface CloudflareContractProxyOptions {
|
|
|
29
29
|
readonly installation?: never
|
|
30
30
|
/** The Operations ingest origin a contract application's `connect-src` admits, from its managed DSN. */
|
|
31
31
|
readonly operationsOrigin?: string
|
|
32
|
+
/** The origins the environment lists for its cross-origin endpoints, from Control's registry (ADR-0022). */
|
|
33
|
+
readonly crossOrigins?: readonly string[]
|
|
32
34
|
}
|
|
33
35
|
|
|
34
36
|
/**
|
|
@@ -110,5 +112,14 @@ function proxyApp(placement: Pick<ProxyApp, 'id' | 'hosts' | 'upstream' | 'schem
|
|
|
110
112
|
}
|
|
111
113
|
const { endpoints, reservedPrefixes, snapshot, csp } = options.endpoints
|
|
112
114
|
const operationsOrigin = options.operationsOrigin
|
|
113
|
-
|
|
115
|
+
const crossOrigins = options.crossOrigins ?? []
|
|
116
|
+
return {
|
|
117
|
+
...placement,
|
|
118
|
+
endpoints,
|
|
119
|
+
reservedPrefixes,
|
|
120
|
+
snapshot,
|
|
121
|
+
csp,
|
|
122
|
+
...(operationsOrigin === undefined ? {} : { operationsOrigin }),
|
|
123
|
+
...(crossOrigins.length === 0 ? {} : { crossOrigins: [...crossOrigins] }),
|
|
124
|
+
}
|
|
114
125
|
}
|
package/src/runner-protocol.ts
CHANGED
|
@@ -22,6 +22,9 @@ export const RUNNER_OUTCOME_FILE_ENV = 'FABRIKA_RUNNER_OUTCOME_FILE'
|
|
|
22
22
|
/** The executor's copy of `CloudflareRunnerJob.installationApps`: a JSON array of `<app>@<env>`. */
|
|
23
23
|
export const INSTALLATION_APPS_ENV = 'FABRIKA_INSTALLATION_APPS'
|
|
24
24
|
|
|
25
|
+
/** The executor's copy of `CloudflareRunnerJob.crossOrigins`: a JSON array of the environment's exact origins. */
|
|
26
|
+
export const CROSS_ORIGINS_ENV = 'FABRIKA_CROSS_ORIGINS'
|
|
27
|
+
|
|
25
28
|
/**
|
|
26
29
|
* The access Control approved for a run (ADR-0050): the contract it read at the commit. The proxy table and
|
|
27
30
|
* `FABRIKA_CONTRACT_DIGEST` follow this, never the checkout.
|