Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -28,6 +29,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

Expand Down
4 changes: 3 additions & 1 deletion build/tor/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 9 additions & 3 deletions docs/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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). |
Expand Down Expand Up @@ -361,7 +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 node container. 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
Expand All @@ -371,7 +374,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
Expand Down
1 change: 1 addition & 0 deletions docs/dev/file-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -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 402
lib/pithead/12-firstboot-wizard.sh 476
lib/pithead/14-local-miner.sh 414
lib/pithead/21-doctor-stack-checks.sh 413
Expand Down
16 changes: 15 additions & 1 deletion docs/operations.md

Large diffs are not rendered by default.

23 changes: 13 additions & 10 deletions lib/pithead/02b-lan-guard.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,27 @@ 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 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) || bind=$(lan_guard_stopped_bind "$name" "$p") || {
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"
Expand Down
5 changes: 5 additions & 0 deletions lib/pithead/02c-lan-guard-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion lib/pithead/07c-support-bundle-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
33 changes: 33 additions & 0 deletions scripts/watch/tor-bump.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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")" \
Expand Down
3 changes: 3 additions & 0 deletions tests/stack/control/test-support-bundle-snapshots.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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"
Expand Down
19 changes: 19 additions & 0 deletions tests/stack/firewall/lan-guard-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,25 @@ 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) 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)" \
"$(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)"
Expand Down
Loading
Loading