diff --git a/elements/bluefin-server/os-k0s-first-boot.bst b/elements/bluefin-server/os-k0s-first-boot.bst index 038a1d99..49e5894a 100644 --- a/elements/bluefin-server/os-k0s-first-boot.bst +++ b/elements/bluefin-server/os-k0s-first-boot.bst @@ -1,5 +1,8 @@ kind: import -description: Install the first-boot k0s sysext activation unit. +description: | + Install the systemd units from files/os/systemd/system: the first-boot k0s + sysext activation units, var.mount, and first-start SSH host key generation + (ssh-host-keygen.service plus its sshd.service drop-in). sources: - kind: local diff --git a/elements/flatcar/flatcar-zfs.bst b/elements/flatcar/flatcar-zfs.bst index 82832969..eabdcf8e 100644 --- a/elements/flatcar/flatcar-zfs.bst +++ b/elements/flatcar/flatcar-zfs.bst @@ -10,6 +10,7 @@ description: | build-depends: - base/base-stack.bst + - freedesktop-sdk.bst:components/sed.bst - freedesktop-sdk.bst:components/squashfs-tools.bst variables: @@ -28,6 +29,20 @@ config: # Extract the SquashFS sysext directly into the element install root unsquashfs -no-xattrs -f -d "%{install-root}" flatcar-zfs.raw - # Also preserve the raw sysext image under /usr/lib/sysexts for runtime sysext usage + # Drop Flatcar's udevd sysext ordering override. In Flatcar, ZFS is loaded as + # a runtime sysext, so udevd was ordered After=systemd-sysext.service. + # In Bluefin Server, ZFS is extracted directly into the OS rootfs at build time. + # Leaving this drop-in causes systemd-udevd to wait for systemd-sysext.service, + # which waits for local-fs.target, which waits for var.mount, which waits for + # the udev device unit — creating a boot deadlock. + rm -rf "%{install-root}/usr/lib/systemd/system/systemd-udevd.service.d" + if [ -f "%{install-root}/usr/lib/tmpfiles.d/10-zfs.conf" ]; then + sed -i "/systemd-udevd\.service\.d/d" "%{install-root}/usr/lib/tmpfiles.d/10-zfs.conf" + fi + + # Preserve a raw sysext image under /usr/lib/sysexts for runtime sysext usage. + # Rebuild it from the cleaned tree rather than shipping the upstream image, so + # the udevd ordering override above cannot reappear if the raw is ever merged. + mksquashfs "%{install-root}" zfs-cleaned.raw -noappend -no-xattrs -all-root mkdir -p "%{install-root}/usr/lib/sysexts" - install -D -m 0644 flatcar-zfs.raw "%{install-root}/usr/lib/sysexts/zfs.raw" + install -D -m 0644 zfs-cleaned.raw "%{install-root}/usr/lib/sysexts/zfs.raw" diff --git a/elements/oci/bluefin-server-ddi.bst b/elements/oci/bluefin-server-ddi.bst index 9f801570..be12df1b 100644 --- a/elements/oci/bluefin-server-ddi.bst +++ b/elements/oci/bluefin-server-ddi.bst @@ -78,12 +78,11 @@ config: printf 'root:x:0:\n' > /layer/etc/group chmod 0644 /layer/etc/group - # Pre-generate SSH host keys for first boot remote diagnostics + # SSH host keys are generated per device on first sshd start + # (ssh-host-keygen.service), never at build time: this DDI is published + # as a public release asset, so baked-in keys would expose every + # deployment's host private keys. mkdir -p /layer/etc/ssh - ssh-keygen -q -N "" -t ed25519 -f /layer/etc/ssh/ssh_host_ed25519_key - ssh-keygen -q -N "" -t rsa -b 3072 -f /layer/etc/ssh/ssh_host_rsa_key - chmod 0600 /layer/etc/ssh/ssh_host_*_key - chmod 0644 /layer/etc/ssh/ssh_host_*.pub # Sum actual file sizes across bind mounts (du -sb reports content bytes, not overlay blocks). ROOT_BYTES=$(du -sb /layer | cut -f1) diff --git a/files/os/systemd/system/ssh-host-keygen.service b/files/os/systemd/system/ssh-host-keygen.service new file mode 100644 index 00000000..8388ff6a --- /dev/null +++ b/files/os/systemd/system/ssh-host-keygen.service @@ -0,0 +1,12 @@ +[Unit] +Description=Generate SSH host keys on first sshd start +Documentation=man:ssh-keygen(1) +# Host keys are deliberately NOT baked into the DDI: the release artifact is +# public, so build-time keys would hand every deployment's host identity to +# anyone who downloads the image. Generate them per device instead. +ConditionPathExists=!/etc/ssh/ssh_host_ed25519_key +Before=sshd.service + +[Service] +Type=oneshot +ExecStart=/usr/bin/ssh-keygen -A diff --git a/files/os/systemd/system/sshd.service.d/10-host-keygen.conf b/files/os/systemd/system/sshd.service.d/10-host-keygen.conf new file mode 100644 index 00000000..f213297d --- /dev/null +++ b/files/os/systemd/system/sshd.service.d/10-host-keygen.conf @@ -0,0 +1,6 @@ +# Ensure per-device host keys exist before sshd starts. See +# ssh-host-keygen.service: keys are generated on the device, never at image +# build time, so the public release DDI carries no private key material. +[Unit] +Wants=ssh-host-keygen.service +After=ssh-host-keygen.service