From 13efda0c20edd29edd741704316e0e532efa2724 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:05 -0600 Subject: [PATCH 01/51] The rendered control-proxy unit carries the same switches as the compose service Source: #4573 Co-Authored-By: Claude Opus 5.5 --- lib/pithead/36-quadlet-units.sh | 2 +- os/quadlet/docker-control.container | 2 +- os/quadlet/local/docker-control.container | 2 +- os/quadlet/payout/docker-control.container | 2 +- tests/stack/test-render-quadlet.sh | 5 +++++ 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/pithead/36-quadlet-units.sh b/lib/pithead/36-quadlet-units.sh index 4bc0e4b53b..610eeb7830 100644 --- a/lib/pithead/36-quadlet-units.sh +++ b/lib/pithead/36-quadlet-units.sh @@ -336,7 +336,7 @@ Description=pithead control socket proxy ContainerName=docker-control Image=docker.io/tecnativa/docker-socket-proxy:v0.5.0@sha256:1f5038b54f06c3e18422902cf00ba21803d1c97805aae032e5e6673d532d3459 Network=proxy.network -Environment=CONTAINERS=1 POST=1 ALLOW_START=1 ALLOW_STOP=1 +Environment=POST=1 ALLOW_START=1 ALLOW_STOP=1 Volume=$proxy_sock:/var/run/docker.sock:ro Tmpfs=/run Tmpfs=/tmp diff --git a/os/quadlet/docker-control.container b/os/quadlet/docker-control.container index ac925b1365..d2e5ee2c2b 100644 --- a/os/quadlet/docker-control.container +++ b/os/quadlet/docker-control.container @@ -4,7 +4,7 @@ Description=pithead control socket proxy ContainerName=docker-control Image=docker.io/tecnativa/docker-socket-proxy:v0.5.0@sha256:1f5038b54f06c3e18422902cf00ba21803d1c97805aae032e5e6673d532d3459 Network=proxy.network -Environment=CONTAINERS=1 POST=1 ALLOW_START=1 ALLOW_STOP=1 +Environment=POST=1 ALLOW_START=1 ALLOW_STOP=1 Volume=/run/podman/podman.sock:/var/run/docker.sock:ro Tmpfs=/run Tmpfs=/tmp diff --git a/os/quadlet/local/docker-control.container b/os/quadlet/local/docker-control.container index ac925b1365..d2e5ee2c2b 100644 --- a/os/quadlet/local/docker-control.container +++ b/os/quadlet/local/docker-control.container @@ -4,7 +4,7 @@ Description=pithead control socket proxy ContainerName=docker-control Image=docker.io/tecnativa/docker-socket-proxy:v0.5.0@sha256:1f5038b54f06c3e18422902cf00ba21803d1c97805aae032e5e6673d532d3459 Network=proxy.network -Environment=CONTAINERS=1 POST=1 ALLOW_START=1 ALLOW_STOP=1 +Environment=POST=1 ALLOW_START=1 ALLOW_STOP=1 Volume=/run/podman/podman.sock:/var/run/docker.sock:ro Tmpfs=/run Tmpfs=/tmp diff --git a/os/quadlet/payout/docker-control.container b/os/quadlet/payout/docker-control.container index ac925b1365..d2e5ee2c2b 100644 --- a/os/quadlet/payout/docker-control.container +++ b/os/quadlet/payout/docker-control.container @@ -4,7 +4,7 @@ Description=pithead control socket proxy ContainerName=docker-control Image=docker.io/tecnativa/docker-socket-proxy:v0.5.0@sha256:1f5038b54f06c3e18422902cf00ba21803d1c97805aae032e5e6673d532d3459 Network=proxy.network -Environment=CONTAINERS=1 POST=1 ALLOW_START=1 ALLOW_STOP=1 +Environment=POST=1 ALLOW_START=1 ALLOW_STOP=1 Volume=/run/podman/podman.sock:/var/run/docker.sock:ro Tmpfs=/run Tmpfs=/tmp diff --git a/tests/stack/test-render-quadlet.sh b/tests/stack/test-render-quadlet.sh index 750cb9bff3..79bbecb9ca 100644 --- a/tests/stack/test-render-quadlet.sh +++ b/tests/stack/test-render-quadlet.sh @@ -174,3 +174,8 @@ assert_eq "quadlet Tari node and wallet images match compose (#2624)" \ assert_eq "tari-wallet quadlet can repair and drop uid (#2454)" "$(grep -Ec '^(User=0:0|AddCapability=CHOWN DAC_OVERRIDE SETUID SETGID)$' "$QPAY/tari-wallet.container")" "2" assert_contains "tari-wallet healthcheck probes gRPC (#2498)" "$(cat "$QPAY/tari-wallet.container")" "HealthCmd=/wallet-config/wallet-healthcheck.sh" assert_eq "local render emits no wallet units" "$(find "$QLOCAL" -name 'wallet-rpc.container' -o -name 'tari-wallet.container' | wc -l | tr -d ' ')" "0" +compose_control_env=$(awk '/^ docker-control:/{f=1;next} f&&/^ [a-z]/{f=0} f' "$ROOT/docker-compose.yml" | sed -nE 's/^ +- ([A-Z_]+=[^ ]*)$/\1/p' | paste -sd ' ' -) +assert_eq "compose parse finds the docker-control switches (control)" "$(grep -oE 'POST=1|ALLOW_START=1|ALLOW_STOP=1' <<<"$compose_control_env" | wc -l | tr -d ' ')" "3" +assert_eq "quadlet docker-control carries exactly the compose switches in all three renders" \ + "$(sed -n 's/^Environment=//p' "$QOUT/docker-control.container" "$QLOCAL/docker-control.container" "$QPAY/docker-control.container")" \ + "$(printf '%s\n' "$compose_control_env" "$compose_control_env" "$compose_control_env")" From 6e732afc15051ae349a3f81df2805771128b3cbb Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:07 -0600 Subject: [PATCH 02/51] install.sh keeps every download on HTTPS and checks the signature of a signed release, with a pinned cosign when none is installed Source: #4574 Co-Authored-By: Claude Opus 5.5 --- install.sh | 51 +++++++++-------- tests/stack/test-install-verify.sh | 89 ++++++++++++++++++++++++++---- 2 files changed, 106 insertions(+), 34 deletions(-) diff --git a/install.sh b/install.sh index d634ccd41e..f26cc37daf 100755 --- a/install.sh +++ b/install.sh @@ -10,6 +10,8 @@ set -euo pipefail REPO="p2pool-starter-stack/pithead" +COSIGN_PIN_URL="https://github.com/sigstore/cosign/releases/download/v2.6.3/cosign-linux-amd64" +COSIGN_PIN_SHA256="7c78a7f2efc00088bd788a758db6e0928e79f3e0eb83eb5d3c499ed98da4c4f4" fail() { echo "[install] ERROR: $*" >&2 exit 1 @@ -37,10 +39,9 @@ for dep in curl tar sha256sum; do command -v "$dep" >/dev/null 2>&1 || fail "'$dep' is required to install. apt install $dep, then re-run." done -# --- Resolve the release tag. No jq yet (setup installs it) — grep the API response. TAG="${PITHEAD_VERSION:-}" if [ -z "$TAG" ]; then - TAG=$(curl -fsSL "https://api.github.com/repos/$REPO/releases/latest" | + TAG=$(curl -fsSL --proto =https --proto-redir =https "https://api.github.com/repos/$REPO/releases/latest" | grep -m1 '"tag_name"' | sed -E 's/.*"tag_name": *"([^"]+)".*/\1/') [ -n "$TAG" ] || fail "Could not resolve the latest release tag from the GitHub API." fi @@ -48,15 +49,11 @@ DIR="${PITHEAD_DIR:-$PWD/pithead-$TAG}" [ -e "$DIR" ] && fail "$DIR already exists — pick another PITHEAD_DIR or remove it." note "Installing Pithead $TAG into $DIR" -# --- Fetch bundle + manifest; verify the bundle against the manifest's sha256 line when the -# release carries one (releases newer than v1.14.0 do; for older ones HTTPS is the trust anchor, -# same as cloning the repo). Image digests are pinned inside the bundle's compose file, and -# `pithead up`/`upgrade` verify cosign signatures when cosign.pub + cosign are present. TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT -curl -fsSL -o "$TMP/pithead.tar.gz" "https://github.com/$REPO/releases/download/$TAG/pithead.tar.gz" || +curl -fsSL --proto =https --proto-redir =https -o "$TMP/pithead.tar.gz" "https://github.com/$REPO/releases/download/$TAG/pithead.tar.gz" || fail "Bundle download failed for $TAG." -if curl -fsSL -o "$TMP/ingredients.md" "https://github.com/$REPO/releases/download/$TAG/ingredients-$TAG.md" 2>/dev/null; then +if curl -fsSL --proto =https --proto-redir =https -o "$TMP/ingredients.md" "https://github.com/$REPO/releases/download/$TAG/ingredients-$TAG.md" 2>/dev/null; then WANT=$(grep -m1 -oE 'bundle sha256: `[a-f0-9]{64}`' "$TMP/ingredients.md" | grep -oE '[a-f0-9]{64}' || true) if [ -n "$WANT" ]; then GOT=$(sha256sum "$TMP/pithead.tar.gz" | cut -d' ' -f1) @@ -69,22 +66,32 @@ else note "No release manifest found — trusting the HTTPS download." fi -# --- Cross-channel signature check: the pinned public key comes from the repo over a different -# endpoint than the release download, so both must agree. Releases before the first signed cut -# carry no .sig — noted and skipped; a present-but-bad signature is always fatal. -if command -v cosign >/dev/null 2>&1; then - if curl -fsSL -o "$TMP/pithead.tar.gz.sig" "https://github.com/$REPO/releases/download/$TAG/pithead.tar.gz.sig" 2>/dev/null; then - curl -fsSL -o "$TMP/cosign.pub" "https://raw.githubusercontent.com/$REPO/main/cosign.pub" || - fail "The release carries a signature but the pinned key could not be fetched from the repo." - cosign verify-blob --key "$TMP/cosign.pub" --signature "$TMP/pithead.tar.gz.sig" \ - --insecure-ignore-tlog=true "$TMP/pithead.tar.gz" >/dev/null 2>&1 || - fail "Bundle signature verification FAILED — the download does not match the release key. Refusing to install." - note "Bundle signature verified (cosign, repo-pinned key)." - else - note "No bundle signature on this release (pre-signing era) — sha256/HTTPS are the trust anchors." +signed_release() { + [[ $1 =~ ^v([0-9]{1,6})\.([0-9]{1,6})\.([0-9]{1,6})$ ]] || return 0 + ((10#${BASH_REMATCH[1]} * 1000000000000 + 10#${BASH_REMATCH[2]} * 1000000 + 10#${BASH_REMATCH[3]} >= 1000018000001)) +} +if curl -fsSL --proto =https --proto-redir =https -o "$TMP/pithead.tar.gz.sig" "https://github.com/$REPO/releases/download/$TAG/pithead.tar.gz.sig" 2>/dev/null; then + curl -fsSL --proto =https --proto-redir =https -o "$TMP/cosign.pub" "https://raw.githubusercontent.com/$REPO/main/cosign.pub" || + fail "The release carries a signature but the pinned key could not be fetched from the repo." + COSIGN=$(command -v cosign || true) + if [ -z "$COSIGN" ]; then + note "cosign not installed — fetching the pinned cosign v2.6.3 into a temporary folder to check the signature." + curl -fsSL --proto =https --proto-redir =https -o "$TMP/cosign" "$COSIGN_PIN_URL" || + fail "Could not download the pinned cosign to check the bundle signature. Install cosign, or run the installer again." + [ "$(sha256sum "$TMP/cosign" | cut -d' ' -f1)" = "$COSIGN_PIN_SHA256" ] || + fail "The downloaded cosign does not match its pinned sha256. Refusing to install." + chmod 700 "$TMP/cosign" + COSIGN="$TMP/cosign" + "$COSIGN" version >/dev/null 2>&1 || + fail "The downloaded cosign could not run (is the temporary folder mounted noexec?). Install cosign, or set TMPDIR to a folder that allows running programs." fi + "$COSIGN" verify-blob --key "$TMP/cosign.pub" --signature "$TMP/pithead.tar.gz.sig" \ + --insecure-ignore-tlog=true "$TMP/pithead.tar.gz" >/dev/null 2>&1 || + fail "Bundle signature verification FAILED — the download does not match the release key. Refusing to install." + note "Bundle signature verified (cosign, repo-pinned key)." else - note "cosign not installed — skipping signature verification (sha256/HTTPS are the trust anchors)." + signed_release "$TAG" && fail "Release $TAG should carry a signature, but the signature could not be downloaded. Refusing to install. If this was a network error, run the installer again." + note "No bundle signature on this release (pre-signing era) — sha256/HTTPS are the trust anchors." fi mkdir -p "$DIR" diff --git a/tests/stack/test-install-verify.sh b/tests/stack/test-install-verify.sh index 4eb3b1c1cf..8c93bf97df 100644 --- a/tests/stack/test-install-verify.sh +++ b/tests/stack/test-install-verify.sh @@ -43,17 +43,12 @@ out=$(PATH="$IBIN:$PATH" bash "$ROOT/install.sh" 2>&1) || true assert_contains "install.sh refuses non-Linux" "$out" "runs on Linux" echo "== unit: install.sh download verification fails CLOSED (#868) ==" -# The two security-critical branches of the public curl installer: the bundle sha256 against the -# release manifest, and the cosign signature against the repo-pinned key. This is the path a new -# operator runs BEFORE any of the bundle's own defenses exist — a tampered bundle that gets -# extracted has already won — so a mismatch must install NOTHING. The stubs model each remote -# artifact as a file served by basename; absent file = curl -f failure, exactly the shape the -# script distinguishes (absent degrades politely, present-but-wrong is fatal). mk_tmpdir ISB mkdir -p "$ISB/bin" "$ISB/srv" "$ISB/work" printf '#!/bin/bash\ncase "$1" in -s) echo Linux ;; -m) echo x86_64 ;; esac\n' >"$ISB/bin/uname" cat >"$ISB/bin/curl" <<'EOF' #!/bin/bash +printf '%s\n' "$*" >>"${CURL_LOG:-/dev/null}" out="" url="" while [ $# -gt 0 ]; do case "$1" in @@ -70,6 +65,7 @@ while [ $# -gt 0 ]; do done src="$CURL_SRV/$(basename "$url")" [ -f "$src" ] || exit 22 +[ -n "$out" ] || cat "$src" [ -n "$out" ] && cp "$src" "$out" exit 0 EOF @@ -86,12 +82,13 @@ tar -czf "$ISB/srv/pithead.tar.gz" -C "$ISB/bundle-src" pithead-x irun() { # [env overrides via preceding assignments] ( cd "$ISB/work" || exit - CURL_SRV="$ISB/srv" PITHEAD_VERSION=v9.9.9 PITHEAD_ALLOW_ANY_DISTRO=1 \ + CURL_SRV="$ISB/srv" PITHEAD_VERSION="${IRUN_TAG-v9.9.9}" PITHEAD_ALLOW_ANY_DISTRO=1 \ PITHEAD_DIR="$ISB/work/$1" PITHEAD_TTY="${IRUN_TTY-$ISB/tty}" PATH="$ISB/bin:$PATH" bash "$ROOT/install.sh" 2>&1 "$ISB/tty" +touch "$ISB/srv/pithead.tar.gz.sig" "$ISB/srv/cosign.pub" out=$(IRUN_TTY="$ISB/no-such-tty" irun no-tty) && rc=0 || rc=$? assert_rc "piped install with no terminal refuses instead of handing setup a pipe" "$rc" "1" assert_contains "the no-terminal refusal says how to continue" "$out" "no terminal is available" @@ -125,8 +122,6 @@ rm -f "$ISB/srv/ingredients-v9.9.9.md" out=$(irun no-manifest) assert_contains "missing manifest degrades to HTTPS trust" "$out" "No release manifest" -# cosign: a present-but-bad signature is FATAL; an absent one is a note; a signature whose -# pinned key cannot be fetched is fatal too (the cross-channel check cannot be half-done). touch "$ISB/srv/pithead.tar.gz.sig" "$ISB/srv/cosign.pub" out=$(irun sig-ok) assert_rc "good signature installs" "$?" "0" @@ -139,12 +134,82 @@ rm -f "$ISB/srv/cosign.pub" out=$(irun sig-nokey) && rc=0 || rc=$? assert_rc "signature without a fetchable pinned key refuses" "$rc" "1" assert_contains "the failure names the pinned key" "$out" "pinned key could not be fetched" +touch "$ISB/srv/cosign.pub" +mkdir -p "$ISB/bin-nocosign" +cp "$ISB/bin/uname" "$ISB/bin/curl" "$ISB/bin-nocosign/" +cat >"$ISB/bin-nocosign/sha256sum" <<'EOF' +#!/bin/bash +if [ -n "${PIN_MATCH:-}" ] && [ "${1##*/}" = cosign ]; then + echo "7c78a7f2efc00088bd788a758db6e0928e79f3e0eb83eb5d3c499ed98da4c4f4 $1" + exit 0 +fi +if command -v /usr/bin/sha256sum >/dev/null; then exec /usr/bin/sha256sum "$@"; fi +exec shasum -a 256 "$@" +EOF +printf '#!/bin/bash\n[ "$1" != version ] || exit 0\nexit "${COSIGN_RC:-0}"\n' >"$ISB/srv/cosign-linux-amd64" +chmod +x "$ISB/bin-nocosign/sha256sum" "$ISB/srv/cosign-linux-amd64" +irun_nocosign() { + ( + cd "$ISB/work" || exit + CURL_SRV="$ISB/srv" PITHEAD_VERSION="${IRUN_TAG-v9.9.9}" PITHEAD_ALLOW_ANY_DISTRO=1 PITHEAD_DIR="$ISB/work/$1" \ + PITHEAD_TTY="$ISB/tty" PATH="$ISB/bin-nocosign:/usr/bin:/bin" bash "$ROOT/install.sh" 2>&1 "$ISB/srv/latest" +out=$(IRUN_TAG='' CURL_LOG="$ISB/curl.log" irun latest-tag) +assert_contains "the latest tag is resolved and installed" "$out" "SETUP-REACHED" +assert_eq "a full install makes five downloads" "$(grep -c . "$ISB/curl.log")" "5" +assert_eq "every installer download is limited to https, redirects included" "$(grep -vc -e '--proto =https --proto-redir =https' "$ISB/curl.log")" "0" +rm -f "$ISB/srv/pithead.tar.gz.sig" +out=$(IRUN_TAG=v1.18.0 irun sig-absent) assert_contains "absent signature is noted, not fatal" "$out" "No bundle signature" +assert_contains "v1.18.0 without a signature installs" "$out" "SETUP-REACHED" +out=$(IRUN_TAG=v1.3.1 irun sig-absent-v1.3.1) +assert_contains "v1.3.1 without a signature installs" "$out" "SETUP-REACHED" +out=$(IRUN_TAG=v1.08.0 irun sig-absent-v1.08.0) +assert_contains "v1.08.0 without a signature installs" "$out" "SETUP-REACHED" +out=$(IRUN_TAG=v1.18.1 irun sig-missing-v1.18.1) && rc=0 || rc=$? +assert_rc "v1.18.1 without a signature refuses" "$rc" "1" +assert_contains "the refusal says the signature could not be downloaded" "$out" "signature could not be downloaded" +assert_eq "nothing was installed for v1.18.1 without a signature" "$([ -e "$ISB/work/sig-missing-v1.18.1" ] && echo present || echo absent)" "absent" +assert_eq "setup was not reached for v1.18.1 without a signature" "$(printf '%s' "$out" | grep -c SETUP-REACHED || true)" "0" +out=$(IRUN_TAG=v1.19.0 irun sig-missing-v1.19.0) && rc=0 || rc=$? +assert_rc "v1.19.0 without a signature refuses" "$rc" "1" +out=$(IRUN_TAG=v2.0.0 irun sig-missing-v2.0.0) && rc=0 || rc=$? +assert_rc "v2.0.0 without a signature refuses" "$rc" "1" +out=$(IRUN_TAG=v1.018.1 irun sig-missing-v1.018.1) && rc=0 || rc=$? +assert_rc "v1.018.1 reads as base 10 and refuses without a signature" "$rc" "1" +out=$(irun sig-missing-v9.9.9) && rc=0 || rc=$? +assert_rc "v9.9.9 without a signature refuses" "$rc" "1" +assert_eq "nothing was installed for v9.9.9 without a signature" "$([ -e "$ISB/work/sig-missing-v9.9.9" ] && echo present || echo absent)" "absent" +out=$(IRUN_TAG=1.18.0 irun sig-missing-no-v) && rc=0 || rc=$? +assert_rc "a tag without the leading v is held to the signed rule" "$rc" "1" +out=$(IRUN_TAG=v1.18.0-rc1 irun sig-missing-rc) && rc=0 || rc=$? +assert_rc "a tag with a suffix is held to the signed rule" "$rc" "1" +out=$(IRUN_TAG=v1.18 irun sig-missing-two) && rc=0 || rc=$? +assert_rc "a tag with two numbers is held to the signed rule" "$rc" "1" -# The remaining guards on the same path: an occupied target refuses before downloading, and a -# bundle with no pithead executable refuses after extraction. +touch "$ISB/srv/pithead.tar.gz.sig" "$ISB/srv/cosign.pub" mkdir -p "$ISB/work/taken" out=$(irun taken) && rc=0 || rc=$? assert_rc "an existing target dir refuses" "$rc" "1" From fae304a096cb5222b85f562debc37fb4283211d4 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:08 -0600 Subject: [PATCH 03/51] A requested factory reset stays requested until the reformat has succeeded Source: #4575 Co-Authored-By: Claude Opus 5.5 --- docs/appliance.md | 5 ++++ lib/pithead/06-doctor.sh | 1 + lib/pithead/20-doctor-install-checks.sh | 8 ++++++ os/overlay/pithead-data-reset | 5 ++-- tests/os/selftest-data-reset-probe.sh | 28 ++++++++++++++++++++- tests/stack/doctor/test-doctor-appliance.sh | 13 ++++++---- 6 files changed, 52 insertions(+), 8 deletions(-) diff --git a/docs/appliance.md b/docs/appliance.md index 086ccd4c89..0846078773 100644 --- a/docs/appliance.md +++ b/docs/appliance.md @@ -711,6 +711,11 @@ failure in the `pithead-data-reset` service journal. An unavailable read-only pr does not authorize further repairs or erasure. A reformat also requires its mount directory to be allocated before formatting starts. +If a factory reset you asked for cannot finish reformatting the data area, the reset +stays requested: the `pithead-data-reset` service journal records the failure, the +reset runs again at the next boot, and +`cd /data/pithead && ./pithead doctor` warns until it has run. + ## Recovering from a backup Fresh flash, restore, done — if the machine is gone (dead disk, stolen, dropped), a backup diff --git a/lib/pithead/06-doctor.sh b/lib/pithead/06-doctor.sh index 4dd35ed606..489b859233 100644 --- a/lib/pithead/06-doctor.sh +++ b/lib/pithead/06-doctor.sh @@ -336,6 +336,7 @@ doctor() { fi check_data_wipe_note + check_reset_requested # --- Summary --- echo "" diff --git a/lib/pithead/20-doctor-install-checks.sh b/lib/pithead/20-doctor-install-checks.sh index 61d4e88223..309b58e985 100644 --- a/lib/pithead/20-doctor-install-checks.sh +++ b/lib/pithead/20-doctor-install-checks.sh @@ -294,3 +294,11 @@ check_appliance_cert() { dr_fail_surface "The dashboard certificate has EXPIRED ($enddate) — browsers will refuse it. Run './pithead apply' to re-mint." "The dashboard certificate has EXPIRED ($enddate) — browsers will refuse it. This machine only re-mints it when the set of names it answers to changes, so it will not renew on its own; replacing it needs console access." fi } + +check_reset_requested() { + is_appliance || return 0 + [ -e "$PRESEED_DIR/pithead-reset" ] || return 0 + echo "" + echo "Factory reset:" + dr_warn "A factory reset is still requested: the next boot erases /data. If the machine already rebooted for it, the reset did not complete; the pithead-data-reset service journal may say why." +} diff --git a/os/overlay/pithead-data-reset b/os/overlay/pithead-data-reset index 52d4ddd9be..7d782667c3 100644 --- a/os/overlay/pithead-data-reset +++ b/os/overlay/pithead-data-reset @@ -220,10 +220,11 @@ main() { log "factory-reset requested — wiping $data_part" if reformat_data "$data_part"; then record_wipe "${marker:+$esp_mnt}" "factory-reset requested" + [ -z "$marker" ] || rm -f "$marker" 2>/dev/null || true else - [ "$?" -ne 2 ] || rc=2 + rc=$? + log "factory reset did not complete — it stays requested and runs again at the next boot" fi - [ "$rc" -eq 2 ] || [ -z "$marker" ] || rm -f "$marker" 2>/dev/null || true ;; reformat-wedged) log "$data_part could not be mounted after every repair — reinitializing it so the box can recover" diff --git a/tests/os/selftest-data-reset-probe.sh b/tests/os/selftest-data-reset-probe.sh index 28abe0883f..d346f66513 100644 --- a/tests/os/selftest-data-reset-probe.sh +++ b/tests/os/selftest-data-reset-probe.sh @@ -13,6 +13,7 @@ TRACE="$work/trace" MKTEMP_FAIL="" MARKER_PRESENT="" MOUNT_RESULT=1 +MKFS_RESULT=0 cases=0 fail() { @@ -30,6 +31,7 @@ reset_fixture() { MKTEMP_FAIL="" MARKER_PRESENT="" MOUNT_RESULT=1 + MKFS_RESULT=0 } mktemp() { @@ -90,7 +92,7 @@ mke2fs() { function mkfs.ext4 { printf 'mkfs.ext4\n' >>"$TRACE" - return 0 + return "$MKFS_RESULT" } for failed_probe in 1 2 3 4 5; do @@ -214,4 +216,28 @@ esp_mnt=$(awk '$1 == "mktemp" { print $2; exit }' "$TRACE") [ -f "$esp_mnt/$MARKER_NAME" ] || fail 'refused reset consumed the reset marker' cases=$((cases + 1)) +reset_fixture +MARKER_PRESENT=1 +MKFS_RESULT=1 +main >"$work/main-output" 2>"$work/main-error" +rc=$? +[ "$rc" -ne 0 ] || fail 'main returned 0 when the requested reformat failed' +[ "$(count 'mkfs.ext4')" -eq 1 ] || fail 'requested reset did not attempt the reformat exactly once' +esp_mnt=$(awk '$1 == "mktemp" { print $2; exit }' "$TRACE") +[ -f "$esp_mnt/$MARKER_NAME" ] || fail 'failed requested reformat consumed the reset marker' +[ ! -e "$esp_mnt/$WIPE_LOG_NAME" ] || fail 'failed requested reformat recorded a wipe' +grep -q 'stays requested and runs again at the next boot' "$work/main-error" || + fail 'failed requested reformat did not say the reset stays requested' +cases=$((cases + 1)) + +reset_fixture +MARKER_PRESENT=1 +main >"$work/main-output" 2>"$work/main-error" +rc=$? +[ "$rc" -eq 0 ] || fail "requested reset returned $rc after a successful reformat" +esp_mnt=$(awk '$1 == "mktemp" { print $2; exit }' "$TRACE") +[ ! -e "$esp_mnt/$MARKER_NAME" ] || fail 'successful requested reset kept the reset marker' +grep -q 'factory-reset requested' "$esp_mnt/$WIPE_LOG_NAME" || fail 'successful requested reset recorded no wipe' +cases=$((cases + 1)) + printf 'selftest-data-reset-probe: %s cases passed\n' "$cases" diff --git a/tests/stack/doctor/test-doctor-appliance.sh b/tests/stack/doctor/test-doctor-appliance.sh index 637b1e99e0..7228defea8 100644 --- a/tests/stack/doctor/test-doctor-appliance.sh +++ b/tests/stack/doctor/test-doctor-appliance.sh @@ -85,10 +85,6 @@ echo "== unit: check_data_wipe_note — doctor surfaces the wipe note, a support mk_tmpdir CDW mkdir -p "$CDW/esp" export PITHEAD_PRESEED_DIR="$CDW/esp" -# Stands in for /run (tmpfs): data_wipe_note()'s one-shot cache has to live in a file, never a -# shell variable, because every caller reads it through `$(...)` command substitution, which -# forks a subshell (#1208 job 557/560 — a variable-based cache never worked, since a subshell's -# writes to it vanish when the subshell exits). export PITHEAD_DATA_WIPE_NOTE_CACHE="$CDW/wipe-note-cache.json" out=$(PITHEAD_APPLIANCE=0 run_sourced "$SANDBOX" check_data_wipe_note 2>&1) @@ -119,7 +115,6 @@ assert_eq "the .pending marker itself stays consumed (never re-armed by a re-run assert_contains "the underlying wipe log is untouched — only the marker was consumed" \ "$(cat "$CDW/esp/pithead-data-wiped")" "2026-08-21T09:00:00Z" -# A LATER boot (cache cleared, marker already consumed on disk) is what finally ends it. rm -f "$PITHEAD_DATA_WIPE_NOTE_CACHE" out=$(PITHEAD_APPLIANCE=1 run_sourced "$SANDBOX" check_data_wipe_note 2>&1) assert_eq "a later boot -> silent, never a stale re-WARN (#1208)" "$out" "" @@ -134,6 +129,14 @@ rm -f "$PITHEAD_DATA_WIPE_NOTE_CACHE" out=$(PITHEAD_APPLIANCE=1 run_sourced "$SANDBOX" check_data_wipe_note 2>&1) assert_eq "a factory-reset info line is one-shot too (later boot -> silent)" "$out" "" +out=$(PITHEAD_APPLIANCE=1 run_sourced "$SANDBOX" check_reset_requested 2>&1) +assert_eq "no factory reset requested -> doctor says nothing" "$out" "" +: >"$CDW/esp/pithead-reset" +out=$(PITHEAD_APPLIANCE=1 run_sourced "$SANDBOX" check_reset_requested 2>&1) +assert_contains "a factory reset still requested -> WARN" "$out" "WARN" +assert_contains "the WARN says the next boot erases /data" "$out" "the next boot erases /data" +out=$(PITHEAD_APPLIANCE=0 run_sourced "$SANDBOX" check_reset_requested 2>&1) +assert_eq "off the appliance -> silent even with a factory reset requested" "$out" "" unset PITHEAD_PRESEED_DIR PITHEAD_DATA_WIPE_NOTE_CACHE rm -rf "$CDW" unset CDW out From 73264e80b1d568793e61cba307a407d93f8ba631 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:10 -0600 Subject: [PATCH 04/51] The egress request runner removes entries that are not regular files Source: #4576 Co-Authored-By: Claude Opus 5.5 --- lib/pithead/02b-tor-egress-apply.sh | 9 ++-- tests/stack/firewall/egress-run-pending.sh | 57 ++++++++++++++++++++++ tests/stack/test-clearnet-firewall.sh | 2 + 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 tests/stack/firewall/egress-run-pending.sh diff --git a/lib/pithead/02b-tor-egress-apply.sh b/lib/pithead/02b-tor-egress-apply.sh index 6ca51adec5..cc7ffb67a1 100644 --- a/lib/pithead/02b-tor-egress-apply.sh +++ b/lib/pithead/02b-tor-egress-apply.sh @@ -238,18 +238,19 @@ egress_sync_run_pending() { mkdir -p "$cdir/results" [ -d "$cdir/requests" ] && [ ! -L "$cdir/requests" ] || return 1 for file in "$cdir"/requests/*.json; do - [ -e "$file" ] || continue + [ -e "$file" ] || [ -L "$file" ] || continue name=${file##*/} id=${name%.json} [[ "$id" =~ ^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$ ]] || { - rm -f "$file" + claimed="$cdir/.claim.egress.$$" + rm -rf -- "$claimed" && mv -T -- "$file" "$claimed" && rm -rf -- "$claimed" || true continue } claimed="$cdir/.claim.egress.$id" - mv -- "$file" "$claimed" || continue + rm -rf -- "$claimed" && mv -T -- "$file" "$claimed" || continue file="$claimed" [ -f "$file" ] && [ ! -L "$file" ] && [ "$(wc -c <"$file")" -le 1024 ] || { - rm -f "$file" + rm -rf -- "$file" continue } chain=$(jq -r --arg id "$id" 'if .id == $id and .action == "egress-sync" and diff --git a/tests/stack/firewall/egress-run-pending.sh b/tests/stack/firewall/egress-run-pending.sh new file mode 100644 index 0000000000..a6501cefae --- /dev/null +++ b/tests/stack/firewall/egress-run-pending.sh @@ -0,0 +1,57 @@ +# shellcheck shell=bash +echo "== egress-run-pending claims every requests entry before it reads one ==" +ERP=$(mktemp -d "$SANDBOX/egress-run.XXXXXX") +ERP_REQ="$ERP/data/control/requests" +ERP_ID=00000000-0000-4000-8000-0000000000e1 +ERP_DIR_ID=00000000-0000-4000-8000-0000000000e2 +ERP_LINK_ID=00000000-0000-4000-8000-0000000000e3 +ERP_OLD_ID=00000000-0000-4000-8000-0000000000e4 +mkdir -p "$ERP_REQ" "$ERP/outside/dir" "$ERP_REQ/empty.json" "$ERP_REQ/full.json" "$ERP_REQ/$ERP_DIR_ID.json" "$ERP_REQ/line"$'\n'"break.json" +printf 'keep\n' >"$ERP/outside/file.txt" +printf 'keep\n' >"$ERP/outside/dir/inner.txt" +chmod 640 "$ERP/outside/file.txt" +chmod 750 "$ERP/outside/dir" +printf 'x\n' >"$ERP_REQ/full.json/x" +printf 'x\n' >"$ERP_REQ/$ERP_DIR_ID.json/x" +printf 'x\n' >"$ERP_REQ/name.json" +ln -s "$ERP/missing" "$ERP_REQ/dangling.json" +ln -s "$ERP/outside/file.txt" "$ERP_REQ/to-file.json" +ln -s "$ERP/outside/dir" "$ERP_REQ/to-dir.json" +ln -s "$ERP/outside/dir" "$ERP_REQ/$ERP_LINK_ID.json" +printf '{"id":"%s","action":"egress-sync","chain":"monero"}\n' "$ERP_ID" >"$ERP_REQ/$ERP_ID.json" +mkdir -p "$ERP/data/control/.claim.egress.$ERP_OLD_ID" "$ERP/data/control/.claim.egress.$$" +printf 'x\n' >"$ERP/data/control/.claim.egress.$ERP_OLD_ID/x" +printf 'x\n' >"$ERP/data/control/.claim.egress.$$/x" +printf '{"id":"%s","action":"egress-sync","chain":"monero"}\n' "$ERP_OLD_ID" >"$ERP_REQ/$ERP_OLD_ID.json" +ERP_RC=$( + cd "$ERP" || exit + # shellcheck disable=SC1090 + source "$STACK" + set +e + egress_sync_refresh() { [ "$1" = monero ]; } + egress_sync_run_pending + printf 'first=%s ' "$?" + egress_sync_run_pending + printf 'empty=%s ' "$?" + mv data/control/requests data/control/gone + egress_sync_run_pending + printf 'missing=%s' "$?" + mv data/control/gone data/control/requests +) +erp_gone() { if [ -e "$ERP_REQ/$2" ] || [ -L "$ERP_REQ/$2" ]; then bad "$1" "still present"; else ok "$1"; fi; } +erp_gone "an empty folder with a non-UUID name is removed" empty.json +erp_gone "a non-empty folder with a non-UUID name is removed" full.json +erp_gone "a folder with a line break in its name is removed" "line"$'\n'"break.json" +erp_gone "a dangling link is removed" dangling.json +erp_gone "a link to a file is removed" to-file.json +erp_gone "a link to a folder is removed" to-dir.json +erp_gone "a regular file with a non-UUID name is removed" name.json +erp_gone "a folder with a UUID name leaves the requests folder" "$ERP_DIR_ID.json" +erp_gone "a link with a UUID name leaves the requests folder" "$ERP_LINK_ID.json" +assert_eq "no claim is left in the control folder" "$(find "$ERP/data/control" -maxdepth 1 -name '.claim.*' | wc -l | tr -d ' ')" "0" +assert_eq "the valid request beside them is applied" "$(jq -r .status "$ERP/data/control/results/$ERP_ID.json")" "applied" +assert_eq "a request whose claim name held an older folder is applied" "$(jq -r .status "$ERP/data/control/results/$ERP_OLD_ID.json")" "applied" +assert_eq "no result is written for the other entries" "$(find "$ERP/data/control/results" -type f | wc -l | tr -d ' ')" "2" +assert_eq "a linked file keeps its content and mode" "$(cat "$ERP/outside/file.txt") $(stat -c %a "$ERP/outside/file.txt")" "keep 640" +assert_eq "a linked folder keeps its file and mode" "$(cat "$ERP/outside/dir/inner.txt") $(stat -c %a "$ERP/outside/dir")" "keep 750" +assert_eq "return codes stay the same for a run, an empty and a missing requests folder" "$ERP_RC" "first=0 empty=0 missing=1" diff --git a/tests/stack/test-clearnet-firewall.sh b/tests/stack/test-clearnet-firewall.sh index 313663221f..c27f428f82 100644 --- a/tests/stack/test-clearnet-firewall.sh +++ b/tests/stack/test-clearnet-firewall.sh @@ -167,6 +167,8 @@ printf '{"id":"%s","action":"egress-sync","chain":"tari"}\n' "$CN_RID" >"$CN_CDI ) assert_eq "control-off retry records the other chain's success" "$(jq -r .status "$CN_CDIR/results/$CN_RID.json")" "applied" assert_eq "control-off result names the verified chain" "$(jq -r .chain "$CN_CDIR/results/$CN_RID.json")" "tari" +# shellcheck source=tests/stack/firewall/egress-run-pending.sh +source "$ROOT/tests/stack/firewall/egress-run-pending.sh" printf '00000000-0000-4000-8000-000000000001\n' >"$CN_SDIR/monero.synced" CN_RESTART_PROBE=$( cd "$V" || exit From 3223ed19b627d97a456689b9ae8faf0aa5d70761 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:11 -0600 Subject: [PATCH 05/51] Support bundles mask the generated login and setup token, and the boot media summary hides worker API tokens Source: #4577 Co-Authored-By: Claude Opus 5.5 --- docs/operations.md | 2 +- lib/pithead/07-support-bundle.sh | 2 ++ os/overlay/pithead-media-config | 4 ++-- .../selftest/selftest-bundle-redact-log.sh | 23 +++++++++++++++++++ tests/stack/appliance/test-appliance-media.sh | 12 +++++----- 5 files changed, 34 insertions(+), 9 deletions(-) diff --git a/docs/operations.md b/docs/operations.md index 15af4c1477..878129a4bd 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -28,7 +28,7 @@ separately, [below](#appliance-only-commands). | `./pithead egress-status` | Check the Tor-only egress firewall the way `doctor` does and write the verdict to `data/control/results/egress-status.json` for the dashboard. Read-only. Fired every two minutes by `pithead-egress.timer`; `up`, `apply` and `upgrade` install the timer, and `network.tor_egress_firewall: false` or `uninstall` removes it. | | `./pithead lan-guard-check` | Check the live LAN-only source rule. If it is missing, remove the node start marker and stop the nodes that publish LAN ports; if a stop cannot be verified, try restoring the rule on all three fixed node ports and keep reporting failure until the stop is verified. Fired every two minutes by `pithead-lan.timer`; `up`, `apply` and `upgrade` install the timer while a LAN port is configured or still published by a node. Run `./pithead up` after fixing the firewall to restore access. | | `./pithead render` | Regenerate every derived file (`.env`, the Caddyfile, service configs, host units) from `config.json` without touching containers. The appliance runs this every boot; run it by hand after replacing the program under an existing config. | -| `./pithead support-bundle` | Collect one `chmod 600` `support-bundle-.zip` in the current directory for a bug report, the same zip the dashboard's **Support bundle** card downloads on a Docker host. The window is `--since TIME` and `--until TIME` (RFC 3339, for example `2026-11-15T10:00:00Z`; the end second is included whole; the end defaults to now, the start to 72 hours before it), or `--hours N` (default 72, clamped to 168); a start after the end, an unparsable time or an end in the future is refused and nothing is written. The zip holds `containers/.log` for every container of the stack, stopped ones included, read in full with the engine's `logs --since --until` for the window (no 200-line limit); `logs/.log` from the host journal for `pithead-egress.service`, `pithead-egress.timer`, `pithead-lan-guard.service`, `pithead-lan-hold.service` and `pithead-lan.timer`; host facts, `doctor` in prose and JSON, a masked config, a redacted `.env`, the container list and `manifest.json`. Launch-line credentials, wallet addresses and the service onion are scrubbed from every container and journal file, as is any Monero address or onion written anywhere else in the text. The manifest has the same fields and size policy as `recovery-bundle` below; a container engine that is stopped, or a system journal this user cannot read (including a user outside the `adm` and `systemd-journal` groups who sees only their own journal), does not fail the bundle: it is listed under `failures` with the reason and no unit file is written, and a unit that is not installed shows as `missing`. Docker's log driver keeps only what its rotation retains, so a window older than that is shorter than asked without a flag. On an appliance the verb collects the journal bundle `recovery-bundle` writes. Read-only, and nothing leaves the box — review it, then share it. | +| `./pithead support-bundle` | Collect one `chmod 600` `support-bundle-.zip` in the current directory for a bug report, the same zip the dashboard's **Support bundle** card downloads on a Docker host. The window is `--since TIME` and `--until TIME` (RFC 3339, for example `2026-11-15T10:00:00Z`; the end second is included whole; the end defaults to now, the start to 72 hours before it), or `--hours N` (default 72, clamped to 168); a start after the end, an unparsable time or an end in the future is refused and nothing is written. The zip holds `containers/.log` for every container of the stack, stopped ones included, read in full with the engine's `logs --since --until` for the window (no 200-line limit); `logs/.log` from the host journal for `pithead-egress.service`, `pithead-egress.timer`, `pithead-lan-guard.service`, `pithead-lan-hold.service` and `pithead-lan.timer`; host facts, `doctor` in prose and JSON, a masked config, a redacted `.env`, the container list and `manifest.json`. Launch-line credentials, wallet addresses and the service onion are scrubbed from every container and journal file, as is any Monero address or onion written anywhere else in the text, the value on the appliance's generated dashboard login line and the setup wizard's one-time token. The manifest has the same fields and size policy as `recovery-bundle` below; a container engine that is stopped, or a system journal this user cannot read (including a user outside the `adm` and `systemd-journal` groups who sees only their own journal), does not fail the bundle: it is listed under `failures` with the reason and no unit file is written, and a unit that is not installed shows as `missing`. Docker's log driver keeps only what its rotation retains, so a window older than that is shorter than asked without a flag. On an appliance the verb collects the journal bundle `recovery-bundle` writes. Read-only, and nothing leaves the box — review it, then share it. | | `./pithead recovery-bundle` | The appliance's journal-only twin of `support-bundle` ([#4038](https://github.com/p2pool-starter-stack/pithead/issues/4038)): no dashboard and no network egress — it reads the system journal, the host state and the local service endpoints over the window you ask for, passes every line through the same redactor, writes one `chmod 600` `support-bundle-.zip` under `/data/pithead/support-bundles/` and prints its path. The window is `--since TIME` and `--until TIME` (RFC 3339, for example `2026-11-15T10:00:00Z`; the end second is included whole; the end defaults to now, the start to 72 hours before it), or the older `--hours N` (default 72, clamped to 168). A start after the end, an unparsable time or an end in the future is refused and nothing is written. The zip holds `journal/all.log` (the whole system journal for the window), `journal/kernel.log` (`journalctl -k`), `journal/boots.txt` (`journalctl --list-boots`), one `logs/.log` per Pithead service and timer and per quadlet-generated unit installed on the box (the list is read from the installed unit files when the bundle is collected), the host facts and `manifest.json`, plus the state snapshots listed under **Snapshots** below. The manifest lists every file with its window, size, state (`ok`, `empty` for a unit with no lines in the window, `missing` for a unit that is not installed and has no lines, `journal_short` when the file has lines but the journal starts after the requested start; the window block carries the same fact for the whole bundle) and truncation, every step that failed or timed out with its reason, the requested and the effective window, the oldest retained journal entry, the journald disk usage and settings, the Pithead version and the collection time. A start older than the oldest retained entry is clamped to it. **Snapshots** below. The manifest lists every file with its window, size, state (`ok`, `empty` for a unit with no lines in the window, `missing` for a unit that is not installed and has no lines, `journal_short` when the file has lines but the journal starts after the requested start; the window block carries the same fact for the whole bundle) and truncation, every step that failed or timed out with its reason, the requested and the effective window, the oldest retained journal entry, the journald disk usage and settings, the Pithead version and the collection time. A start older than the oldest retained entry is clamped to it. **Snapshots** below. The manifest lists every file with its window, size, state (`ok`, `empty` for a unit with no lines in the window, `missing` for a unit that is not installed and has no lines, `journal_short` when the file has lines but the journal starts after the requested start; the window block carries the same fact for the whole bundle) and truncation, every step that failed or timed out with its reason, the requested and the effective window, the oldest retained journal entry, the journald disk usage and settings, the Pithead version and the collection time. A start older than the oldest retained entry is clamped to it. **Snapshots** (#4128): `doctor.json` (`doctor --json`); `status/monerod.json`, `status/tari.json` and `status/p2pool.json`, each with height, peer count and a sync flag, or `reachable: false` and the reason when the service cannot answer (monerod answers `get_info` with the `.env` login, Tari answers its base node gRPC `GetTipInfo` and `GetNetworkStatus`, and P2Pool is read from its data-api files, so its sync flag is derived: every readable file under ten minutes old and a known sidechain height; a node that is remote is skipped and the manifest says so); `tor/control.txt` (bootstrap phase, entry guards and circuit state from the control port, authenticated with the cookie, which is read in memory and never written, with onion-service and SOCKS isolation fields dropped) and `tor/state-guards.txt` (only the `TorVersion`, `LastWritten` and `Guard` lines of the Tor state file, so no key can pass); `network/` (`networkctl status`, `ip addr`, `ip route`, `resolvectl status` and the `nft` ruleset with every IPv4 and IPv6 address redacted); `time/` (`timedatectl status` and the time-sync units); `containers/ps-a.txt` (state, exit code and image of every container) and `containers/images.txt` (image digests); `rauc.txt`, `rauc-detailed.txt` and `boot-slot.txt` (the kernel command line, which names the booted slot); `coredumps.txt` (`coredumpctl list`, metadata only, or "not installed"); `caddy/access.log` (the window's lines from the current and rotated generations, with every header but a short safe list (user agent, content type and length, accept, host, forwarded-for) replaced, every URL query replaced and every long path segment masked); `support-dir/` (every file under `/data/pithead/support/`, redacted); `state-markers.txt` (a bounded listing of `/data/pithead`, with the contents of marker files of 256 bytes or less whose names and contents do not look like a secret, URL or token); and `dashboard-history.jsonl` (every row in the window of the history, event, share, block, raffle, XvB, network, disk, worker, ping-failure and control-audit tables, with no row cap; payout rows are left out; a missing database or table is a manifest entry). **Time limits:** every capture runs under `timeout` (the host facts and unit-list reads under 15 seconds), 20 seconds for a snapshot (`PITHEAD_SUPPORT_SNAP_TIMEOUT`), 90 for doctor, 300 for a journal step, and the whole collection under 1500 seconds (`PITHEAD_SUPPORT_TOTAL_TIMEOUT`); a step that times out, fails, is skipped because the total ran out or is not installed is listed in `manifest.json` `failures` with its name, status, reason and elapsed seconds, the manifest states the limits in `limits`, and the bundle is still produced. **Size policy:** each capped file keeps the oldest quarter and the newest three quarters of a 16 MiB budget with a marker line inside the file saying how many lines and bytes were dropped; the files together are held to 64 MiB uncompressed by shrinking the largest first, and the manifest records every cut. Nothing is refused for size. Journald keeps up to 400 MiB (`SystemMaxUse`), enough for the 168 hours the dashboard offers at the log volume of about 2 MiB per hour the issue reports for a loaded test box (the 200 MiB cap held about 102 hours there; not re-measured when the cap was raised); a window older than the retained journal is flagged in the manifest rather than failing. It is the console recipe for a box that failed boot gating, where the machine stays up for diagnosis and the console advisory names this command (`/opt/pithead/pithead recovery-bundle`) beside the journal. Run it on tty1 or the serial console as root; the path it prints is the archive to copy off. Refuses where no journal exists: there, use `support-bundle`. Review the archive, then attach it to a bug report as the card's steps describe; a box whose dashboard answers collects the same artifact from the browser instead — the **Export logs** card in [Dashboard › Backup view](dashboard.md#backup-view), which works with or without the dashboard control channel. | | `./pithead config-reset` | **DESTRUCTIVE**. Clear the configuration and reopen the setup wizard, keeping every data directory — chains, wallets, Tor onion keys and dashboard history all stay, so reconfiguring costs no resync. Type-to-confirm unless `-y` / `--yes`. If Compose shutdown fails, print its error and warn that containers may still be running, then continue the wipe (exit 0 on completion). The Tor-only egress rules come off only when the container engine shows no stack container still active; otherwise they stay, with a warning, until `./pithead down` stops the stack. | | `./pithead uninstall` | **DESTRUCTIVE**. The clean exit: removes everything pithead put on this host, including the egress firewall rules with their `pithead-egress.service` boot unit and `pithead-egress.timer` check, the LAN-only source rule and its `pithead-lan.timer` check, and deletes NO data, on any flag. One exception: while the container engine shows a stack container still active, or cannot be asked, the egress firewall rules stay for the current boot, with a warning; run `./pithead down` before rebooting, because their boot unit is already gone. Prints the three-column inventory below, resolved for this box, and the exact command to delete the rest. Refuses in a `pithead-vX.Y.Z` directory that `current` does not point at, because every version directory drives the same live stack: run it in the live directory, and delete an old version directory by hand. Type-to-confirm unless `-y` / `--yes`. | diff --git a/lib/pithead/07-support-bundle.sh b/lib/pithead/07-support-bundle.sh index 745df299b3..f4312ac2ab 100644 --- a/lib/pithead/07-support-bundle.sh +++ b/lib/pithead/07-support-bundle.sh @@ -145,6 +145,8 @@ bundle_redact_log() { -e 's/(--wallet[ =])[^-[:space:]][^[:space:]]*/\1[redacted-address]/g' \ -e 's/(--merge-mine[ =][^[:space:]]+[[:space:]]+)[^-[:space:]][^[:space:]]*/\1[redacted-address]/g' \ -e 's/[a-z2-7]{56}\.onion/[redacted].onion/g' \ + -e 's/(][[:space:]]{2,}password: )[^[:space:]]+/\1[redacted]/g' \ + -e 's/(One-time token: )[^[:space:]]+/\1[redacted]/g' \ -e "$xmr_shape" \ -e "$xmr_shape" } diff --git a/os/overlay/pithead-media-config b/os/overlay/pithead-media-config index 9bfb527467..c570596dc9 100644 --- a/os/overlay/pithead-media-config +++ b/os/overlay/pithead-media-config @@ -161,8 +161,8 @@ media_config_diff() { # — requires SECRET_PATHS_JSON (se jq -n -r --slurpfile o "$old" --slurpfile n "$new" --argjson secret "$SECRET_PATHS_JSON" ' def is_secret($p): ($secret | any(. == $p)) - or ($p[0:2] == ["workers","list"] and $p[-1] == "token") - or ($p[0:2] == ["dashboard","workers"] and $p[-1] == "token") + or ($p[0:2] == ["workers","list"] and ($p[-1] == "token" or $p[-1] == "api_token")) + or ($p[0:2] == ["dashboard","workers"] and ($p[-1] == "token" or $p[-1] == "api_token")) or ($p[0:2] == ["notifications","webhooks"]); def show($v): if $v == null then "(unset)" else ($v | tostring) end; ($o[0]) as $O | ($n[0]) as $N | diff --git a/tests/integration/selftest/selftest-bundle-redact-log.sh b/tests/integration/selftest/selftest-bundle-redact-log.sh index 317c67765f..76042a6288 100755 --- a/tests/integration/selftest/selftest-bundle-redact-log.sh +++ b/tests/integration/selftest/selftest-bundle-redact-log.sh @@ -338,5 +338,28 @@ body_kept "a 95-character token with a non-address prefix survives" \ body_kept "a sha256 digest survives" \ "image sha256:$SHA256_HEX pulled" "$SHA256_HEX" +echo "== unit: the generated dashboard login and the one-time setup token are masked ==" +GEN_LOGIN="Synth3ticGeneratedLogin00000000A" +JPFX="Nov 24 10:00:00 fixture pithead-firstboot[812]:" +assert_eq "the generated login line in the journal keeps its prefix and masks the value" \ + "$(printf '%s [pithead] password: %s\n' "$JPFX" "$GEN_LOGIN" | brl)" \ + "$JPFX [pithead] password: [redacted]" +assert_eq "the generated login line without a journal prefix masks the value" \ + "$(printf '[pithead] password: %s\n' "$GEN_LOGIN" | brl)" \ + "[pithead] password: [redacted]" +assert_eq "the one-time token line in the journal keeps its prefix and masks the value" \ + "$(printf '%s [pithead] One-time token: pit-ABC123\n' "$JPFX" | brl)" \ + "$JPFX [pithead] One-time token: [redacted]" +assert_eq "a stratum password status line is unchanged" \ + "$(printf 'Stratum password: none set\n' | brl)" "Stratum password: none set" +assert_eq "a stratum password status line after the log prefix is unchanged" \ + "$(printf '[pithead] Stratum password: none set\n' | brl)" "[pithead] Stratum password: none set" +assert_eq "a line that only names a password is unchanged" \ + "$(printf '[pithead] password: see dashboard.auth.password in config.json\n' | brl)" \ + "[pithead] password: see dashboard.auth.password in config.json" +assert_eq "the rpc-login credential keeps its existing masking" \ + "$(printf -- '--rpc-login %s:%s --zmq-port 18083\n' "$RPC_USER" "$RPC_PASS" | brl)" \ + "--rpc-login [redacted] --zmq-port 18083" + echo "selftest-bundle-redact-log: $IT_PASS passed, $IT_FAIL failed" [ "$IT_FAIL" -eq 0 ] || exit 1 diff --git a/tests/stack/appliance/test-appliance-media.sh b/tests/stack/appliance/test-appliance-media.sh index 777d187809..c762f45ef3 100644 --- a/tests/stack/appliance/test-appliance-media.sh +++ b/tests/stack/appliance/test-appliance-media.sh @@ -186,12 +186,16 @@ EOF diffout=$( export PITHEAD_MEDIA_BIN="$MC/pithead" source "$ROOT/os/overlay/pithead-media-config" - SECRET_PATHS_JSON=$(_secret_paths_json) # the real fetch, against the sandboxed pithead copy - media_config_diff "$MC/good.json" "$MC/changed.json" + SECRET_PATHS_JSON=$(_secret_paths_json) + media_config_diff <(jq '.workers.list=[{name:"rig1",api_token:"api-token-old-value"}] | .dashboard.workers=[{name:"rig2",api_token:"api-token-old-second"}]' "$MC/good.json") \ + <(jq '.workers.list=[{name:"rig1",api_token:"api-token-new-value"}] | .dashboard.workers=[{name:"rig2",api_token:"api-token-new-second"}]' "$MC/changed.json") ) assert_contains "the payout wallet change shows old -> new in full (that IS the point)" "$diffout" "$VALID_PRIMARY -> 44MnN1f3Eto8DZYUWuE5XZNUtE3vcRzt2j6PzqWpPau34e6Cf4fAxt6X2MBmrm6F9YMEiMNjN6W4Shn4pLcfNAja621jwyg" assert_contains "a changed secret (dashboard password) names the path" "$diffout" "dashboard.auth.password" assert_not_contains "a changed secret never shows the new value" "$diffout" "a-new-dashboard-password" +assert_contains "a changed worker API token is listed as changed with its value hidden" "$diffout" "workers.list.0.api_token: changed (value hidden)" +assert_contains "a changed worker API token under dashboard.workers is listed the same way" "$diffout" "dashboard.workers.0.api_token: changed (value hidden)" +assert_eq "no worker API token value is printed, old or new" "$(printf '%s' "$diffout" | grep -c 'api-token-' || true)" "0" rc=$( export PITHEAD_MEDIA_BIN="$MC/pithead" @@ -211,8 +215,6 @@ rc=$( ) assert_eq "a real change -> media_config_identical false" "$rc" "1" -# Masking fails CLOSED: with no secret-path list there is no diff and no "identical" verdict — -# an earlier draft fell back to an empty list, which printed raw secret values to the console. rc=$( export PITHEAD_MEDIA_BIN="$MC/does-not-exist" source "$ROOT/os/overlay/pithead-media-config" @@ -354,8 +356,6 @@ fi assert_contains "the cancelled change is announced on the console" "$(cat "$MC/abort.out")" \ "Media configuration channel: cancelled — no changes applied." -# main() must FAIL CLOSED end to end when the secret-path list can't be read: with a broken host -# program, no diff (which could leak raw secret values) is ever shown and no config is applied. STICK6="$MC/stick-nosecrets" mkdir -p "$STICK6" cp "$MC/changed.json" "$STICK6/pithead-config.json" From 68cd8d5428de94ee35a89b9716c5c36e55f848bf Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:13 -0600 Subject: [PATCH 06/51] Bound XvB player counts, future-dated wins and a rig's config block Source: #4578 Co-Authored-By: Claude Opus 5.5 --- .../mining_dashboard/client/rig_reply.py | 16 +++++- .../mining_dashboard/client/xvb_client.py | 2 +- .../mining_dashboard/service/data_helpers.py | 3 +- .../mining_dashboard/service/data_xvb_sync.py | 10 +++- dashboard/tests/client/test_rig_reply.py | 25 +++++++++ dashboard/tests/client/test_xvb_untrusted.py | 21 +++++++- .../service/test_xvb_winners_gate_window.py | 54 +++++++++++++++++++ 7 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 dashboard/tests/service/test_xvb_winners_gate_window.py diff --git a/dashboard/mining_dashboard/client/rig_reply.py b/dashboard/mining_dashboard/client/rig_reply.py index 361b0438bc..1f68e683e0 100644 --- a/dashboard/mining_dashboard/client/rig_reply.py +++ b/dashboard/mining_dashboard/client/rig_reply.py @@ -1,8 +1,11 @@ +import json + from mining_dashboard.helper.utils import finite_number, plausible_rate, safe_text _TEXT_MAX = 1024 _NUMBER_MAX = 2**63 - 1 _DEPTH_MAX = 16 +_CONFIG_MAX = 65536 def _flag(value): @@ -22,6 +25,11 @@ def clip(value): return clip +def _config(value): + value = _bounded(value) + return value if isinstance(value, dict) and len(json.dumps(value)) <= _CONFIG_MAX else None + + _SHAPE = { "uptime": finite_number, "kind": _text(64), @@ -47,7 +55,7 @@ def clip(value): "max_temp_c": finite_number, }, "control": {"change_id": _text(64), "status": _text(64), "reason": _clipped(500)}, - "config": {}, + "config": _config, "config_meta": {}, }, } @@ -72,7 +80,11 @@ def _bounded(value, depth=0): if depth > _DEPTH_MAX: return None if isinstance(value, dict): - return {key[:_TEXT_MAX]: _bounded(item, depth + 1) for key, item in value.items()} + return { + key[:_TEXT_MAX]: _bounded(item, depth + 1) + for key, item in value.items() + if key.isprintable() + } if isinstance(value, list): return [_bounded(item, depth + 1) for item in value] if isinstance(value, str): diff --git a/dashboard/mining_dashboard/client/xvb_client.py b/dashboard/mining_dashboard/client/xvb_client.py index 5639875846..c85623f542 100644 --- a/dashboard/mining_dashboard/client/xvb_client.py +++ b/dashboard/mining_dashboard/client/xvb_client.py @@ -134,7 +134,7 @@ def parse_round_stats(text): players = int(fields[7]) except ValueError: continue - if players <= 0: + if not 0 < players <= 10**9: continue first_ts = ts if first_ts is None else max(first_ts, ts) last_ts = ts if last_ts is None else min(last_ts, ts) diff --git a/dashboard/mining_dashboard/service/data_helpers.py b/dashboard/mining_dashboard/service/data_helpers.py index 11c57cfca7..c9a013cef8 100644 --- a/dashboard/mining_dashboard/service/data_helpers.py +++ b/dashboard/mining_dashboard/service/data_helpers.py @@ -15,6 +15,7 @@ from datetime import UTC, datetime from mining_dashboard.client.xmrig_client import parse_rigforge +from mining_dashboard.client.xvb_client import _WINNERS_MAX_FUTURE_S from mining_dashboard.config import config from mining_dashboard.helper.utils import effective_hashrate, get_tier_info from mining_dashboard.service import mining_verdict as mv @@ -76,7 +77,7 @@ def _xvb_winners_gate_sec(avg_1h, avg_24h, tiers, last_win_ts, now): _, threshold = get_tier_info(min(avg_1h, avg_24h), tiers) if threshold > 0 and avg_1h <= threshold * (1 + _XVB_WINNERS_MARGIN): return _XVB_WINNERS_SYNC_FAST_SEC - if last_win_ts > 0 and now - last_win_ts < _XVB_WIN_FRESH_S: + if last_win_ts > 0 and -_WINNERS_MAX_FUTURE_S <= now - last_win_ts < _XVB_WIN_FRESH_S: return _XVB_WINNERS_SYNC_FAST_SEC return _XVB_WINNERS_SYNC_SEC diff --git a/dashboard/mining_dashboard/service/data_xvb_sync.py b/dashboard/mining_dashboard/service/data_xvb_sync.py index 4227b6d7e5..4d2bcab82a 100644 --- a/dashboard/mining_dashboard/service/data_xvb_sync.py +++ b/dashboard/mining_dashboard/service/data_xvb_sync.py @@ -3,6 +3,7 @@ import time from mining_dashboard.client.xvb_client import ( + _WINNERS_MAX_FUTURE_S, REG_INVALID, REG_NOT_ELIGIBLE, REG_OK, @@ -117,7 +118,14 @@ async def _sync_xvb_winners(self): xvb.get("avg_1h", 0) or 0, xvb.get("avg_24h", 0) or 0, self.state_manager.get_tiers(), - max((w.get("ts", 0) or 0 for w in recent_wins), default=0.0), + max( + ( + ts + for w in recent_wins + if (ts := w.get("ts", 0) or 0) <= now + _WINNERS_MAX_FUTURE_S + ), + default=0.0, + ), now, ) if now - self._last_xvb_winners_sync < gate: diff --git a/dashboard/tests/client/test_rig_reply.py b/dashboard/tests/client/test_rig_reply.py index c65c59b6eb..7c4b6cdf2d 100644 --- a/dashboard/tests/client/test_rig_reply.py +++ b/dashboard/tests/client/test_rig_reply.py @@ -170,6 +170,31 @@ def test_a_large_unlisted_counter_is_kept(): } +def test_keys_that_are_not_printable_text_are_dropped_with_their_value(): + reply = _reply( + '{"extra": {"a\\u202eb": 1, "ok": 2}, "rigforge": {"config": {"x\\ny": "v",' + ' "pools": [{"u\\u202erl": "h:1", "url": "h:2"}], "DONATION": 1}}}' + ) + assert reply["extra"] == {"ok": 2} + assert reply["rigforge"]["config"] == {"pools": [{"url": "h:2"}], "DONATION": 1} + + +def test_a_config_block_over_the_size_limit_is_dropped_and_the_rest_kept(): + config = {f"k{i}": "v" * 1000 for i in range(70)} + reply = _reply(json.dumps({"uptime": 5, "rigforge": {"version": "1.2.3", "config": config}})) + assert reply["uptime"] == 5 and reply["rigforge"] == {"version": "1.2.3"} + assert parse_rigforge(reply)["config"] is None + assert _reply('{"rigforge": {"config": "x"}}')["rigforge"] == {} + + +def test_a_config_block_under_the_size_limit_is_kept(): + config = {f"k{i}": "v" * 1000 for i in range(60)} + config["DONATION"] = 1 + reply = _reply(json.dumps({"rigforge": {"config": config}})) + assert reply["rigforge"]["config"] == config + assert parse_rigforge(reply)["config"] == {"DONATION": 1} + + class _Response: def __init__(self, status, payload): self.status, self._raw, self.content = status, json.dumps(payload).encode(), self diff --git a/dashboard/tests/client/test_xvb_untrusted.py b/dashboard/tests/client/test_xvb_untrusted.py index 6c3832ff35..93e837326c 100644 --- a/dashboard/tests/client/test_xvb_untrusted.py +++ b/dashboard/tests/client/test_xvb_untrusted.py @@ -2,7 +2,7 @@ import pytest -from mining_dashboard.client.xvb_client import XvbClient, parse_winners +from mining_dashboard.client.xvb_client import XvbClient, parse_round_stats, parse_winners WALLET = "48M2j8GjINNERPARTd8KgGBwa" ROW = "48M2j8Gj...d8KgGBwa\t{when}\t{rate}\t{height}\t\t{block}\t1/1\t1\tdonor\n" @@ -87,3 +87,22 @@ def test_winners_rows_dated_in_the_future_are_dropped(): when="2026-07-18 20:41:38", rate="1kH/s", height=2, block="past" ) assert [win["block_id"] for win in parse_winners(text, WALLET)] == ["past"] + + +@pytest.mark.parametrize("players", ["9" * 400, "9" * 4000, str(10**9 + 1), "0"]) +def test_round_stats_rows_with_a_players_count_out_of_range_are_skipped(players): + when = "2026-07-18 20:41:38" + text = ROW.format(when=when, rate="1kH/s", height=1, block="a").replace( + "\t1\tdonor", "\t27\tdonor" + ) + text += ROW.format(when=when, rate="1kH/s", height=2, block="b").replace( + "\t1\tdonor", f"\t{players}\tdonor" + ) + assert parse_round_stats(text)["types"] == {"donor": {"rounds": 1, "players_avg": 27.0}} + + +def test_round_stats_keep_a_players_count_at_the_limit(): + text = ROW.format(when="2026-07-18 20:41:38", rate="1kH/s", height=1, block="a").replace( + "\t1\tdonor", f"\t{10**9}\tdonor" + ) + assert parse_round_stats(text)["types"] == {"donor": {"rounds": 1, "players_avg": 1e9}} diff --git a/dashboard/tests/service/test_xvb_winners_gate_window.py b/dashboard/tests/service/test_xvb_winners_gate_window.py new file mode 100644 index 0000000000..9b1f1f1959 --- /dev/null +++ b/dashboard/tests/service/test_xvb_winners_gate_window.py @@ -0,0 +1,54 @@ +import time +from unittest.mock import MagicMock + +from mining_dashboard.service.data_helpers import ( + _XVB_WINNERS_SYNC_FAST_SEC, + _XVB_WINNERS_SYNC_SEC, + _xvb_winners_gate_sec, +) +from mining_dashboard.service.data_service import DataService + +TIERS = {"donor": 1_000, "donor_whale": 100_000} +NOW = 1_000_000.0 + + +def _gate(last_win_ts): + return _xvb_winners_gate_sec(250_000, 250_000, TIERS, last_win_ts, NOW) + + +def test_a_win_dated_more_than_an_hour_ahead_keeps_the_baseline(): + assert _gate(NOW + 3601) == _XVB_WINNERS_SYNC_SEC + assert _gate(NOW + 86_400 * 365) == _XVB_WINNERS_SYNC_SEC + + +def test_a_win_up_to_an_hour_ahead_or_in_the_fresh_window_is_fast(): + assert _gate(NOW + 3600) == _XVB_WINNERS_SYNC_FAST_SEC + assert _gate(NOW) == _XVB_WINNERS_SYNC_FAST_SEC + assert _gate(NOW - 5399) == _XVB_WINNERS_SYNC_FAST_SEC + assert _gate(NOW - 5400) == _XVB_WINNERS_SYNC_SEC + + +async def _fetches_after(wins, wait): + sm = MagicMock() + sm.load_snapshot.return_value = None + sm.get_xvb_stats.return_value = {"avg_1h": 250_000, "avg_24h": 250_000} + sm.get_tiers.return_value = TIERS + sm.get_raffle_wins.return_value = wins + sm.add_raffle_wins.return_value = [] + svc = DataService(sm, MagicMock(), MagicMock()) + svc.xvb_client.get_recent_wins.return_value = {"wins": [], "round_stats": {}} + await svc._sync_xvb_winners() + svc._last_xvb_winners_sync -= wait + await svc._sync_xvb_winners() + return svc.xvb_client.get_recent_wins.call_count + + +async def test_a_far_future_row_does_not_hide_a_fresh_win(): + now = time.time() + wins = [{"ts": now - 600}, {"ts": now + 86_400 * 365}] + assert await _fetches_after(wins, _XVB_WINNERS_SYNC_FAST_SEC + 1) == 2 + + +async def test_a_far_future_row_alone_keeps_the_baseline(): + wins = [{"ts": time.time() + 86_400 * 365}] + assert await _fetches_after(wins, _XVB_WINNERS_SYNC_FAST_SEC + 1) == 1 From 72751766c5482507a40faff6c8c7510508230f24 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <328836012+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 27 Nov 2026 17:28:14 -0600 Subject: [PATCH 07/51] Mount the Tari config folder read-only and render config.toml in a private folder Source: #4579 Co-Authored-By: Claude Opus 5.5 --- .gitignore | 1 + docker-compose.yml | 8 +-- lib/pithead/34-inject-service-configs.sh | 29 ++++---- lib/pithead/36-quadlet-units.sh | 2 +- os/quadlet/local/tari.container | 2 +- os/quadlet/payout/tari.container | 2 +- tests/stack/lib/verdict-label-determinism.sh | 1 + tests/stack/run.sh | 6 +- tests/stack/standalone/test_compose.sh | 2 +- tests/stack/test-tari-config-render.sh | 75 ++++++++++++++++++++ 10 files changed, 98 insertions(+), 30 deletions(-) create mode 100644 tests/stack/test-tari-config-render.sh diff --git a/.gitignore b/.gitignore index 7545ee50ea..5a4d295e53 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,7 @@ config.json.bak-control /pithead /.pithead.bundle.* /data/ +/build/.tari-render.* /build/monero/bitmonero.conf /build/tari/config.toml Caddyfile diff --git a/docker-compose.yml b/docker-compose.yml index 441b81b052..4a3bddd742 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -285,15 +285,9 @@ services: - /tmp:size=64m,mode=1777 volumes: - ${TARI_DATA_DIR}:/var/tari/node - - ./build/tari:/var/tari/config - # pithead's "LAN-only source rule is live" marker (#2749), as for monerod. + - ./build/tari:/var/tari/config:ro - ./data/lan-guard:/lan-guard:ro - # Read-only view of the shared clearnet-state dir (#234): the wrapper entrypoint reads the - # dashboard-written "sync complete" marker to decide clearnet-vs-Tor at startup. - ${CLEARNET_STATE_DIR:-./data/clearnet-state}:/clearnet-state:ro - # Pithead wrapper (#183/#234): renders the runtime config (clearnet-vs-Tor, marker-gated) from - # pithead's canonical Tor config, then runs and supervises minotari_node, rewinding a database - # left on the dead 5.3.1 branch past the 350,000 fork first (#2618). entrypoint: - /var/tari/config/entrypoint.sh command: diff --git a/lib/pithead/34-inject-service-configs.sh b/lib/pithead/34-inject-service-configs.sh index adbccbac36..7b913929c1 100644 --- a/lib/pithead/34-inject-service-configs.sh +++ b/lib/pithead/34-inject-service-configs.sh @@ -1,22 +1,19 @@ inject_service_configs() { log "Injecting service configurations..." - cp build/tari/config.toml.template build/tari/config.toml - local tari_onion_short="${TARI_ONION%%.*}" - safe_sed "s//$tari_onion_short/g" build/tari/config.toml - # Rebase the Tor SOCKS IP onto the configured subnet prefix (#180): a no-op at the - # default 172.28.0, rewrites the .25 Tor IP when network.subnet has been moved. - safe_sed "s/172\.28\.0/$NETWORK_PREFIX/g" build/tari/config.toml + local tari_onion_short="${TARI_ONION%%.*}" tari_tmp + if tari_tmp=$(mktemp -d build/.tari-render.XXXXXX); then + cp -P -- build/tari/config.toml.template "$tari_tmp/config.toml" && [ ! -L "$tari_tmp/config.toml" ] && + chmod 644 "$tari_tmp/config.toml" && + safe_sed "s//$tari_onion_short/g" "$tari_tmp/config.toml" && + safe_sed "s/172\.28\.0/$NETWORK_PREFIX/g" "$tari_tmp/config.toml" && + mv -fT -- "$tari_tmp/config.toml" build/tari/config.toml || + warn "Could not render build/tari/config.toml from its template; the file was left as it was." + rm -f "$tari_tmp/config.toml" + rmdir "$tari_tmp" 2>/dev/null || true + else + warn "Could not create a render folder in build/; build/tari/config.toml was left as it was." + fi - # config.toml is always rendered for Tor (onion, socks5 transport through Tor) — the CANONICAL - # config. The optional clearnet initial sync (#183) is applied per-start inside the container by - # build/tari/entrypoint.sh (which copies this file and transforms the copy), gated on the - # TARI_CLEARNET_SYNC flag AND the dashboard's auto-transition marker (#234) — so once synced the - # node returns to Tor on its own and `apply` never re-renders clearnet over it. Same idea for - # monerod, whose entrypoint envsubsts + transforms in-container. Here we only re-arm: - - # Re-arm clearnet auto-sync (#234): clear a chain's "sync complete" marker whenever its flag is - # OFF, so re-enabling later starts a fresh clearnet sync. While a flag is ON, leave the marker - # and its host-owned attestation in place. A firewall toggle must not re-arm a completed sync. local _csdir _cdir _csdir=$(clearnet_state_dir) _cdir=$(env_get CONTROL_DIR 2>/dev/null) diff --git a/lib/pithead/36-quadlet-units.sh b/lib/pithead/36-quadlet-units.sh index 610eeb7830..5a54a29f61 100644 --- a/lib/pithead/36-quadlet-units.sh +++ b/lib/pithead/36-quadlet-units.sh @@ -121,7 +121,7 @@ Environment=WAIT_FOR_TOR=1 $(_qenvq TARI_CLEARNET_SYNC) Entrypoint=/var/tari/config/entrypoint.sh Exec=--disable-splash-screen --non-interactive Volume=$(_qenv TARI_DATA_DIR):/var/tari/node -Volume=$(_qenv QUADLET_HOST_CONFIG_DIR)/build/tari:/var/tari/config +Volume=$(_qenv QUADLET_HOST_CONFIG_DIR)/build/tari:/var/tari/config:ro Volume=$(_qenv CLEARNET_STATE_DIR):/clearnet-state:ro Tmpfs=/tmp:size=64m,mode=1777 PublishPort=$(_qenv TARI_GRPC_BIND):18142:18142 diff --git a/os/quadlet/local/tari.container b/os/quadlet/local/tari.container index d4e74d0d13..64990a08da 100644 --- a/os/quadlet/local/tari.container +++ b/os/quadlet/local/tari.container @@ -13,7 +13,7 @@ Environment=WAIT_FOR_TOR=1 "TARI_CLEARNET_SYNC=false" Entrypoint=/var/tari/config/entrypoint.sh Exec=--disable-splash-screen --non-interactive Volume=/opt/pithead/data/tari:/var/tari/node -Volume=/home/pithead/build/tari:/var/tari/config +Volume=/home/pithead/build/tari:/var/tari/config:ro Volume=/opt/pithead/data/clearnet-state:/clearnet-state:ro Tmpfs=/tmp:size=64m,mode=1777 PublishPort=127.0.0.1:18142:18142 diff --git a/os/quadlet/payout/tari.container b/os/quadlet/payout/tari.container index d4e74d0d13..64990a08da 100644 --- a/os/quadlet/payout/tari.container +++ b/os/quadlet/payout/tari.container @@ -13,7 +13,7 @@ Environment=WAIT_FOR_TOR=1 "TARI_CLEARNET_SYNC=false" Entrypoint=/var/tari/config/entrypoint.sh Exec=--disable-splash-screen --non-interactive Volume=/opt/pithead/data/tari:/var/tari/node -Volume=/home/pithead/build/tari:/var/tari/config +Volume=/home/pithead/build/tari:/var/tari/config:ro Volume=/opt/pithead/data/clearnet-state:/clearnet-state:ro Tmpfs=/tmp:size=64m,mode=1777 PublishPort=127.0.0.1:18142:18142 diff --git a/tests/stack/lib/verdict-label-determinism.sh b/tests/stack/lib/verdict-label-determinism.sh index 8f362a204c..0a0be8f691 100644 --- a/tests/stack/lib/verdict-label-determinism.sh +++ b/tests/stack/lib/verdict-label-determinism.sh @@ -183,6 +183,7 @@ test-spool-audit.sh|audit_size test-spool-audit.sh|entry test-suite-blocks.sh|1 test-suite-blocks.sh|arg +test-tari-config-render.sh|1 test-tor-network.sh|v test-tor-port-validation.sh|invalid_port test-unit-helpers.sh|t_human diff --git a/tests/stack/run.sh b/tests/stack/run.sh index b7e5ac1735..42c500757d 100755 --- a/tests/stack/run.sh +++ b/tests/stack/run.sh @@ -18,11 +18,9 @@ if ! _audit=$(stack_blocks_audit "$HERE/run.sh" "$ROOT/.github/workflows/shell.y printf 'run.sh: the block layout is broken (#2631):\n%s\n' "$_audit" >&2 exit 2 fi -# The full run's tally file, handed down by the loop below. Taken and unset at once, so a fragment -# that starts run.sh itself cannot append to it. _tally="${STACK_TALLY:-}" unset STACK_TALLY -stack_verdict() { #