Skip to content

Per-machine host identity on /data: SSH host keys and machine-id never ship baked - #917

Merged
VijitSingh97 merged 3 commits into
develop-v2from
fix/894-895-identity-on-data
Aug 13, 2026
Merged

Per-machine host identity on /data: SSH host keys and machine-id never ship baked#917
VijitSingh97 merged 3 commits into
develop-v2from
fix/894-895-identity-on-data

Conversation

@VijitSingh97

Copy link
Copy Markdown
Collaborator

Closes #894, closes #895.

Both identities were generated by their packages' postinst inside the Docker build: extractable from any published release, identical across every machine flashed from it, silently rotated whenever the apt layer rebuilt. One mechanism now carries both, per the issues' option 1:

  • Bake (os/rootfs/Dockerfile): ssh_host_* deleted, /etc/machine-id shipped empty; sshd pointed at /data/ssh via sshd_config.d (Debian trixie's stock config Includes it, and one explicit HostKey disables the compiled-in default paths).
  • SSH: an ssh.service drop-in (RequiresMountsFor=/data) runs a generate-if-missing ExecStartPre — ed25519 into /data/ssh, tight modes, idempotent, stale-partial-safe. Identity survives A/B swaps and rebuilds; the debug variant's baked authorized_keys is user auth and untouched.
  • machine-id: an early oneshot (DefaultDependencies=no, Before=systemd-networkd.service systemd-journal-flush.service) restores the persisted id from /data/pithead/machine-id — before the DHCP DUID and the journal directory key observe it — or adopts+persists this boot's id on a true first boot. Handles both PID-1 shapes (direct overlay write and ro bind mount).
  • First-boot containment (review catch): an empty machine-id on a volatile /etc upper makes EVERY boot a first boot, and PID 1's first-boot preset-all with Debian's no-preset-files fallback ("enable") would have quietly re-enabled the disabled ssh.service on release images. A baked disable * preset neutralizes that pass and systemd-firstboot is masked. verify-image pins both.
  • Reset tiers: keep-everything keeps the identity; the data tier explicitly deletes /data/ssh (machine-id already goes with the pithead tree); all/factory-reset destroy everything as before — a handed-over machine keeps nothing.
  • Gates: verify-image asserts no baked keys, empty machine-id, drop-in ordering, unit enablement, preset + mask; the battery asserts machine-id stable across a reboot (boot phase) and both identities surviving the A/B swap (update phase).

make lint + full suite green (stack 2171/0, dashboard 1760, verify-image and run.sh additions shellchecked). The KVM battery run right after merge is the live proof for the new asserts. Verifier + security review passed; ponytail cut two env knobs nothing set.

🤖 Generated with Claude Code

VijitSingh97 and others added 3 commits August 13, 2026 07:38
Both were baked into the appliance image at build time (openssh-server's and
systemd's own postinst), making them extractable from a published release and
identical across every machine flashed from one — and silently rotating on any
image rebuild (#894, #895).

The image now ships neither: no ssh_host_* files, and a 0-byte machine-id so
systemd runs its own documented first-boot semantics. Both are then generated
once, at boot, into /data — the single persistence root Tor's onion identity
already lives on:

- SSH: a baked ssh.service drop-in (RequiresMountsFor=/data) generates a host
  key into /data/ssh before sshd starts, and sshd_config.d points HostKey
  there. The debug variant's baked authorized_keys stays untouched (user auth,
  out of scope).
- machine-id: a new early oneshot unit (pithead-machine-id.service, ordered
  before systemd-networkd and systemd-journal-flush) restores the persisted id
  from /data, or adopts and persists this boot's id on a genuinely first boot.

The installer's reinstall tiers and the appliance's own factory-reset both
already destroy or preserve /data/pithead wholesale, so host identity follows
the same keep/wipe classification as everything else there with one small
addition (pithead-install now also clears /data/ssh, which sits outside the
pithead/ tree the existing wipe already rm -rf's).

tests/os/verify-image.sh asserts the built image ships neither identity
concrete; tests/os/run.sh asserts host identity survives an A/B update and
machine-id stays stable across a plain reboot.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
An empty /etc/machine-id on a volatile /etc upper makes EVERY boot a
first boot to systemd, and PID 1 applies preset-all (enable-only) on
first boot. Debian ships no preset files and systemd's no-preset
fallback is enable — a release image would quietly re-enable the
deliberately-disabled ssh.service each power cycle. Bake a blanket
disable-* preset so the pass is a no-op, and mask systemd-firstboot
(would re-run per boot and can prompt on console for unset basics).

Also harden the machine-id restore for both PID-1 shapes (direct write
into the writable overlay upper vs read-only bind mount from /run):
drop a bind mount if one exists before writing, and correct the
comment that described only the read-only shape. verify-image.sh now
pins the preset file and the firstboot mask alongside the identity
assertions.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…iew)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant