Skip to content

promoter: runs as an updater task too, with a request reader for resume, abandon and approve; updater tasks get credentials - #78

Draft
Savid wants to merge 6 commits into
port-job-scriptsfrom
promoter-updater
Draft

Savid wants to merge 6 commits into
port-job-scriptsfrom
promoter-updater

Conversation

@Savid

@Savid Savid commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

Stacked on #76 (the daily jobs as updater tasks), with #77 (the promoter fails closed) merged in; review only the last commit here.

The promoter now also runs as a task of nixosModules.updater, and a new host-promote requests takes the place of GitHub's "Run workflow" button for resume, abandon and approve. Without UPDATER_TASK, in GitHub Actions, the promoter issues the same git pushes and fetches and gh reads as before; a new test holds it to a recording taken from the promoter before this change.

Credentials for updater tasks. A task's environment is in the Nix store, so there was no safe way to give one a secret. The new per-task credentials.<NAME> = "/run/secrets/…":

  • is loaded with systemd's LoadCredential into that unit's credentials directory;
  • reaches the command as a file named by <NAME>_FILE (%d/<NAME>, which systemd expands in Environment=), never as a value in the environment or argv;
  • is refused at evaluation when it's a Nix path or in the store (the check keyFile had, now shared), or when its name isn't a variable's.

Every task's credential files, like the keys, are in every task's InaccessiblePaths: a task reads its own only through its credentials directory. A program that takes a path in a variable of its own gets it with %d in environment, such as KUBECONFIG = "%d/KUBECONFIG".

  • The promoter reads its webhook from ROLLOUT_DISCORD_WEBHOOK_FILE when ROLLOUT_DISCORD_WEBHOOK isn't set. --apply counts either.
  • refresh-keys reads WEBHOOK_FILE the same way (ci/lib.sh's from_file). The value stays unexported.

The promoter under the updater:

  • Nothing fetches. It reads the branches as the run's own fetch left them.
  • gh (check_passed, and the reader's listing) reads with updater-read-token's token, given only to gh's environment and asked for again with under 10 minutes left. GH_REPO names the repository.
  • A deploy branch moves through updater-push --old <as read> --new <target> --toplevel <path>. The path comes from nix build of that host's system.build.toplevel at the target. A refused or failed push (or build) fails the run after the move is recorded, as a failed git push does in Actions.
  • rollout-state moves through updater-push with --old the commit the write was built on.
    • A refusal stops the run without pushing anything: it can't fetch to rebuild, and the next run starts from a fresh fetch.
    • The README says to run every environment of a fleet in one task, in order, so the task's own runs never race. A refusal then means a run outside it wrote first.
    • After each push the checkout's origin/<branch> moves as git push would, so the next environment in the same task reads it.
  • A dry-run answer (the repository's apply = false) counts as success. It moves nothing locally, says so in the log, and posts no notice: each run would post the same ones again.
  • Halt and approval notices say to ask with the request workflow (staging resume, production approve <full id>) instead of the promote workflow.

The request reader. host-promote requests --requesters FILE [--workflow request.yaml] [--max-age-hours 24] [--context [ENV=]CONTEXT] [--apply]:

  • It lists the request workflow's runs (event=workflow_dispatch, the default branch), oldest first.
  • It acts on a run only when all of these hold:
    • it was dispatched on the default branch from that workflow file there;
    • its actor and triggering_actor are both in the requesters file, which comes from the updater host's configuration, not the fleet repository;
    • it's younger than the window;
    • its run-name is exactly <environment> resume|abandon or <environment> approve <40-hex commit>.
  • It acts through the existing --action path and names who asked in the notice. The run id goes into that environment's state in the same write as the action (requests, the last 200, kept across new rolls), so a second pass or a fresh checkout doesn't act again.
  • A run it refuses gets one notice saying who asked, what, and why: an unlisted actor, a malformed run-name, an unknown environment, a commit that isn't one, or a resume with nothing halted. Its id goes into _requests.json on the state branch, and it's posted only once. A refusal that fails to post isn't recorded, so the next pass tries again.
  • Runs on other branches, from other events or other files, and older runs, are ignored without a notice.
  • Without --apply it only says what it would do.
  • It works under the updater and with a plain gh token.

The README has an example task and request workflow. The workflow's job never runs, so it needs no runner. It's written as if: github.event_name != 'workflow_dispatch' because actionlint refuses a constant if: false.

Tested:

  • rollout/promoter/test_promote.py: 18 new tests, with stubs for updater-push (compare-and-swap, no creating, a toplevel for deploy branches, pushed or dry-run), updater-read-token, gh, nix build and a logging git. Every existing test passes unchanged.
    • Under the updater:
      • no git fetch or push of its own;
      • the exact updater-push calls for a deploy move and a state write;
      • the next environment writes on what the last one wrote;
      • a refused state write stops the run with the deploy branch unmoved;
      • a refused push or a failed build fails the run after the move is recorded;
      • dry-run answers succeed, move nothing and post nothing;
      • the token reaches only gh, and one token serves the run;
      • notices point to the request workflow.
    • The reader:
      • acts once, again after a new roll and from a fresh checkout;
      • acts oldest first;
      • refuses an unlisted actor, or an unlisted triggering_actor, with one notice;
      • refuses eleven malformed requests;
      • ignores other branches, events and paths, and old runs;
      • changes nothing on a dry run;
      • works through the pusher under the updater.
    • ROLLOUT_DISCORD_WEBHOOK_FILE.
    • GitHub Actions: the git pushes and fetches and gh reads of a run, a convergence, approve, resume, abandon and a rebuilt state write equal fixtures/actions-calls.txt, recorded from the previous promote.py.
    • Each new test fails against a mutant that does the plausible wrong thing (24 mutants).
  • updater/test_pusher.py: a ref pushed twice in one run, as the promoter writes rollout-state. The second push's --old is where the first left the ref, with no fetch between them, and it passes; a stale --old is still refused.
  • updater-config: a credential in the store, as a Nix path, or with a bad name is refused. A valid one reaches its unit's LoadCredential and <NAME>_FILE, and the unit file has %d unescaped. Another repository's task gets none, and no task reaches the file.
  • tests/fleet/test-jobs.sh: refresh-keys reads WEBHOOK_FILE, keeps it out of commands' arguments and environment, and fails before anything when the file can't be read. The GitHub Actions recordings are unchanged.
  • tests/vm/updater.nix: a task reads its own credential from $SECRET_FILE, in $CREDENTIALS_DIRECTORY. Neither its own credential's file nor another repository's is readable, even at mode 0644, and neither is another repository's credentials directory while that task runs. Run here under TCG; CI runs it with KVM.
  • formatting, rollout-plan, promoter, updater-pusher, updater-config, fleet-scripts, fleet-example, fleet-rules, workflows and ci pass.

Worth reviewing:

  • Under the updater with apply = false, notices are printed, not posted.
  • --context [ENV=]CONTEXT on the reader, for fleets with one kubeconfig context per environment.
  • _requests.json as the reader's own record on the state branch. Environment names can't start with _.
  • The reader's handling of display_title (the run-name) and of path with or without @<branch>.

Not verified:

  • Nothing here has run against real GitHub: the runs listing's created filter, display_title, and path's exact form for a dispatched run.
  • The updater state branch must exist before a task's first write: the pusher creates no branch outside a proposal prefix.

Savid added 5 commits December 1, 2026 10:05
…, re-posts, one writer per environment)

- --apply (a run or any action) refuses to start without
  ROLLOUT_DISCORD_WEBHOOK, before it reads anything.
- A run fails when none of the environment's installed hosts in the plan
  has its deploy branch on the remote. The plan now says whether each
  host is installed: lib.mkFleet's host.json, and true for any other host.
- A cluster API that doesn't answer counts as the host in flight not
  being back yet, on its last state's budget, then halts and posts; with
  nothing in flight the run fails without moving anything.
- Halts and long waits post again every budgets.repost minutes (240).
- write_state stops without pushing when the environment's own state file
  changed since the run read it; another environment's change is still
  rebuilt on top.
- Fingerprints are evaluated --eval-batch hosts per nix eval (10).
- ROLLOUT_RUN_URL sets the notices' run link.
- approveEvery: listed later environments take only an approved commit.
…me, abandon and approve; updater tasks get credentials

Updater tasks get credentials.<NAME>: a secret file on the host, loaded
with LoadCredential and found at <NAME>_FILE (%d/<NAME>), refused at
evaluation in the store or as a Nix path, and out of every task's reach
but through its own credentials directory. The promoter reads its webhook
from ROLLOUT_DISCORD_WEBHOOK_FILE, refresh-keys from WEBHOOK_FILE.

Under UPDATER_TASK the promoter fetches nothing, reads GitHub with the
pusher's read token in gh's environment alone, moves deploy branches with
updater-push and the toplevel it built at the target, and writes
rollout-state with updater-push from the parent it built on, stopping
when that's refused. In GitHub Actions its git and gh calls are as before,
held to a recording of the previous promote.py.

host-promote requests acts once on each run of a read-only request
workflow dispatched on the default branch by an actor (and triggering
actor) in the requesters file, with a run-name of exactly <env>
resume|abandon or <env> approve <full commit>, recording the run id in the
same state write as the action; anything else it refuses with one notice.
lib.mkFleet's fleet install pushes a host's deploy branch before it
installs it, so a host host.json calls installed that has no branch lost
it, or the token can't read it, and converging without it would stage a
commit it never ran. The plan's installed is now true or false from
host.json and null for any other host, which may not be migrated yet:
those still fail the run only when none of them has its branch.

@redpandabot redpandabot Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

The PR runs the promoter as an updater task (pusher-backed writes, gh read token, no fetch), adds a host-promote requests reader for resume/abandon/approve, per-task credentials loaded with systemd's LoadCredential, approveEvery, and halt/wait reposts. The implementation is careful and well tested, but the two previously open findings still hold: per-task credentials are pooled at the repository's user, and approve/abandon still require a reachable cluster.

Issues

  • 🟡 modules/updater/default.nix:680 — A credential is readable by every task of the same repository, not just its own — see the thread on that line
  • 🔴 rollout/promoter/promote.py:622 — approve and abandon fail on an unreachable cluster though they never read it — see the thread on that line

Reviewed @ 48dd1ae2
"The best code is no code at all." — Jeff Atwood

# The task's own secrets, read by systemd before it sandboxes the
# unit. toString: a Nix path (refused above) must not reach the
# store here.
LoadCredential = lib.mkIf (t.credentials != { }) (

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 A credential is readable by every task of the same repository, not just its own

systemd grants the unit's user an ACL on /run/credentials/<unit> and owns the credential files by that user, and every task of a repository runs as the same updater-<repository> (line 668) — so while updater-fleet-a-promote.service runs, a concurrently running updater-fleet-a-bump.service can read its KUBECONFIG/webhook from /run/credentials/updater-fleet-a-promote.service/. InaccessiblePaths (line 686) only hides the source files, and the new VM subtest (tests/vm/updater.nix:393) checks only another repository's task. Since tasks run the repository's code at the default branch tip, this undercuts the per-task secret isolation the option describes; either state that a repository is the credential trust domain, or give tasks separate users / bind only their own credentials directory.

try:
self.cluster = load_cluster(args.context)
except Unreachable as err:
if args.action != "run":

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 approve and abandon fail on an unreachable cluster though they never read it

__init__ re-raises Unreachable for every action but run, yet only resume uses self.cluster (in manual(), via logic.baseline); approve and abandon touch neither the cluster nor the nodes, so a cluster outage needlessly blocks them — and the halt notice for an unreachable API tells people to resume/abandon. With the new reader this is worse: Reader.handle only catches SystemExit, so an approve/abandon request raises out and aborts the whole pass (later queued requests included) instead of refusing that one. Only re-raise for resume, or load the cluster lazily.

…ollout-state

The second push's old is where the first left the ref, with no fetch
between them, and it passes; a stale old is still refused as moved.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant