From 845a13302cdc3aeb19f000ff504ac50501863c12 Mon Sep 17 00:00:00 2001 From: Jeffrey Sica Date: Thu, 19 Nov 2026 21:20:34 -0600 Subject: [PATCH] fix(ssh): accept a provisioned key while root is still locked Root ships locked ("!unprovisioned"). Ignition users entries and the ssh.authorized_keys.root credential install a key without touching the password, so root stays locked, and sshd without PAM refuses a locked account even for keys ("User root not allowed because account is locked"). The documented ssh root@ path was refused on netboot, Booty and credential-provisioned nodes. UsePAM yes hands the account check to FSDK's /etc/pam.d/sshd, which ignores the password field. PasswordAuthentication and KbdInteractiveAuthentication stay off, so PAM is never asked for a password. The dogfood SSH login no longer unlocks root first, and asserts root is still locked when the key login succeeds. Assisted-by: Claude via Claude Code Co-Authored-By: Claude Code --- docs/skills/systemd-sysupdate-verification.md | 2 +- docs/skills/usb-installer.md | 4 ++-- files/os/ssh/sshd_config.d/bluefin-server.conf | 6 ++++++ files/os/tmpfiles.d/40-bluefin-motd.conf | 2 +- scripts/dogfood-installer.sh | 9 ++++++--- tests/unit/test_automatic_updates.py | 2 +- tests/unit/test_root_credential_contract.py | 12 ++++++++++++ 7 files changed, 29 insertions(+), 8 deletions(-) diff --git a/docs/skills/systemd-sysupdate-verification.md b/docs/skills/systemd-sysupdate-verification.md index 5ad86f44..761a0607 100644 --- a/docs/skills/systemd-sysupdate-verification.md +++ b/docs/skills/systemd-sysupdate-verification.md @@ -159,7 +159,7 @@ last success, the last error and the run it last recorded in `/var/lib/bluefin-update-status/state`, so they survive reboots and updates, and writes `/run/issue.d/40-bluefin-update.issue` (agetty, next to `/usr/lib/issue.d/30-bluefin.issue`) and `/run/motd`. login (`MOTD_FILE` in -`login.defs`) and sshd (`UsePAM no`) only print `/etc/motd`, so +`login.defs`) and sshd (`PrintMotd`) only print `/etc/motd`, so `tmpfiles.d/40-bluefin-motd.conf` links it to `/run/motd` unless the operator has an `/etc/motd` of their own. It only reads local state and contacts nothing. A failed check also stays a failed unit, `systemd-sysupdate.service`, diff --git a/docs/skills/usb-installer.md b/docs/skills/usb-installer.md index 780a9a9c..fec18d2e 100644 --- a/docs/skills/usb-installer.md +++ b/docs/skills/usb-installer.md @@ -343,8 +343,8 @@ printf 'd /home/%s 0700 %s %s -\nd /home/%s/.ssh 0700 %s %s -\nf+~ /home/%s/.ssh # ssh.listen: systemd-ssh-generator takes the binary form only (v261 does # not unbase64); services take the base64 form systemd-creds writes printf 22 | enc ssh.listen - | base64 -d > ssh.listen.cred -# "*": no password login, but not locked like sysusers' default "!*", which -# sshd (UsePAM no) refuses even for keys +# "*": no password login; sshd takes the key either way (UsePAM yes), but +# "*" is not reported locked like sysusers' default "!*" printf '*' | enc "passwd.hashed-password.$user" "passwd.hashed-password.$user.cred" printf '!*' | enc passwd.hashed-password.root passwd.hashed-password.root.cred # copy the five .cred files into /loader/credentials/ on the stick's ESP diff --git a/files/os/ssh/sshd_config.d/bluefin-server.conf b/files/os/ssh/sshd_config.d/bluefin-server.conf index 34d9ade8..c9db7d7d 100644 --- a/files/os/ssh/sshd_config.d/bluefin-server.conf +++ b/files/os/ssh/sshd_config.d/bluefin-server.conf @@ -9,6 +9,12 @@ PermitRootLogin prohibit-password PubkeyAuthentication yes PasswordAuthentication no KbdInteractiveAuthentication no +# Without PAM, sshd refuses a locked account ("!" password) even for a key, +# and root stays locked when Ignition or the ssh.authorized_keys.root +# credential gives it only a key. With PAM, FSDK's /etc/pam.d/sshd account +# stack decides instead; it ignores the password field. The two lines above +# keep PAM out of authentication, so this opens no password path. +UsePAM yes # Keep standard SSH file transfer available without another server process. Subsystem sftp internal-sftp diff --git a/files/os/tmpfiles.d/40-bluefin-motd.conf b/files/os/tmpfiles.d/40-bluefin-motd.conf index 9fa33d91..1f8d3188 100644 --- a/files/os/tmpfiles.d/40-bluefin-motd.conf +++ b/files/os/tmpfiles.d/40-bluefin-motd.conf @@ -1,4 +1,4 @@ -# login (MOTD_FILE in login.defs) and sshd (UsePAM no) print /etc/motd only. +# login (MOTD_FILE in login.defs) and sshd (PrintMotd) print /etc/motd only. # Point it at the runtime message bluefin-update-status writes. Without "+", # an /etc/motd the operator wrote stays. L /etc/motd - - - - ../run/motd diff --git a/scripts/dogfood-installer.sh b/scripts/dogfood-installer.sh index c367f505..78d45ad8 100644 --- a/scripts/dogfood-installer.sh +++ b/scripts/dogfood-installer.sh @@ -873,10 +873,11 @@ sync echo "PROBE update-done" UPDATE # Appended to the probe of step 6: an SSH login through systemd-ssh-generator's -# local socket must print the banner (sshd reads /etc/motd). sshd refuses a -# locked root even for keys, so root gets the unlocked "*" first. +# local socket must print the banner (sshd reads /etc/motd). Root keeps its +# locked password, as with an Ignition- or credential-provisioned key: the +# login proves sshd (UsePAM yes) takes a key for a locked root. cat > "${state}/ssh.sh" <<'SSH' -usermod -p '*' root +echo "PROBE ssh-root-locked=$(passwd -S root | cut -d' ' -f2)" ssh-keygen -q -t ed25519 -N '' -f /run/dogfood-ssh install -d -m 0700 /root/.ssh cat /run/dogfood-ssh.pub >> /root/.ssh/authorized_keys @@ -1113,6 +1114,8 @@ banner_lacks 6-updated boot 'FAILED' banner_lacks 6-updated boot 'staged' grep -aqF "PROBE ssh-motd=Bluefin Server ${next_ver}, automatic updates on" "${state}/6-updated.ttyS1.log" \ || fail "6-updated: an SSH login does not show the banner: $(grep -a 'ssh' "${state}/6-updated.ttyS1.log" | tail -n 5)" +grep -aq 'PROBE ssh-root-locked=L' "${state}/6-updated.ttyS1.log" \ + || fail "6-updated: root was not locked for the SSH key login: $(grep -ao 'PROBE ssh-root-locked=.*' "${state}/6-updated.ttyS1.log")" checked="a local server after reporting an unreachable and a foreign-signed source as failed checks on its banner" [ "${next}" != release ] || checked="the image's own source" diff --git a/tests/unit/test_automatic_updates.py b/tests/unit/test_automatic_updates.py index 17cfa04d..d2f12e8f 100644 --- a/tests/unit/test_automatic_updates.py +++ b/tests/unit/test_automatic_updates.py @@ -248,7 +248,7 @@ def test_the_banners_are_the_files_agetty_login_and_sshd_read() -> None: # agetty merges /run/issue.d with the image's /usr/lib/issue.d banner. assert '"/run/issue.d/40-bluefin-update.issue"' in script assert (ROOT / "files" / "os" / "issue.d" / "30-bluefin.issue").name < "40-bluefin-update.issue" - # shadow's login (MOTD_FILE /etc/motd) and sshd (UsePAM no) read only + # shadow's login (MOTD_FILE /etc/motd) and sshd (PrintMotd) read only # /etc/motd; it links to the runtime file, never over an operator's own. assert '"/run/motd"' in script lines = [line.split() for line in MOTD_LINK.read_text(encoding="utf-8").splitlines() if line and not line.startswith("#")] diff --git a/tests/unit/test_root_credential_contract.py b/tests/unit/test_root_credential_contract.py index b9be6c6e..ebcf127b 100644 --- a/tests/unit/test_root_credential_contract.py +++ b/tests/unit/test_root_credential_contract.py @@ -130,6 +130,18 @@ def test_sshd_dropin_never_permits_password_authentication() -> None: assert not re.search(r"^PasswordAuthentication\s+yes$", sshd, re.MULTILINE) +def test_sshd_accepts_keys_for_a_root_that_has_no_password() -> None: + # Root ships locked ("!unprovisioned"); Ignition and the + # ssh.authorized_keys.root credential give it a key without unlocking it. + # Without PAM, sshd refuses a locked account even for keys. + sshd = SSHD_DROPIN.read_text(encoding="utf-8") + + assert re.search(r"^UsePAM\s+yes$", sshd, re.MULTILINE) + # The dogfood SSH login must prove it on a locked root, not unlock it. + dogfood = (REPO_ROOT / "scripts" / "dogfood-installer.sh").read_text(encoding="utf-8") + assert "usermod -p '*' root" not in dogfood + + def test_generated_sshd_gets_per_device_host_keys() -> None: dropin = GENERATED_SSHD_DROPIN.read_text(encoding="utf-8")