Repository navigation
rolloutPlan, fleet doctor, promoter, promote.yaml: four things that passed or ran without checking - #68
rolloutPlan, fleet doctor, promoter, promote.yaml: four things that passed or ran without checking#68Savid wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
This PR makes four previously silent paths fail loudly: rolloutPlan now refuses classes that can never fire, fleet doctor compares file-mode deploy keys during --live, the promoter refuses an applying run without a Discord webhook, and generated promote.yaml drops its schedule when ci.jobs.promote is off. The accompanying tests and fixtures cover each case, and I found no concrete defect in the implementation or its callers.
Reviewed 21 changed file(s) @ c768986f — no blocking issues found.
Red pandas are famous zoo escape artists. Never trust a default-deny that hasn't been tested.
classify compares the fingerprint keys a class names, and reads a key only one side has as unknown, not changed. So a class naming a key no host's fingerprint has, or that some hosts' lack, never fires for those hosts, and nothing says so: a k3s minor upgrade soaks as a plain reboot, and the class's `alone` guard never runs. The same goes for a misspelt class attribute (`serie` for `series`) and for a class after the first that compares nothing. rolloutPlan now refuses each of these with the class, the key and the hosts that lack it, and says to add the key to every host's fingerprint (a fleet's module can) or drop it from the class. The header says that a class's fields must be keys of every host's fingerprint. ethpandaops.fingerprint's type becomes lazyAttrsOf. With attrsOf, listing the keys forced every value, and `toplevel` is a second evaluation of the whole system, so checking a plan's classes cost one more system evaluation per host (this repository's example plan went from 0.6 to 2.2 GB and from 4 to 29 seconds). Keys are now listed without touching the values, and the values the promoter reads are the same. A key defined only under mkIf false now fails when it's read, instead of being absent. Tested: checks.rollout-plan builds plans over stand-in hosts with and without a fleet's own key. The plan is accepted when every host has the key, and refused when no host has it, when one host lacks it, for a misspelt attribute, for a class with nothing to compare, and for an `alone` field no host has. The example plan, whose default classes name only nixos-modules' own keys, still evaluates. Without the new assertion the check fails.
…--live For a host whose deploy key is a file on it (fleet.nix deployKey = "file"), the github section's deploy-key check passed with "--live compares it", and --live didn't compare it: nothing checked that the key on GitHub is the host's. Now the github section checks only sops keys, which it can read from the repository. With --live, a file-mode host's check reads the public half of its key over SSH (sudo ssh-keygen -y, so no private material leaves the host) and requires GitHub's "comin <config>" to be that key and read-only. A host it can't reach is unread, and a mismatch says how to put the right key back under the right title. Tested in tests/fleet: the github section has no file-mode check; --live passes the matching key; it fails the key under another title and a writable key; it fails as unread when the host can't be reached. All four fail on the previous doctor.
…thing With discord-webhook empty, the promoter moved hosts and only printed its notices to the run's log: a halt, a promotion or a rollback reached nobody, and the run passed. A webhook of the wrong form already stopped the run; a missing one now does too, the way refresh-keys stops without one. A dry run (no --apply) still needs none. host-promote's discord-webhook description says so. It stays optional for a dry run, so a caller needs no change; a fleet whose webhook secret is unset finds out at its first run that applies, which fails before moving anything. Tested: a run that applies with the webhook unset or empty exits 1 with the reason, posts nothing, saves no state and leaves the deploy branch where it was; a dry run without one passes. The first case fails on the previous promoter. ruff and the promoter's 99 tests pass.
With ci.jobs.promote = false, the generated promote.yaml still ran every 10 minutes, and each run only started a plan job to say the promoter is off: 144 idle runs a day on the fleet's runners. Now the schedule is there only when the job is on, and the header says the workflow runs by dispatch only otherwise. Dispatch works either way. The header also says that a run that applies fails without CI_WEBHOOK. A fleet with the job off sees its promote.yaml change at its next fleet upgrade; checks.workflows asks for that run after the bump, as it does for any change to what's generated. Tested: checks.fleet-example renders and lints a promoter fleet with the job off; its promote.yaml has workflow_dispatch and no schedule, while the default one keeps it. Without this change the check fails.
There was a problem hiding this comment.
Summary
Four loud-failure changes: rolloutPlan refuses classes whose fingerprint keys hosts lack, fleet doctor compares file-mode deploy keys over SSH in --live, the promoter fails an applying run with no webhook, and promote.yaml drops its schedule when ci.jobs.promote is off. I traced the doctor's key comparison (including the null deployKeyFile/title/read-only paths), the promoter's early-return ordering, and the rendered YAML indentation, and found no defect there; one concern with the fingerprint option's type change, plus a stale option description.
Issues
- 🟡
modules/fingerprint.nix:22— lazyAttrsOf makes a conditionally-defined fingerprint key present but unreadable — see the thread on that line - 🟢
lib/fleet/files.nix:439— ci.jobs description contradicts promote's dispatch-only behaviour —lib/fleet/schema.nix:238still says a job that's off "still runs its plan job, which says why", but withci.jobs.promote = falsethis change makes the generated workflow dispatch-only, so no plan job runs at all. Worth updating the description with the same change.
Reviewed @ 9a0f6144
Red pandas are famous zoo escape artists. Never trust a default-deny that hasn't been tested.
| type = lib.types.attrsOf lib.types.unspecified; | ||
| # Lazy: listing the keys (lib.rolloutPlan checks every class's) mustn't | ||
| # evaluate toplevel, a second evaluation of the whole system. | ||
| type = lib.types.lazyAttrsOf lib.types.unspecified; |
There was a problem hiding this comment.
🟡 lazyAttrsOf makes a conditionally-defined fingerprint key present but unreadable
lazyAttrsOf does not drop mkIf false attributes (nixpkgs' lib/types.nix at the locked rev): attrNames lists them while reading the value throws, because types.unspecified has no emptyValue. A fleet adding a key as ethpandaops.fingerprint.k3sVersion = lib.mkIf … therefore looks like every host has the key, so the new classProblems check accepts the class, and the failure surfaces later in the promoter's nix eval --json of the fingerprint (breaking the nix eval … .fingerprint documented at the top of this file) instead of being refused up front.
Four places where something passed, or ran, without checking anything. Each is its own commit with a test that fails on the previous code.
lib.rolloutPlan: a class that can never fire stops evaluation. The promoter compares the fingerprint keys a class names, and reads a key that only one side has as unknown. So a class naming a key that no host'sethpandaops.fingerprinthas (or that some hosts lack) never fires for those hosts, silently: a k3s minor upgrade soaks as a plain reboot, and the class'saloneguard never runs. Evaluation now refuses such a class with the class, the key and the hosts that lack it. It also refuses a misspelt class attribute, and a class after the first that compares nothing. To list the keys without evaluating them,ethpandaops.fingerprintbecomeslazyAttrsOf: withattrsOf, listing keys forcedtoplevel, a second evaluation of each host's system, and the example plan went from 0.6 to 2.2 GB to evaluate. It's back to 0.6 GB now. The fingerprint and the example server's system are unchanged apart from the revision in/etc/nixhost/modules.json.fleet doctor: a deploy key that's a file on the host is compared, in--live. FordeployKey = "file", the github section's deploy-key check passed with "--live compares it", but--livenever compared it. Now--livereads the public half of the host's key over SSH (sudo ssh-keygen -y) and requires GitHub'scomin <config>to be that key, read-only. The github section checks only sops keys, which it can read.discord-webhookempty, the promoter moved hosts and only logged its notices, so a halt or a promotion reached nobody. A run with--applyand no webhook now fails first, the way refresh-keys already does; a dry run still needs none.discord-webhookstays optional inhost-promote, so callers need no change.promote.yamlruns on a schedule only whenci.jobs.promoteis on. With the job off, the schedule still started a plan job every 10 minutes just to say so. Now that workflow is dispatch-only. A fleet with the job off sees itspromote.yamlchange at its nextfleet upgrade.Tested
checks.rollout-plan: plans over stand-in hosts with and without a fleet's own key are refused when no host has the key, when one host lacks it, for a misspelt attribute, for a class with nothing to compare, and for analonefield no host has. They're accepted when every host has the key. The example plan still evaluates.tests/fleet(checks.fleet-scripts), 4 new doctor cases: no file-mode check in the github section;--livepasses the matching key, fails the key under another title or a writable key, and is unread when the host can't be reached.checks.fleet-examplerenders and lints a promoter fleet with the job off and finds no schedule.nix buildofrollout-plan,fleet-example,fleet-scripts,formattingandworkflows.