Skip to content

Rig Tor client: persistent state, runs as debian-tor, control socket, shared by updates, time and probes #4151

Open

Description

@pithead-developer

What's the problem

A rig has to reach Tor on its own: rigs are independent of Pithead, get their own time over Tor, and update over Tor. The only rig-side Tor is the on-demand helper os/overlay/pithead-tor (from #4040), whose backport to the 2.0.5 line is #4139. That helper was built for one job and does not fit the rest. This issue is the delta on top of #4139 and does not redo the backport or the update channel tracked in #4143.

  • It uses a throwaway DataDirectory, so every start is a cold bootstrap with fresh guards and no cached consensus. A cold start already needed a 300 s test budget.
  • It runs Tor as debian-tor only when started as root. As any other user, Tor runs as the caller's uid (the id -u branch in the script), so a firewall rule matching skuid debian-tor would not match it.
  • It exits 65 if the clock is behind the /etc/os-release mtime or past 2100, and nothing repairs the clock. A rig with a wrong clock can neither update nor fetch time.
  • It has no control channel, so a clock that is too far off (Tor logs CLOCK_SKEW and stalls) cannot be told apart from a slow network.
  • It exports ALL_PROXY=socks5h://..., which Go clients ignore. A Go-based fetcher on a rig would silently go direct.

What it impacts

Every RigForge rig on the appliance: remote OS update (tracker #4143), time over Tor, and any probe that must go through Tor. Without a client that the egress firewall can identify and that survives a bad clock, those paths either stay on the clearnet or fail with no way to recover.

How I found it

From the Tor-only egress research and plan (owner ruling 2026-11-16: rig Tor on demand with persistent state, running as debian-tor). I read os/overlay/pithead-tor on develop-v2.1.0 with git show: the exit-65 clock checks, the throwaway state directory, the root-only runuser -u debian-tor branch and the ALL_PROXY export. #4139 brings the same helper to the 2.0.5 line, so the change applies on top of it. Unknown: memory, CPU and start time of an on-demand client on rig hardware, whether rig boards have a usable RTC, and whether the Tor version on trixie keeps the roughly 24 h clock tolerance seen in a 2019 test on 0.4.1.

How important is it

High for 2.0.5. The rig update path in #4143 depends on it, and so does the rig time source (#4149 (step 5: time through Tor)) and the per-pool Tor stratum option in p2pool-starter-stack/rigforge (p2pool-starter-stack/rigforge#696 (rigforge defaults)). Small change in size, because it extends an existing helper.

Acceptance criteria

  • The helper keeps one entry point (pithead-tor COMMAND) and Tor stays up only while a command runs. There is no standing listener and no timer.
  • Tor state lives in a persistent DataDirectory on the stick, owned by debian-tor. A second start reuses the cached consensus and guards. AvoidDiskWrites is evaluated against stick wear and the decision is recorded.
  • Tor always runs as debian-tor, whoever calls the helper. A test shows the process uid and that a skuid debian-tor firewall rule matches it.
  • A control socket (not a TCP port) is enabled for the helper. A clock too far off is reported as a distinct failure naming CLOCK_SKEW, not as a timeout.
  • Updates, the rig's time client and probes all go through this one helper. None starts its own Tor.
  • The exit-65 clock check stays. When it fires, the rig says so plainly, never falls back to the clearnet, and the repair path (manual time entry on the rig, Get the clock through Tor onion services and remove NTP and the clearnet htpdate fallback #4149 (step 5: time through Tor)) is reachable.
  • Proxy settings set HTTPS_PROXY and HTTP_PROXY as well as ALL_PROXY, so Go clients cannot go direct.
  • The appliance: rig OS-update contract for self-fetch over Tor, and the on-demand Tor client in the image (#4007, #4008) #4040 contract (masked Tor units, no listener, no timers) and its KVM assertions are amended in the same change to match.
  • Bounded measurement on rig hardware (hours per arm, at most 24 h per run, no soak), cold versus warm start: time to bootstrap, peak memory and CPU, stick bytes written, and hashrate and stale shares during a fetch. The result decides whether always-on is worth revisiting.

Possible solutions

  • Extend the helper (recommended): persistent state, debian-tor, control socket, shared by all callers. Smallest change to code, tests and KVM assertions.
  • Always-on tor@default: simplest, but it reverses the on-demand contract and puts a standing listener on every rig. Only if the measurement shows a clear warm-start gain.
  • Timer-started Tor: brief windows only, but needs a timer, which the contract forbids today, and a missed run leaves the clock uncorrected.
  • Clock repair before Tor: the helper's own os-release mtime floor, plus the cached consensus time in the persistent state, raise a clock that is behind. A clock that is ahead has no automatic repair and needs manual entry.
  • Bridges: deferred; the config key is reserved in Harden the Tor container: SOCKS policy, SafeSocks, dedicated ports, no bridge control listener #4152 (step 7: Tor hardening).

Related: #4144 (tracker), #4143 (this step blocks its update path), #4139 (backport of the helper and hardened channel), #4013, #4140, #4141, #4142, p2pool-starter-stack/rigforge#668 (closed, tor_socks5 merged on develop, untagged), #4154 (step 9: enforce the firewall).

Activity

  1. added this to the v2.0.5 milestone on Nov 16, 2026
  2. added
    enhancement
    security
    appliance
    operator-action
    on Nov 16, 2026
  3. added
    blocked
    on Nov 16, 2026
  4. pithead-developer commented on Nov 16, 2026

    @pithead-developer
    ContributorAuthor

    Blocked on #4147.
    Blocked on #4139.

    Rig Tor client, released with steps 4 and 5 after step 3 (rollout order in #4144). It is a delta on top of the #4139 backport, so it also waits for that.

  5. removed
    operator-action
    on Nov 16, 2026
  6. pithead-architect commented on Nov 27, 2026

    @pithead-architect

    Owner decision (2026-11-27): moving to v2.0.6. The first remote-update slice for USB stick rigs in 2.0.5 works on the Tor client already backported in #4139; this hardening is not needed for a working update.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    applianceblockedenhancementsecurity

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions