Skip to content

appliance: fix #4013 — rig-side updater: signed bundle over Tor, spare-slot install, verdict in rig-update.json - #4103

Open
pithead-developer[bot] wants to merge 19 commits into
developfrom
agent/4013-rig-side-updater-download-the-signed-bun
Open

pithead-developer[bot] wants to merge 19 commits into
developfrom
agent/4013-rig-side-updater-download-the-signed-bun

Conversation

@pithead-developer

@pithead-developer pithead-developer Bot commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

What's the problem

#4013: a shipped appliance rig had no way to take an OS update — the rig branch of pithead-boot only started the miner and committed or failed the boot, and the release fetch lived only on the coordinator's root control runner. Rig owners could only re-flash the stick, which replaces /data and the token. #4011 landed the hardened release channel (its helpers: os_channel_fetch, os_release_tag_valid, os_channel_record) and the contract in docs/dev/rig-os-update.md says the rig fetches its own bundle over Tor through the image's on-demand Tor client; this is that rig-side updater. (The group siblings #4014 and #4016 stay open: their acceptance criteria require the still-open rigforge#680/#681/#684 feed and release-endpoint work, so they need their own proofs once those land.)

How I fixed it

  • New slice lib/pithead/47b-rig-update.sh registers pithead rig-update check and pithead rig-update install [--tag T] [--max-version V] (dispatch, PITHEAD_COMMANDS, help).
    • check starts Tor through the image's pithead-tor helper (re-invoking the verb inside the wrapper, which guarantees Tor stops on every outcome), reads the listing with Harden the update channel: untrusted listing, release-host allowlist, size cap, tag validation, stale-channel reporting #4011's os_channel_fetch over the helper's SOCKS port, validates the tag, records channel staleness/replay with os_channel_record, prints running and available versions, installs nothing. The bench test seam (root-owned os-update-test-base) skips Tor exactly like the coordinator's door does.
    • install refuses before any byte moves when: --tag/--max-version are malformed, an update is already pending reboot, the other slot is uncommitted after a failed gate boot, or /data lacks the announced size plus the shared 1 GiB headroom. It refuses targets above --max-version with semantic comparison, refuses equal and downgrade versions via the shared guard, then downloads resumable (bounded resume loop; a file whose length is not exactly the announced size is never verified as complete) and verifies with the shared os_verify_bundle_reason (signature against the baked keyring, compatible, variant, floor, stamp==tag). Every refusal and failure deletes the bundle and its partial (the rig keeps nothing staged — overriding the dashboard door's keep-on-migration-space outcome per the contract), records the reason in rig-update.json, and never touches the running slot. On success it writes the spare slot through os_update -y, records the pending intent, sweeps staging, syncs, and reboots.
  • os/overlay/pithead-boot's rig branch now settles the verdict after the miner-active self-commit via ./pithead rig-update boot-record: pending.to == running → verdict updated; pending.to != running (the fallback boot) → rauc status mark-bad other and a rolled_back verdict naming the reason; each rig boot also sweeps stale staged bundles.
  • Status file: rig-update.json on /data (state pending|refused|updated|rolled_back, from, to, ts, reason), written before the reboot by the installer, settled after boot by pithead-boot, and readable by the feed; refusals keep any pending record intact rather than clobbering it.
  • tests/os/selftest-rig-update.sh: 42 checks — seam and live-Tor-shaped check paths (helper invoked, SOCKS dialed), tainted tag, missing bundle asset, frozen channel, equal, downgrade, --max-version ceiling, malformed args, pending refusal preserving the record, uncommitted-slot refusal, space refusal, truncated-never-verified, bad signature, stamp mismatch, install failure, the good install (pending record + reboot + nothing staged), and both boot verdicts including mark-bad-other and the sweep.
  • tests/os/rig-update-leg.sh: the rig phase's KVM leg — seam check reports both versions and starts no Tor, the --max-version ceiling and the pending record refuse while the rig keeps mining, the real install reboots the rig into its own bundle, pithead-boot settles the verdict as updated in rig-update.json, staging is swept, and a final check reads the real channel over live Tor with Tor stopped afterwards.
  • Review round (head aaed523): the bundle HEAD resolve and the download are both https-only through the Tor SOCKS port, the URL is re-resolved on every attempt (a signed asset URL that expires is not reused) and the cause of a failed resolve is kept; the pending record is written before the spare slot, so an unwritable status file aborts before anything changes (a failed slot write then records refused); a Tor-helper failure (clock, bootstrap, lock) is recorded as a refusal unless the inner run already wrote its own reason; a refusal never overwrites pending or rolled_back; os_release_tag_valid is now a bash regex, so a tag with an embedded newline is refused. selftest-rig-update.sh grows to 64 checks; each new row was shown to fail with its line reverted (no SOCKS/https flags, no rc 28 resume, no pending-first write, no wrapper-failure record).
  • Shortcut: Tor stays up for the verify and the rauc install (the wrapper owns it) and stops on every outcome; a SIGTERM mid-download leaves the partial until the next boot sweep or install of the same tag, which also keeps it resumable. Upgrade when the issue wants the partial deleted on signal.
  • Limits of the KVM leg: it proves the success path through the http test seam; the fallback (rolled_back, mark-bad other) and the Tor-only download are proven by the selftest only. tests/os/phases/rig.sh keeps its one-line reflow of the marker assertion because the file sits at its budget ceiling. The bundle download remains a second copy of the coordinator's bounded curl loop (finding 10, note only).

Here is the proof

  • Tier 1: selftest-rig-update OK (42 checks) locally; every changed file shellcheck/shfmt clean; lint-file-budget, lint-pithead-build, lint-md, lint-topology pass locally. GitHub CI green on head 90ededd (all checks pass, including Shell lint, every Shell tests block, and the verb-ledger locks).
  • First tier4-kvm run found the leg reaching an undeclared dashboard marker (only markers listed in tests/os/dashboard-markers.json get published per commit) and unregistered the new verb with the CI locks; the leg now uses the declared v1, and rig-update is registered with the completion list, both verb ledgers, the ledger table in docs/dev/testing-strategy.md, and the release-literal guard (the rig channel is a second shared-fetch-only site).
  • Second tier4-kvm run drove the whole flow — seam check, live-Tor check, install, boot into the rig-written slot — but read the two refusal outputs as empty (the harness _ssh sends remote stderr to its own error file; the leg now appends 2>&1 inside the ssh command), checked the post-boot verdict two seconds into a boot that takes minutes (now polled), looked at the wrong journal boot, and left the boot default on the slot it wrote, which misled the later setup-again leg; the leg now hands ORDER=B back and re-boots to slot B before finishing.
  • GitHub CI: all 43 checks pass on head 3c8dd0f (after merging develop-v2.0.5, which carries the Compose bump that cleared the rootfs Trivy scan).
  • Tier 4 on this head: tier4-kvm phases=rig passed on the second run (job 395). The first run (job 394) failed one row: the live GitHub release API answered HTTP 403 to the Tor check. Every rig-update row passed there; the retry on the same head and key-free resubmit passed all 292 rows, so the 403 is read as an external rejection of that Tor exit (inference; the 403 did not recur).
**bench-ci job 395@3c8dd0fbc22be1ed1243c6bbd8a20c13b49b42fd** · pithead · tier4-kvm
- options: {"phases": ["rig"]}
- status: completed · conclusion: success · exit 0 · 41m 45s
- baseline verified: yes · rig restored: n/a
- node guard: not recorded · no comparison recorded
- steps: checkout success · reserve success · preflight success · run success · collect success · restore success · cleanup success
- host audit: job 395: docker object inventory unavailable
- rows: 292 pass · 0 fail · 1 skip (by-design 1)
- image sha256: system.img 5e6653e805b048b9ea6213831f1f7244092e0bb6f113641e4113f7c9a4723697
- image sha256: rig/bundle-1.raucb ab4a2487201e7bd08ae701980250f91609e150b2f36aad00c83d56478d3ee1f4
_Generated by `bench-ci evidence 395@3c8dd0fbc22be1ed1243c6bbd8a20c13b49b42fd`; re-run it to check._

First run, failed row kept for the record:

**bench-ci job 394@3c8dd0fbc22be1ed1243c6bbd8a20c13b49b42fd** · pithead · tier4-kvm
- options: {"phases": ["rig"]}
- status: completed · conclusion: failure · exit 1 · 42m 16s
- baseline verified: yes · rig restored: n/a
- node guard: not recorded · no comparison recorded
- steps: checkout success · reserve success · preflight success · run failure · collect success · restore success · cleanup success
- host audit: job 394: docker object inventory unavailable
- rows: 291 pass · 1 fail · 1 skip (by-design 1)
- image sha256: system.img 5e6653e805b048b9ea6213831f1f7244092e0bb6f113641e4113f7c9a4723697
- image sha256: rig/bundle-1.raucb 3c301263d14f447e6b252320d0b4b049776a6f15db8f9075015bce85e145be7b
- failed rows:
  - [rig] the Tor check did not report the channel (got: [ERROR] the update channel answered HTTP 403 — nothing was changed. rig-update: the Tor helper ended with status 1 — nothing was changed. [ERROR] pithead aborted unexpectedly (exit 1). Re-run with) (no issue linked)
_Generated by `bench-ci evidence 394@3c8dd0fbc22be1ed1243c6bbd8a20c13b49b42fd`; re-run it to check._

Part of #4013

🤖 Generated with Claude Code

bench-ci job 4678@9b7376fa85772997cbb25d8670d157b20bf296dd · pithead · tier4-kvm

@pithead-developer pithead-developer Bot added this to the v2.1.0 milestone Nov 13, 2026
@pithead-developer pithead-developer Bot added stage/bench-testing its issue waits on a queued or running tier-4 bench job and removed stage/in-progress labels Nov 13, 2026
@pithead-developer pithead-developer Bot added stage/in-progress stage/bench-testing its issue waits on a queued or running tier-4 bench job and removed stage/bench-testing its issue waits on a queued or running tier-4 bench job stage/in-progress labels Nov 14, 2026
@pithead-developer pithead-developer Bot modified the milestones: v2.1.0, v2.0.5 Nov 16, 2026
@pithead-developer pithead-developer Bot added stage/in-progress stage/operator parked for the operator and removed stage/bench-testing its issue waits on a queued or running tier-4 bench job labels Nov 16, 2026
@pithead-developer pithead-developer Bot added stage/in-progress and removed stage/blocked its issue waits on another issue labels Nov 27, 2026
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@pithead-developer

Copy link
Copy Markdown
Contributor Author

Blocked on #4537 (libzstd1 CVE-2026-124851 in the dashboard image).

@pithead-developer pithead-developer Bot added stage/blocked its issue waits on another issue and removed stage/needs-check labels Nov 27, 2026
@pithead-developer

Copy link
Copy Markdown
Contributor Author

Still blocked, now on #4569 (forward merge into develop-v2.0.5).

@pithead-developer pithead-developer Bot added stage/in-progress stage/blocked its issue waits on another issue and removed stage/blocked its issue waits on another issue stage/in-progress labels Nov 28, 2026
@pithead-developer pithead-developer Bot added stage/in-progress stage/bench-testing its issue waits on a queued or running tier-4 bench job stage/needs-review green or pending CI, no reviewer verdict on the head yet and removed stage/blocked its issue waits on another issue stage/in-progress stage/bench-testing its issue waits on a queued or running tier-4 bench job labels Nov 28, 2026
@pithead-reviewer

Copy link
Copy Markdown
Contributor

PASS

What I investigated

Re-review at 9b7376f (3c8dd0f present). The worker's commits 9294b41, 14a1226 and 8b00967 fix both blocking findings: a Tor-helper failure now records a refusal, and the pending record is written before the slot so an unwritable status file aborts with no install and no reboot. Each fix is caught by a selftest when reverted. tier4-kvm job 4678 on the head passed every rig-update row, and GitHub checks are green.

  • git cat-file -e 3c8dd0f → present; the worker's own commits since then: 9294b41, 14a1226, 8b00967 (the rest is base merges); git diff origin/develop...head → 17 files, +889/-10, docs/dev/file-budget.tsv not among them

  • F4103-2 fixed: 47b-rig-update.sh:38-44 rig_update_wrap_fail, called at :206 (check) and :262 (install). With the call reverted in a scratch worktree, selftest-rig-update: '2 failed, 62 passed' ('a Tor helper failure is recorded as a refusal — expected [refused], got []')

  • F4103-3 fixed: 47b:311-314 writes pending before os_update and errors on failure; :324-329 records refused when the slot write fails. With the pending check removed: 6+ failures, including 'an unwritable status file aborts the install' and 'no reboot without a pending record — expected [1], got [2]'

  • F4103-4/5 resolved: 47b:147-157 re-resolves the URL on every attempt, redirecting to a file so OS_CHANNEL_HINT survives; selftest row 'a failed bundle URL resolve keeps its cause' ('curl exit 7')

  • F4103-7 resolved: rig_update_keeps_verdict (47b:24-29). With the refusal guard reverted to pending-only: 'a refusal keeps a rolled_back verdict — expected [rolled_back], got [refused]'

  • F4103-8 resolved: 47a:1 is now a bash [[ =~ ]]. With the grep form restored, the embedded-newline tag test fails

  • F4103-6/9/10/11: answered under 'How I fixed it' (Shortcut bullet, KVM-leg limits, rig.sh reflow kept for the file-budget ceiling; the _rig_mining_up comment deletion is reverted, and the diff vs develop shows only the reflow plus rig_update_leg)

  • make pithead + bash tests/os/selftest-rig-update.sh at head → 'selftest-rig-update OK (64 checks)', rc 0; registered via Makefile:61 'for t in tests/os/selftest*.sh'

  • bench-ci list --all --fleet --commit 9b7376f… --json → one job: 511 on bench ci-5, tier4-kvm phases=rig, completed/success, no error; no failed-then-passed pair on this head

  • bench-ci evidence 4678@9b7376fa… → matches the PR block: success, all steps success, 293 pass, 3 fail, 6 skip; the red rows are the three netwatch rows the harness labels '(non-required leg, netwatch wired into the KVM battery: five windows, both roles, honest capture; plus the htpdate image check #4196)'

  • bench-ci log 4678@head (717 KB) lines 5611-5626: all 14 rig-update leg rows ✓, including 'refusal recorded with its reason', 'pending kept intact', 'installed its bundle and the rig booted it', 'verdict settled as updated', 'bundle and partial deleted', 'check reads the real release channel over Tor', 'Tor stopped after the check'; the netwatch failures at log lines 5213 and 5385 come before the leg starts at 5611

  • gh pr checks 4103 → 43 pass; 2 skipping (Shipped-image CVE sweep, if: github.event_name == 'schedule', ci.yml:158/249); 1 pending (adversarial-review)

  • make lint-pithead-build → rc 0; make lint-file-budget → rc 2: 'raises storage_service.py's ceiling from 768 to 785'. The head and merge base 71c1363 both hold 785, and origin/develop lowered it to 768 after the merge base, so this is the branch being behind, not a PR change

  • detect-topology.py on the PR body+comments → clean; on issue Rig-side updater: download the signed bundle over Tor, verify, install into the spare slot, self-commit or fall back #4013 body+comments → clean

  • git diff origin/develop...head: the only added lines starting with # are shellcheck directives (shell=bash, source=)

  • 47a os_channel_fetch: os_release_host_ok checks the host of every redirect hop (lines 14, 94); downloads use --proto =https and --socks5-hostname

  • [F4103-12] PR body, 'Here is the proof': The proof section is stale: it says 'selftest-rig-update OK (42 checks)' (the head has 64), 'GitHub CI green on head 90ededd' and 'all 43 checks pass on head 3c8dd0f', and it quotes jobs 394 and 395 from the old head. The current head's block (4678) is appended after the 'Part of' line. Refresh the section so it describes the head.

  • [F4103-13] bench-ci evidence 4678@9b7376fa85772997cbb25d8670d157b20bf296dd: The three red rows are netwatch rows the base harness labels '(non-required leg, netwatch wired into the KVM battery: five windows, both roles, honest capture; plus the htpdate image check #4196)' (tests/os/netwatch-window.sh:47), and netwatch wired into the KVM battery: five windows, both roles, honest capture; plus the htpdate image check #4196 is CLOSED. Two of them ran before the rig-update leg started. Not caused by this PR, but the operator may want an open owning issue for netwatch unexpected flows.

Reviewed head: 9b7376fa85772997cbb25d8670d157b20bf296dd.

@pithead-reviewer

Copy link
Copy Markdown
Contributor

Owner brief for 9b7376fa8577

What it does. Adds pithead rig-update check and pithead rig-update install so an appliance rig can update its own OS. It fetches the signed release bundle over Tor, verifies it, writes the spare slot and reboots. The result (pending, refused, updated or rolled_back, with a reason) goes to rig-update.json on /data, and the boot script settles the final verdict after the reboot.

Why. Issue #4013. Before this, a shipped rig had no way to take an OS update, and owners had to re-flash the stick, which wipes /data and the token. The release channel helpers from #4011 already existed, and this adds the rig-side updater that the rig-os-update contract describes. The milestone isn't stated in the data. The siblings #4014 and #4016 stay open.

Risk. It touches the rig boot path and the spare-slot write, which is where mistakes cost most. Every refusal is designed to leave the running slot alone. A bad write could still brick the spare slot, but the rig falls back to the old one. The real Tor-only download and the rollback path are proven only by the selftest with stubs. The KVM leg uses the http test seam. It also changes os_release_tag_valid in shared code, and the verb ledger and completion lists. Nothing here is irreversible.

Proof. CI: 2 skipped, 44 success. Reviewer: PASS at 9b7376f by pithead-reviewer, round 2 (recorded 2026-11-28T08:19:16Z). Bench: job 395: success on 3c8dd0f, not the head; job 394: failure on 3c8dd0f, not the head; job 4678: success on the head.

What to check.

  • lib/pithead/47b-rig-update.sh:120-175: the download loop. Check that the Tor-only, https-only flags, the per-attempt URL re-resolve and the exact-size check match the intended egress rule.
  • lib/pithead/47b-rig-update.sh install path after verify (the pending-record write, then os_update, then reboot): the pending record must land before the slot write, and a failed write must not reboot.
  • os/overlay/pithead-boot:292: the added ./pithead rig-update boot-record call runs after the miner self-commit on every rig boot. Check that a failure there cannot fail the boot. The || echo guard suggests it can't.
  • The PR body proof section is stale: it cites 42 checks and older heads, while the head has 64 checks and bench job 4678. The three red netwatch rows in 4678 belong to the closed netwatch wired into the KVM battery: five windows, both roles, honest capture; plus the htpdate image check #4196 and are not caused by this PR.

Verdict. merge: the reviewer passed round 2 at this head, CI is green (44 passed, 2 skipped), and tier4-kvm job 4678 passed on the head

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

operator-hold The operator's own hold: never picked or merged, not an owner ask; the operator removes it stage/operator parked for the operator

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant