Repository navigation
fix(scripts): regenerate machine-id and SSH host keys per board on first boot - #424
Merged
Merged
Conversation
RobeMartins
approved these changes
Nov 20, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
RF50 SD images are cloned from a booted box, so every printer shares
/etc/machine-idand SSH host keys. NetworkManager derives stable-privacy IPv6 addresses from the machine-id, so boxes on one network get the same IPv6 addresses. avahi then reports a host name conflict and renames the box to<hostname>-N.local. This change gives each board its own identity on its first boot.Changes
scripts/hostname-helper.sh: regenerates the identity once per board, while the boot unit runs beforebasic.target(systemctl is-system-runningreportsinitializing). Each step has its own marker holding the CPU serial, so a failure retries only that step and never re-rolls an earlier one:/var/lib/blocksscreen/identity-serial): replace/etc/machine-idatomically, keep/var/lib/dbus/machine-ida symlink to it, and delete a v1 NetworkManagersecret_key. v2 keys are hashed with the machine-id; v1 keys are used raw and would keep the shared IPv6 seed. NM writes a fresh v2 key at start./var/lib/blocksscreen/hostkeys-serial): generate into a staging dir, rename over the old keys, then delete key types and host certificates the new set does not replace. Ifssh-keygenfails, the current keys stay.Each marker is written after a
sync.The gate is the boot state, not a unit flag. Release-2.0 boxes run an older unit, and only this script rewrites it at boot, because updates hard-reset the tree and
post-mergenever runs. Those boxes regenerate on their first reboot after updating.tests/scripts/test_hostname_helper.py: covers:ssh-keygenkeeping the current keys and retrying only them, with the machine-id stable across retries;secret_key, including a binary one;basic.target.Motivation
Each printer needs a unique machine-id for unique IPv6 addresses and a stable
.localname. Shared SSH host keys also let one box impersonate another.What changes with the machine-id on RF50:
known_hostsentry.dhcp-client-id/dhcp-duidand noNetworkManager.confoverride exists, so the client ID stays MAC-based.Storage=volatile, so no per-machine-id log directory is lost.MACAddressPolicy=persistent: not applicable, every interface has a permanent MAC.Notes:
basic.targetand see the new identity.ssh-keygenhas full entropy. Regeneration adds 1 to 5 s to that one boot, mostly RSA key generation./etc/machine-idand no host keys so systemd and sshd create them natively; this change repairs boards already in the field.Tests
pytest tests/scripts/test_hostname_helper.py: 12 passed. shellcheck is clean.