ci(cmux-next): promote a smoked VM image snapshot to the dev channel from a workflow
claude-sr2's decision, word for word: "Same secret, same environment, contents: read, no new tokens: that's no new trust, and the dev channel is ours. Build the promote workflow exactly as you described, including the guarded delete_snapshot input."
What it changes
-
.github/workflows/cloud-vm-image-promote.yml(new,workflow_dispatchonly). Inputs arechannel(a choice withdevas the only option, and refused again in the first step),snapshot(sh-ā¦),bake_runand an optionaldelete_snapshot. It runs in environmentcmux-next-vm-image-devand refuses any ref other thanfeat-cmux-next. Steps:- Check the inputs: the id formats,
bake_runis required withsnapshot, anddelete_snapshotmay not be the snapshot being promoted. - Check that
bake_runis a successfulfeat-cmux-nextworkflow_dispatchrun ofcloud-vm-image-bake.ymlin this repo. - Download that run's
cmux-vm-image-bake-<run>artifact and append itschannel-dev.json, minusschemaandenv, tochannels/dev.jsonhistory(web/scripts/cmux-vm-image/promote-record.ts). It refuses a candidate whose id, run, smoke result, name prefix or var doesn't match, and it never edits an existing entry. - Run
bun ../images/cmux-vm/promote.ts --channel dev --snapshot <id> --var <candidate's var>. That is promote.ts's own fresh-clone smoke on the dev account. - Upload
git diffofimages/cmux-vm/channels/dev.jsonandbackend/apps/api/wrangler.jsoncas the artifactpromote-dev-<snapshot>.diff(kept 3 days). - Write the diff, the fresh-clone smoke record and promote.ts's rollback lines to the job summary.
It pushes nothing and opens no PR. A lane applies the diff on a branch, opens the channel PR, and lands it after review; the next development deploy ships it.
- Check the inputs: the id formats,
-
delete_snapshotgoes through a newcleanup.ts --snapshot <sh-id>mode, which callsfreestyle'svms.snapshots.get/delete, the same client the ledger cleanup already uses. It refuses:- an id that any
images/cmux-vm/channels/*.jsonstring mentions: pointer,previous,team_vm,history, prose notes; - an id that
backend/apps/api/wrangler.jsoncmentions; - a snapshot whose slug or display name is mentioned in any of those files;
- a snapshot not named
cmuxnp-dev-vmimg-*.
The scan fails closed and catches hidden mentions:
- a channel file that doesn't parse refuses the delete;
- the scan covers parsed values and keys, every JSON-decoded string literal (so a duplicate key or an escape can't hide an id) and raw lines;
- matching is case-insensitive and on whole tokens.
It checks both the job's checkout and
feat-cmux-nextfetched just before the delete, so a channel PR that lands mid-run still protects its snapshot. It prints every reference it finds (<file>: <json path>or<file>:<line> <key>). If the job also promoted, the check reads the promoted files, so the old pointer, nowprevious, stays protected. - an id that any
-
Tests.
web/tests/vm-image-cmux-vm-promote-workflow.test.ts(wired intocloud-vm-image-lock.yml) checks:- dispatch only, no
pull_request_target; - permissions exactly
contents: readandactions: read, and no job-level permissions; - environment
cmux-next-vm-image-dev; cancel-in-progress: false;- no expression interpolated into a run script;
- the input refusals;
- key handling: it runs the real step scripts with a stub
bunand checks that the key is not in argv or the environment, the file is mode 600, and the file is gone afterwards; - every reference refusal, plus the real channel files protecting the serving image and all history entries;
- promote-record's refusals.
tests/test_supplychain_security.pypins the same permissions, environment and trigger. - dispatch only, no
-
Docs. "Promote from CI" in
plans/cmux-next/release-rails.md.
Permissions and key
- Workflow permissions are
contents: readandactions: read, the latter only soactions/download-artifactcan read the bake run's artifact. There is no write scope, no PR token and nopull_request_target, and checkout runs withpersist-credentials: false. - The key is the existing
FREESTYLE_API_KEYsecret of thecmux-next-vm-image-devenvironment, the same secret and environmentcloud-vm-image-bake.ymluses. - Each step that uses the key first copies it to an unexported shell variable and unsets the env var, so no child process (mktemp, git, grep, bun) inherits it. It then writes the key to a
mktempfile in$RUNNER_TEMPunderumask 077/chmod 600. promote.ts and smoke.ts read it throughFREESTYLE_API_KEY_FILE, and atrapdeletes the file on exit. The key is never on a command line or echoed. - The diff step refuses to upload an artifact that contains the key.
Risk
- Low. The workflow can only run when someone dispatches it, and it changes nothing in the repo or on any Worker.
- The one provider write that doesn't come from promote.ts is
delete_snapshot, which refuses any snapshot a channel or the Worker config names. - No existing workflow changes behavior:
cloud-vm-image-lock.ymlonly runs one more test file, andcleanup.ts --ledgeris unchanged.
Testing
cmux-ci test(fleet Linux) at the head:bun test tests/vm-image-cmux-vm-promote-workflow.test.ts tests/vm-image-cmux-vm-bake-workflow.test.tspassed 58 tests, and actionlint is clean on both workflows.- The key test shims every external command the key steps run and fails if any of them sees the key.
tests/test_supplychain_security.pypassed 7.- The other workflow guard tests fail there only on files this PR doesn't touch (
chief-evals.yml,cmux-next.yml,nightly.yml,ci.yml), so those are base reds.
Size: 992 changed lines, 452 of them the test file. That is over the ~800 guide. I kept it as one PR because the workflow, its delete guard and their tests went through six review rounds together.
First use: sh-305c4f86261349909f5b0330781b7623 from bake run 40270232246 (source 41c5481957f3, smoke PASSED, 25 checks).
Agent session: agent session
š¤ Generated with Claude Code