Two contracts that are easy to break from either side, and did break repeatedly during hardware validation: who decides which step the operator is on, and which certificate the machine presents. Both are written down here because the failures they produce look like something else entirely — a crash, a hang, a dead page.
The setup flow itself is in appliance.md; building and releasing images
is in appliance-release.md.
| Piece | Where | Job |
|---|---|---|
| host loop | pithead firstboot-wizard |
mints the token and certificate, runs the container, consumes the spool, provisions |
| server | mining_dashboard/wizard/server.py |
token gate, /api/wizard-state, spool writes. Renders no HTML |
| client | web/static/wizard/wizard.mjs |
preact/htm views on the dashboard's stack |
| shared logic | web/static/config/configsync.mjs |
path access, typed coercion, address/pair guidance — also used by the dashboard's config tab |
| spool | /data/pithead/data/firstboot |
the only channel between container and host |
The split is deliberate: the container asks, the host decides. Every privileged action — validation, disk installs, provisioning — happens host-side, the same trust shape as the #33 control channel. A compromised container can write the spool and nothing more.
Failed tokens are counted per direct peer address from request.remote; forwarded-address
headers do not select the bucket. Entries below the threshold expire 60 seconds after their
latest failure. The fifth failure starts a fixed 60-second cooldown and returns 429 with
Retry-After; blocked requests do not extend it, and even the correct token must wait. The
wizard keeps running and keeps the same token, so the browser tells that peer when to retry it
instead of asking for a replacement. Successful authentication clears only that
peer's failures and creates its session. Existing authenticated cookies retain access,
including for operators sharing the blocked peer. The failure map holds at most 1,024 peers and
evicts the entry it began tracking first when full, even if that peer is still in cooldown. Guessing is bounded per peer (five tries a minute), not globally, and the token does not rotate, so several peers multiply the rate; the six-character token holds about 29.7 bits. A network failure is reported separately from throttling.
wizard_stage() in wizard/server.py derives the step from spool files only, and the client
renders what it is told. The client must never infer the stage.
/status exposes coarse progress without authentication. Stored error.txt details require
the current wizard session; anonymous failed or rejected states use generic text. Status
responses use Cache-Control: no-store, as does the authenticated /api/wizard-state payload.
| Stage | True when | View |
|---|---|---|
failed |
the installation medium has error.txt |
the failure reason and Back to the settings |
handoff |
handoff.json exists and handoff-ack does not |
credentials card |
installing |
installing or installed exists |
install progress, then the switch-off steps |
done |
applied or handoff-ack exists — but installing when the machine is the installation medium |
provisioning notice |
installer |
disks.tsv exists (host booted from removable media with a target) |
the COMBINED form: config + disk + reinstall choice |
setup |
none of the above | the config form |
Order matters twice. handoff outranks everything: applied is written first and the
credentials must win while they are still unsaved. And the ack means two different things —
on an installed machine it releases provisioning (done), on the installation medium it
releases the ERASE, so the same ack lands on installing and the switch-off steps.
The installation medium runs the whole flow on one page (config + disk + wipe mode in one submission, gated server-side), publishes the credentials card BEFORE anything touches the disk — the machine powers off after installing, so the page cannot deliver anything after — and stages an ordinary accepted config onto the target's ESP. A restore instead remains in root-owned volatile storage while the installer applies it directly to target data; first boot finishes either path headlessly, with no second wizard. A missing ack installs nothing: the erase waits for a human, and a timeout hands the form back intact.
The connection card includes a stratum password or explicit absence and, when enabled, the
TLS fingerprint. The password question defaults off in the CLI, JavaScript page and form-submit
fallback. The typed wizard stores an enabled password as a generated literal; existing "auto"
configurations retain their mode and rendered seed. A config-only installer restore publishes
only its validated stratum seed beside the private candidate, then removes that sidecar.
Before the card, the host resolves credentials once. Installed setup reuses or creates its stratum certificate in its final data directory. The installer retains a kept target's existing pair through a read-only mount, or creates one in the root-only volatile carry directory. After installation it copies that pair directly to target data, never to the ESP. The install request must still name the target and wipe choice whose identity the card showed. Cleanup removes the carry along with the existing restore credentials.
On a reinstall the form opens with the previous machine's answers. When the inventory holds
exactly one disk that already carries an install, the host mounts its data partition
read-only, reads the previous config.json, strips every secret
(strip_config_secrets — the login, worker inventory, node credentials, view keys, alert
tokens, the ssh key) and publishes the remainder through the same last-attempt.json channel
the pre-seed path fills; an operator pre-seed outranks it. Derived fresh each boot and cleared
first — a fleet stick's spool survives between machines, and machine 2 must never open on
machine 1's answers. Pure convenience: any failure (no config, unreadable, ambiguous targets)
opens the form blank and blocks nothing. On keep, none of it matters — the survivor config
wins and no config crosses.
Before a pre-fill reaches the form, the server moves the removed xmrig_proxy.* and
dashboard.workers[] names to xvb.* and workers.list[]. It then drops keys absent from the
current reference schema. The JSON pane refuses duplicate keys before updating the form.
The submit endpoint also refuses duplicates and case-insensitive PASTE_ / YOUR_ string
placeholders before normalization or staging, including in unknown keys. Refusals name the
key path without echoing values. The same preparation runs again on submit, so a hand-edited
JSON pane cannot put an obsolete or unknown name back into the host's candidate. Known keys keep their
values and types for the host parser to validate; the wizard never weakens that gate. The page
lists changed key paths without rendering their values.
An install error outranks a stale installing marker and survives a page refresh as failed.
The authenticated return action clears only the error and stale progress marker. The settings
come from the retained last-attempt.json; the disk and wipe choice return, but the typed disk
confirmation does not. Retype it before another destructive attempt. Passwords and payout
addresses stay in the config copy and are never included in the changed-path summary.
Why the server owns this. Two defects came from the client deciding:
- A client-side stage flag was set with
setStateand read back on the next line. Preact batches, so the read saw the old value and the credentials card could never render — for two releases. Server-owned stage removes the variable that could be stale. - A page refresh mid-provisioning was handed the setup form again, because the client had no way to know a config had already been accepted.
Rule for changes: any new step is a new spool file and a new wizard_stage() branch.
Never a client flag. /api/wizard-state carries the handoff payload inline for the same
reason — a separate fetch is a separate race.
The page's FIRST disclosure, above the disk, is what the machine IS. One select, reading exactly Pithead / Pithead + RigForge / RigForge, and everything downstream reshapes to the answer the same way the disk choice already reshapes the form:
| Role | The form | What lands |
|---|---|---|
| Pithead | today's flow, byte for byte — the regression bar | config.json (the whole contract above) |
| Pithead + RigForge | the default. Pithead's form, opening with the mine-on-this-machine switch already on. The role IS local_miner.enabled — the select and the switch are two views of ONE value, so moving either moves the other, and choosing Pithead submits today's config unchanged |
config.json with local_miner.enabled: true; the boot contract's step 5 starts the miner |
| RigForge | collapses to a pool address, a worker name and an optional stratum password. The pool field opens pre-filled when the host found a Pithead answering pithead.local:3333 — dialed HOST-side and published to the spool as rig-defaults.json, the way the disk inventory travels, failing open to an empty field. The disk section gains Run from this USB stick as a first-class target: a rig holds almost no state, so the stick can BE the system — no erase, no commitment on machines whose disks belong to something else. The card shows the worker name and where it points; a rig has no dashboard and no login |
machine-role + rig.json (below) |
Validation-before-erase, the card-then-ack gate, self-power-off and the headless first boot apply to every fresh install. On a disk holding an existing installation, keep preserves the survivor configuration and role. On a blank disk, keep is a fresh install: a pending rig submission must reach pool validation and its token-bearing card before installation. The bare keep-reinstall shortcut accepts neither a role marker nor a rig request, including an unusable request entry.
The rig submission travels on its own spool channel (rig-request.json; the server never
writes a config.json candidate for it), and the host dials the pool BEFORE anything
irreversible — the same discipline the wizard server gives remote nodes.
Before it stages a configuration, the wizard server asks every configured remote endpoint the
same protocol-level question its mining consumer needs (#1889). Monero RPC must answer
get_info, using the configured Digest login, and its ZMQ port must complete a ZMTP handshake
with a publication-capable peer.
A Tari base node must answer GetTipInfo over gRPC. The browser names those checks while they run.
Failure keeps the operator's complete form in last-attempt.json, removes any install request,
and returns the report as node_probe; nothing writes a config.json candidate.
The server resolves a name once, dials that vetted address and stores its numeric form in the
accepted candidate. Loopback, unspecified, link-local,
multicast and reserved addresses are refused, including names that resolve to one (#1946). With
the Tor egress firewall on, a name must answer with at least one address in the private LAN or VPN
IPv4 ranges the mining container can dial and with no public IPv4 at all; the lowest such address
is the one pinned. Other IPv6 answers (global or unique-local) are ignored rather than refused:
the firewall is an IPv4 allowlist and only the pinned address reaches the config, so a dual-stack
LAN name is accepted on its A record instead of sending the operator back to typing the literal
address (#2351). The host-side preflight a day-two configuration commit runs
(remote_node_address in lib/pithead/10-node-probe.sh) applies the same acceptance rule.
Credentials are used only for the RPC request and never enter the report.
| Field | Meaning |
|---|---|
ok |
the verdict, and the ONLY gate — true when every configured endpoint was probed and every probe passed |
configured |
endpoints the config asked for: a remote Monero node contributes 2 (RPC and ZMQ), a remote Tari node 1 |
probed |
rows actually produced; a skipped endpoint emits no row, so probed < configured is how the page names one |
probes[] |
{target, host, resolved_host, port, ok, checked, reason, detail, elapsed_ms} per endpoint |
reason is one of ok, protocol, timeout, refused, auth, address, dns, unusable,
missing-tool or unknown. Two do not mean the node is unreachable: auth means a node answered
but rejected the configured login, and legacy missing-tool reports that the machine could not
run its old check. A reason the page does not recognise reads as "the check did not complete" —
never as "not reached", because inventing a reachability claim for an unrecognised value is the
defect #1913 names.
checked says what was proved: rpc, zmq and grpc are live protocol checks. The renderer
still understands a legacy connect row, but qualifies it because any open socket can satisfy a
bare TCP dial.
An ABSENT report is not a failed one. A machine running its own nodes probes nothing and writes no
file, so node_probe is null there and on any host older than the report; the wizard reads the
verdict only when ok arrives as a real boolean, and a malformed file falls through to null the
way every other spool reader fails open.
nodeprobe.mjs renders it, and owns the operator's words for all nine reasons in one place: the
setup screen shows the report today, and the Configuration view's preview will show the same one
once the control channel carries a probe of its own, so a reason worded twice cannot come to mean
two things. Three rules in it are load-bearing rather than stylistic. A reason the module does not
recognise reads as "the check did not complete" and never as "not reached"; an invented
reachability claim would reintroduce the defect this fallback prevents. A missing-tool row drops
the host's own detail, which is the generic
reach sentence naming the operator's host, port and LAN switch — none of them at fault when the
check could not run at all. And the module renders no control: the gate is the wizard server's, so
a failed probe leaves the form editable and the submit button live, which is the only way out.
What the boot path reads, written by the host at the moment a role is accepted:
File (under /data/pithead) |
Meaning |
|---|---|
machine-role |
pithead, both or rig. Absent means pithead — every machine provisioned before this contract. The coordinator values are derivable from config.json (both IS local_miner.enabled); the rig value is load-bearing, because a rig has no config.json at all. |
rig.json |
rig role only: pool, worker, access_token and stratum_password when one was set. |
A rig install to a disk stages the accepted answers as pithead-rig.json on the ESP —
carried to the target by pithead-install beside the config and token pre-seeds — and the
installed machine's first boot lands them as the two files above, scrubbing the ESP copy the
way the config pre-seed is scrubbed. The stick keeps neither copy after a disk install: a
stick whose own /data carries the rig marker IS a rig (run-from-USB), and that marker
outranks installer mode on every later boot — except one chosen from the boot menu's Set up
again entry, which opens the wizard beside the role (below).
The stick mints the control token BEFORE the card (rig_access_token in firstboot_consume_rig,
above write_handoff_card), so the card the operator confirms on the stick already carries the
token the installed machine will enforce — the only place that token is ever shown. The landing
leg therefore requires a well-formed access_token in the staged file, alongside the pool it
already required, and treats a file without one as unusable. A refused file is then scrubbed
off the ESP exactly as a consumed one is (scrub_staged_rig, shared by both branches): it is
unusable by definition, it may still carry a stratum_password, and a VFAT ESP keeps no mode 600
to protect one. As with the consumed path and the config pre-seed, the scrub is skipped on
removable media — that stick is the operator's own fleet tool, theirs to keep.
What changes on a machine: a disk install staged by a stick older than #1836 carries no token,
so its first boot now stops on the setup page instead of coming up as a rig mining under a token
nobody was ever shown — which is to say, one no coordinator could adopt. Re-run that install from
a current stick and the answers land as before. A file any stick since #1836 staged carries the
token off its own card and is unaffected; hand-writing pithead-rig.json onto an ESP was never a
documented path and now needs the token the card would have carried.
Getting a machine back out of the rig role is the boot menu's Set up again entry (#1318) or the installer, never a setting: a rig serves no dashboard and answers on no port, so there is nothing to log into and change. Boot the stick beside it and install with the wipe, and it is a blank machine that can pick any role again. A keep reinstall deliberately leaves it a rig — keep means keep whatever the role says.
os/rauc/grub.cfg's fourth entry boots the slot the default would have booted and appends
pithead.setup=1 to that one boot's kernel cmdline. pithead-setup-again.service, the flag's
only reader, runs pithead firstboot-wizard on a provisioned machine with PITHEAD_SETUP_AGAIN=1
and Before=pithead-boot.service, so the role's normal boot waits behind the page. Each
announcement atomically publishes the URL, one-time token and certificate fingerprint to
/run/issue.d/pithead-setup.issue with mode 0600. The login prompts reload that file and
print it again when either getty starts; the same text is copied directly to tty1 and ttyS0.
A new round replaces the file. The wizard's exit trap and both units' ExecStopPost remove it.
Under the switch (lib/pithead/12a-setup-again.sh) three things change and nothing else:
the "already a rig" and "config.json present" short-circuits are skipped; stage_wizard_spool publishes
saved-role.json and points the pre-fill at the saved answers (rig-defaults.json gets the saved
pool + worker; last-attempt.json gets config.json through strip_config_secrets, unless a
failed retry's context is already there); and the inner loop honours keep-role. The page shows
its Keep it / Set up again screen exactly when saved-role.json exists (saved_role in
/api/state, null otherwise; a malformed file falls through to the normal form).
| Spool file | Written by | Meaning |
|---|---|---|
saved-role.json |
host | present only on a set-up-again boot: {role, pool, worker} for a rig, {role} for a coordinator, never a secret |
keep-role |
page | Keep it: the host ends the session with nothing on /data touched, the unit exits, pithead-boot runs the normal boot |
Set up again is the ordinary submit. On an installed coordinator, an accepted browser
submission calls the confirmed setup worker after the credential handoff. It can re-provision
the saved deployment without a terminal prompt; direct headless pithead setup still refuses
an existing deployment, even with PITHEAD_SETUP_AGAIN=1. A rig accepted with the same worker name keeps its
access_token (firstboot_consume_rig carries it over); any other change mints a new one on the
next render. record_machine_role removes rig.json when the accepted role is not rig, so a
role's data goes with the role. A coordinator's config.json is NOT removed by a change to rig:
it is operator data, and the factory reset is the erase.
A third spool channel, beside the config candidate and the rig request: a Pithead backup as an
alternative to the config form. The established archive formats remain accepted: an encrypted
.tar.gz.enc requires the passphrase shown when the backup was made; a plaintext .tar.gz
requires none. POST /submit-restore writes restore-archive and the optional, read-once
restore-passphrase. On the installation medium the disk/wipe fields ride beside them through
the same side-effect-free disk validation a typed submission takes. When setup TLS is
unavailable, /api/wizard-state marks restore unavailable, the page offers no upload control,
and the restore endpoint refuses a crafted request; reboot after setup TLS is available before
restoring.
firstboot_consume_restore (host-side) does the whole job in one call, staged through a COPY —
the same "validate before mutating real state" idiom consume_preseed_config already uses:
- Magic-byte format check, then a full-stream integrity verify (decrypt when needed, followed
by
tar -tzf) — identical tostack_restore's own pre-flight — BEFORE anything is extracted. - Read a numeric-owner listing, enforce member and expanded-byte caps, and reject links,
special files and members outside the appliance backup layout before extracting to a private
staging tree. The accepted items are
config.json,.env,Caddyfile, and thedata/{tor,dashboard,monero,tari,p2pool}trees, all rooted at a single directory found from whereconfig.jsonsits in the archive — the box that made the backup's own working directory, not necessarily this one (a supported prior release's Compose bundle ran from wherever the operator placed it). Backups with custom data paths, or whose members do not share one consistent root, need the administrative restore workflow. - Validate the staged
config.jsonthrough the same fresh-processparse_and_validate_configcallfirstboot_consume_spooluses. A valid restored remote-node configuration is not redialed under a later release's new-configuration preflight policy. - Regenerate
.envandCaddyfilefrom the validated configuration, retaining only opaque generated secrets and Tor identity from the archived environment. The restored dashboard password remains inconfig.json; its archived bcrypt hash and fingerprint are kept exactly while the fingerprint matches it and the hash is well-formed, and are regenerated from it otherwise. Only on success: install the configuration files at mode0600, apply the accepted data trees, and publishapplied.data/toranddata/dashboard(identity and the dashboard database) replace whatever is already there outright.data/{monero,tari,p2pool}— optional, within the upload cap; normal backups exclude it — MERGE into whatever chain data is already on this box instead, an existing file winning on a name collision. The shared restore collision rule explains why this differs frompithead restore. On awipe=keepreinstall, the installer's restore replaces the target's priorconfig.jsonandmachine-roleon its data partition, and chain data stays intact for the merge. The firstboot loop reaches this door unconditionally before checking for a config;prepare_directories(run by thesetupit feeds) unconditionally re-chowns every data dir, so restore does not need to.
A rejected archive (bad passphrase, wrong format, failed integrity, unparseable config) writes
error.txt and returns 1 — nothing already on disk is touched, and the page falls back to the
form exactly like a rejected typed config. Only encrypted archive bytes may occupy the ordinary
spool while the request is pending. A plaintext archive, its optional passphrase, page write
temporaries, decrypted stages, validated installer candidate and credentials card remain in
root-owned volatile storage. The ready marker is published last, so the host ignores a partial
generation; another upload is refused while that request or the host's restore-inflight
acknowledgement exists. Server restart removes crash-left page temporaries, and firstboot restart
removes private snapshots, named submissions, stages, candidates, cards and handoff files before
any early exit. A cleanup failure publishes no success marker, stops first boot until reboot,
and reports only the class of file that could not be cleared.
For an install-to-disk restore, the validated config used to render the credentials card, the
card itself, the passphrase, a plaintext upload, and decrypted staging remain in root-owned
tmpfs. An encrypted upload stays in the private ordinary spool while it is pending, then moves
to the volatile handoff after acceptance. The installer creates the target's normal data
partition and applies the restore there; no archive or passphrase is copied to the public ESP.
Restore installs leave unrelated config, token, and rig pre-seeds on the installer medium and pass
--no-preseeds so the generic installer does not copy them to the target. The installed system
carries only a non-secret .restore-pending marker, which makes its first boot finish setup
before the ordinary render. An interrupted write retains a non-secret .restore-incomplete
marker and first boot fails closed until the restore is submitted again.
Success and rejection both scrub legacy ESP carry files; a failed scrub stops first boot rather
than provisioning with credentials still on the ESP. If an accepted restore returns to the form,
its in-flight marker and volatile carry are cleared, and only the existing secret-stripped retry
fields reach persistent last-attempt.json; credentials must be entered again. Publication or
cleanup failure is shown without echoing credentials, and the installer stops instead of repeating
an install after a credential cleanup failure.
A RigForge-only rig (#1836) has no config.json and no dashboard — record_machine_role removes
rig.json on any non-rig role and a rig never gets a config.json in the first place, so
stack_backup has nothing to archive there (backup_require_items refuses without one). Restore
does not cover that role: the credentials card preserves the rig's control access token, while an
optional Stratum password is separate and must be retained or entered again. Getting a rig role
back is Set up again, not a restore upload.
Deliberately reuses stack_backup's archive format (#786 sub-issue A) rather than inventing a
second one, and deliberately does NOT reuse stack_restore directly — that CLI command mutates
real state immediately (no staging) and is written for an operator who already has a shell,
which the wizard's pre-provisioning trust level does not assume.
The plain setup port redirects to HTTPS. The host passes its global interface addresses
in WIZARD_HOST_ADDRESSES, excluding bridge interfaces before starting the container.
The console and log banners use the same list. A recognised Host header keeps the typed
address or machine name; an unknown header uses the first host address, or pithead.local
when the inventory is unavailable. The container socket address never selects a redirect.
Caddy keeps a recognised typed host after provisioning.
One certificate for the machine's whole life, at appliance_tls_dir()
(/data/pithead/data/tls), presented by the wizard and by Caddy afterwards.
first boot ──> appliance_mint_cert() compares, doesn't date-guess: keeps a cert whose SANs
│ still match, re-mints when they don't
┌───────────┴───────────┐
wizard serves generate_caddyfile() calls it on every render, then emits
(copy in spool) tls /pithead-tls/wizard.crt
Both the certificate's SAN list and Caddy's site list come from one shared builder,
appliance_site_names(): a name is either served and certified, or neither. dashboard.host
pinned collapses both to that one name; unpinned, both expand to every address the machine
answers on (mDNS name, LAN IPs, localhost).
Four properties, each earned:
- One cert, not two. Caddy used to mint its own via
tls internal, replacing the wizard's at the moment provisioning succeeded. A second, different self-signed certificate for one hostname is not a second warning — Safari refuses outright, Chrome throwsERR_SSL_PROTOCOL_ERROR. The setup page appeared to die exactly when it had worked. - Minted wherever it is named, on every render.
generate_caddyfilecallsappliance_mint_certunconditionally now, not only when the pair is missing — the mint decides idempotency itself (property 3), so calling it every time is what lets a stale certificate get caught instead of surviving forever. It was previously created only by the wizard, so any machine that skips the wizard — a pre-seeded config, or a reinstall whose preserved/dataalready heldconfig.json— got a Caddyfile pointing at a file that did not exist. Caddy then answered:443with no usable certificate, forever, and the console was silent becausepithead-firstboot.service'sConditionPathExists=!…/config.jsonhad skipped the unit. Rebooting could not clear it; only reflashing or minting could. - Re-minted only when the name list it covers actually changed. The mint reads the SANs
already on the certificate back with
openssl x509 -ext subjectAltName— never guessed from a mint date — and set-compares them againstappliance_site_names()'s current answer. Unchanged, the existing pair is kept: swapping a certificate that still names the machine correctly is indistinguishable from an attack, and the browser treats it that way. Changed — a DHCP lease moved,dashboard.hostwas just pinned — it re-mints and says so on the console, because an operator who pinned the old fingerprint needs to know it just moved. - Checked, not just trusted.
doctor's appliance lane reads the served certificate (openssl x509 -ext subjectAltName -enddate, no network) and FAILs if a name Caddy serves is missing from its SANs, or if it is within 30 days of expiry. With property 3 in place a coverage gap should not occur on a healthy render, so this is belt-and-braces there; expiry is the check nothing else derives. An unreadable certificate file WARNs instead —doctoris one ofpithead-boot's three health-gate signals, and a FAIL there reboots the box, so a read failure that doesn't prove the certificate is actually broken must not cause one. - The remedy is real, and the gate does not punish the update for it (#1265).
applyreaches the mint even whenconfig.jsonis unchanged: on an appliance the no-change branch re-renders the Caddyfile — the mint inside it is idempotent — and restarts Caddy only when the certificate or the Caddyfile moved, so the commanddoctorprints does what it names.pithead-boot's gate keeps the coverage FAIL as its re-mint trigger; once its bounded re-mint cannot clear the gap (render mints nothing, or the budget is spent) the slot commits with the gap recorded as the verdict'sadvisoryinstead of rolling back a good update for a fact about the machine's addresses. Interactivedoctorstill FAILs on it.
The SHA-256 fingerprint is printed on the console beside the token so the browser warning can actually be verified. A warning nobody can check is theatre.
Rule for changes: if a component serves TLS for this machine, it serves that pair. If
minting fails, fall back to tls internal and say so — a dashboard behind an unfamiliar
certificate beats no dashboard.
After provisioning, every boot runs one unit — pithead-boot. Provisioned has two shapes,
and the unit's condition names both: a coordinator states it with config.json (every machine
provisioned before the role contract has only that), a rig with machine-role — it has no
config.json and never will. Both are triggering conditions — the | prefix — so either one
admits the unit while the /data mount check still has to hold. The mirror image guards the
wizard: pithead-firstboot is excluded by either file, or a rig would re-open a setup page
on every boot while the unit that owns its miner sat skipped beside it.
The marker and not rig.json, deliberately: a fleet stick holds a rig's answers in flight
while installing that rig onto a disk, and must stay an installer through it. Only an accepted
role writes the marker, and only onto the machine that IS that role.
The condition only decides whether the unit runs — existence is all a systemd condition can test. Which leg runs is the marker's VALUE, read by the script.
A rig is not a small coordinator. It runs no containers, so the image loader is skipped before
it costs anything; it has no config.json to render from and no stack to bring up. pithead-boot
forks first thing and does two steps:
pithead local-miner, which reads the marker and takes the rig branch:rig.json→ RigForge'sconfig.json(pool, worker name aspools[].user, stratum password when one was set, and no HugePages headroom — there is no stack here to leave room for) → the same appliance-mode setup the Both role runs, from the same tree on/data, against the same prebuilt XMRig the image baked. Nothing on this path clones or compiles; a Tor-only box could not. A native rebuild is the operator's option, cached on/data, never a requirement.- The same health-gated slot commit, on the miner running. The gate is deliberately pool-independent: a rig whose coordinator is late still starts, still retries, and still commits. Rolling a slot back cannot fix a switch nobody plugged in, and a gate that punished it would flap the A/B pair every boot the LAN was slow.
The leg also does the removable-root minimization the run-from-USB rig needs, because that
machine's root IS the stick it mines from. The image ships journald persistent with a 200 MB
cap, whose files land on that same medium; the rig leg flips it to volatile — logs in memory,
no rotating writes on the stick — and converges it on every boot, since /etc and /run are
both volatile here and no drop-in survives a reboot. Swap needs no code at all: the appliance
declares no swap partition and creates none, in any role. And /data needs no rig-sized repart
rule, because it is sized to the medium rather than to the role — a 16 GB stick leaves a rig
roughly 6 GiB after the ESP and both slots, which is plenty with no chains. It could not be
role-conditional in any case: systemd-repart runs at first boot, before the wizard has asked
what the machine is (os/rootfs/repart.d/40-data.conf carries the full reasoning).
Five steps, each answering a hardware-validated failure:
-
pithead load-images— load the baked container-image archives when their content changed. The archives ship in the read-only slot, the engine's storage lives on/data, and every release tags its images identically — so without this step a keep-reinstall or A/B update boots the new OS and keeps serving the old containers (a keep-reinstall did exactly that on hardware: new slot, RC-old dashboard, every shipped fix absent). Keyed on the archive's digest, recorded beside the store it describes; a normal boot pays one sha256 per archive. The first-boot wizard runs the same loader before it serves, so both boot owners converge the same way. Harness marker variants are signed before Compose digest pinning; the archive and runtime declaration select that same final image. -
pithead render— regenerate every derived file (.env, Caddyfile, service configs, host units) fromconfig.jsonplus the program that is actually running. Derived files are never inspected or repaired, only rebuilt: an A/B update swaps the whole program, and a bench machine once served a days-old Caddyfile whose site list predated the code around it. On the read-only root, host units render into/run/systemd/system(--runtimeenablement) and are recreated here each boot. -
pithead up— start the selected services, compare each container's immutable image ID with its Compose image declaration, and force recreation of mismatches. Verify the replacement ID before reporting success; a failed comparison or recreation fails boot before slot commit. Services held for data migration stay deferred until commit. After each compose pass it renames a container that an interrupted recreate left under its temporary<id>_<service>name, once the old container no longer holds the name. Its predecessor,podman-restart, started the stack into its own oneshot cgroup, and systemd SIGKILLed the containers it had just spawned. -
Health-gated slot commit —
rauc status mark-goodonly once the slot passes three gates. First the dashboard must answer through Caddy on the vhost rendered in.env, with the connection forced to loopback and the exact/.pithead-boot-healthpath rewritten to/. The probe sends a capability derived from the owner-only salted login hash on curl's stdin. Caddy requires the capability and removes it from logs and upstream requests; only this credential-free local request gets the boot marker in its access log. Its locked 401 proves the login gate answers without adding a failed-login warning. With login off, the dashboard must return a nonempty page. This checks the derived-config → Caddy → dashboard chain. Secondpithead doctor --jsonmust exit clean: it FAILs on a crashed revenue container (monerod/p2pool/tari, including one an interrupted compose recreate left under its temporary<id>_<service>name), a dead Tor backbone, or a missing egress firewall, so a slot that serves a dashboard while mining is dead does not commit. Thirdpithead statusmust exit 0 — every expected container running and healthy, none restarting; only a miner deliberately created/exited/stopped by the sync gate, or a chain service explicitly withheld by a pending data migration, is exempt. Restarting or unhealthy services still fail. doctor judges only the revenue containers, so before #2383 a non-revenue container leftunhealthy(the dashboard's own healthcheck failing, caddy in a restart loop) passed both earlier gates while the box's own status command already called it broken: manual battery M9 committed exactly that slot. Each gate is a subset of the next, and the third closes the last gap. The refusal names the container, carried into the in-flight flag so the fallback boot's rollback verdict says which one held the gate. The gate is deliberately sync-tolerant: a node's healthcheck is a liveness probe that passes from early in a days-long initial sync, and the sync-held miners (p2pool/xmrig-proxy, stopped by the dashboard until the node catches up) never count as crashed by doctor, nor againststatus's own exit code — so a still-syncing box commits while a genuinely broken one does not. Certificate coverage the boot-time re-mint could not clear still commits only afterpithead statuspasses (#1265): that drift is the machine's address list, not the slot. A slot that boots but is not healthy stays uncommitted on purpose: that is the state A/B fallback exists for. Fresh unprovisioned machines never commit, and an unverified update before provisioning reverts.config-resetrecords an already-good booted slot with its exactBUILD_COMMIT, only after the provisioned boot unit has completed successfully in the current boot. Once the reset wizard container starts, firstboot restores that slot's good state on each configless boot, including a reboot with setup still open. The record remains until the provisioned health gate succeeds. A different slot or source cannot use it. The next provisioned boot still runs all three health gates; reset does not commit an unverified update. -
pithead local-miner— converge the built-in RigForge worker tolocal_miner.enabled, deliberately LAST: the miner needs the stack's stratum listening, and it must never delay or block the slot commit — the stack serving is the product's health, the miner is a passenger (|| true). The appliance checks an active, enabled local miner every 30 seconds. A successful proxy worker-list reading that finds the proxy container restarted since the recorded identity while the local miner still has no connection queues an immediate XMRig restart — a proxy replaced underneath a live miner is the stall XMRig never recovers from itself, so it does not wait out the window. The guard brackets each reading with the container identity and moves the recorded identity only on a successful reading that saw no change across it, so a proxy recreated during a failed or connected reading still reads as a recreation on the next reading. Otherwise five minutes of successful proxy worker-list readings with no connection for the local miner’s rendered identity queue an XMRig restart, logged bypithead-miner-recovery.service. On a rig the same service reads the rig's own XMRig API and restarts XMRig after 120 seconds without a pool connection or hashing with no new share, with a 300 second cooldown between restarts. Other connected rigs do not reset that window. Missing readings, a connected local miner, a stopped miner, or a busy stack operation reset that window. The guard holds the mutation lock only for that busy check and around the restart, never while it reads the proxy, so a zero-wait command such aspithead tor-recoveris not refused because of it. The guard honorsPITHEAD_LOCK_FILEwhen supplied to its service, matching the CLI mutation lock. This guard runs only on coordinators; it does not start a disabled miner or change slot-commit policy. When enabled, this runs RigForge's setup in appliance mode from the treepithead-synckeeps on/data/rigforge: its unit renders into/runwith--runtimeenablement (gone every boot, recreated here, like the control-runner units), and the cached XMRig build on/datamakes the run a re-render rather than a recompile. The miner's config is derived byrender(step 2's family): the stack's own stratum over loopback, the stratum password, and the stack's HugePages budget declared ashugepages_reserve_extra_mb— RigForge's grow-only sysctl then sizes the shared pool as the single writer, and pithead's own HugePages write never shrinks a grown pool back.
Step 4 and forward-only data migrations. On the first boot of a data_migration-flagged
update, up (step 3) deliberately withholds the chain services — monerod, tari and their
wallets, the holders of forward-only lmdb migrations — so the commit at step 4 is decided
before any migration touches /data, and a failed health check still falls back onto data
the old OS can read. The chain services start, and the migration runs, only after the slot
commits. pithead os-update separately refuses a manual rollback below the /data
migration floor — both halves are described in
appliance-release.md.
Rule for changes: anything generated from config.json or the program is derived and must
be rebuilt by render — adding one anywhere else recreates the staleness bug. The container
images are derived in the same sense: functions of the running slot, converged every boot by
load-images. Genuine state (config.json, wallets, chain data, Tor keys, opaque generated secrets)
is never regenerated; it gets validation and a safe fallback instead.
The invariant, asserted by the provision phase: corrupt any derived file, reboot, and the machine must serve again.
The layering is deliberate: three defects reached hardware because a layer that looked covered had a gap between it and the next one.
| Layer | File | Covers |
|---|---|---|
| server contracts | tests/web/test_wizard*.py |
token gate, stage machine, spool writes, install guards, TLS selection |
| pure logic | tests/frontend/config/configsync.test.mjs |
path access, typed coercion, address/pair guidance |
| view rendering | tests/frontend/wizard/wizard.test.mjs (probes) |
each view given its props |
| app orchestration | tests/frontend/wizard/wizard-{state,install,submit}.test.mjs (stubbed server) |
stage mapping, the handoff arriving through the poll, refresh-mid-provision, rejection round-trip, request bodies |
| host logic | tests/stack/run.sh |
cert minting + idempotence, remote-node preflight, pre-seed, install requests, the digest-keyed image loader, reinstall pre-fill (secret strip + fail-open), the local-miner legs (derived config, sync seeding, boot-leg wiring), the rig-role legs (pool discovery publisher, rig request consumption, the role marker, the rig boot leg's derived config + prebuilt-first + volatile journal + refusals, and both unit conditions), restore-at-setup (firstboot_consume_restore: accept against a genuine backup archive, wrong passphrase, missing passphrase, oversize, malformed archive, empty spool; installer restore applies from volatile carry to target data and reports cleanup failure without exposing the passphrase), the data-wipe note (data_wipe_note reads the ESP's dated log and its one-shot .pending marker, consumed on read, and caches the result in a tmpfs file for the rest of the boot — a shell variable would not survive the $(...) subshell every caller reads it through — so a wipe surfaces once per boot, never forever after; publish_data_wipe_note carries it to the spool, check_data_wipe_note is the doctor line) |
| the artifact | tests/os/verify-image.sh |
both role paths present in the shipped image: the boot script's fork, the unit conditions that admit each role, the baked prebuilt, no swap anywhere |
| the real thing | tests/os/run.sh --phase provision |
token from the console → submit → handoff → ack → running stack → built-in miner up and its shares accepted → reboot through a corrupted Caddyfile → no failed units → slot self-commit → miner back |
| the other real thing | tests/os/run.sh --phase rig |
the same page answered RigForge → rig card with no login → mining from the byte-identical baked binary → no containers at all → reboot owned by pithead-boot, wizard closed → slot self-commit on an unanswered pool → A/B install, uncommitted rollback, self-commit, persistence |
| the restore leg | tests/os/run.sh --phase install |
a real encrypted backup taken off a live machine after its provisioning units have finished (the wizard's up holds the mutation lock through its tor-health wait for minutes after podman ps looks live, #1945), then a checked-in encrypted v1.20.0 fixture generated from the signed compose bundle, each uploaded through /submit-restore on a FRESH installer boot instead of the form, the second onto the first's kept disk; the powered-off installer medium is inspected for leftover restore credentials, and the powered-off target is inspected before first boot to prove its ESP has no restore secret and its data partition has the validated state plus only a non-secret handoff marker. The created P2Pool container's configured wallet, Tor identity and opaque RPC/onion secrets must match each archive. The startup probe requires the fresh sync-gate hold first. Before its one start, it rejects prior crashes, restarts and OOM kills; a stopped exit 137 is eligible only when bounded logs from that container start show both SIGTERM and stopping. After proving the sync-gate hold, the harness pauses the dashboard, starts that restored P2Pool container once, and requires it to remain running with exit code zero and zero restarts across four samples over 30 seconds. It then stops P2Pool, restores the dashboard and rechecks the sync gate; failures name the probe checkpoint and include bounded daemon and kernel diagnostics. Prior stop evidence is escaped and limited to 30 lines of 240 columns; the start bound uses the shared Go-time-to-RFC3339 converter. This proves startup, not synced mining. The dashboard hash and fingerprint follow the rule in step 4 of the restore flow (kept while the fingerprint matches the preserved password), both the fixture's chain sentinel and the target's pre-restore sentinel must survive, and the fixture's removed 1.x keys (xmrig_proxy.*, telegram.control) must migrate or drop as documented without leaving a config.json.bak-1x on /data |
The orchestration row is the one that was missing. pytest proved the endpoint published the credentials; a render probe proved the card renders given them; nothing proved the app asked. When adding a step, cover it at the layer that owns the promise and at the seam to the next one.
The host owns the wizard spool directory (root:1000, mode 1770). The page
runs as UID/GID 1000. Host publishers create a private temporary directory, write
mode-0600 files there, and rename completed files into the spool. TLS files,
schema, inventories, saved role and the credentials card remain root:1000 at
mode 0640. The page can read these files but cannot replace them.
error.txt, last-attempt.json and installing belong to UID/GID 1000 at mode
0600 after publication. The page removes or replaces them during retry. On an
installed system, a full retry snapshot can contain credentials and receives the
same private creation as the credentials card. On installation media, retry
snapshots derived from a restore pass through strip_config_secrets; those restored
credentials stay volatile and must be entered again. An operator-provided fleet pre-seed remains
the operator's original private file. No host writer opens published paths for writing or changes
their ownership after publication. The page's atomic writers also remove failed temporary files;
a failed removal is reported generically.
Host consumers pin a request without following links, reject nonregular files
and existing hard links, and copy accepted bytes into a private inode before
validation. Each request publishes submission-staging first and submission-active last; host
consumers ignore a generation until the final marker exists, and startup removes an interrupted
partial generation. Parsing and application use the pinned copy. The page can still replace its
request or hold its original inode open; neither changes the validated copy.
The shared helpers live in lib/pithead/11a-wizard-spool.sh; the install window and the
restore and installer-credential cleanup live in lib/pithead/12b-wizard-install-window.sh. The shell boundary
suite exercises hostile entries, replacement, private creation and the real root
and page permissions. The integrated KVM battery checks boot and browser setup.
A new installer session clears saved configuration, disk selection, authentication choice and change notices from the previous machine. Retry re-staging keeps those files for the current attempt. The bare reinstall path enforces its keep-only policy on the consumed request. Oversize or unsafe restore submissions consume the submitted passphrase when rejected.