@fabrika/provider-cloudflare 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 +11 -11
- package/src/bounds.ts +25 -9
- package/src/provider.ts +1 -1
- package/src/proxy-worker.ts +5 -2
- package/src/proxy.ts +19 -5
- package/types/src/control.d.ts +8 -8
- package/types/src/proxy.d.ts +14 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/provider-cloudflare",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -38,20 +38,20 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"typecheck": "
|
|
41
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
42
42
|
"test": "bun test"
|
|
43
43
|
},
|
|
44
44
|
"dependencies": {
|
|
45
45
|
"zod": "^3.25.76",
|
|
46
|
-
"@fabrika/app": "0.9.0-dev.
|
|
47
|
-
"@fabrika/auth": "0.9.0-dev.
|
|
48
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
49
|
-
"@fabrika/check": "0.9.0-dev.
|
|
50
|
-
"@fabrika/email": "0.9.0-dev.
|
|
51
|
-
"@fabrika/iam-contract": "0.9.0-dev.
|
|
52
|
-
"@fabrika/installation-init": "0.9.0-dev.
|
|
53
|
-
"@fabrika/proxy-core": "0.9.0-dev.
|
|
54
|
-
"@fabrika/provider-contract": "0.9.0-dev.
|
|
46
|
+
"@fabrika/app": "0.9.0-dev.13",
|
|
47
|
+
"@fabrika/auth": "0.9.0-dev.13",
|
|
48
|
+
"@fabrika/auth-core": "0.9.0-dev.13",
|
|
49
|
+
"@fabrika/check": "0.9.0-dev.13",
|
|
50
|
+
"@fabrika/email": "0.9.0-dev.13",
|
|
51
|
+
"@fabrika/iam-contract": "0.9.0-dev.13",
|
|
52
|
+
"@fabrika/installation-init": "0.9.0-dev.13",
|
|
53
|
+
"@fabrika/proxy-core": "0.9.0-dev.13",
|
|
54
|
+
"@fabrika/provider-contract": "0.9.0-dev.13",
|
|
55
55
|
"ignore": "^5.3.2",
|
|
56
56
|
"oblaka-iac": "^0.0.18"
|
|
57
57
|
}
|
package/src/bounds.ts
CHANGED
|
@@ -6,7 +6,14 @@ import type { GeneratedConfig, Worker } from 'oblaka-iac'
|
|
|
6
6
|
import { CloudflareClient } from 'oblaka-iac/src/client'
|
|
7
7
|
import { ResourceProcessor } from 'oblaka-iac/src/commands/resource-processor'
|
|
8
8
|
import { PLATFORM_RESOURCE_NAMES } from './plan'
|
|
9
|
-
import {
|
|
9
|
+
import {
|
|
10
|
+
CLOUDFLARE_PROXY_WORKER_DIR,
|
|
11
|
+
IAM_APPLICATION_ENTRYPOINT,
|
|
12
|
+
IAM_SERVICE,
|
|
13
|
+
type IamBindingHolder,
|
|
14
|
+
iamBindingProps,
|
|
15
|
+
PROXY_MANIFEST_DEFINE,
|
|
16
|
+
} from './proxy'
|
|
10
17
|
|
|
11
18
|
type WranglerConfig = GeneratedConfig['config']
|
|
12
19
|
|
|
@@ -238,7 +245,13 @@ const field = (entry: unknown, name: string): unknown => typeof entry === 'objec
|
|
|
238
245
|
* The one platform service an application may bind is IAM, and only at `IAM_APPLICATION_ENTRYPOINT`: the default
|
|
239
246
|
* export issues keys and approves devices. Another application's Worker is never bound.
|
|
240
247
|
*/
|
|
241
|
-
const assertServices = (
|
|
248
|
+
const assertServices = (
|
|
249
|
+
worker: string,
|
|
250
|
+
config: WranglerConfig,
|
|
251
|
+
names: ApplicationNames,
|
|
252
|
+
holder: IamBindingHolder,
|
|
253
|
+
connectors: Readonly<Record<string, string>>,
|
|
254
|
+
): void => {
|
|
242
255
|
const env = names.self.env
|
|
243
256
|
const iam = env === 'local' ? IAM_SERVICE : `${env}-${IAM_SERVICE}`
|
|
244
257
|
for (const entry of entries(config.services, worker, 'services')) {
|
|
@@ -256,7 +269,7 @@ const assertServices = (worker: string, config: WranglerConfig, names: Applicati
|
|
|
256
269
|
`cloudflare: Worker \`${worker}\` binds \`${service}\` to ${bound}; an application binds \`${IAM_APPLICATION_ENTRYPOINT}\` (use \`iamServiceReference()\`)`,
|
|
257
270
|
)
|
|
258
271
|
}
|
|
259
|
-
assertIamIdentity(worker, binding, field(entry, 'props'), names)
|
|
272
|
+
assertIamIdentity(worker, binding, field(entry, 'props'), names, holder)
|
|
260
273
|
continue
|
|
261
274
|
}
|
|
262
275
|
assertOwnRemote(`Worker \`${worker}\` binds service`, service, names)
|
|
@@ -264,17 +277,19 @@ const assertServices = (worker: string, config: WranglerConfig, names: Applicati
|
|
|
264
277
|
}
|
|
265
278
|
|
|
266
279
|
/**
|
|
267
|
-
* IAM reads a binding's `props
|
|
268
|
-
*
|
|
280
|
+
* IAM reads a binding's `props` as the calling application (ADR-0067 §3) and, on the application Worker's, as the mark
|
|
281
|
+
* that refuses it a delegation grant (ADR-0022 rule 6). So an IAM binding carries exactly what the deployer writes for
|
|
282
|
+
* the Worker that holds it (`iamBindingProps`), and nothing else.
|
|
269
283
|
*/
|
|
270
|
-
const assertIamIdentity = (worker: string, binding: unknown, props: unknown, names: ApplicationNames): void => {
|
|
284
|
+
const assertIamIdentity = (worker: string, binding: unknown, props: unknown, names: ApplicationNames, holder: IamBindingHolder): void => {
|
|
271
285
|
const app = appEnvironmentId(names.self.app, names.self.env)
|
|
286
|
+
const expected = Object.entries(iamBindingProps(app, holder))
|
|
272
287
|
const keys = typeof props === 'object' && props !== null ? Object.keys(props) : []
|
|
273
|
-
if (keys.length !==
|
|
288
|
+
if (keys.length !== expected.length || expected.some(([name, value]) => field(props, name) !== value)) {
|
|
274
289
|
throw new Error(
|
|
275
290
|
`cloudflare: Worker \`${worker}\` binds IAM as \`${
|
|
276
291
|
String(binding)
|
|
277
|
-
}\` without naming its own application \`${app}
|
|
292
|
+
}\` without naming its own application \`${app}\` as the deployer does; only the deployer's \`IAM\` binding reaches IAM`,
|
|
278
293
|
)
|
|
279
294
|
}
|
|
280
295
|
}
|
|
@@ -509,7 +524,8 @@ export const assertGeneratedConfigs = (configs: readonly GeneratedConfig[], boun
|
|
|
509
524
|
}
|
|
510
525
|
}
|
|
511
526
|
assertOwnRemote('the Worker is named', config.name, names)
|
|
512
|
-
assertServices(worker, config, names,
|
|
527
|
+
if (isPlatformProxy(generated, bounds)) assertServices(worker, config, names, 'proxy', {})
|
|
528
|
+
else assertServices(worker, config, names, 'application', bounds.connectors)
|
|
513
529
|
assertResourceBindings(worker, config, names)
|
|
514
530
|
assertBoundedAssets(worker, config.assets)
|
|
515
531
|
if (isPlatformProxy(generated, bounds)) {
|
package/src/provider.ts
CHANGED
|
@@ -315,7 +315,7 @@ const withIamIdentity = (authored: Worker, iamAppId: string): Worker => {
|
|
|
315
315
|
if (declared === undefined || 'getId' in declared) return authored
|
|
316
316
|
const configured = new Worker({
|
|
317
317
|
...application.options,
|
|
318
|
-
bindings: { ...application.options.bindings, IAM: new IamApplicationReference(iamAppId, declared) },
|
|
318
|
+
bindings: { ...application.options.bindings, IAM: new IamApplicationReference(iamAppId, 'application', declared) },
|
|
319
319
|
})
|
|
320
320
|
return replaceApplicationWorker(authored, configured)
|
|
321
321
|
}
|
package/src/proxy-worker.ts
CHANGED
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
applyHeaderPolicy,
|
|
33
33
|
crossOriginHeaders,
|
|
34
34
|
type HeaderPolicy,
|
|
35
|
+
inlineFileTypes,
|
|
35
36
|
withResponseHeaders,
|
|
36
37
|
} from '@fabrika/proxy-core/headers'
|
|
37
38
|
import { type ContractProxyApp, isApplicationEntry, parseProxyManifestJson, type ProxyApp, type ProxyManifest } from '@fabrika/proxy-core/manifest'
|
|
@@ -229,7 +230,8 @@ type AnswerHeaders = (endpoint: string | null, status: number) => (headers: Head
|
|
|
229
230
|
function contractAnswerHeaders(app: ContractProxyApp): AnswerHeaders {
|
|
230
231
|
const policy: HeaderPolicy = appHeaderPolicy(app)
|
|
231
232
|
const fileTreatment: HeaderPolicy = appFileTreatment(app)
|
|
232
|
-
|
|
233
|
+
// A download's inline types, by row: an `inline-file` row also shows the XML documents.
|
|
234
|
+
const downloads = new Map(app.endpoints.filter(answersFile).map((row) => [row.id, inlineFileTypes('response' in row ? row.response : undefined)]))
|
|
233
235
|
const cached = new Map<string, EndpointCache>()
|
|
234
236
|
for (const row of app.endpoints) {
|
|
235
237
|
if ('cache' in row && row.cache !== undefined) cached.set(row.id, row.cache)
|
|
@@ -237,7 +239,8 @@ function contractAnswerHeaders(app: ContractProxyApp): AnswerHeaders {
|
|
|
237
239
|
return (endpoint, status) => {
|
|
238
240
|
const id = endpoint === null ? null : (parseEndpointHeader(endpoint)?.id ?? null)
|
|
239
241
|
return (headers) => {
|
|
240
|
-
|
|
242
|
+
const inline = id === null ? undefined : downloads.get(id)
|
|
243
|
+
if (inline !== undefined) applyFileTreatment(headers, fileTreatment, inline)
|
|
241
244
|
else applyHeaderPolicy(headers, policy)
|
|
242
245
|
const cache = id === null ? undefined : cached.get(id)
|
|
243
246
|
if (cache !== undefined) applyAnswerCache(headers, { cache }, status)
|
package/src/proxy.ts
CHANGED
|
@@ -74,21 +74,35 @@ export const IAM_APPLICATION_ENTRYPOINT = 'PropustkaApplication'
|
|
|
74
74
|
/** The `IAM` binding of an application Worker; a generated config that binds IAM any other way is refused. */
|
|
75
75
|
export const iamServiceReference = (): ServiceReference => new ServiceReference(IAM_SERVICE, IAM_APPLICATION_ENTRYPOINT)
|
|
76
76
|
|
|
77
|
+
/** Which Worker of a deployment holds an `IAM` binding: the application Worker, or the proxy Worker the platform builds. */
|
|
78
|
+
export type IamBindingHolder = 'application' | 'proxy'
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* The `props` the deployer writes on an `IAM` binding. `app` is the deployment's IAM application id. The application
|
|
82
|
+
* Worker's binding also carries `worker: 'application'`, which IAM refuses a delegation grant to (ADR-0022 rule 6). The
|
|
83
|
+
* proxy's carries no mark, so a proxy deployed before the mark existed keeps obtaining grants.
|
|
84
|
+
*/
|
|
85
|
+
export const iamBindingProps = (app: string, holder: IamBindingHolder): Readonly<Record<string, string>> =>
|
|
86
|
+
holder === 'application' ? { app, worker: 'application' } : { app }
|
|
87
|
+
|
|
77
88
|
/**
|
|
78
89
|
* The deployer's `IAM` binding: what the Worker declared, with the IAM service entry's `props` naming the deployment's
|
|
79
|
-
* IAM application id. IAM reads it as `ctx.props
|
|
80
|
-
* membership transport key is over HTTP (ADR-0067 §3). An application cannot choose it: the deployer
|
|
81
|
-
* bounds refuse an IAM binding
|
|
90
|
+
* IAM application id (`iamBindingProps`). IAM reads it as `ctx.props`, the transport identity of a call over the
|
|
91
|
+
* binding, as the membership transport key is over HTTP (ADR-0067 §3). An application cannot choose it: the deployer
|
|
92
|
+
* writes it, and the bounds refuse an IAM binding whose `props` are anything else. Repository code holding the account
|
|
93
|
+
* token can still deploy past the bounds (ADR-0048, backlog 86).
|
|
82
94
|
*/
|
|
83
95
|
export class IamApplicationReference implements Binding {
|
|
84
96
|
constructor(
|
|
85
97
|
private readonly app: string,
|
|
98
|
+
private readonly holder: IamBindingHolder,
|
|
86
99
|
private readonly declared: Binding = iamServiceReference(),
|
|
87
100
|
) {}
|
|
88
101
|
|
|
89
102
|
configureBinding(args: Parameters<Binding['configureBinding']>[0]): ReturnType<Binding['configureBinding']> {
|
|
90
103
|
const config = this.declared.configureBinding(args)
|
|
91
|
-
const
|
|
104
|
+
const props = iamBindingProps(this.app, this.holder)
|
|
105
|
+
const services = (config.services ?? []).map((entry) => entry.binding === args.binding ? { ...entry, props } : entry)
|
|
92
106
|
return { ...config, services }
|
|
93
107
|
}
|
|
94
108
|
}
|
|
@@ -134,7 +148,7 @@ export function createCloudflareProxyWorker(options: CloudflareProxyWorkerOption
|
|
|
134
148
|
define: { [PROXY_MANIFEST_DEFINE]: JSON.stringify(encodeProxyManifestJson(manifest)) },
|
|
135
149
|
vars: { FABRIKA_IAM_ISSUER: options.iamUrl ?? '' },
|
|
136
150
|
bindings: {
|
|
137
|
-
IAM: options.installation === undefined ? new IamApplicationReference(options.appId, iam) : iam,
|
|
151
|
+
IAM: options.installation === undefined ? new IamApplicationReference(options.appId, 'proxy', iam) : iam,
|
|
138
152
|
APP: options.app,
|
|
139
153
|
},
|
|
140
154
|
})
|
package/types/src/control.d.ts
CHANGED
|
@@ -175,10 +175,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
175
175
|
secrets?: {
|
|
176
176
|
[k: string]: string;
|
|
177
177
|
} | undefined;
|
|
178
|
+
domain?: string | undefined;
|
|
178
179
|
operationsOrigin?: string | undefined;
|
|
179
180
|
crossOrigins?: string[] | undefined;
|
|
180
181
|
dryRun?: boolean | undefined;
|
|
181
|
-
domain?: string | undefined;
|
|
182
182
|
managedEnvironment?: {
|
|
183
183
|
[k: string]: string;
|
|
184
184
|
} | undefined;
|
|
@@ -209,10 +209,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
209
209
|
repoUrl: string;
|
|
210
210
|
vars?: unknown;
|
|
211
211
|
secrets?: unknown;
|
|
212
|
+
domain?: string | undefined;
|
|
212
213
|
operationsOrigin?: string | undefined;
|
|
213
214
|
crossOrigins?: string[] | undefined;
|
|
214
215
|
dryRun?: boolean | undefined;
|
|
215
|
-
domain?: string | undefined;
|
|
216
216
|
managedEnvironment?: unknown;
|
|
217
217
|
applicationObjects?: {
|
|
218
218
|
object: string;
|
|
@@ -253,10 +253,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
253
253
|
secrets?: {
|
|
254
254
|
[k: string]: string;
|
|
255
255
|
} | undefined;
|
|
256
|
+
domain?: string | undefined;
|
|
256
257
|
operationsOrigin?: string | undefined;
|
|
257
258
|
crossOrigins?: string[] | undefined;
|
|
258
259
|
dryRun?: boolean | undefined;
|
|
259
|
-
domain?: string | undefined;
|
|
260
260
|
managedEnvironment?: {
|
|
261
261
|
[k: string]: string;
|
|
262
262
|
} | undefined;
|
|
@@ -287,10 +287,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
287
287
|
repoUrl: string;
|
|
288
288
|
vars?: unknown;
|
|
289
289
|
secrets?: unknown;
|
|
290
|
+
domain?: string | undefined;
|
|
290
291
|
operationsOrigin?: string | undefined;
|
|
291
292
|
crossOrigins?: string[] | undefined;
|
|
292
293
|
dryRun?: boolean | undefined;
|
|
293
|
-
domain?: string | undefined;
|
|
294
294
|
managedEnvironment?: unknown;
|
|
295
295
|
applicationObjects?: {
|
|
296
296
|
object: string;
|
|
@@ -331,10 +331,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
331
331
|
secrets?: {
|
|
332
332
|
[k: string]: string;
|
|
333
333
|
} | undefined;
|
|
334
|
+
domain?: string | undefined;
|
|
334
335
|
operationsOrigin?: string | undefined;
|
|
335
336
|
crossOrigins?: string[] | undefined;
|
|
336
337
|
dryRun?: boolean | undefined;
|
|
337
|
-
domain?: string | undefined;
|
|
338
338
|
managedEnvironment?: {
|
|
339
339
|
[k: string]: string;
|
|
340
340
|
} | undefined;
|
|
@@ -365,10 +365,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
365
365
|
repoUrl: string;
|
|
366
366
|
vars?: unknown;
|
|
367
367
|
secrets?: unknown;
|
|
368
|
+
domain?: string | undefined;
|
|
368
369
|
operationsOrigin?: string | undefined;
|
|
369
370
|
crossOrigins?: string[] | undefined;
|
|
370
371
|
dryRun?: boolean | undefined;
|
|
371
|
-
domain?: string | undefined;
|
|
372
372
|
managedEnvironment?: unknown;
|
|
373
373
|
applicationObjects?: {
|
|
374
374
|
object: string;
|
|
@@ -409,10 +409,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
409
409
|
secrets?: {
|
|
410
410
|
[k: string]: string;
|
|
411
411
|
} | undefined;
|
|
412
|
+
domain?: string | undefined;
|
|
412
413
|
operationsOrigin?: string | undefined;
|
|
413
414
|
crossOrigins?: string[] | undefined;
|
|
414
415
|
dryRun?: boolean | undefined;
|
|
415
|
-
domain?: string | undefined;
|
|
416
416
|
managedEnvironment?: {
|
|
417
417
|
[k: string]: string;
|
|
418
418
|
} | undefined;
|
|
@@ -443,10 +443,10 @@ export declare const cloudflareRunnerJobSchema: z.ZodEffects<z.ZodEffects<z.ZodE
|
|
|
443
443
|
repoUrl: string;
|
|
444
444
|
vars?: unknown;
|
|
445
445
|
secrets?: unknown;
|
|
446
|
+
domain?: string | undefined;
|
|
446
447
|
operationsOrigin?: string | undefined;
|
|
447
448
|
crossOrigins?: string[] | undefined;
|
|
448
449
|
dryRun?: boolean | undefined;
|
|
449
|
-
domain?: string | undefined;
|
|
450
450
|
managedEnvironment?: unknown;
|
|
451
451
|
applicationObjects?: {
|
|
452
452
|
object: string;
|
package/types/src/proxy.d.ts
CHANGED
|
@@ -52,16 +52,26 @@ export declare const IAM_SERVICE = "propustka-worker";
|
|
|
52
52
|
export declare const IAM_APPLICATION_ENTRYPOINT = "PropustkaApplication";
|
|
53
53
|
/** The `IAM` binding of an application Worker; a generated config that binds IAM any other way is refused. */
|
|
54
54
|
export declare const iamServiceReference: () => ServiceReference;
|
|
55
|
+
/** Which Worker of a deployment holds an `IAM` binding: the application Worker, or the proxy Worker the platform builds. */
|
|
56
|
+
export type IamBindingHolder = 'application' | 'proxy';
|
|
57
|
+
/**
|
|
58
|
+
* The `props` the deployer writes on an `IAM` binding. `app` is the deployment's IAM application id. The application
|
|
59
|
+
* Worker's binding also carries `worker: 'application'`, which IAM refuses a delegation grant to (ADR-0022 rule 6). The
|
|
60
|
+
* proxy's carries no mark, so a proxy deployed before the mark existed keeps obtaining grants.
|
|
61
|
+
*/
|
|
62
|
+
export declare const iamBindingProps: (app: string, holder: IamBindingHolder) => Readonly<Record<string, string>>;
|
|
55
63
|
/**
|
|
56
64
|
* The deployer's `IAM` binding: what the Worker declared, with the IAM service entry's `props` naming the deployment's
|
|
57
|
-
* IAM application id. IAM reads it as `ctx.props
|
|
58
|
-
* membership transport key is over HTTP (ADR-0067 §3). An application cannot choose it: the deployer
|
|
59
|
-
* bounds refuse an IAM binding
|
|
65
|
+
* IAM application id (`iamBindingProps`). IAM reads it as `ctx.props`, the transport identity of a call over the
|
|
66
|
+
* binding, as the membership transport key is over HTTP (ADR-0067 §3). An application cannot choose it: the deployer
|
|
67
|
+
* writes it, and the bounds refuse an IAM binding whose `props` are anything else. Repository code holding the account
|
|
68
|
+
* token can still deploy past the bounds (ADR-0048, backlog 86).
|
|
60
69
|
*/
|
|
61
70
|
export declare class IamApplicationReference implements Binding {
|
|
62
71
|
private readonly app;
|
|
72
|
+
private readonly holder;
|
|
63
73
|
private readonly declared;
|
|
64
|
-
constructor(app: string, declared?: Binding);
|
|
74
|
+
constructor(app: string, holder: IamBindingHolder, declared?: Binding);
|
|
65
75
|
configureBinding(args: Parameters<Binding['configureBinding']>[0]): ReturnType<Binding['configureBinding']>;
|
|
66
76
|
}
|
|
67
77
|
/**
|