@fabrika/provider-cloudflare 0.4.2 → 0.4.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fabrika/provider-cloudflare",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,13 +42,14 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "zod": "^3.25.76",
45
- "@fabrika/app": "^0.4.2",
46
- "@fabrika/auth": "^0.4.2",
47
- "@fabrika/auth-core": "^0.4.2",
48
- "@fabrika/check": "^0.4.2",
49
- "@fabrika/installation-init": "^0.4.2",
50
- "@fabrika/proxy-core": "^0.4.2",
51
- "@fabrika/provider-contract": "^0.4.2",
45
+ "@fabrika/app": "^0.4.4",
46
+ "@fabrika/auth": "^0.4.4",
47
+ "@fabrika/auth-core": "^0.4.4",
48
+ "@fabrika/check": "^0.4.4",
49
+ "@fabrika/iam-contract": "^0.4.4",
50
+ "@fabrika/installation-init": "^0.4.4",
51
+ "@fabrika/proxy-core": "^0.4.4",
52
+ "@fabrika/provider-contract": "^0.4.4",
52
53
  "oblaka-iac": "^0.0.18"
53
54
  }
54
55
  }
package/src/command.ts CHANGED
@@ -3,7 +3,7 @@ import { readFile } from 'node:fs/promises'
3
3
  import { z } from 'zod'
4
4
  import type { CloudflareAppConfig } from './authoring'
5
5
  import { loadCloudflareConfig } from './collaborators'
6
- import { type CloudflareDeployResult, createCloudflareDeployer } from './provider'
6
+ import { type CloudflareDeployResult, createCloudflareDeployer, type PlatformIamTarget } from './provider'
7
7
  import { APPROVED_ACCESS_FILE_ENV, INSTALLATION_APPS_ENV, type RunnerApprovedAccess, runnerApprovedAccessSchema } from './runner-protocol'
8
8
 
9
9
  const requiredEnvironmentValue = (name: string): string => {
@@ -109,6 +109,8 @@ export interface CloudflareCommandDeployOptions {
109
109
  readonly managedVarNames?: readonly string[]
110
110
  /** Defaults to `refuse`: only fabrika deploying its own components may name a platform resource. */
111
111
  readonly platformResources?: 'refuse' | 'allow'
112
+ /** Where a platform deploy registers a component's schema (ADR-0058); only the installation sets it. */
113
+ readonly platformIam?: PlatformIamTarget
112
114
  readonly signal?: AbortSignal
113
115
  readonly log?: (line: string) => void
114
116
  }
@@ -123,6 +125,7 @@ export const deployCloudflareConfig = async (options: CloudflareCommandDeployOpt
123
125
  accountId: requiredEnvironmentValue('CLOUDFLARE_ACCOUNT_ID'),
124
126
  apiToken: requiredEnvironmentValue('CLOUDFLARE_API_TOKEN'),
125
127
  platformResources: options.platformResources ?? 'refuse',
128
+ ...(options.platformIam === undefined ? {} : { platformIam: options.platformIam }),
126
129
  })
127
130
  const domain = environmentValue('FABRIKA_CONTROL_DOMAIN')
128
131
  const returnOrigins = parseReturnOrigins(environmentValue('FABRIKA_IAM_RETURN_ORIGINS'))
@@ -1,7 +1,10 @@
1
+ import { IAM_APP_ID, IAM_APP_SCHEMA } from '@fabrika/iam-contract'
1
2
  import type { InstallationCli, InstallationCommand } from '@fabrika/provider-contract/installation'
2
3
  import { resolve } from 'node:path'
3
4
  import { parseCloudflareArgs, platformComponents } from '../cli-args'
4
5
  import { deployCloudflareConfig } from '../command'
6
+ import type { PlatformIamTarget } from '../provider'
7
+ import { defaultReconcileSchema } from '../schema'
5
8
  import { initCommand } from './init'
6
9
 
7
10
  const USAGE = `Cloudflare installation
@@ -43,10 +46,18 @@ one platform config (IAM, Operations) — the stages a pipeline runs before that
43
46
  name a platform resource; \`fabrika app deploy\` may not.
44
47
  `
45
48
 
49
+ /** IAM's origin and the provisioning key, when the stage names both; a component with a schema needs them. */
50
+ const platformIam = (): PlatformIamTarget | undefined => {
51
+ const url = process.env['FABRIKA_IAM_ISSUER']
52
+ const adminKey = process.env['FABRIKA_IAM_PROVISIONING_KEY']
53
+ return url === undefined || url === '' || adminKey === undefined || adminKey === '' ? undefined : { url, adminKey }
54
+ }
55
+
46
56
  const deployPlatform = async (argv: readonly string[], forceDryRun: boolean): Promise<void> => {
47
57
  const args = parseCloudflareArgs(['platform', 'deploy', ...argv, ...(forceDryRun ? ['--dry-run'] : [])])
48
58
  const env = args.env ?? 'prod'
49
59
  const stateNamespace = process.env['CLOUDFLARE_STATE_NAMESPACE']
60
+ const iam = platformIam()
50
61
  const rootCwd = process.cwd()
51
62
  for (const component of platformComponents(args)) {
52
63
  const absolute = resolve(rootCwd, component.configPath)
@@ -61,6 +72,7 @@ const deployPlatform = async (argv: readonly string[], forceDryRun: boolean): Pr
61
72
  cwd,
62
73
  dryRun: args.dryRun,
63
74
  platformResources: 'allow',
75
+ ...(iam === undefined ? {} : { platformIam: iam }),
64
76
  // Honoured because the scaffolded workflow states it on the IAM stage; absent elsewhere.
65
77
  ...(stateNamespace === undefined ? {} : { stateNamespace }),
66
78
  })
@@ -72,6 +84,22 @@ const deployPlatform = async (argv: readonly string[], forceDryRun: boolean): Pr
72
84
  process.chdir(rootCwd)
73
85
  }
74
86
  }
87
+ // IAM's own vocabulary registers beside the console's (ADR-0058): its own stage cannot, its keys sync after it deploys.
88
+ if (args.componentConfig === undefined || args.componentConfig === '') {
89
+ await registerIamVocabulary(iam, args.dryRun)
90
+ }
91
+ }
92
+
93
+ const registerIamVocabulary = async (iam: PlatformIamTarget | undefined, dryRun: boolean): Promise<void> => {
94
+ if (dryRun) {
95
+ console.info(`would reconcile \`${IAM_APP_ID}\`'s own vocabulary with IAM`)
96
+ return
97
+ }
98
+ if (iam === undefined) {
99
+ throw new Error(`registering \`${IAM_APP_ID}\`'s vocabulary needs FABRIKA_IAM_ISSUER and FABRIKA_IAM_PROVISIONING_KEY`)
100
+ }
101
+ await defaultReconcileSchema({ url: iam.url, app: IAM_APP_ID, schema: IAM_APP_SCHEMA, adminKey: iam.adminKey, signal: new AbortController().signal })
102
+ console.info(`${IAM_APP_ID}: vocabulary reconciled`)
75
103
  }
76
104
 
77
105
  const run = async (command: InstallationCommand, argv: readonly string[]): Promise<void> => {
@@ -59,9 +59,28 @@ jobs:
59
59
  ref: ${{ steps.ref.outputs.fabrika }}
60
60
  path: fabrika-platform
61
61
 
62
+ - name: Resolve the Bun release of the pinned tag
63
+ id: bun
64
+ working-directory: fabrika-platform
65
+ env:
66
+ PINNED_REF: ${{ steps.ref.outputs.fabrika }}
67
+ # Exactly the Bun the tag was built and released with, never `latest`: a newer Bun rewrites the
68
+ # lockfile. Tags up to v0.4.3 carry no `.bun-version` and were all released with Bun 1.3.14.
69
+ run: |
70
+ if [ -f .bun-version ]; then
71
+ version="$(tr -d '[:space:]' < .bun-version)"
72
+ else
73
+ version=1.3.14
74
+ fi
75
+ if ! printf '%s' "$version" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
76
+ echo "fabrika-platform@$PINNED_REF names no exact Bun release in .bun-version: '$version'." >&2
77
+ exit 1
78
+ fi
79
+ echo "version=$version" >> "$GITHUB_OUTPUT"
80
+
62
81
  - uses: oven-sh/setup-bun@v2
63
82
  with:
64
- bun-version: latest
83
+ bun-version: ${{ steps.bun.outputs.version }}
65
84
  # wrangler launches under Node even via Bun and needs Node 22+.
66
85
  - uses: actions/setup-node@v5
67
86
  with:
@@ -102,7 +121,8 @@ jobs:
102
121
  run: bunx wrangler delete --name "$LEGACY"
103
122
 
104
123
  # ── Stage 1 — IAM (root authz) ───────────────────────────────────────────────────────────────────
105
- # IAM is a regular Cloudflare provider bundle. Its empty schema needs no self-reconcile.
124
+ # IAM is a regular Cloudflare provider bundle. It declares no schema: its keys sync after its Worker deploys,
125
+ # so IAM cannot authenticate a reconcile in its own stage.
106
126
  - name: Deploy IAM
107
127
  working-directory: fabrika-platform/packages/iam
108
128
  env:
@@ -151,8 +171,10 @@ jobs:
151
171
  CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
152
172
  CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
153
173
  FABRIKA_CONTROL_VAULT_KEY: ${{ secrets.FABRIKA_CONTROL_VAULT_KEY }}
154
- # The seeded IAM provisioning key — the control plane reconciles its own schema with it (Bearer px_).
174
+ # The seeded IAM provisioning key — this stage registers the console's schema, with the console's return
175
+ # origin, and IAM's own vocabulary with it (Bearer px_), at FABRIKA_IAM_ISSUER.
155
176
  FABRIKA_IAM_PROVISIONING_KEY: ${{ secrets.FABRIKA_IAM_PROVISIONING_KEY }}
177
+ FABRIKA_IAM_RETURN_ORIGINS: https://${{ vars.FABRIKA_CONTROL_DOMAIN }}
156
178
  OPERATIONS_SYNC_KEY: ${{ secrets.OPERATIONS_SYNC_KEY }}
157
179
  # `wrangler secret put FABRIKA_RUNNER_KEY` on BOTH Workers this step deploys: the control plane
158
180
  # presents it to the deploy runner, and the runner rejects an RPC caller without it. One step,
package/src/provider.ts CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  FABRIKA_IAM_ISSUER,
10
10
  isFrameworkVariableName,
11
11
  } from '@fabrika/auth-core'
12
- import { type DeployStepResult, type ProviderManagedEnvironment, runSteps } from '@fabrika/provider-contract'
12
+ import { type DeployStepResult, type ProviderManagedEnvironment, runSteps, type SchemaReconciler } from '@fabrika/provider-contract'
13
13
  import { isPolicyOrigin } from '@fabrika/proxy-core/headers'
14
14
  import { contractProxyTable } from '@fabrika/proxy-core/manifest'
15
15
  import { dirname, resolve } from 'node:path'
@@ -29,6 +29,7 @@ import { type CloudflareCollaborators, defaultCloudflareCollaborators } from './
29
29
  import { configSchema } from './config-schema'
30
30
  import { buildPlan, type CloudflareStep, findMigratableDatabases } from './plan'
31
31
  import { createCloudflareProxyWorker } from './proxy'
32
+ import { defaultReconcileSchema } from './schema'
32
33
 
33
34
  const CANCELLED = 'deploy cancelled'
34
35
 
@@ -237,6 +238,8 @@ interface StepEnv {
237
238
  readonly dir: string
238
239
  readonly cf: CloudflareCollaborators
239
240
  readonly platformResources: 'refuse' | 'allow'
241
+ readonly platformIam: PlatformIamTarget | undefined
242
+ readonly reconcileSchema: SchemaReconciler
240
243
  readonly bounds: DeploymentBounds
241
244
  generatedConfigs: readonly GeneratedConfig[]
242
245
  }
@@ -328,13 +331,32 @@ const runStep = async (spec: CloudflareStep, env: StepEnv): Promise<void> => {
328
331
  if (schema === null) return
329
332
  const returnOrigins = run.returnOrigins !== undefined && run.returnOrigins.length > 0 ? run.returnOrigins : undefined
330
333
  if (dryRun) {
331
- run.log(` [dry-run] would report the authz schema for \`${config.id}\` to the control plane`)
334
+ run.log(
335
+ env.platformResources === 'allow'
336
+ ? ` [dry-run] would reconcile the authz schema for \`${config.id}\` with IAM`
337
+ : ` [dry-run] would report the authz schema for \`${config.id}\` to the control plane`,
338
+ )
332
339
  if (returnOrigins !== undefined) {
333
340
  run.log(` [dry-run] would register return origins for \`${config.id}\`: ${returnOrigins.join(', ')}`)
334
341
  }
335
342
  return
336
343
  }
337
344
  assertRunning(signal)
345
+ // The installation deploying its own component holds IAM's provisioning key and registers the schema itself.
346
+ if (env.platformResources === 'allow') {
347
+ if (env.platformIam === undefined) {
348
+ throw new Error('reconcile-schema: a platform deploy registers its schema with IAM; set FABRIKA_IAM_ISSUER and FABRIKA_IAM_PROVISIONING_KEY')
349
+ }
350
+ await env.reconcileSchema({
351
+ url: env.platformIam.url,
352
+ app: config.id,
353
+ schema,
354
+ ...(returnOrigins === undefined ? {} : { returnOrigins }),
355
+ adminKey: env.platformIam.adminKey,
356
+ signal,
357
+ })
358
+ return
359
+ }
338
360
  // The reconcile itself happens in the CONTROL plane, which holds IAM's admin key; this
339
361
  // container runs the checkout's own code and never sees it (ADR-0022).
340
362
  await cf.writeOutcome({ iamReconcile: { app: config.id, schemaJson: JSON.stringify(schema) } })
@@ -376,6 +398,16 @@ export interface CloudflareDeployerOptions {
376
398
  * operator deploying fabrika itself passes `allow`; a checkout is never trusted with it.
377
399
  */
378
400
  readonly platformResources?: 'refuse' | 'allow'
401
+ /** Where a platform deploy (`allow`) registers a component's schema. Never set for an application deploy. */
402
+ readonly platformIam?: PlatformIamTarget
403
+ /** Replaces the HTTP reconcile with IAM (tests). */
404
+ readonly reconcileSchema?: SchemaReconciler
405
+ }
406
+
407
+ /** IAM's origin and the installation's provisioning key, as the installation's own deploy holds them. */
408
+ export interface PlatformIamTarget {
409
+ readonly url: string
410
+ readonly adminKey: string
379
411
  }
380
412
 
381
413
  export interface CloudflareDeployRun {
@@ -463,6 +495,8 @@ export const createCloudflareDeployer = (options: CloudflareDeployerOptions) =>
463
495
  dir,
464
496
  cf,
465
497
  platformResources,
498
+ platformIam: options.platformIam,
499
+ reconcileSchema: options.reconcileSchema ?? defaultReconcileSchema,
466
500
  bounds,
467
501
  generatedConfigs: [],
468
502
  }