@fabrika/provider-cloudflare 0.9.0-dev.1 → 0.9.0-dev.11
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 +17 -15
- package/src/authoring.ts +56 -6
- package/src/bounds.ts +145 -4
- package/src/cli-args.ts +2 -2
- package/src/cli.ts +14 -0
- package/src/command.ts +29 -4
- package/src/contract-support.ts +235 -0
- package/src/control.ts +55 -118
- package/src/deploy-order.ts +35 -0
- package/src/index.ts +19 -3
- package/src/installation/init.ts +11 -18
- package/src/installation/installation.ts +2 -4
- package/src/installation/scaffold.ts +29 -2
- package/src/installation/templates/README.md +30 -12
- package/src/installation/templates/platform.yml +12 -5
- package/src/managed-secrets.ts +61 -0
- package/src/plan.ts +13 -3
- package/src/provider.ts +467 -64
- package/src/proxy-worker.ts +40 -16
- package/src/proxy.ts +48 -16
- package/src/runner-protocol.ts +35 -2
- package/src/spa-assets.ts +176 -0
- package/types/src/assets.d.ts +8 -0
- package/types/src/authoring.d.ts +39 -0
- package/types/src/bounds.d.ts +84 -0
- package/types/src/checkout.d.ts +7 -0
- package/types/src/cli-args.d.ts +25 -0
- package/types/src/cli.d.ts +8 -0
- package/types/src/codec.d.ts +8 -0
- package/types/src/collaborators.d.ts +52 -0
- package/types/src/command.d.ts +54 -0
- package/types/src/config-schema.d.ts +9 -0
- package/types/src/contract-support.d.ts +80 -0
- package/types/src/control.d.ts +503 -0
- package/types/src/deploy-order.d.ts +8 -0
- package/types/src/index.d.ts +18 -0
- package/types/src/installation/cloudflare.d.ts +40 -0
- package/types/src/installation/envfile.d.ts +39 -0
- package/types/src/installation/index.d.ts +2 -0
- package/types/src/installation/init-options.d.ts +59 -0
- package/types/src/installation/init.d.ts +114 -0
- package/types/src/installation/installation.d.ts +2 -0
- package/types/src/installation/scaffold.d.ts +39 -0
- package/types/src/managed-secrets.d.ts +19 -0
- package/types/src/plan.d.ts +21 -0
- package/types/src/provider.d.ts +98 -0
- package/types/src/proxy-worker.d.ts +15 -0
- package/types/src/proxy.d.ts +72 -0
- package/types/src/runner-protocol.d.ts +142 -0
- package/types/src/schema.d.ts +17 -0
- package/types/src/spa-assets.d.ts +28 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `fabrika platform init --provider=cloudflare <account>` — bring up a CF account's fabrika control-plane base.
|
|
3
|
+
* Idempotent + resumable (every captured value lands in the per-account env file `openEnvFile` binds and
|
|
4
|
+
* reloads). The REAL deploy runs in GitHub Actions (the scaffolded pipeline calls `fabrika platform deploy`),
|
|
5
|
+
* so this machine never needs the CF toolchain or docker.
|
|
6
|
+
*
|
|
7
|
+
* It prompts for nothing: every input is a flag or an environment variable (`init-options.ts`). What stays
|
|
8
|
+
* is one confirmation before each step that cannot be taken back, answered by `--yes` when nobody watches.
|
|
9
|
+
*
|
|
10
|
+
* Order: CF token → account + zones → IAM and email config → vault key → provisioning key → runner key →
|
|
11
|
+
* scaffold the base repo → write the GitHub Environment → trigger. Secret VALUES flow only into the env
|
|
12
|
+
* file, `gh` over stdin, and child env — never through `log.ts`. GitHub source connections are made later
|
|
13
|
+
* from the console (ADR-0029); init creates no GitHub App.
|
|
14
|
+
*/
|
|
15
|
+
import { type Confirmations, type EnvironmentConfig, type InstallationEmail, type ProtectionOutcome } from '@fabrika/installation-init';
|
|
16
|
+
import { type CfAccount, type CfZone } from './cloudflare';
|
|
17
|
+
import { type InitInput } from './init-options';
|
|
18
|
+
import { type ScaffoldInput, type ScaffoldResult } from './scaffold';
|
|
19
|
+
/** Everything collected before the scaffold + environment write. */
|
|
20
|
+
export interface Collected {
|
|
21
|
+
account: string;
|
|
22
|
+
accountId: string;
|
|
23
|
+
apiToken: string;
|
|
24
|
+
controlPlaneDomain: string;
|
|
25
|
+
operationsHostname: string;
|
|
26
|
+
platformRepo: string;
|
|
27
|
+
iamUrl: string;
|
|
28
|
+
/** IAM's admin hostname (the host of `iamUrl`) — its Custom Domain + token `iss`. */
|
|
29
|
+
iamHostname: string;
|
|
30
|
+
oidcEnabled: boolean;
|
|
31
|
+
passwordEnabled: boolean;
|
|
32
|
+
/** OIDC provider issuer IAM federates human login to (discovery URL base). */
|
|
33
|
+
oidcIssuer: string;
|
|
34
|
+
/** OIDC client id (public). The placeholder constant when the operator deferred real SSO. */
|
|
35
|
+
oidcClientId: string;
|
|
36
|
+
/** Email domains admitted as a human at IAM login (self-provisioning allowlist). */
|
|
37
|
+
humanEmailDomains: string[];
|
|
38
|
+
/** IAM's mail transport. */
|
|
39
|
+
email: InstallationEmail;
|
|
40
|
+
bootstrapAdmins: string[];
|
|
41
|
+
}
|
|
42
|
+
/** A resume read off an injectable source, with fromEnv's empty-string-is-absent semantics. */
|
|
43
|
+
export declare function readResumeValue(source: Readonly<Record<string, string | undefined>>, name: string): string | undefined;
|
|
44
|
+
/** Everything `runInit` does outside this machine. Each GitHub write is confirmed first. */
|
|
45
|
+
export interface InitEffects {
|
|
46
|
+
/** Only decides how the scaffold confirmation is phrased; the scaffold itself re-reads it. */
|
|
47
|
+
repositoryExists(repo: string): Promise<boolean>;
|
|
48
|
+
listAccounts(token: string): Promise<CfAccount[]>;
|
|
49
|
+
/** Best effort: `false` means "could not confirm", never "invalid". */
|
|
50
|
+
verifyToken(token: string, accountId: string): Promise<boolean>;
|
|
51
|
+
findZone(token: string, hostname: string): Promise<CfZone | null>;
|
|
52
|
+
scaffold(input: ScaffoldInput): Promise<ScaffoldResult>;
|
|
53
|
+
configureEnvironment(config: EnvironmentConfig): Promise<void>;
|
|
54
|
+
triggerWorkflow(repo: string): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
export interface InitCollaborators {
|
|
57
|
+
readonly prompts: Confirmations;
|
|
58
|
+
readonly effects: InitEffects;
|
|
59
|
+
}
|
|
60
|
+
/** `platform init` from its command line: open the account's env file, parse against it, run. */
|
|
61
|
+
export declare function initCommand(argv: readonly string[]): Promise<void>;
|
|
62
|
+
/** Run the full bring-up. The installer env file must already be open (`openEnvFile`). */
|
|
63
|
+
export declare function runInit(input: InitInput, collaborators: InitCollaborators): Promise<void>;
|
|
64
|
+
/** The real collaborators: a TTY (or `--yes`), the Cloudflare API, `gh` and git. */
|
|
65
|
+
export declare function consoleInitCollaborators(input: InitInput): InitCollaborators;
|
|
66
|
+
/** Everything `init` generated or fetched, ready to be split into the Environment's two halves. */
|
|
67
|
+
export interface GeneratedInstallation {
|
|
68
|
+
readonly vaultKey: string;
|
|
69
|
+
readonly provisioning: string;
|
|
70
|
+
readonly operationsSyncKey: string;
|
|
71
|
+
readonly runnerKey: string;
|
|
72
|
+
readonly signingKeys: string;
|
|
73
|
+
readonly oidcClientSecret?: string;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* What the GitHub Environment holds, split by the one rule: a credential is a SECRET, never a variable
|
|
77
|
+
* (a variable value reaches `gh` on argv).
|
|
78
|
+
*/
|
|
79
|
+
export declare function environmentPayload(collected: Collected, generated: GeneratedInstallation): {
|
|
80
|
+
secrets: Record<string, string>;
|
|
81
|
+
vars: Record<string, string>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Generate the M4 vault KEK: 32 random bytes, base64. It lives nowhere else (never in D1 or logs), so
|
|
85
|
+
* losing it is unrecoverable. Persist it locally and tell the operator where to secure it.
|
|
86
|
+
*/
|
|
87
|
+
interface VaultKeyDependencies {
|
|
88
|
+
readonly source: Readonly<Record<string, string | undefined>>;
|
|
89
|
+
persist(name: string, value: string): Promise<void>;
|
|
90
|
+
generate(): string;
|
|
91
|
+
created(message: string, details: string[]): void;
|
|
92
|
+
}
|
|
93
|
+
export declare function ensureVaultKey(dependencies?: VaultKeyDependencies): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
* Generate the runner key: the shared 256-bit bearer the control plane presents to the deploy executor,
|
|
96
|
+
* whose service binding alone proves nothing about the caller. The SAME value is pushed to both Workers,
|
|
97
|
+
* so it must be durable — a resumed init reuses it rather than rolling half the pair.
|
|
98
|
+
*/
|
|
99
|
+
export declare function ensureRunnerKey(): Promise<string>;
|
|
100
|
+
/** What the closing summary reports beyond the repository itself. */
|
|
101
|
+
export interface FinalNotes {
|
|
102
|
+
readonly repo: string;
|
|
103
|
+
readonly account: string;
|
|
104
|
+
readonly controlPlaneDomain: string;
|
|
105
|
+
readonly dir: string;
|
|
106
|
+
readonly ref: string;
|
|
107
|
+
readonly passwordEnabled: boolean;
|
|
108
|
+
/** Absent when the repository already existed, so this run did not touch its protection. */
|
|
109
|
+
readonly branchProtection?: ProtectionOutcome;
|
|
110
|
+
readonly environmentPolicy?: ProtectionOutcome;
|
|
111
|
+
}
|
|
112
|
+
/** Closing notes: the checkout, the env file, what is protected, the escape hatch, and what runs in CI. */
|
|
113
|
+
export declare function finalNotes(notes: FinalNotes): void;
|
|
114
|
+
export {};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The per-account base repo `<org>/fabrika-platform`: which files it carries, and the one migration that
|
|
3
|
+
* must stop a refresh. The create/clone/commit/push mechanics are shared
|
|
4
|
+
* (`@fabrika/installation-init`); everything here is Cloudflare's answer to what gets written.
|
|
5
|
+
*
|
|
6
|
+
* `fabrika.ref` is written ONLY when absent (operator-owned after creation — bumping it is how you roll a new
|
|
7
|
+
* base); `platform.yml` / `README.md` / `.gitignore` are CLI-owned and refreshed every run.
|
|
8
|
+
*/
|
|
9
|
+
import { INITIAL_SCAFFOLD_COMMIT_MESSAGE, type ProtectionOutcome, REFRESH_SCAFFOLD_COMMIT_MESSAGE } from '@fabrika/installation-init';
|
|
10
|
+
export { INITIAL_SCAFFOLD_COMMIT_MESSAGE, REFRESH_SCAFFOLD_COMMIT_MESSAGE };
|
|
11
|
+
export interface ScaffoldInput {
|
|
12
|
+
/** The base repo, e.g. `acme/fabrika-platform`. */
|
|
13
|
+
repo: string;
|
|
14
|
+
/** The account label (positional `init` arg) — substituted into the templates + the env/summary names. */
|
|
15
|
+
account: string;
|
|
16
|
+
/** Local directory to check the repo out into. */
|
|
17
|
+
dir: string;
|
|
18
|
+
}
|
|
19
|
+
/** Result of scaffolding: the local checkout dir + whether the repo was freshly created. */
|
|
20
|
+
export interface ScaffoldResult {
|
|
21
|
+
dir: string;
|
|
22
|
+
created: boolean;
|
|
23
|
+
/** Set only for a repository this run created; absent means an existing repo was left as it is. */
|
|
24
|
+
branchProtection?: ProtectionOutcome;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Materialize the CLI-owned files and the write-once source pin.
|
|
28
|
+
*
|
|
29
|
+
* Legacy two-repository pins need an operator-chosen merged-repository ref. Stop before writing anything
|
|
30
|
+
* so a refresh cannot hide the migration requirement or delete operator-owned files.
|
|
31
|
+
*/
|
|
32
|
+
export declare function materializePlatformScaffold(dir: string, account: string): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Ensure `<org>/fabrika-platform` exists + carries the current scaffold. Returns the local checkout dir.
|
|
35
|
+
* Requires `gh` authed with rights to create/admin the repo.
|
|
36
|
+
*/
|
|
37
|
+
export declare function scaffoldPlatformRepo(input: ScaffoldInput): Promise<ScaffoldResult>;
|
|
38
|
+
/** Read the configured `fabrika.ref` (for display), or 'main' when absent. Used in the final summary. */
|
|
39
|
+
export declare function readFabrikaRef(dir: string): Promise<string>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ProviderManagedEnvironment } from '@fabrika/provider-contract';
|
|
2
|
+
export interface ManagedSplit {
|
|
3
|
+
readonly vars: Readonly<Record<string, string>>;
|
|
4
|
+
readonly secrets: Readonly<Record<string, string>>;
|
|
5
|
+
}
|
|
6
|
+
/** The values a deploy writes: a credential as a Worker secret, any other as a plain var; a null value is not written. */
|
|
7
|
+
export declare const splitManagedEnvironment: (managed: ProviderManagedEnvironment) => ManagedSplit;
|
|
8
|
+
/**
|
|
9
|
+
* Run `body` with the secrets in a JSON file only its owner reads, in a directory of its own, removed however `body`
|
|
10
|
+
* ends. `body` gets null when there is nothing to write.
|
|
11
|
+
*/
|
|
12
|
+
export declare const withSecretsFile: <T>(secrets: Readonly<Record<string, string>>, body: (path: string | null) => Promise<T>) => Promise<T>;
|
|
13
|
+
/** The names `wrangler secret list --format json` printed. */
|
|
14
|
+
export declare const parseSecretNames: (stdout: string) => readonly string[];
|
|
15
|
+
/**
|
|
16
|
+
* The framework secrets a Worker still holds that this deploy no longer writes. Wider than `staleManagedVariables`: the
|
|
17
|
+
* executor writes no framework secret of its own, so any other one is stale.
|
|
18
|
+
*/
|
|
19
|
+
export declare const staleManagedSecrets: (present: readonly string[], written: Readonly<Record<string, string>>) => readonly string[];
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Worker } from 'oblaka-iac';
|
|
2
|
+
import type { CloudflareAppConfig } from './authoring';
|
|
3
|
+
export type CloudflareStepKind = 'build' | 'provision-resources' | 'migrate' | 'deploy-worker' | 'reconcile-schema' | 'sync-secrets';
|
|
4
|
+
export interface CloudflareStep {
|
|
5
|
+
readonly id: string;
|
|
6
|
+
readonly kind: CloudflareStepKind;
|
|
7
|
+
readonly description: string;
|
|
8
|
+
}
|
|
9
|
+
export interface MigratableDatabase {
|
|
10
|
+
readonly binding: string;
|
|
11
|
+
readonly name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const findMigratableDatabases: (worker: Worker) => MigratableDatabase[];
|
|
14
|
+
/**
|
|
15
|
+
* Every resource name fabrika's own components declare (control, IAM, Operations, the runner and the
|
|
16
|
+
* installation's oblaka state). oblaka ADOPTS an existing `${env}-${name}`, so a checkout that names
|
|
17
|
+
* one would take over the platform's own Worker, database or bucket.
|
|
18
|
+
*/
|
|
19
|
+
export declare const PLATFORM_RESOURCE_NAMES: ReadonlySet<string>;
|
|
20
|
+
/** `regeneratesEntry`: the release pins the generated entry, so the build step always runs, after `pipeline.build`. */
|
|
21
|
+
export declare const buildPlan: (config: CloudflareAppConfig, worker: Worker, regeneratesEntry: boolean) => readonly CloudflareStep[];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { type AppEnvironment, type ApplicationObjects, type ContractArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import { type DeployStepResult, type ProviderManagedEnvironment, type SchemaReconciler } from '@fabrika/provider-contract';
|
|
3
|
+
import { Worker } from 'oblaka-iac';
|
|
4
|
+
import type { CloudflareAppConfig } from './authoring';
|
|
5
|
+
import { type CloudflareCollaborators } from './collaborators';
|
|
6
|
+
import type { RunnerApprovedAccess } from './runner-protocol';
|
|
7
|
+
import { type AssetMount } from './spa-assets';
|
|
8
|
+
/**
|
|
9
|
+
* The secrets stored for the environment that `fabrika.config.ts` does not name in `pipeline.secrets`, by name. The deploy
|
|
10
|
+
* writes only declared ones, so these never reach the Worker; the run log says so, as an author would otherwise wonder.
|
|
11
|
+
*/
|
|
12
|
+
export declare const undeclaredSecrets: (config: CloudflareAppConfig, run: Pick<CloudflareDeployRun, "secrets">) => string[];
|
|
13
|
+
export interface CloudflareDeployerOptions {
|
|
14
|
+
readonly accountId: string;
|
|
15
|
+
readonly apiToken: string;
|
|
16
|
+
readonly collaborators?: CloudflareCollaborators;
|
|
17
|
+
/**
|
|
18
|
+
* `refuse` (the default) rejects a config that names one of fabrika's own resources. Only the
|
|
19
|
+
* operator deploying fabrika itself passes `allow`; a checkout is never trusted with it.
|
|
20
|
+
*/
|
|
21
|
+
readonly platformResources?: 'refuse' | 'allow';
|
|
22
|
+
/** Where a platform deploy (`allow`) registers a component's schema. Never set for an application deploy. */
|
|
23
|
+
readonly platformIam?: PlatformIamTarget;
|
|
24
|
+
/** Replaces the HTTP reconcile with IAM (tests). */
|
|
25
|
+
readonly reconcileSchema?: SchemaReconciler;
|
|
26
|
+
}
|
|
27
|
+
/** IAM's origin and the installation's provisioning key, as the installation's own deploy holds them. */
|
|
28
|
+
export interface PlatformIamTarget {
|
|
29
|
+
readonly url: string;
|
|
30
|
+
readonly adminKey: string;
|
|
31
|
+
}
|
|
32
|
+
export interface CloudflareDeployRun {
|
|
33
|
+
readonly appId: string;
|
|
34
|
+
readonly env: string;
|
|
35
|
+
readonly domain?: string;
|
|
36
|
+
/** The environment's cross-origin list from Control's registry (ADR-0022); the proxy Worker's manifest entry lists it. */
|
|
37
|
+
readonly crossOrigins?: readonly string[];
|
|
38
|
+
/** The origin of the environment's Operations ingest, from Control; the proxy Worker's `connect-src` admits it. */
|
|
39
|
+
readonly operationsOrigin?: string;
|
|
40
|
+
/** Every origin IAM may hand this environment a session at, registered under `<app>@<env>`. */
|
|
41
|
+
readonly returnOrigins?: readonly string[];
|
|
42
|
+
readonly cwd: string;
|
|
43
|
+
readonly configPath: string;
|
|
44
|
+
readonly stateNamespace?: string;
|
|
45
|
+
readonly secrets: Readonly<Record<string, string>>;
|
|
46
|
+
readonly vars: Readonly<Record<string, string>>;
|
|
47
|
+
/** Platform-owned runtime configuration, separate from operator-managed application vars. */
|
|
48
|
+
readonly managedEnvironment: ProviderManagedEnvironment;
|
|
49
|
+
/**
|
|
50
|
+
* The contract Control approved for this run (ADR-0050), with the digest the application's release computes. Absent
|
|
51
|
+
* outside Control (a local deploy), the deployer reads `fabrika.contract.ts` from the checkout, as Control does.
|
|
52
|
+
*/
|
|
53
|
+
readonly approved?: RunnerApprovedAccess;
|
|
54
|
+
/** Every Cloudflare deployment of the installation in Control's registry; a name of another application is refused. */
|
|
55
|
+
readonly installationApps?: readonly AppEnvironment[];
|
|
56
|
+
/** The serving object and the listed objects Control records (ADR-0070 §9); absent, `application` and `rehearsal`. */
|
|
57
|
+
readonly applicationObjects?: ApplicationObjects;
|
|
58
|
+
readonly dryRun: boolean;
|
|
59
|
+
readonly signal: AbortSignal;
|
|
60
|
+
readonly log: (line: string) => void;
|
|
61
|
+
}
|
|
62
|
+
export interface CloudflareDeployResult {
|
|
63
|
+
readonly appId: string;
|
|
64
|
+
readonly env: string;
|
|
65
|
+
readonly status: 'succeeded' | 'failed';
|
|
66
|
+
readonly steps: readonly DeployStepResult[];
|
|
67
|
+
}
|
|
68
|
+
export declare const createCloudflareDeployer: (options: CloudflareDeployerOptions) => (run: CloudflareDeployRun) => Promise<CloudflareDeployResult>;
|
|
69
|
+
/** The SPA files `stageLocalAssets` staged for a local run: the mounts it copied, in the order a deploy stages them. */
|
|
70
|
+
export interface StagedLocalAssets {
|
|
71
|
+
readonly mounts: readonly AssetMount[];
|
|
72
|
+
readonly files: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Stage the contract's SPA and link mounts for a local run, with the code a deploy stages them with: each mount's
|
|
76
|
+
* built directory under `root` into `root/fabrika/assets`, where the generated `wrangler.jsonc` beside the config points
|
|
77
|
+
* its `ASSETS`. Run it before oblaka generates the config (`await` at the top of `oblaka.ts`) and after the SPA build.
|
|
78
|
+
*/
|
|
79
|
+
export declare const stageLocalAssets: (contract: ContractArtifact, root: string) => Promise<StagedLocalAssets>;
|
|
80
|
+
/** What `composeLocalApplication` needs: the config, the contract it serves, and the IAM a local run reaches. */
|
|
81
|
+
export interface LocalApplicationOptions {
|
|
82
|
+
readonly config: CloudflareAppConfig;
|
|
83
|
+
readonly contract: ContractArtifact;
|
|
84
|
+
/** What `stageLocalAssets` staged; required when the contract has an SPA or link mount and the Worker no `assets`. */
|
|
85
|
+
readonly assets?: StagedLocalAssets;
|
|
86
|
+
/** IAM's origin, the issuer of the local run's tokens. */
|
|
87
|
+
readonly iamOrigin: string;
|
|
88
|
+
readonly env: string;
|
|
89
|
+
readonly domain?: string;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* The proxy Worker and the application Worker of a local run (`oblaka.ts`, lopata), composed by the code a deploy runs:
|
|
93
|
+
* the platform's proxy over the contract's endpoint table, and the application's object, files bucket and repair tick,
|
|
94
|
+
* as a release that serves alarms gets them. No deploy takes it. With no Control to write them, the framework values
|
|
95
|
+
* come from here, and the proxy secret, which a deploy uploads as a Worker secret, is drawn anew on each call and
|
|
96
|
+
* written as a variable into the ignored `wrangler.jsonc`.
|
|
97
|
+
*/
|
|
98
|
+
export declare const composeLocalApplication: (options: LocalApplicationOptions) => Worker;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ProxyLogger } from '@fabrika/proxy-core';
|
|
2
|
+
export interface CloudflareProxyEnv {
|
|
3
|
+
readonly IAM?: unknown;
|
|
4
|
+
/** The manifest JSON the handler serves; the deployed Worker passes the one baked into its bundle. */
|
|
5
|
+
readonly FABRIKA_PROXY_MANIFEST_JSON?: string;
|
|
6
|
+
readonly FABRIKA_IAM_ISSUER?: string;
|
|
7
|
+
readonly [binding: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
type ProxyFetch = (request: Request) => Promise<Response>;
|
|
10
|
+
/** Factory exported for Lopata and unit tests; production uses the default Worker fetch below. */
|
|
11
|
+
export declare function createCloudflareProxyHandler(env: CloudflareProxyEnv, logger?: ProxyLogger): ProxyFetch;
|
|
12
|
+
declare const _default: {
|
|
13
|
+
fetch(request: Request, env: CloudflareProxyEnv): Promise<Response>;
|
|
14
|
+
};
|
|
15
|
+
export default _default;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type ContractProxyTable, type InstallationProxyTable } from '@fabrika/proxy-core/manifest';
|
|
2
|
+
import { ServiceReference, Worker } from 'oblaka-iac';
|
|
3
|
+
/** A binding as oblaka configures it into a Worker's generated config. */
|
|
4
|
+
type Binding = Pick<ServiceReference, 'configureBinding'>;
|
|
5
|
+
interface CloudflareProxyWorkerBase {
|
|
6
|
+
/** Name of the proxy Worker before the environment prefix is applied by oblaka. */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
/** The application Worker. It must not have a public route of its own. */
|
|
9
|
+
readonly app: Worker;
|
|
10
|
+
/** IAM application id used to mint and verify the upstream token. */
|
|
11
|
+
readonly appId: string;
|
|
12
|
+
/** Host matched by the proxy manifest. Use the public custom domain when one exists. */
|
|
13
|
+
readonly appHost: string;
|
|
14
|
+
/** Optional Cloudflare custom domain for the proxy Worker. */
|
|
15
|
+
readonly domain?: string;
|
|
16
|
+
/** IAM service name. The global default is the platform IAM Worker. */
|
|
17
|
+
readonly iamService?: string;
|
|
18
|
+
/** IAM origin used for login redirects and token issuer validation. */
|
|
19
|
+
readonly iamUrl?: string;
|
|
20
|
+
}
|
|
21
|
+
interface CloudflareContractProxyOptions {
|
|
22
|
+
readonly endpoints: ContractProxyTable;
|
|
23
|
+
readonly installation?: never;
|
|
24
|
+
/** The Operations ingest origin a contract application's `connect-src` admits, from its managed DSN. */
|
|
25
|
+
readonly operationsOrigin?: string;
|
|
26
|
+
/** The origins the environment lists for its cross-origin endpoints, from Control's registry (ADR-0022). */
|
|
27
|
+
readonly crossOrigins?: readonly string[];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* What the proxy enforces: a contract application's endpoint table (`contractProxyTable(artifact)`) or an installation
|
|
31
|
+
* service's table (`serviceProxyTable(service, …)`). Exactly one. The deployer passes only the first; `installation`
|
|
32
|
+
* is written by the platform's own service configs, which is what makes the marker trusted composition (ADR-0022
|
|
33
|
+
* "Installation entries").
|
|
34
|
+
*/
|
|
35
|
+
export type CloudflareProxyWorkerOptions = (CloudflareProxyWorkerBase & CloudflareContractProxyOptions) | (CloudflareProxyWorkerBase & {
|
|
36
|
+
readonly installation: InstallationProxyTable;
|
|
37
|
+
readonly endpoints?: never;
|
|
38
|
+
});
|
|
39
|
+
/** Where `createCloudflareProxyWorker` points its Worker: the deployer builds every application's proxy from here. */
|
|
40
|
+
export declare const CLOUDFLARE_PROXY_WORKER_DIR: string;
|
|
41
|
+
export declare const CLOUDFLARE_PROXY_WORKER_MAIN = "./proxy-worker.ts";
|
|
42
|
+
/**
|
|
43
|
+
* The identifier the proxy Worker's bundle reads its manifest from. The generated config's `define` replaces it with
|
|
44
|
+
* the manifest as a string literal when wrangler bundles the Worker, so the table has no Worker variable's 5 KB cap.
|
|
45
|
+
*/
|
|
46
|
+
export declare const PROXY_MANIFEST_DEFINE = "__FABRIKA_PROXY_MANIFEST__";
|
|
47
|
+
/** The manifest JSON a proxy Worker built here carries, or null for any other Worker. */
|
|
48
|
+
export declare const proxyManifestJson: (worker: Worker) => string | null;
|
|
49
|
+
/** IAM's Worker: the one platform service an application binds, and only through the entrypoint below. */
|
|
50
|
+
export declare const IAM_SERVICE = "propustka-worker";
|
|
51
|
+
/** IAM's narrow `WorkerEntrypoint`, which carries neither key issuing nor device approval (`packages/iam/src/index.ts`). */
|
|
52
|
+
export declare const IAM_APPLICATION_ENTRYPOINT = "PropustkaApplication";
|
|
53
|
+
/** The `IAM` binding of an application Worker; a generated config that binds IAM any other way is refused. */
|
|
54
|
+
export declare const iamServiceReference: () => ServiceReference;
|
|
55
|
+
/**
|
|
56
|
+
* 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.app`, the transport identity of a call over the binding, as the
|
|
58
|
+
* membership transport key is over HTTP (ADR-0067 §3). An application cannot choose it: the deployer writes it, and the
|
|
59
|
+
* bounds refuse an IAM binding that names any other application.
|
|
60
|
+
*/
|
|
61
|
+
export declare class IamApplicationReference implements Binding {
|
|
62
|
+
private readonly app;
|
|
63
|
+
private readonly declared;
|
|
64
|
+
constructor(app: string, declared?: Binding);
|
|
65
|
+
configureBinding(args: Parameters<Binding['configureBinding']>[0]): ReturnType<Binding['configureBinding']>;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Build the Cloudflare side of the accepted proxy topology: the public Worker owns the route and
|
|
69
|
+
* binds the private application Worker. IAM remains a global service binding.
|
|
70
|
+
*/
|
|
71
|
+
export declare function createCloudflareProxyWorker(options: CloudflareProxyWorkerOptions): Worker;
|
|
72
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { type ContractArtifact } from '@fabrika/auth-core';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
export declare const runnerStateSchema: z.ZodEnum<["pending", "cloning", "installing", "deploying", "succeeded", "failed"]>;
|
|
4
|
+
/** The lifecycle a run moves through inside the transport container. */
|
|
5
|
+
export type RunnerState = z.infer<typeof runnerStateSchema>;
|
|
6
|
+
/** The IAM schema the executor compiled from the checkout, as JSON text; the control plane parses, validates and applies it with its own key. */
|
|
7
|
+
export declare const runnerIamReconcileSchema: z.ZodObject<{
|
|
8
|
+
app: z.ZodString;
|
|
9
|
+
schemaJson: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
app: string;
|
|
12
|
+
schemaJson: string;
|
|
13
|
+
}, {
|
|
14
|
+
app: string;
|
|
15
|
+
schemaJson: string;
|
|
16
|
+
}>;
|
|
17
|
+
export type RunnerIamReconcile = z.infer<typeof runnerIamReconcileSchema>;
|
|
18
|
+
/** What the executor leaves at `$FABRIKA_RUNNER_OUTCOME_FILE` for the runner to fold into its terminal status. */
|
|
19
|
+
export interface RunnerOutcomeFile {
|
|
20
|
+
readonly iamReconcile?: RunnerIamReconcile;
|
|
21
|
+
}
|
|
22
|
+
export declare const RUNNER_OUTCOME_FILE_ENV = "FABRIKA_RUNNER_OUTCOME_FILE";
|
|
23
|
+
/** The executor's copy of `CloudflareRunnerJob.installationApps`: a JSON array of `<app>@<env>`. */
|
|
24
|
+
export declare const INSTALLATION_APPS_ENV = "FABRIKA_INSTALLATION_APPS";
|
|
25
|
+
/** The executor's copy of `CloudflareRunnerJob.crossOrigins`: a JSON array of the environment's exact origins. */
|
|
26
|
+
export declare const CROSS_ORIGINS_ENV = "FABRIKA_CROSS_ORIGINS";
|
|
27
|
+
/** The executor's copy of `CloudflareRunnerJob.operationsOrigin`: the origin of the environment's Operations ingest. */
|
|
28
|
+
export declare const OPERATIONS_ORIGIN_ENV = "FABRIKA_OPERATIONS_ORIGIN";
|
|
29
|
+
/** The executor's copy of `CloudflareRunnerJob.applicationObjects`: JSON `{ object, objects }`, the pointer Control records. */
|
|
30
|
+
export declare const APPLICATION_OBJECTS_ENV = "FABRIKA_RUNNER_APPLICATION_OBJECTS";
|
|
31
|
+
/**
|
|
32
|
+
* The serving object and the listed objects as the job and the executor carry them: the shape `parseApplicationObjects`
|
|
33
|
+
* accepts, so a pointer the application would refuse never reaches a deploy.
|
|
34
|
+
*/
|
|
35
|
+
export declare const applicationObjectsSchema: z.ZodEffects<z.ZodObject<{
|
|
36
|
+
object: z.ZodString;
|
|
37
|
+
objects: z.ZodArray<z.ZodString, "many">;
|
|
38
|
+
}, "strict", z.ZodTypeAny, {
|
|
39
|
+
object: string;
|
|
40
|
+
objects: string[];
|
|
41
|
+
}, {
|
|
42
|
+
object: string;
|
|
43
|
+
objects: string[];
|
|
44
|
+
}>, import("@fabrika/auth-core").ApplicationObjects, {
|
|
45
|
+
object: string;
|
|
46
|
+
objects: string[];
|
|
47
|
+
}>;
|
|
48
|
+
/**
|
|
49
|
+
* The access Control approved for a run (ADR-0050): the contract it read at the commit, in this release's model, and
|
|
50
|
+
* the digest the application's own framework release computes for it. The proxy table and `FABRIKA_CONTRACT_DIGEST`
|
|
51
|
+
* follow this, never the checkout. The digest is not `contractDigest(contract)` when Control upcast the contract from
|
|
52
|
+
* an older release's artifact (ADR-0062), so the executor cannot recompute it and takes Control's.
|
|
53
|
+
*/
|
|
54
|
+
export interface RunnerApprovedAccess {
|
|
55
|
+
readonly kind: 'contract';
|
|
56
|
+
readonly contract: ContractArtifact;
|
|
57
|
+
readonly contractDigest: string;
|
|
58
|
+
/**
|
|
59
|
+
* The framework release the application pins (`applicationRelease`), which every release gate of the deployer reads:
|
|
60
|
+
* the Durable Object from 0.9, the stateless Worker before it. An older Control sends its reader's
|
|
61
|
+
* release here, a newer patch of the same minor. Absent from a Control older than the runner, which deploys the
|
|
62
|
+
* older shape.
|
|
63
|
+
*/
|
|
64
|
+
readonly framework?: string;
|
|
65
|
+
}
|
|
66
|
+
export declare const runnerApprovedAccessSchema: z.ZodEffects<z.ZodObject<{
|
|
67
|
+
kind: z.ZodLiteral<"contract">;
|
|
68
|
+
contract: z.ZodUnknown;
|
|
69
|
+
contractDigest: z.ZodEffects<z.ZodString, string, string>;
|
|
70
|
+
framework: z.ZodOptional<z.ZodString>;
|
|
71
|
+
}, "strict", z.ZodTypeAny, {
|
|
72
|
+
kind: "contract";
|
|
73
|
+
contractDigest: string;
|
|
74
|
+
contract?: unknown;
|
|
75
|
+
framework?: string | undefined;
|
|
76
|
+
}, {
|
|
77
|
+
kind: "contract";
|
|
78
|
+
contractDigest: string;
|
|
79
|
+
contract?: unknown;
|
|
80
|
+
framework?: string | undefined;
|
|
81
|
+
}>, RunnerApprovedAccess, {
|
|
82
|
+
kind: "contract";
|
|
83
|
+
contractDigest: string;
|
|
84
|
+
contract?: unknown;
|
|
85
|
+
framework?: string | undefined;
|
|
86
|
+
}>;
|
|
87
|
+
/** Where the runner leaves the job's `RunnerApprovedAccess` as JSON for the executor — beside the checkout, never inside it. */
|
|
88
|
+
export declare const APPROVED_ACCESS_FILE_ENV = "FABRIKA_APPROVED_ACCESS_FILE";
|
|
89
|
+
/** The terminal and in-progress status polled from the container, and persisted by the runner Worker once terminal. */
|
|
90
|
+
export declare const runnerStatusSchema: z.ZodObject<{
|
|
91
|
+
runId: z.ZodString;
|
|
92
|
+
state: z.ZodEnum<["pending", "cloning", "installing", "deploying", "succeeded", "failed"]>;
|
|
93
|
+
exitCode: z.ZodOptional<z.ZodNumber>;
|
|
94
|
+
error: z.ZodOptional<z.ZodString>;
|
|
95
|
+
artifactState: z.ZodOptional<z.ZodEnum<["complete", "incomplete", "not_applicable"]>>;
|
|
96
|
+
iamReconcile: z.ZodOptional<z.ZodObject<{
|
|
97
|
+
app: z.ZodString;
|
|
98
|
+
schemaJson: z.ZodString;
|
|
99
|
+
}, "strip", z.ZodTypeAny, {
|
|
100
|
+
app: string;
|
|
101
|
+
schemaJson: string;
|
|
102
|
+
}, {
|
|
103
|
+
app: string;
|
|
104
|
+
schemaJson: string;
|
|
105
|
+
}>>;
|
|
106
|
+
/** A preview: nothing was deployed and nothing may be applied from it. */
|
|
107
|
+
dryRun: z.ZodOptional<z.ZodBoolean>;
|
|
108
|
+
startedAt: z.ZodNumber;
|
|
109
|
+
finishedAt: z.ZodOptional<z.ZodNumber>;
|
|
110
|
+
}, "strip", z.ZodTypeAny, {
|
|
111
|
+
state: "failed" | "pending" | "succeeded" | "cloning" | "installing" | "deploying";
|
|
112
|
+
runId: string;
|
|
113
|
+
startedAt: number;
|
|
114
|
+
error?: string | undefined;
|
|
115
|
+
dryRun?: boolean | undefined;
|
|
116
|
+
exitCode?: number | undefined;
|
|
117
|
+
artifactState?: "incomplete" | "complete" | "not_applicable" | undefined;
|
|
118
|
+
iamReconcile?: {
|
|
119
|
+
app: string;
|
|
120
|
+
schemaJson: string;
|
|
121
|
+
} | undefined;
|
|
122
|
+
finishedAt?: number | undefined;
|
|
123
|
+
}, {
|
|
124
|
+
state: "failed" | "pending" | "succeeded" | "cloning" | "installing" | "deploying";
|
|
125
|
+
runId: string;
|
|
126
|
+
startedAt: number;
|
|
127
|
+
error?: string | undefined;
|
|
128
|
+
dryRun?: boolean | undefined;
|
|
129
|
+
exitCode?: number | undefined;
|
|
130
|
+
artifactState?: "incomplete" | "complete" | "not_applicable" | undefined;
|
|
131
|
+
iamReconcile?: {
|
|
132
|
+
app: string;
|
|
133
|
+
schemaJson: string;
|
|
134
|
+
} | undefined;
|
|
135
|
+
finishedAt?: number | undefined;
|
|
136
|
+
}>;
|
|
137
|
+
export type RunnerStatus = z.infer<typeof runnerStatusSchema>;
|
|
138
|
+
export declare const RUNNER_PORT = 8080;
|
|
139
|
+
export declare const RUNNER_RUN_PATH = "/run";
|
|
140
|
+
export declare const RUNNER_LOGS_PATH = "/logs";
|
|
141
|
+
export declare const RUNNER_STATUS_PATH = "/status";
|
|
142
|
+
export declare const RUNNER_HEALTH_PATH = "/health";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AppSchema } from '@fabrika/auth';
|
|
2
|
+
import type { SchemaReconciler } from '@fabrika/provider-contract';
|
|
3
|
+
/** Default IAM schema reconciler shared by production Cloudflare sessions. */
|
|
4
|
+
export declare const defaultReconcileSchema: SchemaReconciler;
|
|
5
|
+
/** A parsed vocabulary, or the reason the deploy is refused — the message names the offending field. */
|
|
6
|
+
export type AppSchemaParse = {
|
|
7
|
+
readonly ok: true;
|
|
8
|
+
readonly schema: AppSchema;
|
|
9
|
+
} | {
|
|
10
|
+
readonly ok: false;
|
|
11
|
+
readonly message: string;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Narrow an untrusted authz vocabulary — it arrives as JSON text compiled inside the deploy container —
|
|
15
|
+
* to the `AppSchema` the reconcile sends IAM. IAM validates it again on the way in.
|
|
16
|
+
*/
|
|
17
|
+
export declare const parseAppSchema: (value: unknown) => AppSchemaParse;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { ContractArtifact } from '@fabrika/auth-core';
|
|
2
|
+
/** Where the deploy stages the mounts' files, beside the generated `wrangler.jsonc` of the application Worker. */
|
|
3
|
+
export declare const SPA_ASSETS_DIRECTORY = "fabrika/assets";
|
|
4
|
+
/** The `assets` the platform writes into an application Worker that declares none and has a mount with files. */
|
|
5
|
+
export declare const SPA_ASSETS: {
|
|
6
|
+
readonly directory: "fabrika/assets";
|
|
7
|
+
readonly binding: "ASSETS";
|
|
8
|
+
readonly run_worker_first: true;
|
|
9
|
+
};
|
|
10
|
+
/** A mount that serves files: its prefix, and its build directory relative to the application's root. */
|
|
11
|
+
export interface AssetMount {
|
|
12
|
+
readonly name: string;
|
|
13
|
+
readonly prefix: string;
|
|
14
|
+
readonly dir: string;
|
|
15
|
+
}
|
|
16
|
+
/** Every SPA and link mount of the contract with the directory its files come from, the most specific prefix first. */
|
|
17
|
+
export declare const assetMounts: (contract: ContractArtifact) => readonly AssetMount[];
|
|
18
|
+
/**
|
|
19
|
+
* Copy each mount's build directory under `root` into `target` at its prefix, after removing whatever `target` held. A
|
|
20
|
+
* file of a mount that lies under a longer mount's prefix is that mount's path, so it is left out; a source map is never
|
|
21
|
+
* served (the platform build uploads it to Operations), so it is left out too, and so is Workers Assets' own
|
|
22
|
+
* configuration at the root (`ASSET_CONFIG_PATHS`), what the mount's `.assetsignore` excludes, and version control
|
|
23
|
+
* metadata (`VCS_NAMES`) at any depth. A mount whose directory is missing, a symbolic link anywhere on
|
|
24
|
+
* its path or in its tree, or anything but a regular file or a directory is refused: the staged tree is uploaded
|
|
25
|
+
* publicly, and a link would publish its target. `target` is `SPA_ASSETS_DIRECTORY` under `base`, with no link on the
|
|
26
|
+
* way either. Returns how many files it staged.
|
|
27
|
+
*/
|
|
28
|
+
export declare const stageSpaAssets: (mounts: readonly AssetMount[], root: string, base: string) => Promise<number>;
|