Repository navigation
feat(deploy): the deploy pipeline, with its own rollback, manual gate and controls - #165
Merged
Merged
Conversation
… and controls The third of four staged PRs for the deploy pipeline (ADR-0110 round 29). It adds `deploy.yml` and everything it runs: build a bundle of the commit with no secret in the job, attest it, deploy it to an environment, prove it with the smoke, and roll back by itself when the proof fails. Nothing deploys until the repository variable THRUST_DEPLOY_ENABLED is `true` and the environments have their variables. How a run goes (.github/workflows/deploy.yml, scripts/deploy-worker.sh): - plan: what the event is and which commit. A push to main deploys staging after `ci` passed; a manual run names an environment and a commit of main, from main; a pull request is a dry run. The commit's own `gate` must have passed, asked for by name on that commit, and the environments that gate the deploy must have required reviewers (GitHub creates an unprotected one if a name is mistyped). - build: the Worker and the `migrate` binary, in a job with no secret, into one bundle, attested (SLSA provenance). - deploy (environment `<env>`): verify the attestation, render the configuration from the environment's variables, read what is live, classify the change against it, run the expand migration only when migration files changed, `wrangler deploy --tag <sha>` at 100 %, the smoke, and the smoke's control (it must refuse a version nobody deployed). A failing smoke ends in `wrangler rollback` to the previous version and a probe that shows it answering; the run stays red. - deploy-do (environment `<env>-do-lifecycle`, with reviewers): the first deploy to an environment, any change to `[[migrations]]`, and a live state that cannot be read are not made by `deploy`: it finds that out first, deploys nothing, and this job deploys them after approval, without an automatic rollback (a rollback is refused across a Durable Object lifecycle change). - dry-run (a pull request that touches the deploy files): the bundle is built and wrangler checks the rendered configuration with --dry-run. No environment, no secret. It is what shows, before the merge, that the workflow starts. The pieces, each a script with a test (all run in `ci-scripts`, under dash): scripts/render-wrangler.sh with crates/thrust-worker/wrangler.deploy.toml (the template; the renderer refuses an unset variable, an all-zero id, a thrust-spike name, an unknown marker); .github/scripts/ classify-deploy.sh (does the expand migration run, is it a lifecycle change); active-version.py (which version is live and its tag); plan-deploy.sh; assert-sha-checks.sh; assert-gated-environments.sh; lint-workflow.sh (pinned actions, explicit permissions, no expression in a `run:`, secrets only in the two gated jobs); scripts/deploy-worker.sh and its test, which runs the whole flow against a fake Cloudflare that keeps state (what the edge serves), so the rollback, the control and the manual gate are shown before staging exists. The tests found real faults, fixed here: the renderer accepted a name with a capital letter in a UTF-8 locale on macOS (`[a-z]` matched it); `jq | sort || fail` tested sort's status and read a jq failure as "nothing reported"; and the first bundle copied `build/worker/` only, when worker-build also writes `build/index.js` and `build/index_bg.wasm`, which the shim imports (found by building the Worker and running wrangler on it). Each script was also broken by hand, one way at a time, 69 ways in all, and its own test caught 68 of them; the one it did not is a redundant guard (a leftover-marker check that cannot be reached once the earlier checks pass). Three first survived and showed gaps, now closed: only one pair of equal rate-limit ids was tested, no stale rendered file existed to prove a refused render removes it, and no case pinned that only a `required_reviewers` rule counts as a gate. crates/thrust-adapters-postgres/tests/tls.rs now reads the Cloudflare Origin CA root the deploy trusts (.github/deploy/, byte for byte the file Cloudflare publishes, its fingerprint pinned by a test) and shows rustls accepts it as a `verify-ca` root, with a control. Deviates from ADR-0101 and ADR-0110 on one point, on the owner's decision: the Cloudflare credential is a scoped API token in the environment's secrets, because Cloudflare documents no OIDC federation for wrangler. The deviation goes into the ADR in the last PR. Not verified: any of it against Cloudflare. The shape of `wrangler deployments list --json` and `versions list --json` is the documented one (the parser treats every other shape as "cannot tell", which sends the deploy to the manual gate); the attestation flow, the token's scopes, and `wrangler deploy` attaching the queue consumer with a dead-letter queue have not run. The first staging deploy is the check. Refs: #49 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
added a commit
that referenced
this pull request
Nov 14, 2026
…r deletion Main gained #165, the deploy pipeline, while this branch's PR was open. The merge is clean as text, with no conflicts, and it adds no contract test (EXPECT_MAIN stays 73). It is not clean in meaning: the pipeline's template, renderer, workflow and action declare the `RL_CREATE` binding this branch deletes, and `test-deploy-template.sh` holds the template to the same bindings as wrangler.toml, so the template has to follow. That is the next commit. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
aRustyDev
added a commit
that referenced
this pull request
Nov 14, 2026
…ation The deploy pipeline (#165) declared the binding that this PR's earlier commit deletes from the Worker and the other configs: the template crates/thrust-worker/wrangler.deploy.toml had an `RL_CREATE` block with a `__RL_CREATE_ID__` marker, scripts/render-wrangler.sh filled it from `THRUST_RL_CREATE_ID`, and deploy.yml and the deploy-worker action passed that variable through. Left alone it fails CI: `test-deploy-template.sh` requires the template and wrangler.toml to bind the same things (`deploy_parity.py`), and the template would still have a binding wrangler.toml no longer has. My first push did not have #165 in it; the failure was found when main moved, by searching its tree for the names this PR deletes. Changed: - wrangler.deploy.toml: the `RL_CREATE` block and its marker go; the comment says the environment has two namespace ids, not three, and that there was a third. - render-wrangler.sh: the marker, the variable, the id list in the header and the self-test fixtures go, and the rule that the ids differ is about two ids now (its message says "the two"; the self-test's fragment "must differ from one another" still matches). The cases for `THRUST_RL_CREATE_ID` unset and empty and for the two equalities that involved it go with it (four cases). Two cases are added, as the control for the removal: a template that still has the retired `__RL_CREATE_ID__` marker is refused ("which this script does not know"), with or without `THRUST_RL_CREATE_ID` still in the environment, so a stale template cannot be rendered into a config that declares a binding the Worker does not use. - The deploy-worker action loses its `rl-create-id` input and its `THRUST_RL_CREATE_ID` env; deploy.yml loses the variable from its list of an environment's variables, from the dry run's environment and from both `rl-create-id:` inputs; test-deploy-worker.sh drops it from its good environment. - G-26 records this. Checked, under dash in an Ubuntu 24.04 container (CI's shell) on this tree and, as a baseline, on origin/main, with python3, jq and nc installed: every test of the `ci-scripts` job and both deploy guards (the renderer's `--self-test` and the workflow lint of deploy.yml and the action) pass on both. The renderer's self-test is 43 ok on this tree and 45 on main: four cases removed, two added. `scripts/check-placement.sh` passes. clippy and rustfmt are clean on the merged tree. Control: main's template against this wrangler.toml fails the parity check (exit 1: the template has `RL_CREATE`, wrangler.toml does not); the fixed template agrees. The `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now. It is harmless and deleting it is the owner's. A deploy of this commit renders a config with two rate-limit bindings and a Worker that asks for those two. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This was referenced Nov 14, 2026
aRustyDev
added a commit
that referenced
this pull request
Nov 14, 2026
…nd its settings (#166) * refactor(rate-limits): delete the slice's create limit, its binding and its settings Step 5c-3c of moving off /api/_slice, the last piece of step 5c-3 (the owner's order was the core, then the adapters, then this, one PR each). The per-user create limit was applied by the slice's `create_work_item`, which #161 deleted. Nothing reads it now, and /api/v1 has its own per-key allowance. Deleted: - `CoreConfig.create_rate_limit` and `THRUST_CREATE_RATE_LIMIT`, in the native server and the Worker. - `CoreConfig.rate_window_secs` and `THRUST_RATE_WINDOW_SECS`, and the Worker's startup check of that window. Only the create limit's use-case read them (checked: no other reader in the workspace); /api/v1's window is the period in `THRUST_V1_RATE_LIMIT` and sign-in's is a constant of the core's config. - The `RL_CREATE` binding and its `[[ratelimits]]` block in wrangler.toml, wrangler.stage2.toml and wrangler.pg.stage.toml, and the Worker's `env.rate_limiter("RL_CREATE")`. - In thrust-adapters-cloudflare, `KeyClass::Create` and `CfRateLimiter.create`. A key that starts with `create:` is a key of no class now: an error, never a free pass. The tests list it, as three refused keys. - `Target::create_limit` (no caller) and `THRUST_EXPECT_CREATE_LIMIT`; `THRUST_WORKER_CREATE_LIMIT` and the create handling in scripts/worker-dev.sh; `RATE_LIMIT` in scripts/contract.sh; the create refusal in scripts/stage2-contract.sh. One option is retargeted, not deleted: `scripts/spike-0002-pg.sh deploy --create-limit N` is `--v1-limit N` and rewrites the `RL_V1` limit (marker `__V1_LIMIT__` on that line, default 60). The engine pass goes through /api/v1, so RL_V1 is the binding it needs raised on a deployed Worker; `--create-limit` raised one that the pass no longer touched. The infra, contract-suite and defect-matrix pages and G-26 say so. Operations: the Worker built from this commit and this commit's config are a pair. The code no longer asks for `RL_CREATE` and the config no longer declares it, so the previous Worker with this config would fail to start (it asks for a binding that is not there). Deploy them together. The two assertions that changed in thrust-adapters-cloudflare/tests/rate_limiter.rs are the class list (two classes, not three) and the setting name the period tests pass to `check_binding_period`, which was `THRUST_RATE_WINDOW_SECS` and is the name the Worker still passes (`the period of THRUST_V1_RATE_LIMIT`). Checked: native-memory main 70 of 70, sweeper 3 of 3, csrfoff 6 of 6, engine 4 of 4; worker-memory main 70 of 70; worker-cf main 70 of 70 and bindings 5 of 5, from a config with RL_SIGNIN and RL_V1 only; `cargo nextest run` 3860 of 3860 (6 fewer than before: the class tests have 2 classes where they had 3, and the 3 refused keys are added); doctests; clippy and rustfmt; `sh -n` of the four changed scripts under dash (an Ubuntu container). One test, thrust-api-v1's `parity_slugify_of_drawn_names_is_the_pins`, was reported "leaky" once in the full parallel run and passed clean in three solo runs; it is in a crate this change does not touch. Controls, temporary and reverted: - `create` mapped to a class again in `KeyClass::of`: the 3 refused-key cases fail, 127 others pass. - a Worker that asks for a binding its config lacks never comes up (wrangler: "Binding ... is undefined", exit 4), so the worker-cf cell catches a binding mismatch and its pass without RL_CREATE is evidence. - stage2-contract.sh refuses `THRUST_EXPECT_V1_LIMIT=1000000` (exit 2) and passes the guard at the default. - the spike script's `sed` on the staging template changes only the RL_V1 line (a dry run; nothing is deployed from here). - the dash check of the scripts fails a deliberately broken script. Not run: native-pg (CI runs it) and any deploy. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> * refactor(deploy): drop the RL_CREATE binding from the deploy configuration The deploy pipeline (#165) declared the binding that this PR's earlier commit deletes from the Worker and the other configs: the template crates/thrust-worker/wrangler.deploy.toml had an `RL_CREATE` block with a `__RL_CREATE_ID__` marker, scripts/render-wrangler.sh filled it from `THRUST_RL_CREATE_ID`, and deploy.yml and the deploy-worker action passed that variable through. Left alone it fails CI: `test-deploy-template.sh` requires the template and wrangler.toml to bind the same things (`deploy_parity.py`), and the template would still have a binding wrangler.toml no longer has. My first push did not have #165 in it; the failure was found when main moved, by searching its tree for the names this PR deletes. Changed: - wrangler.deploy.toml: the `RL_CREATE` block and its marker go; the comment says the environment has two namespace ids, not three, and that there was a third. - render-wrangler.sh: the marker, the variable, the id list in the header and the self-test fixtures go, and the rule that the ids differ is about two ids now (its message says "the two"; the self-test's fragment "must differ from one another" still matches). The cases for `THRUST_RL_CREATE_ID` unset and empty and for the two equalities that involved it go with it (four cases). Two cases are added, as the control for the removal: a template that still has the retired `__RL_CREATE_ID__` marker is refused ("which this script does not know"), with or without `THRUST_RL_CREATE_ID` still in the environment, so a stale template cannot be rendered into a config that declares a binding the Worker does not use. - The deploy-worker action loses its `rl-create-id` input and its `THRUST_RL_CREATE_ID` env; deploy.yml loses the variable from its list of an environment's variables, from the dry run's environment and from both `rl-create-id:` inputs; test-deploy-worker.sh drops it from its good environment. - G-26 records this. Checked, under dash in an Ubuntu 24.04 container (CI's shell) on this tree and, as a baseline, on origin/main, with python3, jq and nc installed: every test of the `ci-scripts` job and both deploy guards (the renderer's `--self-test` and the workflow lint of deploy.yml and the action) pass on both. The renderer's self-test is 43 ok on this tree and 45 on main: four cases removed, two added. `scripts/check-placement.sh` passes. clippy and rustfmt are clean on the merged tree. Control: main's template against this wrangler.toml fails the parity check (exit 1: the template has `RL_CREATE`, wrangler.toml does not); the fixed template agrees. The `THRUST_RL_CREATE_ID` variable of the GitHub environments is unused now. It is harmless and deleting it is the owner's. A deploy of this commit renders a config with two rate-limit bindings and a Worker that asks for those two. Refs: #58 Co-Authored-By: Claude Sonnet 5.5 <[email protected]> --------- Co-authored-by: Claude Sonnet 5.5 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
The third of four staged PRs for the deploy pipeline (#49, ADR-0110 round 29). #153 (version header, smoke) and #154 (
migrateover verified TLS, the Access-tunnel script) are merged. This addsdeploy.ymland everything it runs. The last PR (hashed assets, docs and the ADR note) finishes the work; #49 stays open until then.Nothing deploys when this merges. Automatic deploys wait for the repository variable
THRUST_DEPLOY_ENABLED=true, and a manual run needs an environment that has its variables. Until then a merge tomainplans, sees the switch off, and stops.How a run goes
plancipassed; a manual run namesstagingorproductionand a commit of main, and must itself run from main; a pull request is a dry run. The commit's owngatemust have passed, asked for by name on that commit, and the environments that gate the deploy must have required reviewers (GitHub creates an unprotected one if a name is mistyped, which would silently open the manual gate)buildmigratebinary into one bundle, attested (SLSA provenance)deploy(env<env>)wrangler deploy --tag <sha>at 100 %; the smoke; the smoke's control (it must refuse a version nobody deployed). A failing smoke ends inwrangler rollbackto the previous version and a probe showing it answer. The run stays reddeploy-do(env<env>-do-lifecycle, reviewers)deploydeferred: the first deploy to an environment, any change to[[migrations]], a live state that cannot be read.deployfinds that out first and deploys nothing; this job deploys after approval, with no automatic rollback (Cloudflare refuses a rollback across a Durable Object lifecycle change)dry-runwrangler deploy --dry-runcheck the rendered configuration. It is what shows, before the merge, that this workflow startsEach secret reaches only the process that needs it: wrangler gets the Cloudflare token and nothing of the database, the tunnel or the smoke account; the expand step gets the database's and the tunnel's but not the Cloudflare token; the smoke gets only its own account. A test has each fake report what it could see.
Operating it (the owner's side)
staging,staging-do-lifecycle,production,production-do-lifecycleexist. Required reviewers onstaging-do-lifecycle,productionandproduction-do-lifecycle:planrefuses to start a deploy if they are missing. Deployment branches restricted tomainis worth setting too.stagingandstaging-do-lifecycleare copies of each other): variablesCLOUDFLARE_ACCOUNT_ID THRUST_WORKER_NAME THRUST_BASE_URL THRUST_HYPERDRIVE_ID THRUST_R2_BUCKET THRUST_QUEUE THRUST_QUEUE_DLQ THRUST_RL_CREATE_ID THRUST_RL_SIGNIN_ID THRUST_RL_V1_ID THRUST_CSRF_ENFORCE DB_ACCESS_HOSTNAME SMOKE_EMAIL SMOKE_WORKSPACE(andSMOKE_PROJECT, defaultsmoke); secretsCLOUDFLARE_API_TOKEN TUNNEL_SERVICE_TOKEN_ID TUNNEL_SERVICE_TOKEN_SECRET DATABASE_URL SMOKE_PASSWORD. A missing variable is named in the run's error and nothing is deployed.THRUST_CSRF_ENFORCEhas no default on purpose: turning it on for production should be a decision.stagingwithfirst_deploy_skip_smoke(the hostname does not exist yet).deploydefers, you approvedeploy-do, the schema is made and the Worker is created. Then infra attaches the Custom Domain (ApiraTech/infrastructure #1017), you runscripts/smoke-bootstrap.shonce, and a normal dispatch of the same commit runs the smoke for real.stagingwithinject_smoke_failureafter any normal deploy. Expect a red run, awrangler rollback, and the previous version answering. Refused for production.THRUST_DEPLOY_ENABLED=truewhen you want pushes to deploy.Decisions to look at
THRUST_DEPLOY_ENABLED): without it every merge would start a deploy to an environment that does not exist.first_deploy_skip_smokeexists because a Custom Domain needs the Worker to exist first.scripts/deploy-worker.shrefuses it for any environment that already has a live version, and before a reviewer is asked to approve anything.--source-digest. On aworkflow_runthe workflow's own commit is the tip of main, not the commitciran on. The bundle names the commit it was built from inside the attested file, and the deploy compares that with its own.cloudflaredis a pinned release binary (2026.10.7, SHA-256 checked, and checked again by me against a download on 2026-11-14).Tests and controls
Everything below runs in
ci-scripts(under dash) ordeps.scripts/deploy-worker.shagainst a fake Cloudflare that keeps state (what the edge serves). The smoke is truthful about it, so a rollback verifies only if it really made the previous version answer. Cases: an ordinary deploy; migrations before the deploy; a failing expand step; a stale edge; a broken app; an injected failure; a smoke that accepts any version (caught by the control, rolled back); a failed and an unverified rollback; the first deploy and a lifecycle change at the manual gate (deferred, nothing deployed, no automatic rollback even when the smoke fails); an unreadable live state; refusals before anything is touched; the secrets each process sees.plan-deploy.shover every combination of its finite inputs (2,640),classify-deploy.shover every pair of commits of a real history against a state-based oracle,assert-sha-checks.shandassert-gated-environments.shagainst a fakegh,render-wrangler.sh --self-test, a parity test ofwrangler.deploy.tomlagainstwrangler.toml, a pin of the CA root's fingerprint, andlint-workflow.shwith a broken copy for each of its seven rules.required_reviewersrule counts).worker-buildand ranwrangler deploy --dry-runon the rendered template (wrangler 4.123.0 locally; CI uses the pinned 4.151.2): the bindings are exactly the intended ones, with no credentials. The CIdry-runjob repeats it on this PR.crates/thrust-adapters-postgres/tests/tls.rsreads the real Cloudflare Origin CA root the deploy trusts (byte for byte the file Cloudflare publishes) and shows rustls accepts it as averify-caroot, with a control.Faults the tests and the real build found, corrected here: the renderer accepted a name with a capital letter in a UTF-8 locale on macOS (
[a-z]matched it);jq | sort || failtestedsort's status and read a jq failure as "nothing reported"; the first bundle copiedbuild/worker/only, whenworker-buildalso writesbuild/index.jsandbuild/index_bg.wasm, which the shim imports, so the deployed Worker would not have started.Not verified
None of this has run against Cloudflare or GitHub's environments, and this PR's own CI run is the first time
deploy.ymlstarts.wrangler deployments list --jsonandversions list --json. The parser accepts the documented one and treats every other as "cannot tell", which sends the deploy to the manual gate and never to an automatic rollback. The first staging deploy settles it.wrangler deployattaches the queue consumer with a dead-letter queue, and the token scopes it needs (likely Queues > Edit as well as Workers Scripts > Edit).gh attestation verifywith these flags on a real attestation).GITHUB_TOKENcan read an environment's protection rules. If it cannot,planfails closed with a message that says so, and the remedy is a permission, not a weaker check.Checks run locally
cargo fmt --all --check, clippy on every target and for the wasm Worker,cargo nextest run --profile ci --workspace(3,868 passed), the doctests,check-deps,check-topology(with its self-test),check-placement,render-wrangler.sh --self-test,lint-workflow.sh, and all the script tests under dash.Refs: #49
🤖 Generated with Claude Code