From 8918986433b3dae563e23f31e1b920e63333413d Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Wed, 2 Dec 2026 23:35:08 -0600 Subject: [PATCH 1/4] =?UTF-8?q?lan-guard:=20fix=20#4598=20=E2=80=94=20a=20?= =?UTF-8?q?stopped=20loopback=20node=20no=20longer=20installs=20the=20boot?= =?UTF-8?q?=20check?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit lan_guard_watched_ports watched a fixed port whenever the engine read for a node container failed or came back empty, which is exactly what every stopped container answers after a reboot. The appliance therefore installed pithead-lan.timer at boot and the same function took it down minutes later once Compose converged: churn, a false "checked every 2 minutes" promise, and no protection because the read-back was empty either way. The read-back now wins when it says something, and a successful empty read-back publishes nothing. A failed read-back asks the engine whether the container is running: stopped means not watched, running or unreadable stays watched, and an unreadable container list still watches all fixed ports. The two-minute check is installed only when the render installs it, and a configured LAN bind is watched with every node stopped, so #3290 crash recovery and the switch-off teardown keep their behavior. Co-Authored-By: Claude Code --- docs/dev/file-budget.tsv | 1 + lib/pithead/02b-lan-guard.sh | 24 ++++++++++++++---------- tests/stack/firewall/lan-guard-check.sh | 17 +++++++++++++++++ 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/docs/dev/file-budget.tsv b/docs/dev/file-budget.tsv index acecffcf31..c945a98593 100644 --- a/docs/dev/file-budget.tsv +++ b/docs/dev/file-budget.tsv @@ -46,6 +46,7 @@ dashboard/tests/web/test_worker_detail_meta.py 425 dashboard/tests/web/views/test_infra_views.py 580 dashboard/tests/web/views/test_views.py 750 docs/tools/recovery-config-builder.html 424 +lib/pithead/02b-lan-guard.sh 403 lib/pithead/12-firstboot-wizard.sh 476 lib/pithead/14-local-miner.sh 414 lib/pithead/21-doctor-stack-checks.sh 413 diff --git a/lib/pithead/02b-lan-guard.sh b/lib/pithead/02b-lan-guard.sh index f3a7611cfb..861c8f7144 100644 --- a/lib/pithead/02b-lan-guard.sh +++ b/lib/pithead/02b-lan-guard.sh @@ -67,24 +67,28 @@ lan_guard_published() { # Include ports still published by running containers after .env changed but Compose did not # converge. If the engine cannot be read, watch all fixed ports rather than dropping the timer. lan_guard_watched_ports() { - local kp p c containers name bind + local kp p c containers name bind running watch for kp in $LAN_GUARD_BINDS; do p=${kp#*:} c=$(lan_guard_container "$p") case "$(env_get "${kp%%:*}" 2>/dev/null)" in '' | 127.0.0.1) - containers=$(docker ps -a --filter label=com.docker.compose.project=pithead --filter "label=com.docker.compose.service=$c" --format '{{.Names}}' 2>/dev/null) || { - printf '%s\n' "$p" - continue - } + watch=0 + containers=$(docker ps -a --filter label=com.docker.compose.project=pithead --filter "label=com.docker.compose.service=$c" --format '{{.Names}}' 2>/dev/null) || watch=1 while IFS= read -r name; do [ -n "$name" ] || continue - bind=$(docker port "$name" "$p/tcp" 2>/dev/null) || break - [ -n "$bind" ] || break - grep -qv '^127\.0\.0\.1:' <<<"$bind" && break + bind=$(docker port "$name" "$p/tcp" 2>/dev/null) || { + running=$(docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null) || true + [ "$running" = false ] || watch=1 + continue + } + [ -n "$bind" ] && grep -qv '^127\.0\.0\.1:' <<<"$bind" && { + watch=1 + break + } done <<<"$containers" - [ -n "$name" ] || continue - [ -n "$bind" ] && ! grep -qv '^127\.0\.0\.1:' <<<"$bind" && continue + [ "$watch" = 1 ] && printf '%s\n' "$p" + continue ;; esac printf '%s\n' "$p" diff --git a/tests/stack/firewall/lan-guard-check.sh b/tests/stack/firewall/lan-guard-check.sh index d24c388c35..000d0bbca7 100644 --- a/tests/stack/firewall/lan-guard-check.sh +++ b/tests/stack/firewall/lan-guard-check.sh @@ -55,6 +55,23 @@ assert_eq "a stale stopped LAN publish keeps the timer after .env switches off" assert_eq "the check watches the stopped container's old port" "$(lg "$lg_stale lan_guard_watched_ports")" 18142 lg_prefixed='docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo 123456789abc_tari; return 0 ;; port) echo 0.0.0.0:18142 ;; stop) echo "$2" >>"$LG_STOP" ;; esac; };' assert_eq "a Compose recreate name keeps the old port watched after switch-off" "$(lg "$lg_prefixed lan_guard_watched_ports")" 18142 +lg_stopped='docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) return 1 ;; inspect) echo false ;; esac; };' +assert_eq "a stopped loopback node publishes nothing and is not watched (#4598)" "$(lg "$lg_stopped lan_guard_watched_ports")" "" +assert_eq "a stopped node read back with no binding publishes nothing (#4598)" \ + "$(lg 'docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) ;; esac; }; lan_guard_watched_ports')" "" +assert_eq "a running node with an unreadable bind stays watched (#4598)" \ + "$(lg 'docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) return 1 ;; inspect) echo true ;; esac; }; lan_guard_watched_ports')" 18142 +assert_eq "a stopped node cannot hide a published engine read-back (#4598)" \ + "$(lg 'docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) echo 0.0.0.0:18142 ;; inspect) echo false ;; esac; }; lan_guard_watched_ports')" 18142 +lg_timer_out="$(lg "$lg_stopped provision_lan_guard_check_units")" +assert_eq "stopped loopback nodes take the already-installed timer down (#4598)" "$(test -e "$LGD/units/pithead-lan.timer" && echo present)" "" +assert_eq "the boot render never promises a check it did not install (#4598)" "$(printf '%s' "$lg_timer_out" | grep -c "checked every 2 minutes" || true)" "0" +printf 'TARI_GRPC_BIND=0.0.0.0\n' >"$LGD/.env" +assert_eq "a configured LAN bind is watched with every node stopped (#4598)" "$(lg "$lg_stopped lan_guard_watched_ports")" 18142 +lg_timer_out="$(lg "$lg_stopped provision_lan_guard_check_units")" +assert_eq "a configured LAN bind installs the timer while stopped (#4598)" "$(test -e "$LGD/units/pithead-lan.timer" && echo present)" present +assert_contains "the install names the two-minute check (#4598)" "$lg_timer_out" "checked every 2 minutes" +printf 'TARI_GRPC_BIND=127.0.0.1\n' >"$LGD/.env" printf 'MONERO_RPC_BIND=0.0.0.0\nTARI_GRPC_BIND=127.0.0.1\n' >"$LGD/.env.new" assert_eq "transition protects the new bind and the old container publish" "$(lg "$lg_stale lan_guard_transition_ports '$LGD/.env.new'")" $'18142\n18081' lg_apply="$(run_sourced "$LGD" declare -f apply)" From 3b03392fa86841393152b825096fd8cdc0c6e357 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:18:29 -0600 Subject: [PATCH 2/4] =?UTF-8?q?lan-guard:=20docs=20for=20#4598=20=E2=80=94?= =?UTF-8?q?=20the=20boot=20timer=20is=20installed=20only=20on=20a=20real?= =?UTF-8?q?=20exposure?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The configuration prose said the check "also runs on the appliance after pithead up" and that a port published "by a node container" keeps the timer. Neither was what the appliance now does: the boot render decides with the same read-back rules the check uses, so a loopback-only box installs nothing and never mentions the two-minute check, and a stopped container that publishes nothing no longer keeps the timer on a Docker install either. Co-Authored-By: Claude Code --- CHANGELOG.md | 4 ++++ docs/configuration.md | 9 +++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 17c83dfad8..d61aad6d11 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,10 @@ per the process in [`docs/dev/releasing.md`](docs/dev/releasing.md). - The egress panel no longer calls Caddy firewalled. Caddy runs on the host network, so the container egress fence never covered it; its per-service posture now says so, like the host-networked dashboard's already did (#4197). +- A loopback-only appliance no longer installs `pithead-lan.timer` at boot only to remove it minutes + later: a stopped node container that publishes nothing is no longer watched, a failed read of a + running container still is, a configured LAN bind stays watched with every node stopped, and boot + mentions the two-minute check only when it actually installed it (#4598). ### Security diff --git a/docs/configuration.md b/docs/configuration.md index 0c4ecb6fc6..ee1a814e74 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -361,7 +361,9 @@ the rule is live but the guard is not enabled. `pithead` removes both units when runs `pithead up`, which installs the rule first. `pithead-lan.timer` checks the live rule every two minutes while any LAN port is configured or -still published by a node container. A failed `apply` that leaves an old LAN bind running keeps the +still published by a running node container; a node that is stopped and publishes nothing — what +every stopped container answers after a reboot — does not keep the check, and a container whose +publish cannot be read stays watched unless the engine reports it stopped (#4598). A failed `apply` that leaves an old LAN bind running keeps the timer. `apply` guards the ports in the new configuration and any still published by old containers before committing a new `.env`; the old port stays guarded until Compose replaces the container. If an external firewall reload removes the rule or its jump, the check deletes the node @@ -371,7 +373,10 @@ restore the rule for all three fixed node ports, but keeps the marker invalid an the node stop is verified. An existing connection can survive a restored rule. When Docker can stop the nodes, the ports close by the next check; a start outside `pithead` then fails the marker gate. Fix the firewall and run `./pithead up` to restore the rule -and restart the nodes. This check also runs on the appliance after `pithead up`. +and restart the nodes. On the appliance the same decision is made at boot: the check is installed +only when a LAN port is configured or published, so a loopback-only appliance never installs and +then removes it, and its boot only mentions the two-minute check when the check was installed +(#4598). Turning a `*_lan_access` switch on changes how a crashed node comes back on the Docker install: Docker itself no longer restarts `monerod` or `tari`. Instead the same `pithead-lan.timer` check From 2e15d09fde3f2dee99b905b37c4ade827dc24e07 Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Thu, 3 Dec 2026 00:18:49 -0600 Subject: [PATCH 3/4] =?UTF-8?q?tor:=20fix=20#4263=20=E2=80=94=20enforce=20?= =?UTF-8?q?the=200.4.9.17=20floor=20and=20keep=20the=2064=20pending=20cap?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Upstream Tor developers advise against raising MaxClientCircuitsPending: a client in trouble pushes twice as many circuit builds into a network that is already stressed. Review the whole dial budget against that advice and record the decision: keep 64. Raising it amplifies exactly the failure the wedges showed, the 32 default does not fit the current budget (monerod's default 24 plus the Tari and P2Pool dials dial about 44 at boot), and an adaptive cap would rise when the network is least able to take it. Capping Tari's simultaneous outbound dials waits for the diagnostics measurement of what fills the pending queue during a wedge; the operations doc now carries that reasoning and the out_peers row points at it. Enforce the version half. The tor image build now refuses a pin below the 0.4.9.17 floor before apk runs, the daily bump tool reads the floor from the Dockerfile and refuses a pin below it (and refuses every pin when the floor line is malformed), and the support bundle's tor/control.txt asks GETINFO version, so the floor an appliance runs is auditable from a bundle instead of inferred from the pin. Co-Authored-By: Claude Code --- CHANGELOG.md | 1 + build/tor/Dockerfile | 4 ++- docs/configuration.md | 2 +- docs/operations.md | 16 ++++++++- lib/pithead/07c-support-bundle-snapshots.sh | 2 +- scripts/watch/tor-bump.sh | 33 +++++++++++++++++++ .../control/test-support-bundle-snapshots.sh | 3 ++ tests/stack/test-harness-tooling.sh | 5 +++ 8 files changed, 62 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d61aad6d11..2021a146d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ per the process in [`docs/dev/releasing.md`](docs/dev/releasing.md). - The **Stack Topology & Egress** panel shows the host's own traffic: a scope pill, host-OS nodes for time sync, OS and release fetches and image pulls, a warning when the host audit counted flows outside the allowlist, and a not-observed notice when the audit table is not loaded. `GET /api/system/egress-audit` and `egress_audit` in `/api/state` expose the counters (#4415, #4416, #4417). - With `tor.auto_heal`, a Tor stuck at 95% bootstrap with no circuit and an up guard (a relay refusing circuit creation) is cured by a guard rotation (`DROPGUARDS`) on the NEWNYM budget instead of a refresh that keeps the guards, and the heal never restarts Tor after one (#4121). +- The Tor image now fails to build below the 0.4.9.17 version floor, the version-bump tool refuses a pin below it, and the support bundle's `tor/control.txt` reports the running Tor version, so the floor is auditable from a bundle; the pending-circuit budget behind `MaxClientCircuitsPending 64` is documented and kept (#4263). ### Fixed diff --git a/build/tor/Dockerfile b/build/tor/Dockerfile index 1901d30064..4c4faf8ce4 100644 --- a/build/tor/Dockerfile +++ b/build/tor/Dockerfile @@ -3,7 +3,9 @@ FROM alpine:3.24@sha256:f59abe656b692d901e184be3445e084786602108599d2a51d229c0f5a48c71bf ARG TOR_VERSION=0.4.9.17-r0 -RUN apk add --no-cache --upgrade libcrypto3 libssl3 musl musl-utils "tor=${TOR_VERSION}" netcat-openbsd \ +ARG TOR_MIN_VERSION=0.4.9.17 +RUN [ "$(printf '%s\n%s\n' "${TOR_VERSION%-r*}" "$TOR_MIN_VERSION" | sort -V | head -1)" = "$TOR_MIN_VERSION" ] \ + && apk add --no-cache --upgrade libcrypto3 libssl3 musl musl-utils "tor=${TOR_VERSION}" netcat-openbsd \ && tor --version | grep -F "Tor version ${TOR_VERSION%-r*}." COPY torrc.template /etc/tor/torrc.template diff --git a/docs/configuration.md b/docs/configuration.md index ee1a814e74..6190737807 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -279,7 +279,7 @@ the desired value is not presented as proof of what the still-running services u | `dashboard.hashrate_drop_minutes` | `10` | How many minutes the hashrate must stay below the threshold before the drop is reported — the debounce that keeps a brief blip from pinging you. | | **Advanced** | | _Tune storage, memory, networking, Tor, and update behavior._ | | `monero.prep_blocks_threads` | `auto` | Block-verification threads during sync. `auto` = host cores − 2, clamped to 4–8. | -| `monero.out_peers` | `24` | monerod's outbound peer target (8–1024). Over Tor each outbound peer is roughly one long-lived circuit, so this is the main steady-state lever on Tor's CPU (#595). The default is sized against the Tor container's `MaxClientCircuitsPending 64` (#4078): 24 monerod dials plus Tari and P2Pool onion dials (budgeted at about 20) leave about 20 pending circuits of headroom at boot, where the former 48 plus those dials needed about 68 against Tor's default of 32. The headroom is gone at 44; an existing `config.json` that sets `48` keeps it and no longer has any, so lower it to 24. The clearnet initial sync (#183) uses 32. | +| `monero.out_peers` | `24` | monerod's outbound peer target (8–1024). Over Tor each outbound peer is roughly one long-lived circuit, so this is the main steady-state lever on Tor's CPU (#595). The default is sized against the Tor container's `MaxClientCircuitsPending 64` (#4078): 24 monerod dials plus Tari and P2Pool onion dials (budgeted at about 20) leave about 20 pending circuits of headroom at boot, where the former 48 plus those dials needed about 68 against Tor's default of 32. The headroom is gone at 44; an existing `config.json` that sets `48` keeps it and no longer has any, so lower it to 24. The clearnet initial sync (#183) uses 32. The #4263 review checked the 64 cap against upstream advice and kept it; the pending-circuit budget in [Operations](operations.md) records the reasoning. | | `monero.data_dir` | `auto` | Where the Monero blockchain lives on the host. `auto` = `./data/monero`. Point this at an existing `.bitmonero` directory to reuse a synced node. See [Reusing an existing node](#reusing-an-existing-node). | | `monero.mem_limit` | `auto` | Upper limit on the monerod container's memory, so a leak/runaway OOM-restarts monerod alone instead of the host's OOM-killer picking a victim. `auto` is a generous ceiling (6 GB) that won't trip during normal operation or initial sync. monerod's OOM-triggering memory is small (~0.1 GiB at rest, ~1–3 GiB during sync) while its multi-GB blockchain DB is reclaimable, memory-mapped page cache that the kernel evicts under pressure rather than OOM-killing. Lower it only to free RAM. Raise it for a full (unpruned) node doing a heavy initial sync on a fast disk, or if a low-RAM host ever OOMs monerod during IBD (it restarts and resumes; the on-disk chain is transactional, no data loss). Accepts any Docker memory value, e.g. `"8g"`. (Tari has its own `tari.mem_limit`; the dashboard, P2Pool, Tor, and the proxies carry fixed ceilings in `docker-compose.yml`. P2Pool's is 4 GB, so it can hold its RandomX dataset when the HugePages reservation is short.) | | `tari.data_dir` | `auto` | Where the Tari node data lives on the host. `auto` = `./data/tari`. Unused with `tari.mode: remote` or `off` — no local node runs, and `setup`/`doctor` drop Tari's 200 GiB from this host's disk budget. Switching to `off` does not delete it, so switching back resumes from the chain already there. See [Hardware › Running a node elsewhere](hardware.md#running-a-node-elsewhere). | diff --git a/docs/operations.md b/docs/operations.md index c9dfe81fd6..e08e255fa8 100644 --- a/docs/operations.md +++ b/docs/operations.md @@ -29,7 +29,7 @@ separately, [below](#appliance-only-commands). | `./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 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 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, version, 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`. | | `./pithead version` | Print the installed stack version on one line (also `-V` / `--version`). Offline; no update check. `doctor` repeats it in its header. | @@ -1019,6 +1019,20 @@ Docker restart) opens a fresh outage window and resets the clock, budget and coo restarts more often than every 5 minutes never reaches an action or the warning. DIY installs stay opt-in; appliances enable `tor.auto_heal` when the key is absent. A confirmed state reset sends one alert per outage explaining the circuit state and guard reset. +**The pending-circuit cap stays at 64 (#4263).** It is the Tor half of the #4088 dial budget: monerod's default +24 outbound peers plus Tari and P2Pool onion dials budgeted at about 20 leave roughly 20 pending circuits of +headroom at boot, sized in `monero.out_peers` in [Configuration](configuration.md). Upstream Tor developers +advise against raising the cap: a client in trouble then pushes twice as many circuit builds into a network that +is already stressed. Pithead neither raises it above 64 nor returns it to the 32 default — the current defaults +dial about 44 at boot, so the 32 cap does not fit the budget before any peer is connected — and an adaptive cap +would rise exactly when the network is stressed, which is the failure upstream warns about. The wedges of +2026-11-19 happened with the new cap in place: the budget lowers wedge frequency, a cap does not cure a wedge, +and recovery stays the auto-heal's job above. Revisiting the number — including capping Tari's simultaneous +outbound dials when HSDir lookups dominate — waits for the diagnostics measurement of what fills the pending +queue during a wedge; the support bundle's `tor/control.txt` carries `status/circuit-established`, the circuit +list and, since #4263, the Tor version, so the 0.4.9.17 floor is auditable from the bundle. The floor itself is +enforced when the image builds, and the pin bump tool refuses a version below it. + **Saturated Tor circuit history while chains stop advancing or egress stays down.** A completed bootstrap, a failed clearnet probe, or unavailable chain RPC alone cannot authorize a state reset. If Tor repeatedly reports invalid circuit build timing, run `./pithead tor-recover check`. A refused precondition diff --git a/lib/pithead/07c-support-bundle-snapshots.sh b/lib/pithead/07c-support-bundle-snapshots.sh index 8a0e4d2753..ae1d98c34b 100644 --- a/lib/pithead/07c-support-bundle-snapshots.sh +++ b/lib/pithead/07c-support-bundle-snapshots.sh @@ -163,7 +163,7 @@ def tor(datadir, addr): raise OSError("authentication refused: %s" % auth[-1]) out = [] for query in ("status/bootstrap-phase", "status/circuit-established", "status/enough-dir-info", - "entry-guards", "circuit-status"): + "entry-guards", "version", "circuit-status"): fh.write(("GETINFO %s\r\n" % query).encode()) fh.flush() out.extend(tor_reply(fh)) diff --git a/scripts/watch/tor-bump.sh b/scripts/watch/tor-bump.sh index 1fbcce7d74..3537d1f34f 100755 --- a/scripts/watch/tor-bump.sh +++ b/scripts/watch/tor-bump.sh @@ -5,6 +5,7 @@ ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" DOCKERFILE="${TOR_DOCKERFILE:-$ROOT/build/tor/Dockerfile}" ALPINE_BRANCH_RE='^[0-9]+\.[0-9]+$' VERSION_RE='^[0-9]+(\.[0-9]+)+-r[0-9]+$' +MIN_RE='^[0-9]+(\.[0-9]+)+$' alpine_branch() { local branch @@ -42,12 +43,28 @@ newer_than() { [ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | tail -1)" = "$1" ] } +min_pin() { + sed -n 's/^ARG TOR_MIN_VERSION=//p' "$DOCKERFILE" | head -1 +} + +below_floor() { + local floor + floor="$(min_pin)" + [ -n "$floor" ] || return 1 + [[ "$floor" =~ $MIN_RE ]] || return 0 + [ "$(printf '%s\n%s\n' "${1%-r*}" "$floor" | sort -V | head -1)" != "$floor" ] +} + apply_pin() { local version="$1" tmp [[ "$version" =~ $VERSION_RE ]] || { echo "refusing malformed version '$version'" >&2 return 1 } + if below_floor "$version"; then + echo "refusing $version: below the floor $(min_pin) in $DOCKERFILE" >&2 + return 1 + fi tmp="$(mktemp)" sed "s/^ARG TOR_VERSION=.*/ARG TOR_VERSION=${version}/" "$DOCKERFILE" >"$tmp" cat "$tmp" >"$DOCKERFILE" @@ -131,6 +148,22 @@ self_test() { $'FROM alpine:3.24@sha256:294b683cb724975bec92580e1e685676bd4b50bda910ddb8c51d4cabeaec77e6\nARG TOR_VERSION=0.4.9.18-r1\nRUN x "tor=${TOR_VERSION}"' check "apply_pin refuses a malformed version" "$(apply_pin '1; rm -rf /' 2>/dev/null && echo applied || echo refused)" refused check "refusal leaves the file untouched" "$(current_pin)" "0.4.9.18-r1" + printf 'FROM alpine:3.24@sha256:abc\nARG TOR_VERSION=0.4.9.17-r0\nARG TOR_MIN_VERSION=0.4.9.17\nRUN x "tor=${TOR_VERSION}"\n' >"$t/Dockerfile-floor" + check "apply_pin refuses a version below the Dockerfile floor (#4263)" \ + "$(DOCKERFILE="$t/Dockerfile-floor" apply_pin 0.4.9.16-r0 2>/dev/null && echo applied || echo refused)" refused + check "a refused floor violation leaves the pin untouched" \ + "$(DOCKERFILE="$t/Dockerfile-floor" current_pin)" "0.4.9.17-r0" + check "apply_pin accepts a revision bump at the floor (#4263)" \ + "$(DOCKERFILE="$t/Dockerfile-floor" apply_pin 0.4.9.17-r1 2>/dev/null && echo applied || echo refused)" applied + check "apply_pin accepts a version above the floor (#4263)" \ + "$(DOCKERFILE="$t/Dockerfile-floor" apply_pin 0.4.9.18-r1 2>/dev/null && echo applied || echo refused)" applied + check "the floor line survives a pin rewrite (#4263)" \ + "$(DOCKERFILE="$t/Dockerfile-floor" min_pin)" "0.4.9.17" + check "a malformed floor refuses every version (#4263)" "$( + sed 's/^ARG TOR_MIN_VERSION=.*/ARG TOR_MIN_VERSION=not-a-version/' "$t/Dockerfile-floor" >"$t/Dockerfile-badfloor" + DOCKERFILE="$t/Dockerfile-badfloor" apply_pin 0.4.9.18-r1 2>/dev/null && echo applied || echo refused + )" refused + DOCKERFILE="$t/Dockerfile" printf '[{"number":1,"headRefName":"bot/tor-0.4.9.18-r1","author":{"login":"app/github-actions"}},{"number":2,"headRefName":"bot/tor-0.4.9.17-r0","author":{"login":"github-actions[bot]"}},{"number":3,"headRefName":"bot/tor-9.9.9-r0","author":{"login":"github-actions"}},{"number":4,"headRefName":"bot/tor-8.8.8-r0","author":{"login":"app/dependabot"}},{"number":5,"headRefName":"bot/tor-7.7.7-r0","author":{"login":"some-human"}},{"number":6,"headRefName":"feature/tor-idea","author":{"login":"app/github-actions"}},{"number":7,"headRefName":null,"author":{"login":"app/github-actions"}}]' >"$t/prs.json" check "superseded keeps only the want head across all three author shapes" \ "$(superseded bot/tor-0.4.9.18-r1 <"$t/prs.json")" \ diff --git a/tests/stack/control/test-support-bundle-snapshots.sh b/tests/stack/control/test-support-bundle-snapshots.sh index 39e8691e8a..30821115db 100644 --- a/tests/stack/control/test-support-bundle-snapshots.sh +++ b/tests/stack/control/test-support-bundle-snapshots.sh @@ -49,6 +49,8 @@ while True: fh.write(b'250-status/bootstrap-phase=NOTICE BOOTSTRAP PROGRESS=100 TAG=done SUMMARY="Done"\r\n250 OK\r\n') elif line == "GETINFO entry-guards": fh.write(b"250+entry-guards=\r\n$AAAAAAAAAAAAAAAAAAAA~guardone up\r\n.\r\n250 OK\r\n") + elif line == "GETINFO version": + fh.write(b"250-version=Tor version 0.4.9.17 (git-stub)\r\n250 OK\r\n") elif line == "GETINFO circuit-status": fh.write(b"250+circuit-status=\r\n123 BUILT $AAAA~guardone,$BBBB~mid PURPOSE=HS_CLIENT_REND REND_QUERY=seededrendquery SOCKS_USERNAME=seededsocksuser\r\n.\r\n250 OK\r\n") else: @@ -240,6 +242,7 @@ assert_not_contains "the monerod login never reached a command line" "$(cat "$SN echo "== support bundle snapshots: Tor control state and the guard section, never a key ==" assert_contains "Tor bootstrap phase" "$(cat "$B/tor/control.txt")" "PROGRESS=100" assert_contains "Tor entry guards" "$(cat "$B/tor/control.txt")" "guardone" +assert_contains "Tor version for the floor review (#4263)" "$(cat "$B/tor/control.txt")" "version=Tor version 0.4.9.17" assert_contains "Tor circuit state" "$(cat "$B/tor/control.txt")" "BUILT" assert_contains "the state file's guard line is kept" "$(cat "$B/tor/state-guards.txt")" "nickname=guardone" assert_not_contains "a seeded key in the Tor state file is excluded" "$(cat "$B/tor/state-guards.txt")" "SEEDEDSTATEKEY" diff --git a/tests/stack/test-harness-tooling.sh b/tests/stack/test-harness-tooling.sh index 20bd4d8016..85e579bb72 100644 --- a/tests/stack/test-harness-tooling.sh +++ b/tests/stack/test-harness-tooling.sh @@ -161,6 +161,11 @@ echo "== unit: image builds pull base security fixes past the digest pin (#3923, for alpine_image in build/tor tests/integration/tor-client tests/netwatch; do assert_contains "alpine image build pulls the base's musl past the digest pin with the openssl libs (#3929)" "$(cat "$ROOT/$alpine_image/Dockerfile")" 'apk add --no-cache --upgrade libcrypto3 libssl3 musl musl-utils'; done assert_contains "tor image pins the apk tor package to an explicit version (#4125)" "$(cat "$ROOT/build/tor/Dockerfile")" '"tor=${TOR_VERSION}"' assert_contains "tor image build fails unless the installed tor reports the pinned version (#4125)" "$(cat "$ROOT/build/tor/Dockerfile")" 'tor --version | grep -F "Tor version ${TOR_VERSION%-r*}."' +assert_contains "tor image names the upstream version floor its build must not go below (#4263)" "$(cat "$ROOT/build/tor/Dockerfile")" 'ARG TOR_MIN_VERSION=0.4.9.17' +assert_contains "tor image build refuses a pin below the floor before apk runs (#4263)" "$(cat "$ROOT/build/tor/Dockerfile")" '"${TOR_VERSION%-r*}" "$TOR_MIN_VERSION" | sort -V' +assert_eq "the pinned tor version satisfies its own floor (#4263)" \ + "$(printf '%s\n%s\n' "$(sed -n 's/^ARG TOR_VERSION=//p' "$ROOT/build/tor/Dockerfile" | head -1 | sed 's/-r[0-9]*$//')" "$(sed -n 's/^ARG TOR_MIN_VERSION=//p' "$ROOT/build/tor/Dockerfile" | head -1)" | sort -V | head -1)" \ + "$(sed -n 's/^ARG TOR_MIN_VERSION=//p' "$ROOT/build/tor/Dockerfile" | head -1)" assert_contains "netwatch build pulls the base's zlib with the rest (#3929)" "$(cat "$ROOT/tests/netwatch/Dockerfile")" 'musl musl-utils zlib' for debian_image in dashboard os/rootfs; do assert_contains "debian image build lists zlib1g to pull its security build (#3923)" "$(cat "$ROOT/$debian_image/Dockerfile")" 'zlib1g'; done echo "== unit: patch-coverage overlap self-test (#1000) ==" From 9ea7385f90595803851568ea2485ac816012b8cb Mon Sep 17 00:00:00 2001 From: "pithead-developer[bot]" <4933481+pithead-developer[bot]@users.noreply.github.com> Date: Fri, 4 Dec 2026 02:34:13 -0600 Subject: [PATCH 4/4] =?UTF-8?q?lan-guard:=20fix=20#4598=20=E2=80=94=20a=20?= =?UTF-8?q?stopped=20container=20is=20judged=20by=20its=20configured=20bin?= =?UTF-8?q?d,=20not=20dropped?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- docs/configuration.md | 7 ++++--- docs/dev/file-budget.tsv | 2 +- lib/pithead/02b-lan-guard.sh | 7 +++---- lib/pithead/02c-lan-guard-check.sh | 5 +++++ tests/stack/firewall/lan-guard-check.sh | 4 +++- 5 files changed, 16 insertions(+), 9 deletions(-) diff --git a/docs/configuration.md b/docs/configuration.md index 6190737807..31303dfede 100644 --- a/docs/configuration.md +++ b/docs/configuration.md @@ -361,9 +361,10 @@ the rule is live but the guard is not enabled. `pithead` removes both units when runs `pithead up`, which installs the rule first. `pithead-lan.timer` checks the live rule every two minutes while any LAN port is configured or -still published by a running node container; a node that is stopped and publishes nothing — what -every stopped container answers after a reboot — does not keep the check, and a container whose -publish cannot be read stays watched unless the engine reports it stopped (#4598). A failed `apply` that leaves an old LAN bind running keeps the +still published by a node container. A stopped container is judged by the bind it was created with: +a loopback or empty bind does not keep the check — what every loopback-only node answers after a +reboot — while an all-interface bind does, and a running container whose publish cannot be read +stays watched (#4598). A failed `apply` that leaves an old LAN bind running keeps the timer. `apply` guards the ports in the new configuration and any still published by old containers before committing a new `.env`; the old port stays guarded until Compose replaces the container. If an external firewall reload removes the rule or its jump, the check deletes the node diff --git a/docs/dev/file-budget.tsv b/docs/dev/file-budget.tsv index c945a98593..73d7a2878c 100644 --- a/docs/dev/file-budget.tsv +++ b/docs/dev/file-budget.tsv @@ -46,7 +46,7 @@ dashboard/tests/web/test_worker_detail_meta.py 425 dashboard/tests/web/views/test_infra_views.py 580 dashboard/tests/web/views/test_views.py 750 docs/tools/recovery-config-builder.html 424 -lib/pithead/02b-lan-guard.sh 403 +lib/pithead/02b-lan-guard.sh 402 lib/pithead/12-firstboot-wizard.sh 476 lib/pithead/14-local-miner.sh 414 lib/pithead/21-doctor-stack-checks.sh 413 diff --git a/lib/pithead/02b-lan-guard.sh b/lib/pithead/02b-lan-guard.sh index 861c8f7144..c738457e04 100644 --- a/lib/pithead/02b-lan-guard.sh +++ b/lib/pithead/02b-lan-guard.sh @@ -67,7 +67,7 @@ lan_guard_published() { # Include ports still published by running containers after .env changed but Compose did not # converge. If the engine cannot be read, watch all fixed ports rather than dropping the timer. lan_guard_watched_ports() { - local kp p c containers name bind running watch + local kp p c containers name bind watch for kp in $LAN_GUARD_BINDS; do p=${kp#*:} c=$(lan_guard_container "$p") @@ -77,9 +77,8 @@ lan_guard_watched_ports() { containers=$(docker ps -a --filter label=com.docker.compose.project=pithead --filter "label=com.docker.compose.service=$c" --format '{{.Names}}' 2>/dev/null) || watch=1 while IFS= read -r name; do [ -n "$name" ] || continue - bind=$(docker port "$name" "$p/tcp" 2>/dev/null) || { - running=$(docker inspect -f '{{.State.Running}}' "$name" 2>/dev/null) || true - [ "$running" = false ] || watch=1 + bind=$(docker port "$name" "$p/tcp" 2>/dev/null) || bind=$(lan_guard_stopped_bind "$name" "$p") || { + watch=1 continue } [ -n "$bind" ] && grep -qv '^127\.0\.0\.1:' <<<"$bind" && { diff --git a/lib/pithead/02c-lan-guard-check.sh b/lib/pithead/02c-lan-guard-check.sh index 56fbd5c2e1..4db20ac4a7 100644 --- a/lib/pithead/02c-lan-guard-check.sh +++ b/lib/pithead/02c-lan-guard-check.sh @@ -133,3 +133,8 @@ lan_guard_check_now() { [ "$rc" = 0 ] || return "$rc" return 1 } + +lan_guard_stopped_bind() { + [ "$(docker inspect -f '{{.State.Running}}' "$1" 2>/dev/null)" = false ] || return 1 + docker inspect -f "{{range (index .HostConfig.PortBindings \"$2/tcp\")}}{{if .HostIp}}{{.HostIp}}{{else}}0.0.0.0{{end}}:{{.HostPort}}{{println}}{{end}}" "$1" 2>/dev/null +} diff --git a/tests/stack/firewall/lan-guard-check.sh b/tests/stack/firewall/lan-guard-check.sh index 000d0bbca7..9986449ed9 100644 --- a/tests/stack/firewall/lan-guard-check.sh +++ b/tests/stack/firewall/lan-guard-check.sh @@ -55,8 +55,10 @@ assert_eq "a stale stopped LAN publish keeps the timer after .env switches off" assert_eq "the check watches the stopped container's old port" "$(lg "$lg_stale lan_guard_watched_ports")" 18142 lg_prefixed='docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo 123456789abc_tari; return 0 ;; port) echo 0.0.0.0:18142 ;; stop) echo "$2" >>"$LG_STOP" ;; esac; };' assert_eq "a Compose recreate name keeps the old port watched after switch-off" "$(lg "$lg_prefixed lan_guard_watched_ports")" 18142 -lg_stopped='docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) return 1 ;; inspect) echo false ;; esac; };' +lg_stopped='docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) return 1 ;; inspect) case "$*" in *State.Running*) echo false ;; *) echo "${LG_BINDINGS-127.0.0.1:18142}" ;; esac ;; esac; };' assert_eq "a stopped loopback node publishes nothing and is not watched (#4598)" "$(lg "$lg_stopped lan_guard_watched_ports")" "" +assert_eq "a stopped node whose configured bind is all-interface stays watched (#4598)" "$(LG_BINDINGS=0.0.0.0:18142 lg "$lg_stopped lan_guard_watched_ports")" 18142 +assert_eq "a stopped node with no configured binding is not watched (#4598)" "$(LG_BINDINGS="" lg "$lg_stopped lan_guard_watched_ports")" "" assert_eq "a stopped node read back with no binding publishes nothing (#4598)" \ "$(lg 'docker() { case "$1" in ps) [[ " $* " == *"service=tari"* ]] && echo tari; return 0 ;; port) ;; esac; }; lan_guard_watched_ports')" "" assert_eq "a running node with an unreadable bind stays watched (#4598)" \