From 6888c2fff690634b1ad0cf4546c3a4fff10bbd3e Mon Sep 17 00:00:00 2001 From: mendezr Date: Thu, 24 Sep 2026 10:33:06 +0000 Subject: [PATCH] fix(security): force rotation of seeded root password at first login MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The DDI seeds a well-known root password ('bluefin', hash public in this repo) into every shipped image with shadow last-change 19700, so the credential never expires and is identical fleet-wide. PR #169 already restored the sshd drop-in hardening (PermitRootLogin prohibit-password, PasswordAuthentication no), which closes the remote root path; the remaining gap from #168 is that console bring-up never forces rotation. Set the shadow last-change field to 0 (the `chage -d 0 root` equivalent): every login as root — console included — is forced onto a per-install password before any shell is granted. Update the console banner to disclose the forced change, and add a unit contract locking in both the rotation and the SSH no-password-auth policy as a regression guard. The long-term removal of the baked password (core operator account, systemd-credentials key provisioning) is tracked by #80; this is the minimal interim hardening requested by the issue. Fixes: #168 Hive-Run: projectbluefin/server#168 Hive-Plan: Security remediation — interim hardening of seeded root credential (issue #168, recommendation item 2) Hive-Spec: docs/superpowers/specs/2026-09-09-core-login-design.md#interim-shadow-expiry Assisted-by: GLM (z-ai/glm-5.3-flash) via GitHub Copilot Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: mendezr --- elements/oci/bluefin-server-ddi.bst | 9 ++- files/os/issue.d/40-kubestellar.issue | 2 +- tests/unit/test_root_credential_contract.py | 71 +++++++++++++++++++++ 3 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 tests/unit/test_root_credential_contract.py diff --git a/elements/oci/bluefin-server-ddi.bst b/elements/oci/bluefin-server-ddi.bst index c58f9d8e..a6915963 100644 --- a/elements/oci/bluefin-server-ddi.bst +++ b/elements/oci/bluefin-server-ddi.bst @@ -76,9 +76,14 @@ config: # Ensure all standard virtual, serial, and hypervisor consoles allow root login printf 'tty0\ntty1\ntty2\ntty3\ntty4\ntty5\ntty6\nttyS0\nttyS1\nconsole\nhvc0\n' > /layer/etc/securetty - # Seed default root password 'bluefin' into /etc/shadow for console and ssh login + # Seed default root password 'bluefin' for local console bring-up only. + # The last-change field is 0 (equivalent to `chage -d 0 root`), so the + # password is expired at first login and the console forces a per-install + # rotation before any shell is granted. The seeded credential must never + # be usable over the network: the sshd drop-in sets PermitRootLogin + # prohibit-password and PasswordAuthentication no. mkdir -p /layer/etc - printf 'root:$6$bluefin123$o2pQjPN1n3ZCnYUROlA01xAdnGO7mhVRAVw98x4xc8LAUIJv7b44bBNoER6fM4P.rrj4ePYFfkx9WvZICU8nt/:19700:0:99999:7:::\n' > /layer/etc/shadow + printf 'root:$6$bluefin123$o2pQjPN1n3ZCnYUROlA01xAdnGO7mhVRAVw98x4xc8LAUIJv7b44bBNoER6fM4P.rrj4ePYFfkx9WvZICU8nt/:0:0:99999:7:::\n' > /layer/etc/shadow chmod 0600 /layer/etc/shadow printf 'root:x:0:0:root:/root:/bin/bash\n' > /layer/etc/passwd chmod 0644 /layer/etc/passwd diff --git a/files/os/issue.d/40-kubestellar.issue b/files/os/issue.d/40-kubestellar.issue index 862fc3b5..cef7eaaf 100644 --- a/files/os/issue.d/40-kubestellar.issue +++ b/files/os/issue.d/40-kubestellar.issue @@ -1,5 +1,5 @@ Bluefin Server (\l) -Default login: root / bluefin +Default login: root / bluefin (password change forced at first login) KubeStellar Console: https://127.0.0.1:8080/ (loopback, TLS only) Remote access: ssh -L 8080:127.0.0.1:8080 @ diff --git a/tests/unit/test_root_credential_contract.py b/tests/unit/test_root_credential_contract.py new file mode 100644 index 00000000..8ee2ba95 --- /dev/null +++ b/tests/unit/test_root_credential_contract.py @@ -0,0 +1,71 @@ +"""Contracts for the seeded root credential and SSH login policy. + +The shipped DDI seeds a well-known default root password for local console +bring-up only. This file pins the two safety contracts around it: + +- the password is expired at first login (shadow last-change field 0, the + `chage -d 0` equivalent), so every install is forced onto a per-install + secret before any shell is granted; and +- the effective SSH policy never allows the seeded password (or any password) + over the network. +""" + +from __future__ import annotations + +import re +from pathlib import Path + +REPO_ROOT = Path(__file__).resolve().parents[2] +DDI_ELEMENT = REPO_ROOT / "elements" / "oci" / "bluefin-server-ddi.bst" +SSHD_DROPIN = REPO_ROOT / "files" / "os" / "ssh" / "sshd_config.d" / "bluefin-server.conf" +ISSUE_FILE = REPO_ROOT / "files" / "os" / "issue.d" / "40-kubestellar.issue" + + +def _root_shadow_fields(ddi_element: str) -> list[str]: + match = re.search( + r"printf '(root:[^']*)", ddi_element + ) + assert match, "DDI element must seed a root account into /etc/shadow" + shadow_line = match.group(1).split("\\n")[0] + fields = shadow_line.split(":") + assert fields[0] == "root", "seeded shadow line must be the root account" + assert len(fields) == 9, "seeded shadow line must have all 9 shadow fields" + return fields + + +def test_root_password_is_expired_for_first_login_rotation() -> None: + ddi_element = DDI_ELEMENT.read_text(encoding="utf-8") + fields = _root_shadow_fields(ddi_element) + + # shadow field 2 is the last-change date: 0 means expired, so login + # (console included) forces a password rotation before any shell. + assert fields[2] == "0", ( + "seeded root password must be expired at first login (last-change 0); " + "a fixed date leaves the well-known default usable indefinitely" + ) + + +def test_root_password_uses_no_fixed_build_date() -> None: + ddi_element = DDI_ELEMENT.read_text(encoding="utf-8") + fields = _root_shadow_fields(ddi_element) + + # Regression guard: a fixed last-change date (e.g. 19700) ships the same + # usable credential in every image with no rotation enforced. + assert fields[2] != "19700" + + +def test_sshd_dropin_never_permits_password_authentication() -> None: + sshd = SSHD_DROPIN.read_text(encoding="utf-8") + + assert re.search(r"^PermitRootLogin\s+prohibit-password$", sshd, re.MULTILINE) + assert re.search(r"^PasswordAuthentication\s+no$", sshd, re.MULTILINE) + assert re.search(r"^KbdInteractiveAuthentication\s+no$", sshd, re.MULTILINE) + assert not re.search(r"^PermitRootLogin\s+yes$", sshd, re.MULTILINE) + assert not re.search(r"^PasswordAuthentication\s+yes$", sshd, re.MULTILINE) + + +def test_console_banner_discloses_forced_password_change() -> None: + banner = ISSUE_FILE.read_text(encoding="utf-8") + + assert "Default login: root / bluefin" in banner + assert "password change forced at first login" in banner