32 KiB
phase, plan, subsystem, tags, requires, provides, affects, tech-stack, key-files, key-decisions, requirements-completed, coverage, duration, completed, status
| phase | plan | subsystem | tags | requires | provides | affects | tech-stack | key-files | key-decisions | requirements-completed | coverage | duration | completed | status | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 10-key-material-hardening | 03 | iso-build |
|
|
|
|
|
|
|
1h | 2026-08-02 | complete |
Phase 10 Plan 03: Fail-closed first-boot secrets + identity-free rootfs — Summary
First-boot per-device secret regeneration now retries with backoff and then fails closed, and the rootfs tar it repairs no longer carries the fleet-shared SSH host keys, TLS keypair or machine-id it was silently papering over. Closes the build side of audit finding F-03.
Task 3 (C-4 build-host evidence) is a blocking checkpoint and is NOT done. It needs an ISO build host.
docs/security/KEY-02-ROOTFS-EVIDENCE.mdcarries the exact command sequence and is marked UNVERIFIED. Nothing in this plan claims the tar listing was observed.
What was wrong
first-boot-secrets.sh (a heredoc inside image-recipe/_archived/build-auto-installer-iso.sh,
which is live — image-recipe/build-debian-iso.sh execs it) had two fail-open branches that
logged WARNING: ... keeping baked key and continued, and touch "$MARKER" ran unconditionally
outside both if blocks. Combined with the unit's
ConditionPathExists=!/var/lib/archipelago/.secrets-regenerated and the script's own
[ -f "$MARKER" ] && exit 0, one transient failure at first boot left that node on the
image-wide shared SSH host key and TLS private key permanently and silently — and the ISO is
a published artefact, so every downloader holds those keys.
Commits
| Commit | Task | What |
|---|---|---|
21043096 |
1 | Fail-closed, retried regeneration + tests/first-boot-secrets/run-tests.sh |
408b328c |
2 | Rootfs identity-strip layer + two comment corrections that follow from it |
201ef474 |
3 (prep) | docs/security/KEY-02-ROOTFS-EVIDENCE.md, marked UNVERIFIED |
2efab5f2 |
follow-up | Single-producer unification, build-time generator assertion, self-heal timer, 3 new test cases |
d9b3a7d5 |
follow-up | Quote the Dockerfile.rootfs heredoc so comments cannot execute (closes deferred D1) |
40b77e39 |
follow-up | Refuse to bless a cert minted under an untrustworthy clock; backdate notBefore |
Nothing was pushed, tagged, built or deployed, per the execution brief.
Task 1 — fail-closed regeneration
ROOT="${FIRST_BOOT_SECRETS_ROOT:-}"prefixes every absolute path. Unset in production the expansion is empty and behaviour is byte-identical; set, it is what makes the negative property assertable at all.retry()runs each generator up to N times with waits fromFIRST_BOOT_SECRETS_BACKOFF(default2 8 20). Staging-then-swap is preserved for both generators, with.newfiles removed on failure so no half-keypair is left behind.touch "$MARKER"now lives inside aTLS_OK == 1 && SSH_OK == 1branch. Any other outcome writes/var/lib/archipelago/first-boot-secrets.failed(timestamp, which generator failed, both flags), shouts to console +logger+ stderr, andexit 1so the unit lands infailedrather thanactive. A later successful boot deletes the record so a recovered node does not carry a stale alarm.After=systemd-random-seed.serviceadded to the unit. A no-op today (no seed file is baked, which the audit verified) and correct if one is ever introduced.- The script header states the operational trade in plain words, including that recovery from a terminal failure needs the physical console.
Harness results (final, all six cases)
extracted 236 lines from the builder; bash -n clean
PASS: both generators succeed -> exit 0, marker set, keys swapped in
PASS: openssl fails every attempt -> exit non-zero, NO marker, failure record names TLS
PASS: ssh-keygen fails twice then succeeds -> backoff recovers within one boot (3 attempts)
PASS: TLS fails every attempt on a stripped root -> NO key, NO marker, non-zero exit, record names TLS
PASS: self-heal: failed run then a later successful run -> key present, marker set, failed units restarted
PASS: single-producer invariant: every key-creating invocation is inside gen_tls/gen_ssh
──────── first-boot-secrets summary ────────
passed: 6 failed: 0
Negative control (required by the plan's acceptance criteria)
touch "$MARKER" moved back outside the success branch, harness re-run, then reverted:
SCRATCH APPLIED: marker touch moved back outside the success branch
--- harness against the fail-open variant ---
extracted 175 lines from the builder; bash -n clean
PASS: both generators succeed -> exit 0, marker set, keys swapped in
FAIL: openssl fails every attempt -> MARKER-SET-ON-FAILURE
exit=1 root=/tmp/tmp.Ta1YFhHWdi/root-tls-fail
stderr: ARCHIPELAGO FIRST BOOT FAILED: could not generate this device's TLS key material. ...
PASS: ssh-keygen fails twice then succeeds -> backoff recovers within one boot (3 attempts)
──────── first-boot-secrets summary ────────
passed: 2 failed: 1
EXIT=1
The test fails on exactly the regression it exists to pin, and only that case.
Task 2 — identity-free rootfs
Final RUN layer added to Dockerfile.rootfs, after every package install and after the
openssl req layer, so nothing regenerates the material afterwards:
rm -f /etc/ssh/ssh_host_*(private keys and.pubalike)rm -fthe archipelago TLS key and crt, keeping the/etc/archipelago/ssldirectory: > /etc/machine-id(systemd's documented regenerate-on-next-boot state)/var/lib/dbus/machine-idremoved only if it is a real file, not the usual symlink- writes
/opt/archipelago/rootfs-identity-strippedlisting what it removed, with no timestamp so RECIPE_HASH reproducibility is unaffected
The openssl req layer is deliberately unmodified.
RECIPE_HASH changed. The strip layer is inside the hashed region
(sed -n '/^# STEP 1.../,/^# STEP 2.../p' | grep -c rootfs-identity-stripped → 1), so the next
build is forced to rebuild the rootfs tar. Task 3's evidence would be meaningless against a
cached tar, and --rebuild is specified as well.
grep -c 'ssh_host' on the builder went 3 → 6.
Deviations from Plan
1. [Rule 1 — Bug] Backticks in my own strip-layer comment would have hung every ISO build
- Found during: Task 2, self-check of the added block.
- Issue:
Dockerfile.rootfsis written with an unquoted heredoc (<<DOCKERFILE), so backticks in its body are command substitution evaluated by the build shell. Two comment lines I wrote contained`openssl req`. Reproduced in isolation: the heredoc hung for the full 2-minute timeout asopenssl reqwaited on stdin.bash -nis clean on this — syntax checking cannot catch it. - Fix: replaced with double quotes, and added an explicit
NOTE:in the block warning that the heredoc is unquoted and backticks must never appear there. - Commit:
408b328c
2. [Rule 1 — Correctness] Script header claim about TLS, twice corrected
- Found during: Task 2, after discovering the installer's TLS fallback.
- Issue: the Task 1 header claimed "the nginx TLS listener will not start". With the installer fallback in place that was false — the web UI would still come up. Shipping a confident false statement in a security-critical script is worse than shipping none.
- First fix (
408b328c): narrowed the claim to SSH only, and described the TLS fallback honestly as per-install, never image-wide. - Second fix (
2efab5f2): the fallback is gone, so the original claim is true again for both. Restored, with the reasoning attached rather than left implicit. No comment anywhere in the builder now implies a TLS fallback exists.
3. [Rule 2 — Threat coverage] /var/lib/dbus/machine-id
- Issue: T-10-26 is machine-id correlation across nodes. The plan named
/etc/machine-idonly. If dbus ships a real copy rather than the usual symlink, truncating/etc/machine-idalone leaves correlated state. - Fix: guarded removal — symlinks are left alone, real files are removed.
- Commit:
408b328c
Follow-up: unify to a single producer (2efab5f2)
The installer's TLS fallback prompted a decision cycle worth recording, because the reasoning matters more than the outcome.
The false trade. The question was framed as "keep the fallback (a second source of keys) or delete it (a first-boot failure costs the user the web UI, recoverable only at the console)". Both options were wrong, and the framing was wrong. The defect in F-03 was never that a second attempt to create a key existed. It was that failure was silent and the completion marker lied about it. A second attempt is only dangerous when it is an unaudited second producer — carrying its own idea of success, its own absent retry policy, its own absent failure record. So the fix is to unify, not to delete and accept a dead node.
What shipped:
-
One producer per secret.
gen_tls()andgen_ssh()are the only code in the ISO build that create the TLS keypair and the SSH host keys. Two secondary producers were folded out: the Dockerfile'sopenssl reqlayer (which baked a keypair the strip layer deleted moments later in the same build) and the installer's "ensure SSL cert exists" block. The invariant is checked mechanically, not asserted in prose — case 6 of the harness fails if any executableopenssl req/ssh-keygen -Ainvocation appears outside the generator heredoc. -
The deterministic failure is caught at build time. The one realistic way generation fails on every retry forever is a missing generator binary, and that is deterministic — no retry or reboot fixes it. A rootfs
RUNlayer now fails the build if/usr/bin/opensslor/usr/bin/ssh-keygenis missing or non-executable. The build already guaranteed these (opensslandopenssh-serverare both in the package list, andopenssh-serverhard-dependsopenssh-client, which shipsssh-keygen), so this is cheap insurance rather than a fix. It earns its place the first time someone edits that package list. -
Failure self-heals; it never dead-ends.
archipelago-first-boot-secrets.timer(OnBootSec=5min,OnUnitActiveSec=15min) re-runs the service until it succeeds. The service's existingConditionPathExists=!makes every trigger a no-op once the marker exists, so a healthy node pays nothing and no teardown is needed. Two details that would have made this theatre if missed:chroot systemctl enablecan fail silently, and every other enable in this file ends in|| true. The timer's enable has a hand-written symlink fallback, because the absence of self-heal is invisible until a node is already broken.try-reload-or-restartis a no-op on a failed unit. Without special handling, a self-healed node would have valid keys on disk and nginx still down. Consumers found infailedare now explicitly restarted (--no-block, to avoid a boot-transaction deadlock at first boot, where we are orderedBefore=them).
-
Never serve a bogus key.
gen_tlsnow parses both halves back (openssl pkey,openssl x509) before the staging swap, so a truncated or half-written artefact is never what nginx reads. Fail-closed governs serving; retry-and-self-heal governs recovering. They are different properties and both hold.
Negative controls for the three new cases
Each defect was reintroduced, the suite run, and the defect reverted. Each lights up exactly one case — a test that goes red for several reasons at once is not pinning any of them.
Control A — reintroduce a fallback-style key creation on the failure path (the deleted installer block's behaviour, moved into the script):
FAIL: TLS fails every attempt on a stripped root -> TLS-KEY-EXISTS-AFTER-FAILURE TLS-CRT-EXISTS-AFTER-FAILURE
passed: 5 failed: 1
(First run of this control also reddened case 5, because case 5's run-1 block redundantly re-asserted case 4's property. That assertion was removed — case 5 now tests recovery only — and the control re-run to confirm it is isolated. The transcript above is the re-run.)
Control B — dead-end a node that has already failed once (exit 0 early if the failure
record exists, a plausible "don't retry a known-bad node" optimisation):
FAIL: self-heal -> run2-marker-missing run2-key-missing run2-crt-missing run2-stale-failure-record run2-did-not-restart-failed-nginx
passed: 5 failed: 1
Control C — reintroduce the installer's chroot ... openssl req block verbatim:
FAIL: single-producer invariant -> SECOND-PRODUCER-at-line-3586
generator heredoc spans lines 1713-1950 of image-recipe/_archived/build-auto-installer-iso.sh
passed: 5 failed: 1
All three reverted; suite back to 6/6.
Residual operational risk — stated plainly
A machine on which secret generation can never succeed ends up with no SSH host key and no TLS key. sshd will not start, nginx will not serve the web UI, and that node needs physical console access. That is the honest worst case and it is not softened anywhere in the code comments either.
What shrinks it to genuinely-broken-hardware:
- The deterministic cause is gone before shipping. A missing
opensslorssh-keygenfails the ISO build, so it cannot reach a node. - Transient causes are absorbed. Three attempts with backoff inside the boot (proven by harness case 3, which shows a generator failing twice and succeeding on the third), then every 15 minutes on the timer, then again on every boot — indefinitely, because the marker is never written on failure.
- Recovery completes itself. On a later success the script restarts the units that refused to start, so the node comes back without a reboot and without a human (harness case 5).
What is left is a machine where openssl or ssh-keygen is present but cannot ever produce a
key — a disk that is permanently full, or failing hardware. On that machine the node refuses to
serve rather than serving on a key nobody generated, which is the trade this phase exists to
make. It says so on the console, in the journal, and in
/var/lib/archipelago/first-boot-secrets.failed.
Follow-up: quote the Dockerfile heredoc (d9b3a7d5) — closes deferred D1
cat > "$WORK_DIR/Dockerfile.rootfs" <<DOCKERFILE was unquoted, so the build shell
performed command substitution on the Dockerfile body: a backtick inside a Dockerfile comment
was executed on the build host and its output spliced into the generated file. Six comments did
this, and one of them ran systemctl start archipelago-fips.service against the build machine
on every ISO build.
Boundary checked before editing. Only lines inside the heredoc body are at risk. The other
backticked comments in this file (:264, :809, :1188, :1289, :1506, :1605, :3597,
:3651) are ordinary shell comments outside any unquoted heredoc, plus one inside the quoted
SECRETSSCRIPT heredoc — none were ever evaluated, and none were touched.
Fixed the class, not the instances. The body needs exactly four build-time values, all
package names (LINUX_IMAGE_PKG, GRUB_EFI_PKG, GRUB_EFI_SIGNED_PKG, GRUB_PC_PKG), on four
consecutive lines — so quoting was entirely practical. The heredoc is split into
DOCKERFILE_HEAD and DOCKERFILE_TAIL, both quoted, with one explicit printf interpolating
those four names between them. Escapes that existed only because the heredoc was unquoted were
undone in the same pass: six trailing \\ → \ (Docker line continuations) and four \$ → $
(RUN arguments reach the shell verbatim; Docker does not substitute variables in RUN).
Substance verified by rendering, not by inspection. The generated Dockerfile was rendered before and after with identical inputs and diffed normalised (continuations joined, whitespace collapsed). Both are 190 normalised lines and the only differences are the six comments regaining their text — every instruction byte-identical:
< # the archipelago backend calls
> # the archipelago backend calls `systemctl start archipelago-fips.service`
< # fips-gateway is gated behind the Cargo feature (depends on
> # fips-gateway is gated behind the `gateway` Cargo feature (depends on
Case 7 asserts every heredoc writing Dockerfile.rootfs has a quoted delimiter, and when one
does not, reports which body lines would execute. The assertion is on the delimiter, not on
backticks — with quoting a backticked comment is legal, and six of them are back in the body on
purpose; flagging backticks would flag a non-bug and fail on the very comments this restored.
Controls:
Control D — unquote the delimiter (the real regression):
FAIL: Dockerfile heredoc quoting -> UNQUOTED-DELIMITER-at-line-287 would-execute-at-lines:317,318
passed: 6 failed: 1
Control E — add a backticked comment, delimiter still quoted:
PASS: Dockerfile heredoc delimiters are quoted — a backticked comment cannot execute
passed: 7 failed: 0
and it renders intact:
175:# Control E: a backticked `systemctl start archipelago-fips.service` comment
Control E is the more informative of the two: the backtick that used to be a build-host RCE is now inert and renders as written. That is what "fixed the class" means, and it is why a bare backtick reintroduction correctly reddens nothing.
deferred-items.md held D1 as its only entry and has been deleted — nothing was left that is
genuinely out of scope.
Follow-up: untrustworthy clock at cert-minting time (40b77e39)
The failure fail-closed cannot catch, because generation succeeds. This unit runs before time
has synced; openssl req -x509 stamps notBefore from whatever the clock says. Dead RTC or flat
CMOS battery → clock ahead gives "not yet valid" (harder to diagnose than a self-signed warning),
clock behind gives an already-expired cert once time syncs. The marker was then set and never
revisited: a node permanently serving a cert nothing accepts.
Finding, established rather than assumed: this image does not use systemd-timesyncd. It
installs and enables chrony (:388, :575), and chrony-wait.service — the unit that is
Before=time-sync.target — is not enabled. So time-sync.target is inert here and ordering
After= it would buy nothing. Enabling chrony-wait to make it meaningful would stall boot
behind NTP on a node with no network, and these nodes are routinely offline at first boot.
Decision: no ordering change. Not deadlocking boot outranks cert-date elegance (constraint 3). Fixed locally instead:
- Backdate
notBeforeby 24h so ordinary node/client skew cannot invalidate a fresh cert. This does not weaken a self-signed cert —notBeforeis not a security control here.-not_before/-not_afterarrived in OpenSSL 3.5 and the rootfs isdebian:trixiewhich ships it, but the capability is probed, not assumed: guessing wrong would fail every attempt and brick the node, the exact outcome all of this exists to prevent. Without the flags we do not backdate, and rule 2 still covers the dangerous case. - Refuse to bless a cert dated outside a plausible window (2026-01-01 … 2056-01-01). The
material stays installed — the node is usable, sshd comes up — but the dates are recorded as
failed=cert-datesand the cert is regenerated automatically once time syncs.
Generation is now driven by need rather than "is the marker absent", and
ConditionPathExists=! was removed from the unit so a node that already completed can still be
re-examined. Skipping the unit is precisely how such a node would stay broken forever. On a
healthy node the script exits in milliseconds.
Anti-spin is one condition: a date-driven regeneration happens only when the clock is currently plausible. A node whose clock is still wrong re-checks and mints nothing.
Regression I introduced and caught
Driving generation purely by content made needs_ssh() false whenever any host key existed —
which would have left an image-baked, fleet-shared host key in place forever. That is F-03
reopened. The marker check is back in both needs_ functions. Case 1 — which prestages a baked
key and asserts it was replaced — is what caught it.
Controls
Control F — bless the cert regardless of clock (the pre-fix behaviour):
FAIL: wrong clock -> run1-BAD-DATES-NOT-RECORDED
passed: 7 failed: 1
Control G — remove the anti-spin guard:
FAIL: wrong clock -> SPINNING-reminted-while-clock-still-wrong(1->2)
passed: 7 failed: 1
Control G first passed against a deliberately broken guard, which was a flaw in my test, not
in the fix: the assertion compared certificate dates, and a re-mint under a frozen fake clock
produces a byte-identical notBefore. Dates cannot distinguish "left alone" from "regenerated
again". The assertion now counts openssl req invocations, which can — and only then did the
control redden. Worth recording as the second time in this plan that a first-draft assertion
looked green for the wrong reason.
Not covered here
Nodes already deployed from earlier ISOs never receive this script — it is installed by the
installer, not shipped by OTA. Fleet remediation for those nodes is 10-04/OTA work in core/**,
which is held by other executors, so per the standing constraint it is reported rather than
attempted.
Known Stubs
None. No placeholder values, no TODOs, no unwired code paths.
Threat Flags
None. No new network endpoint, auth path, file-access pattern or schema change at a trust boundary. The plan installs no packages (T-10-SC: accept); none were added.
UNVERIFIED — needs hardware
Task 3's C-4 checkpoint is now more important, not less: with the rootfs stripped and no install-time fallback, the tar listing is the only pre-hardware evidence that the shipped image is identity-free.
| Item | Audit ref | What it needs | Command |
|---|---|---|---|
| Rootfs tar is identity-free after a forced rebuild | C-4 | ISO build host with podman/docker and disk for a full rootfs rebuild | UNBUNDLED=1 bash image-recipe/build-debian-iso.sh --rebuild, then the tar listings in docs/security/KEY-02-ROOTFS-EVIDENCE.md steps 2/4/5/5b/6 |
| The build-time generator assertion actually fires | C-4 | same build host | grep 'first-boot secret generators present' <build log> — evidence doc step 5b |
| The self-heal timer ships and is enabled on the target | — | same build host, then a node | evidence doc step 5 (timer present on installer media); systemctl status archipelago-first-boot-secrets.timer on a node |
| Two nodes flashed from one ISO get different keys | C-3 | two physical machines | audit §779; both SSH and TLS fingerprints are now equally sharp signals — see the C-3 section of the evidence doc |
| The console leg of the failure shout reaches a real screen | — | a real node, or a VM console | force a first-boot failure and observe /dev/console |
The harness proves the script half of self-heal (a failed run followed by a successful run recovers the node and restarts the failed units). It does not and cannot prove systemd's scheduling — that the timer is enabled and actually fires at 5min/15min. That is hardware verification.
Self-Check
image-recipe/_archived/build-auto-installer-iso.sh— FOUND,bash -ncleantests/first-boot-secrets/run-tests.sh— FOUND, mode 755, exits 0 with 8 PASSdocs/security/KEY-02-ROOTFS-EVIDENCE.md— FOUND, containsC-4deferred-items.md— DELETED; its only entry (D1) is fixed, not filed- Commits
21043096,408b328c,201ef474,2efab5f2,d9b3a7d5,40b77e39— all FOUND - Generated
Dockerfile.rootfsrendered before/after the heredoc change and diffed normalised: 190 lines each, only the six comment restorations differ - Single-producer grep: the only executable key-creating invocations in the builder are
openssl reqandssh-keygen -Ainside the generator heredoc; every other match is a comment git status --porcelain image-recipe/— clean;_archived/not moved or renamed- No file authored by a concurrent agent (
core/archipelago/src/**,neode-ui/**,.planning/STATE.md) was staged in any commit