From 8ebdca5b751cdd98ea7d392945a88eea9b99a0fd Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:30:07 -0600 Subject: [PATCH 1/5] pithead-sync: install the RigForge Rust binary only on checksum pass (#4532) Part of #4532 Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/appliance-wizard.md | 10 ++++ os/overlay/pithead-sync | 29 ++++++--- .../test-appliance-sync-rigforge-bin.sh | 59 +++++++++++++++++++ tests/stack/run.sh | 2 + 4 files changed, 93 insertions(+), 7 deletions(-) create mode 100644 tests/stack/appliance/test-appliance-sync-rigforge-bin.sh diff --git a/docs/dev/appliance-wizard.md b/docs/dev/appliance-wizard.md index f88ce53862..c4dd018e74 100644 --- a/docs/dev/appliance-wizard.md +++ b/docs/dev/appliance-wizard.md @@ -461,6 +461,16 @@ forks first thing and does two steps: appliance-mode setup the Both role runs, from the same tree on `/data`, against the same prebuilt XMRig the image baked. Nothing on this path clones or compiles; a Tor-only box could not. A native rebuild is the operator's option, cached on `/data`, never a requirement. + + When the baked tree carries a RigForge Rust binary seed (`prebuilt/rust/rigforge` plus its + `rigforge.sha256` record), `pithead-sync` installs it on every boot, but only after + `sha256sum -c` passes. It installs mode 0755 root:root into `/data/pithead/rigforge-bin/` + (`PITHEAD_SYNC_RIGFORGE_BIN` overrides the path), outside the synced tree, through a temporary + file and a rename. A seed whose checksum fails, or whose record is missing, prints one + `REFUSED rigforge binary` line and leaves the installed binary alone; the rest of the sync + still completes. A seed with a different valid checksum replaces the installed binary, which is + how a pin move delivers its binary on the new slot's first boot. Without a seed the sync is + unchanged (pithead#4212, rigforge#709). 2. **The same health-gated slot commit**, on the miner running. The gate is deliberately *pool-independent*: a rig whose coordinator is late still starts, still retries, and still commits. Rolling a slot back cannot fix a switch nobody plugged in, and a gate that punished diff --git a/os/overlay/pithead-sync b/os/overlay/pithead-sync index e1b53dfba9..84b8d02dee 100755 --- a/os/overlay/pithead-sync +++ b/os/overlay/pithead-sync @@ -7,6 +7,7 @@ SRC="${PITHEAD_SYNC_SRC:-/opt/pithead}" DST="${PITHEAD_SYNC_DST:-/data/pithead}" RF_SRC="${PITHEAD_SYNC_RIGFORGE_SRC:-/opt/rigforge}" RF_DST="${PITHEAD_SYNC_RIGFORGE_DST:-/data/rigforge}" +RF_BIN="${PITHEAD_SYNC_RIGFORGE_BIN:-/data/pithead/rigforge-bin/rigforge}" mkdir -p "$DST" for f in pithead pithead-completion.bash VERSION docker-compose.yml \ @@ -34,22 +35,15 @@ fi # An images/ copy from an older layout is dead weight on the data partition — reclaim it. rm -rf "${DST:?}/images" -# The RigForge leg: the image bakes a pinned RigForge tree, and the miner must run from /data — -# RigForge roots its workspace under its own script dir (DYNAMIC_HOME), so tree placement alone -# puts the XMRig build on writable storage. Program files are replaced wholesale like pithead's; -# state the baked tree never carries (config.json — pithead-rendered — and the data/ workspace) -# is untouched by construction, because only names present in the source are replaced. if [ -d "$RF_SRC" ]; then mkdir -p "$RF_DST" for f in "$RF_SRC"/* "$RF_SRC"/.[!.]*; do [ -e "$f" ] || continue base=$(basename "$f") - # prebuilt/ is a seed, not a program file — handled below, never synced as a tree. [ "$base" = "prebuilt" ] && continue rm -rf "${RF_DST:?}/$base" cp -a "$f" "$RF_DST/$base" done - # Reseed when the commit or donate-min marker differs, since a Tor-only box cannot recompile. if [ -d "$RF_SRC/prebuilt/xmrig" ]; then baked_commit=$(cat "$RF_SRC/prebuilt/xmrig/.rigforge-commit" 2>/dev/null || true) have_commit=$(cat "$RF_DST/data/worker/xmrig/.rigforge-commit" 2>/dev/null || true) @@ -61,6 +55,27 @@ if [ -d "$RF_SRC" ]; then cp -a "$RF_SRC/prebuilt/xmrig" "$RF_DST/data/worker/xmrig" fi fi + rf_seed="$RF_SRC/prebuilt/rust" + if [ -f "$rf_seed/rigforge" ]; then + if [ -f "$rf_seed/rigforge.sha256" ] && (cd "$rf_seed" && sha256sum -c --status rigforge.sha256) >/dev/null 2>&1; then + if ! cmp -s "$rf_seed/rigforge" "$RF_BIN"; then + rf_bin_dir=$(dirname "$RF_BIN") + rf_owner=() + [ "$(id -u)" = 0 ] && rf_owner=(-o root -g root) + rf_tmp="$RF_BIN.new.$$" + if mkdir -p "$rf_bin_dir" && chmod 755 "$rf_bin_dir" && + { [ "$(id -u)" != 0 ] || chown root:root "$rf_bin_dir"; } && + install -m 755 "${rf_owner[@]}" "$rf_seed/rigforge" "$rf_tmp" && mv -f "$rf_tmp" "$RF_BIN"; then + echo "pithead-sync: rigforge binary installed at $RF_BIN" + else + rm -f "$rf_tmp" + echo "pithead-sync: REFUSED rigforge binary: install failed; keeping the installed version" >&2 + fi + fi + else + echo "pithead-sync: REFUSED rigforge binary: checksum mismatch or missing record; keeping the installed version" >&2 + fi + fi echo "pithead-sync: rigforge tree synced to $RF_DST (state preserved)" fi # repart formats /data with ext4's default 5% root reserve — ~50 GB lost on a 1 TB disk that diff --git a/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh b/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh new file mode 100644 index 0000000000..74412f6f3a --- /dev/null +++ b/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh @@ -0,0 +1,59 @@ +# shellcheck shell=bash +: "${STACK_SUITE:?is unset: this file is a tests/stack/run.sh fragment, not a script — run tests/stack/run.sh}" + +echo "== unit: pithead-sync installs the RigForge Rust binary only on checksum pass (#4532) ==" +RBSCRIPT="$ROOT/os/overlay/pithead-sync" +mk_tmpdir RBS +mkdir -p "$RBS/opt-pithead" "$RBS/opt-rigforge/prebuilt/rust" +rb_seed() { + printf '%s' "$1" >"$RBS/opt-rigforge/prebuilt/rust/rigforge" + (cd "$RBS/opt-rigforge/prebuilt/rust" && sha256sum rigforge >rigforge.sha256) +} +rb_sync() { + PITHEAD_SYNC_SRC="$RBS/opt-pithead" PITHEAD_SYNC_DST="$RBS/data/pithead" \ + PITHEAD_SYNC_RIGFORGE_SRC="$RBS/opt-rigforge" PITHEAD_SYNC_RIGFORGE_DST="$RBS/data/rigforge" \ + PITHEAD_SYNC_RIGFORGE_BIN="$RBS/data/pithead/rigforge-bin/rigforge" \ + bash "$RBSCRIPT" 2>&1 +} +RB_BIN="$RBS/data/pithead/rigforge-bin/rigforge" +printf 'program' >"$RBS/opt-rigforge/rigforge.sh" + +out=$(rb_sync) +assert_rc "seed absent: sync runs clean" "$?" "0" +if [ -e "$RB_BIN" ]; then bad "seed absent: nothing installed" "present"; else ok "seed absent: nothing installed"; fi +assert_not_contains "seed absent: no refusal line" "$out" "REFUSED" + +rb_seed 'rust-v1' +out=$(rb_sync) +assert_rc "good seed: sync runs clean" "$?" "0" +assert_eq "good seed: binary installed" "$(cat "$RB_BIN" 2>/dev/null)" "rust-v1" +assert_eq "good seed: mode 0755" "$(stat -c %a "$RB_BIN" 2>/dev/null)" "755" +assert_eq "good seed: directory not writable by others" "$(stat -c %a "$(dirname "$RB_BIN")")" "755" +if [ -e "$RBS/data/rigforge/prebuilt" ]; then bad "seed is never synced into the tree" "synced"; else ok "seed is never synced into the tree"; fi +assert_contains "good seed: install is announced" "$out" "rigforge binary installed" + +printf 'tampered' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_rc "tampered seed: sync still completes" "$?" "0" +assert_eq "tampered seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" +assert_contains "tampered seed: one loud refusal line" "$out" "REFUSED rigforge binary: checksum mismatch" +assert_eq "tampered seed: exactly one refusal line" "$(printf '%s\n' "$out" | grep -c REFUSED)" "1" +assert_eq "tampered seed: the tree sync still ran" "$(cat "$RBS/data/rigforge/rigforge.sh")" "program" +assert_contains "tampered seed: sync reports completion" "$out" "program tree synced" + +rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" +out=$(rb_sync) +assert_contains "seed without a checksum record is refused" "$out" "REFUSED rigforge binary" +assert_eq "seed without a checksum record: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" + +rb_seed 'rust-v2' +out=$(rb_sync) +assert_eq "replaced seed with a valid checksum installs the new version" "$(cat "$RB_BIN")" "rust-v2" +assert_not_contains "replaced seed: no refusal" "$out" "REFUSED" + +out=$(rb_sync) +assert_not_contains "unchanged seed: no reinstall" "$out" "installed at" +assert_eq "unchanged seed: binary intact" "$(cat "$RB_BIN")" "rust-v2" +rm -rf "$RBS" +unset -f rb_seed rb_sync +unset RBS RBSCRIPT RB_BIN out diff --git a/tests/stack/run.sh b/tests/stack/run.sh index 052e0c1875..e03e70fd5a 100755 --- a/tests/stack/run.sh +++ b/tests/stack/run.sh @@ -319,6 +319,8 @@ if in_block 5; then # shellcheck source=tests/stack/appliance/test-appliance-boot.sh disable=SC2015 _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-boot.sh" && domain_ran test-appliance-boot.sh "$_d0" "$?" || domain_ran test-appliance-boot.sh "$_d0" "$?" + # shellcheck source=tests/stack/appliance/test-appliance-sync-rigforge-bin.sh disable=SC2015 + _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-sync-rigforge-bin.sh" && domain_ran test-appliance-sync-rigforge-bin.sh "$_d0" "$?" || domain_ran test-appliance-sync-rigforge-bin.sh "$_d0" "$?" # shellcheck source=tests/stack/appliance/test-appliance-baked-images.sh disable=SC2015 _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-baked-images.sh" && domain_ran test-appliance-baked-images.sh "$_d0" "$?" || domain_ran test-appliance-baked-images.sh "$_d0" "$?" # shellcheck source=tests/stack/appliance/test-appliance-boot-remint.sh disable=SC2015 From c448de14145db7dc1e616e27766ac1ec22278980 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:32:00 -0600 Subject: [PATCH 2/5] pithead-sync: bind the checksum to the seed file, refuse symlinks, repair mode drift (#4532) Co-Authored-By: Claude Sonnet 5.5 --- docs/dev/appliance-wizard.md | 4 +- os/overlay/pithead-sync | 20 +++++++--- .../test-appliance-sync-rigforge-bin.sh | 37 ++++++++++++++++++- 3 files changed, 51 insertions(+), 10 deletions(-) diff --git a/docs/dev/appliance-wizard.md b/docs/dev/appliance-wizard.md index c4dd018e74..05b41a0cca 100644 --- a/docs/dev/appliance-wizard.md +++ b/docs/dev/appliance-wizard.md @@ -464,9 +464,9 @@ forks first thing and does two steps: When the baked tree carries a RigForge Rust binary seed (`prebuilt/rust/rigforge` plus its `rigforge.sha256` record), `pithead-sync` installs it on every boot, but only after - `sha256sum -c` passes. It installs mode 0755 root:root into `/data/pithead/rigforge-bin/` + the hash of the seed file equals the one recorded for `rigforge` in `rigforge.sha256`. It installs mode 0755 root:root into `/data/rigforge-bin/` (`PITHEAD_SYNC_RIGFORGE_BIN` overrides the path), outside the synced tree, through a temporary - file and a rename. A seed whose checksum fails, or whose record is missing, prints one + file, re-hashed before a rename. A symlinked seed, record or install directory, or a directory at the install path, is refused. The binary is reinstalled when its mode or owner drifts. A seed whose checksum fails, or whose record is missing, prints one `REFUSED rigforge binary` line and leaves the installed binary alone; the rest of the sync still completes. A seed with a different valid checksum replaces the installed binary, which is how a pin move delivers its binary on the new slot's first boot. Without a seed the sync is diff --git a/os/overlay/pithead-sync b/os/overlay/pithead-sync index 84b8d02dee..14faef0db0 100755 --- a/os/overlay/pithead-sync +++ b/os/overlay/pithead-sync @@ -7,7 +7,7 @@ SRC="${PITHEAD_SYNC_SRC:-/opt/pithead}" DST="${PITHEAD_SYNC_DST:-/data/pithead}" RF_SRC="${PITHEAD_SYNC_RIGFORGE_SRC:-/opt/rigforge}" RF_DST="${PITHEAD_SYNC_RIGFORGE_DST:-/data/rigforge}" -RF_BIN="${PITHEAD_SYNC_RIGFORGE_BIN:-/data/pithead/rigforge-bin/rigforge}" +RF_BIN="${PITHEAD_SYNC_RIGFORGE_BIN:-/data/rigforge-bin/rigforge}" mkdir -p "$DST" for f in pithead pithead-completion.bash VERSION docker-compose.yml \ @@ -56,16 +56,24 @@ if [ -d "$RF_SRC" ]; then fi fi rf_seed="$RF_SRC/prebuilt/rust" - if [ -f "$rf_seed/rigforge" ]; then - if [ -f "$rf_seed/rigforge.sha256" ] && (cd "$rf_seed" && sha256sum -c --status rigforge.sha256) >/dev/null 2>&1; then - if ! cmp -s "$rf_seed/rigforge" "$RF_BIN"; then - rf_bin_dir=$(dirname "$RF_BIN") + if [ -e "$rf_seed/rigforge" ] || [ -L "$rf_seed/rigforge" ]; then + rf_want="" + if [ -f "$rf_seed/rigforge" ] && [ ! -L "$rf_seed/rigforge" ] && [ -f "$rf_seed/rigforge.sha256" ] && [ ! -L "$rf_seed/rigforge.sha256" ]; then + rf_want=$(awk 'NF == 2 && $2 == "rigforge" && $1 ~ /^[0-9a-f]{64}$/ { print $1 }' "$rf_seed/rigforge.sha256") + fi + rf_have=$(sha256sum <"$rf_seed/rigforge" 2>/dev/null | cut -d' ' -f1 || true) + if [ -n "$rf_want" ] && [ "$rf_want" = "$rf_have" ]; then + rf_bin_dir=$(dirname "$RF_BIN") + if [ -d "$RF_BIN" ] || [ -L "$rf_bin_dir" ]; then + echo "pithead-sync: REFUSED rigforge binary: install location is not a plain path; keeping the installed version" >&2 + elif ! cmp -s "$rf_seed/rigforge" "$RF_BIN" || [ "$(stat -c %a:%u "$RF_BIN" 2>/dev/null)" != "755:$(id -u)" ]; then rf_owner=() [ "$(id -u)" = 0 ] && rf_owner=(-o root -g root) rf_tmp="$RF_BIN.new.$$" if mkdir -p "$rf_bin_dir" && chmod 755 "$rf_bin_dir" && { [ "$(id -u)" != 0 ] || chown root:root "$rf_bin_dir"; } && - install -m 755 "${rf_owner[@]}" "$rf_seed/rigforge" "$rf_tmp" && mv -f "$rf_tmp" "$RF_BIN"; then + install -m 755 "${rf_owner[@]}" "$rf_seed/rigforge" "$rf_tmp" && + [ "$(sha256sum <"$rf_tmp" | cut -d' ' -f1)" = "$rf_want" ] && mv -fT "$rf_tmp" "$RF_BIN"; then echo "pithead-sync: rigforge binary installed at $RF_BIN" else rm -f "$rf_tmp" diff --git a/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh b/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh index 74412f6f3a..22bf6acae5 100644 --- a/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh +++ b/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh @@ -12,10 +12,10 @@ rb_seed() { rb_sync() { PITHEAD_SYNC_SRC="$RBS/opt-pithead" PITHEAD_SYNC_DST="$RBS/data/pithead" \ PITHEAD_SYNC_RIGFORGE_SRC="$RBS/opt-rigforge" PITHEAD_SYNC_RIGFORGE_DST="$RBS/data/rigforge" \ - PITHEAD_SYNC_RIGFORGE_BIN="$RBS/data/pithead/rigforge-bin/rigforge" \ + PITHEAD_SYNC_RIGFORGE_BIN="$RBS/data/rigforge-bin/rigforge" \ bash "$RBSCRIPT" 2>&1 } -RB_BIN="$RBS/data/pithead/rigforge-bin/rigforge" +RB_BIN="$RBS/data/rigforge-bin/rigforge" printf 'program' >"$RBS/opt-rigforge/rigforge.sh" out=$(rb_sync) @@ -54,6 +54,39 @@ assert_not_contains "replaced seed: no refusal" "$out" "REFUSED" out=$(rb_sync) assert_not_contains "unchanged seed: no reinstall" "$out" "installed at" assert_eq "unchanged seed: binary intact" "$(cat "$RB_BIN")" "rust-v2" +chmod 777 "$RB_BIN" +out=$(rb_sync) +assert_eq "mode drift on an unchanged binary is repaired" "$(stat -c %a "$RB_BIN")" "755" +assert_contains "mode drift: reinstall announced" "$out" "installed at" + +printf '%s other\n' "$(sha256sum <"$RBS/opt-rigforge/prebuilt/rust/rigforge" | cut -d' ' -f1)" >"$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" +printf 'evil' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_contains "a record naming another file is refused" "$out" "REFUSED rigforge binary: checksum mismatch" +assert_eq "a record naming another file: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" + +rb_seed 'rust-v3' +mv "$RBS/opt-rigforge/prebuilt/rust/rigforge" "$RBS/real-seed" +ln -s "$RBS/real-seed" "$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_contains "a symlinked seed is refused" "$out" "REFUSED rigforge binary" +assert_eq "a symlinked seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" +rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge" + +rb_seed 'rust-v4' +mv "$RBS/data/rigforge-bin" "$RBS/real-bin" +ln -s "$RBS/real-bin" "$RBS/data/rigforge-bin" +out=$(rb_sync) +assert_contains "a symlinked install directory is refused" "$out" "REFUSED rigforge binary" +assert_eq "a symlinked install directory: nothing written through it" "$(cat "$RBS/real-bin/rigforge")" "rust-v2" +rm -f "$RBS/data/rigforge-bin" +mv "$RBS/real-bin" "$RBS/data/rigforge-bin" + +rm -f "$RB_BIN" +mkdir "$RB_BIN" +out=$(rb_sync) +assert_contains "a directory at the install path is refused" "$out" "REFUSED rigforge binary" +if [ -z "$(ls -A "$RB_BIN")" ]; then ok "a directory at the install path stays empty"; else bad "a directory at the install path stays empty" "written into"; fi rm -rf "$RBS" unset -f rb_seed rb_sync unset RBS RBSCRIPT RB_BIN out From 2ea5dc3fef0e01edeef0e9a09167b95515d185bb Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:41:54 -0600 Subject: [PATCH 3/5] tests: source the sync-binary fragment from the baked-images fragment, keeping run.sh at its ceiling (#4532) Co-Authored-By: Claude Sonnet 5.5 --- tests/stack/appliance/test-appliance-baked-images.sh | 3 +++ tests/stack/run.sh | 2 -- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/stack/appliance/test-appliance-baked-images.sh b/tests/stack/appliance/test-appliance-baked-images.sh index ca2f4859a5..4ac8f9b44c 100644 --- a/tests/stack/appliance/test-appliance-baked-images.sh +++ b/tests/stack/appliance/test-appliance-baked-images.sh @@ -55,3 +55,6 @@ done rm -rf "$SLB" unset SLB appliance unset -f slb_probe + +# shellcheck source=tests/stack/appliance/test-appliance-sync-rigforge-bin.sh +source "$HERE/appliance/test-appliance-sync-rigforge-bin.sh" diff --git a/tests/stack/run.sh b/tests/stack/run.sh index e03e70fd5a..052e0c1875 100755 --- a/tests/stack/run.sh +++ b/tests/stack/run.sh @@ -319,8 +319,6 @@ if in_block 5; then # shellcheck source=tests/stack/appliance/test-appliance-boot.sh disable=SC2015 _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-boot.sh" && domain_ran test-appliance-boot.sh "$_d0" "$?" || domain_ran test-appliance-boot.sh "$_d0" "$?" - # shellcheck source=tests/stack/appliance/test-appliance-sync-rigforge-bin.sh disable=SC2015 - _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-sync-rigforge-bin.sh" && domain_ran test-appliance-sync-rigforge-bin.sh "$_d0" "$?" || domain_ran test-appliance-sync-rigforge-bin.sh "$_d0" "$?" # shellcheck source=tests/stack/appliance/test-appliance-baked-images.sh disable=SC2015 _d0=$((PASS + FAIL)) && source "$HERE/appliance/test-appliance-baked-images.sh" && domain_ran test-appliance-baked-images.sh "$_d0" "$?" || domain_ran test-appliance-baked-images.sh "$_d0" "$?" # shellcheck source=tests/stack/appliance/test-appliance-boot-remint.sh disable=SC2015 From b5116fc692b0d36aa72966f507490a9d772488fc Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 13:56:31 -0600 Subject: [PATCH 4/5] tests: put the sync-binary cases in the baked-images fragment so run.sh and the block audit stay unchanged (#4532) Co-Authored-By: Claude Sonnet 5.5 --- .../appliance/test-appliance-baked-images.sh | 92 ++++++++++++++++++- .../test-appliance-sync-rigforge-bin.sh | 92 ------------------- 2 files changed, 90 insertions(+), 94 deletions(-) delete mode 100644 tests/stack/appliance/test-appliance-sync-rigforge-bin.sh diff --git a/tests/stack/appliance/test-appliance-baked-images.sh b/tests/stack/appliance/test-appliance-baked-images.sh index 4ac8f9b44c..663a9df55d 100644 --- a/tests/stack/appliance/test-appliance-baked-images.sh +++ b/tests/stack/appliance/test-appliance-baked-images.sh @@ -56,5 +56,93 @@ rm -rf "$SLB" unset SLB appliance unset -f slb_probe -# shellcheck source=tests/stack/appliance/test-appliance-sync-rigforge-bin.sh -source "$HERE/appliance/test-appliance-sync-rigforge-bin.sh" + +echo "== unit: pithead-sync installs the RigForge Rust binary only on checksum pass (#4532) ==" +RBSCRIPT="$ROOT/os/overlay/pithead-sync" +mk_tmpdir RBS +mkdir -p "$RBS/opt-pithead" "$RBS/opt-rigforge/prebuilt/rust" +rb_seed() { + printf '%s' "$1" >"$RBS/opt-rigforge/prebuilt/rust/rigforge" + (cd "$RBS/opt-rigforge/prebuilt/rust" && sha256sum rigforge >rigforge.sha256) +} +rb_sync() { + PITHEAD_SYNC_SRC="$RBS/opt-pithead" PITHEAD_SYNC_DST="$RBS/data/pithead" \ + PITHEAD_SYNC_RIGFORGE_SRC="$RBS/opt-rigforge" PITHEAD_SYNC_RIGFORGE_DST="$RBS/data/rigforge" \ + PITHEAD_SYNC_RIGFORGE_BIN="$RBS/data/rigforge-bin/rigforge" \ + bash "$RBSCRIPT" 2>&1 +} +RB_BIN="$RBS/data/rigforge-bin/rigforge" +printf 'program' >"$RBS/opt-rigforge/rigforge.sh" + +out=$(rb_sync) +assert_rc "seed absent: sync runs clean" "$?" "0" +if [ -e "$RB_BIN" ]; then bad "seed absent: nothing installed" "present"; else ok "seed absent: nothing installed"; fi +assert_not_contains "seed absent: no refusal line" "$out" "REFUSED" + +rb_seed 'rust-v1' +out=$(rb_sync) +assert_rc "good seed: sync runs clean" "$?" "0" +assert_eq "good seed: binary installed" "$(cat "$RB_BIN" 2>/dev/null)" "rust-v1" +assert_eq "good seed: mode 0755" "$(stat -c %a "$RB_BIN" 2>/dev/null)" "755" +assert_eq "good seed: directory not writable by others" "$(stat -c %a "$(dirname "$RB_BIN")")" "755" +if [ -e "$RBS/data/rigforge/prebuilt" ]; then bad "seed is never synced into the tree" "synced"; else ok "seed is never synced into the tree"; fi +assert_contains "good seed: install is announced" "$out" "rigforge binary installed" + +printf 'tampered' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_rc "tampered seed: sync still completes" "$?" "0" +assert_eq "tampered seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" +assert_contains "tampered seed: one loud refusal line" "$out" "REFUSED rigforge binary: checksum mismatch" +assert_eq "tampered seed: exactly one refusal line" "$(printf '%s\n' "$out" | grep -c REFUSED)" "1" +assert_eq "tampered seed: the tree sync still ran" "$(cat "$RBS/data/rigforge/rigforge.sh")" "program" +assert_contains "tampered seed: sync reports completion" "$out" "program tree synced" + +rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" +out=$(rb_sync) +assert_contains "seed without a checksum record is refused" "$out" "REFUSED rigforge binary" +assert_eq "seed without a checksum record: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" + +rb_seed 'rust-v2' +out=$(rb_sync) +assert_eq "replaced seed with a valid checksum installs the new version" "$(cat "$RB_BIN")" "rust-v2" +assert_not_contains "replaced seed: no refusal" "$out" "REFUSED" + +out=$(rb_sync) +assert_not_contains "unchanged seed: no reinstall" "$out" "installed at" +assert_eq "unchanged seed: binary intact" "$(cat "$RB_BIN")" "rust-v2" +chmod 777 "$RB_BIN" +out=$(rb_sync) +assert_eq "mode drift on an unchanged binary is repaired" "$(stat -c %a "$RB_BIN")" "755" +assert_contains "mode drift: reinstall announced" "$out" "installed at" + +printf '%s other\n' "$(sha256sum <"$RBS/opt-rigforge/prebuilt/rust/rigforge" | cut -d' ' -f1)" >"$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" +printf 'evil' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_contains "a record naming another file is refused" "$out" "REFUSED rigforge binary: checksum mismatch" +assert_eq "a record naming another file: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" + +rb_seed 'rust-v3' +mv "$RBS/opt-rigforge/prebuilt/rust/rigforge" "$RBS/real-seed" +ln -s "$RBS/real-seed" "$RBS/opt-rigforge/prebuilt/rust/rigforge" +out=$(rb_sync) +assert_contains "a symlinked seed is refused" "$out" "REFUSED rigforge binary" +assert_eq "a symlinked seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" +rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge" + +rb_seed 'rust-v4' +mv "$RBS/data/rigforge-bin" "$RBS/real-bin" +ln -s "$RBS/real-bin" "$RBS/data/rigforge-bin" +out=$(rb_sync) +assert_contains "a symlinked install directory is refused" "$out" "REFUSED rigforge binary" +assert_eq "a symlinked install directory: nothing written through it" "$(cat "$RBS/real-bin/rigforge")" "rust-v2" +rm -f "$RBS/data/rigforge-bin" +mv "$RBS/real-bin" "$RBS/data/rigforge-bin" + +rm -f "$RB_BIN" +mkdir "$RB_BIN" +out=$(rb_sync) +assert_contains "a directory at the install path is refused" "$out" "REFUSED rigforge binary" +if [ -z "$(ls -A "$RB_BIN")" ]; then ok "a directory at the install path stays empty"; else bad "a directory at the install path stays empty" "written into"; fi +rm -rf "$RBS" +unset -f rb_seed rb_sync +unset RBS RBSCRIPT RB_BIN out diff --git a/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh b/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh deleted file mode 100644 index 22bf6acae5..0000000000 --- a/tests/stack/appliance/test-appliance-sync-rigforge-bin.sh +++ /dev/null @@ -1,92 +0,0 @@ -# shellcheck shell=bash -: "${STACK_SUITE:?is unset: this file is a tests/stack/run.sh fragment, not a script — run tests/stack/run.sh}" - -echo "== unit: pithead-sync installs the RigForge Rust binary only on checksum pass (#4532) ==" -RBSCRIPT="$ROOT/os/overlay/pithead-sync" -mk_tmpdir RBS -mkdir -p "$RBS/opt-pithead" "$RBS/opt-rigforge/prebuilt/rust" -rb_seed() { - printf '%s' "$1" >"$RBS/opt-rigforge/prebuilt/rust/rigforge" - (cd "$RBS/opt-rigforge/prebuilt/rust" && sha256sum rigforge >rigforge.sha256) -} -rb_sync() { - PITHEAD_SYNC_SRC="$RBS/opt-pithead" PITHEAD_SYNC_DST="$RBS/data/pithead" \ - PITHEAD_SYNC_RIGFORGE_SRC="$RBS/opt-rigforge" PITHEAD_SYNC_RIGFORGE_DST="$RBS/data/rigforge" \ - PITHEAD_SYNC_RIGFORGE_BIN="$RBS/data/rigforge-bin/rigforge" \ - bash "$RBSCRIPT" 2>&1 -} -RB_BIN="$RBS/data/rigforge-bin/rigforge" -printf 'program' >"$RBS/opt-rigforge/rigforge.sh" - -out=$(rb_sync) -assert_rc "seed absent: sync runs clean" "$?" "0" -if [ -e "$RB_BIN" ]; then bad "seed absent: nothing installed" "present"; else ok "seed absent: nothing installed"; fi -assert_not_contains "seed absent: no refusal line" "$out" "REFUSED" - -rb_seed 'rust-v1' -out=$(rb_sync) -assert_rc "good seed: sync runs clean" "$?" "0" -assert_eq "good seed: binary installed" "$(cat "$RB_BIN" 2>/dev/null)" "rust-v1" -assert_eq "good seed: mode 0755" "$(stat -c %a "$RB_BIN" 2>/dev/null)" "755" -assert_eq "good seed: directory not writable by others" "$(stat -c %a "$(dirname "$RB_BIN")")" "755" -if [ -e "$RBS/data/rigforge/prebuilt" ]; then bad "seed is never synced into the tree" "synced"; else ok "seed is never synced into the tree"; fi -assert_contains "good seed: install is announced" "$out" "rigforge binary installed" - -printf 'tampered' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" -out=$(rb_sync) -assert_rc "tampered seed: sync still completes" "$?" "0" -assert_eq "tampered seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" -assert_contains "tampered seed: one loud refusal line" "$out" "REFUSED rigforge binary: checksum mismatch" -assert_eq "tampered seed: exactly one refusal line" "$(printf '%s\n' "$out" | grep -c REFUSED)" "1" -assert_eq "tampered seed: the tree sync still ran" "$(cat "$RBS/data/rigforge/rigforge.sh")" "program" -assert_contains "tampered seed: sync reports completion" "$out" "program tree synced" - -rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" -out=$(rb_sync) -assert_contains "seed without a checksum record is refused" "$out" "REFUSED rigforge binary" -assert_eq "seed without a checksum record: previous binary kept" "$(cat "$RB_BIN")" "rust-v1" - -rb_seed 'rust-v2' -out=$(rb_sync) -assert_eq "replaced seed with a valid checksum installs the new version" "$(cat "$RB_BIN")" "rust-v2" -assert_not_contains "replaced seed: no refusal" "$out" "REFUSED" - -out=$(rb_sync) -assert_not_contains "unchanged seed: no reinstall" "$out" "installed at" -assert_eq "unchanged seed: binary intact" "$(cat "$RB_BIN")" "rust-v2" -chmod 777 "$RB_BIN" -out=$(rb_sync) -assert_eq "mode drift on an unchanged binary is repaired" "$(stat -c %a "$RB_BIN")" "755" -assert_contains "mode drift: reinstall announced" "$out" "installed at" - -printf '%s other\n' "$(sha256sum <"$RBS/opt-rigforge/prebuilt/rust/rigforge" | cut -d' ' -f1)" >"$RBS/opt-rigforge/prebuilt/rust/rigforge.sha256" -printf 'evil' >"$RBS/opt-rigforge/prebuilt/rust/rigforge" -out=$(rb_sync) -assert_contains "a record naming another file is refused" "$out" "REFUSED rigforge binary: checksum mismatch" -assert_eq "a record naming another file: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" - -rb_seed 'rust-v3' -mv "$RBS/opt-rigforge/prebuilt/rust/rigforge" "$RBS/real-seed" -ln -s "$RBS/real-seed" "$RBS/opt-rigforge/prebuilt/rust/rigforge" -out=$(rb_sync) -assert_contains "a symlinked seed is refused" "$out" "REFUSED rigforge binary" -assert_eq "a symlinked seed: previous binary kept" "$(cat "$RB_BIN")" "rust-v2" -rm -f "$RBS/opt-rigforge/prebuilt/rust/rigforge" - -rb_seed 'rust-v4' -mv "$RBS/data/rigforge-bin" "$RBS/real-bin" -ln -s "$RBS/real-bin" "$RBS/data/rigforge-bin" -out=$(rb_sync) -assert_contains "a symlinked install directory is refused" "$out" "REFUSED rigforge binary" -assert_eq "a symlinked install directory: nothing written through it" "$(cat "$RBS/real-bin/rigforge")" "rust-v2" -rm -f "$RBS/data/rigforge-bin" -mv "$RBS/real-bin" "$RBS/data/rigforge-bin" - -rm -f "$RB_BIN" -mkdir "$RB_BIN" -out=$(rb_sync) -assert_contains "a directory at the install path is refused" "$out" "REFUSED rigforge binary" -if [ -z "$(ls -A "$RB_BIN")" ]; then ok "a directory at the install path stays empty"; else bad "a directory at the install path stays empty" "written into"; fi -rm -rf "$RBS" -unset -f rb_seed rb_sync -unset RBS RBSCRIPT RB_BIN out From 8d7abac0febdddcea07e64cbf2f81f85a2606b94 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 14:05:09 -0600 Subject: [PATCH 5/5] tests: shfmt the baked-images fragment (#4532) Co-Authored-By: Claude Sonnet 5.5 --- tests/stack/appliance/test-appliance-baked-images.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/stack/appliance/test-appliance-baked-images.sh b/tests/stack/appliance/test-appliance-baked-images.sh index 663a9df55d..e1dc73fb7c 100644 --- a/tests/stack/appliance/test-appliance-baked-images.sh +++ b/tests/stack/appliance/test-appliance-baked-images.sh @@ -56,7 +56,6 @@ rm -rf "$SLB" unset SLB appliance unset -f slb_probe - echo "== unit: pithead-sync installs the RigForge Rust binary only on checksum pass (#4532) ==" RBSCRIPT="$ROOT/os/overlay/pithead-sync" mk_tmpdir RBS