From faa05685a4f5643ed227d3dfdfed26c4fcb07613 Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Tue, 17 Nov 2026 21:18:40 -0800 Subject: [PATCH 1/3] feat(packer): build 901 without networking in its initramfs Every clone of template 901 asked the lab's DHCP server for an address from its dracut initramfs before its static address applied; eden leased from the pool at each boot. The Ubuntu build now omits net-lib and systemd-networkd from every initramfs and fails if one survives, the smoke test fails a clone that DHCPs before switch-root, and eden's runbook carries the step for clones of an older 901. Co-Authored-By: Claude Opus 5.5 --- docs/changelog.md | 20 +++++++++ docs/runbooks/build-the-bloodhound-guest.md | 44 +++++++++++++++++++ docs/runbooks/build-the-lab-templates.md | 10 ++++- packer/ubuntu.pkr.hcl | 7 +++ packer/ubuntu/no-initramfs-network.sh | 48 +++++++++++++++++++++ scripts/packer-smoke.sh | 22 ++++++++++ 6 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 packer/ubuntu/no-initramfs-network.sh diff --git a/docs/changelog.md b/docs/changelog.md index 59e12235..e18118d8 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -19,6 +19,26 @@ docstring gives: it is a record, not a claim about now. ## 2026-11-18 +- **`eden` no longer asks for an address while it boots, and template `901` + stops making guests that do.** `eden` was off when "Every 26.04 lab guest + asked the lab's DHCP server for an address while it booted", below, was + written. Read when it next started, its initramfs had leased `.106` from + the pool on both boots of 2026-11-16 and `.101` at 05:10 UTC today. `eden` + is not an ISO install but a clone of Packer template `901`, so the cause is + in the template, and every later clone would have done the same. + - **The template:** `packer/ubuntu/no-initramfs-network.sh` now runs after + the upgrade. It writes the drop-in the hand-installed guests carry, + rebuilds every initramfs, and fails the build if one still has + networking. `901` has not been rebuilt with it yet. + - **The smoke test:** `scripts/packer-smoke.sh` now fails a Linux clone whose + journal shows DHCP before switch-root. Run against `eden` before the fix, + its check read 2. + - **`eden` itself:** `build-the-bloodhound-guest.md` §2 carries the step for + a clone of an older `901`. Applied at 05:15 UTC, the reboot at 05:16 + showed no DHCP or networkd before switch-root, and `eth0` held only `.41`. + `/srv/bloodhound-data` was mounted, all five BloodHound containers came + back, and the rollback copy is deleted. + - **`fenrir`'s login from `10.0.30.110` was `Saruman`, on the evening it moved.** This answers what "`fenrir`'s audit of 2026-11-13 is closed on the box", filed under 2026-11-17, left open. `fenrir`'s journal records diff --git a/docs/runbooks/build-the-bloodhound-guest.md b/docs/runbooks/build-the-bloodhound-guest.md index edca1481..12b259ad 100644 --- a/docs/runbooks/build-the-bloodhound-guest.md +++ b/docs/runbooks/build-the-bloodhound-guest.md @@ -183,6 +183,50 @@ sudo stat -c '%a %u %n' /srv/bloodhound-data/postgres/18/docker # 700 999 `qm guest cmd 141 get-fsinfo` on `Saruman` should list `/` and `/srv/bloodhound-data`. +### No network in the initramfs + +Ubuntu 26.04's initramfs is dracut's. It carries systemd-networkd and a +catch-all, `zzzz-dracut-default.network`, that runs DHCP on every interface, +so the NIC asks the lab's DHCP server for an address before the static `.41` +applies. `eden` leased `.106` from the pool on both of its boots on +2026-11-16, and `.101` on 2026-11-18. Template `901` leaves networking out of +the initramfs since `packer/ubuntu/no-initramfs-network.sh`, so a clone of a +template built after that needs only the check below. A clone of an older +`901`, `eden` as built, needs the drop-in the hand-installed guests carry +([`build-the-lab-guest.md`](build-the-lab-guest.md) §2): + +```bash +sudo tee /etc/dracut.conf.d/10-homelab-no-network.conf >/dev/null <<'CONF' +# eden: no networking in the initramfs (build-the-bloodhound-guest.md §2). +# The root disk is local. With systemd-networkd in the image, its catch-all +# DHCPs the NIC before the static address applies. +# Same line as dracut's own dracut.conf.d/no-network profile. +omit_dracutmodules+=" net-lib systemd-networkd " +CONF +ls /var/run/reboot-required 2>/dev/null && echo 'reboot first' +k="$(uname -r)" +sudo cp -p "/boot/initrd.img-$k" "/boot/initrd.img-$k.pre-no-network" +sudo update-initramfs -u -k "$k" +sudo lsinitrd -m "/boot/initrd.img-$k" | grep -E 'net-lib|systemd-networkd' # nothing +``` + +If `reboot first` prints, reboot, then run the last four lines. The +`dracut[E]` line for `dyn-netconf` is the omit working, as `alexander`'s §2 +says. If the new image does not boot, open VM 141's console in the Proxmox web +UI, hold Esc for GRUB's menu, press `e`, add `.pre-no-network` to the end of +the `initrd` line's file name, and boot with Ctrl-X. + +Either way, reboot and check that nothing before switch-root asked for an +address. The initramfs calls the NIC `ens18`; the running system calls it +`eth0`: + +```bash +sudo journalctl -b -o short-iso | awk '/Switching root/{exit} {print}' | grep -cE 'DHCPv4|zzzz-dracut-default' # 0 +ip -4 -o addr show eth0 | awk '{print $4}' # 10.0.30.41/24 +``` + +Then delete the copy, if you made one. + ## 3. Docker, the repository, and its own key Install Docker, `age`, `git` and `make` as `alexander`'s §3 describes, and add diff --git a/docs/runbooks/build-the-lab-templates.md b/docs/runbooks/build-the-lab-templates.md index b0894f31..67f67925 100644 --- a/docs/runbooks/build-the-lab-templates.md +++ b/docs/runbooks/build-the-lab-templates.md @@ -370,7 +370,11 @@ What each one does, so a stall can be placed: `autoinstall` off the kernel line, and fails the build if any of that is left. Packer then upgrades, turns off X11 forwarding, takes `lxd` out of cloud-init's default user groups, and wipes cloud-init's state, machine-id - and host keys. It then deletes the `packer` user. + and host keys. `packer/ubuntu/no-initramfs-network.sh` then rebuilds every + initramfs without networking, so a clone does not ask the lab's DHCP server + for an address while it boots, and fails the build if one still has it. It + prints a `dracut[E]` line for `dyn-netconf`, which is the omit working. + It then deletes the `packer` user. - **Fedora** picks "Install Fedora" from the GRUB menu, whose default is the media check. Anaconda finds `ks.cfg` on the `OEMDRV` disc by itself, installs Server unattended in text mode, and reboots. The rest is @@ -669,7 +673,9 @@ scripts/packer-smoke.sh 910 Each run makes a full clone at VMID 999. For Linux, it gives the clone user `smoke`, `phoenix`'s key and DHCP through cloud-init, boots it, and waits for the agent to report an address. It then checks the hostname and SSHes in. -Finally it destroys the clone. +Where the clone booted through a systemd initramfs, it checks the journal +shows no DHCP before switch-root; a clone of a `901` built before +`no-initramfs-network.sh` fails there. Finally it destroys the clone. A Windows clone runs specialize and OOBE first. Its guest agent is disabled in the template, and `SetupComplete.cmd` starts it as its last step, so the diff --git a/packer/ubuntu.pkr.hcl b/packer/ubuntu.pkr.hcl index 72cb9247..d8ac8c44 100644 --- a/packer/ubuntu.pkr.hcl +++ b/packer/ubuntu.pkr.hcl @@ -152,6 +152,13 @@ build { ] } + # After the upgrade, so every kernel a clone can boot has its image rebuilt + # without networking. The script fails the build if one still carries it. + provisioner "shell" { + execute_command = "sudo -E sh -eu '{{ .Path }}'" + script = "${abspath(path.root)}/ubuntu/no-initramfs-network.sh" + } + # Last: remove the build user. -f because this session is that user's, and # skip_clean because the script cannot delete itself from a home directory # that no longer exists. The builder then shuts the guest down through the diff --git a/packer/ubuntu/no-initramfs-network.sh b/packer/ubuntu/no-initramfs-network.sh new file mode 100644 index 00000000..1088aeaf --- /dev/null +++ b/packer/ubuntu/no-initramfs-network.sh @@ -0,0 +1,48 @@ +#!/bin/sh +# Leaves networking out of every initramfs in the template, as root over +# Packer's SSH session (packer/ubuntu.pkr.hcl). Runs after the upgrade, so the +# kernel a clone boots is one of the images rebuilt here. +# +# Ubuntu 26.04's initramfs is dracut's, and it carries systemd-networkd with a +# catch-all, zzzz-dracut-default.network, that runs DHCP on every interface. +# Every clone of 901 therefore took a lease from the lab pool while it booted, +# before cloud-init's static address applied: eden leased .106 and .101 on its +# boots of 2026-11-16 and 2026-11-18 (docs/changelog.md). The root disk is +# local, so the initramfs needs no network at all. This is the drop-in the +# hand-installed guests carry (build-the-sensor-guest.md §3). +# +# update-initramfs prints a dracut[E] line for dyn-netconf, from +# cloud-initramfs-dyn-netconf, which depends on systemd-networkd. That is the +# omit working; the lsinitrd check below is what decides. +set -eu + +cat > /etc/dracut.conf.d/10-homelab-no-network.conf <<'CONF' +# No networking in the initramfs (packer/ubuntu/no-initramfs-network.sh). +# The root disk is local. With systemd-networkd in the image, its catch-all +# DHCPs every interface before cloud-init's static address applies. +# Same line as dracut's own dracut.conf.d/no-network profile. +omit_dracutmodules+=" net-lib systemd-networkd " +CONF +chmod 644 /etc/dracut.conf.d/10-homelab-no-network.conf + +built=0 +for v in /boot/vmlinuz-*; do + [ -e "$v" ] || continue + k="${v#/boot/vmlinuz-}" + update-initramfs -u -k "$k" + built=$((built + 1)) +done +if [ "$built" -eq 0 ]; then + echo "no-initramfs-network.sh: no kernel found under /boot" >&2 + exit 1 +fi + +# Fail the build rather than ship a template whose clones still DHCP at boot. +for img in /boot/initrd.img-*; do + [ -e "$img" ] || continue + if lsinitrd -m "$img" | grep -qE 'net-lib|systemd-networkd'; then + echo "no-initramfs-network.sh: $img still carries networking" >&2 + exit 1 + fi +done +echo "no-initramfs-network.sh: $built initramfs image(s) rebuilt without networking" diff --git a/scripts/packer-smoke.sh b/scripts/packer-smoke.sh index bc5b098d..cb7b4272 100755 --- a/scripts/packer-smoke.sh +++ b/scripts/packer-smoke.sh @@ -14,6 +14,8 @@ # Linux the clone takes its name, user and key from the Proxmox cloud-init # drive: the agent reports an address, get-host-name returns the name # given here, and phoenix's key opens an SSH session that prints it. +# Where the clone booted through a systemd initramfs, its journal +# shows no DHCP before switch-root. # Windows the generalised image finishes OOBE unattended and the guest agent # comes up with an address. The agent is disabled in the template # and started by SetupComplete.cmd as its last act, so an address @@ -203,6 +205,26 @@ if [[ "${ostype}" == l26 ]]; then got="$(ssh_hostname smoke)" || die "smoke@${addr} admitted no SSH login in three minutes" [[ "${got}" == "${NAME}" ]] || die "ssh smoke@${addr} printed ${got}, expected ${NAME}" ok "phoenix's key opens smoke@${addr}" + # A clone must not ask for an address before switch-root. Ubuntu's dracut + # initramfs did, on every clone of 901, until no-initramfs-network.sh: eden + # leased from the lab pool at each boot (packer/ubuntu/no-initramfs-network.sh). + # Only where the boot went through a systemd initramfs, whose journal marks + # the switch; a template without one has nothing here to check. + early="$(ssh -i "${SSH_KEY}" -o BatchMode=yes -o StrictHostKeyChecking=no \ + -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR "smoke@${addr}" \ + 'command -v journalctl >/dev/null || { echo none; exit 0; } + j="$(sudo -n journalctl -b -o cat 2>/dev/null)" || { echo unreadable; exit 0; } + printf "%s\n" "$j" | grep -q "Switching root" || { echo none; exit 0; } + printf "%s\n" "$j" | awk "/Switching root/{exit} {print}" | grep -cE "DHCPv4 address|zzzz-dracut-default" || true' \ + 2>/dev/null | tr -d '\r')" + case "${early}" in + 0) ok "no DHCP before switch-root" ;; + none) ok "no systemd initramfs on this family, so no early DHCP to check" ;; + # Skipped, not passed: a family whose cloud-init user has no passwordless + # sudo cannot be read here. 901's can (eden, a clone, has it). + unreadable) printf '\033[0;33m SKIP\033[0m %s\n' "smoke@${addr} cannot read the journal with sudo -n: early DHCP not checked" ;; + *) die "the clone asked for an address before switch-root (${early:-no answer}): the initramfs still carries networking" ;; + esac else ok "hostname ${host} (sysprep's random name; the real one is ansible/'s)" # The way ansible/ reaches every guest (ADR-0077): sshd, started by From 562f84e0704ce4339eb83eee11bc723a365a29dc Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Tue, 17 Nov 2026 21:18:54 -0800 Subject: [PATCH 2/3] chore(packer): make no-initramfs-network.sh executable, as prune.sh is Co-Authored-By: Claude Opus 5.5 --- packer/ubuntu/no-initramfs-network.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 packer/ubuntu/no-initramfs-network.sh diff --git a/packer/ubuntu/no-initramfs-network.sh b/packer/ubuntu/no-initramfs-network.sh old mode 100644 new mode 100755 From 507260556eb78a274e040032e9029fa8687e0265 Mon Sep 17 00:00:00 2001 From: Gerrrt Date: Tue, 17 Nov 2026 21:22:51 -0800 Subject: [PATCH 3/3] fix(packer): fail the initramfs check when lsinitrd fails In `if lsinitrd | grep -q`, the status is grep's and set -e does not apply, so a failed lsinitrd read as an image without networking. Read the module list first and fail if lsinitrd errors or lists nothing. Co-Authored-By: Claude Opus 5.5 --- packer/ubuntu/no-initramfs-network.sh | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packer/ubuntu/no-initramfs-network.sh b/packer/ubuntu/no-initramfs-network.sh index 1088aeaf..e1c08d01 100755 --- a/packer/ubuntu/no-initramfs-network.sh +++ b/packer/ubuntu/no-initramfs-network.sh @@ -38,9 +38,16 @@ if [ "$built" -eq 0 ]; then fi # Fail the build rather than ship a template whose clones still DHCP at boot. +# The module list is read first, on its own: in `lsinitrd | grep` inside an +# `if`, the status is grep's and `set -e` does not apply, so an lsinitrd that +# failed would read as an image with no networking. for img in /boot/initrd.img-*; do [ -e "$img" ] || continue - if lsinitrd -m "$img" | grep -qE 'net-lib|systemd-networkd'; then + if ! mods="$(lsinitrd -m "$img")" || [ -z "$mods" ]; then + echo "no-initramfs-network.sh: lsinitrd could not list the modules in $img" >&2 + exit 1 + fi + if printf '%s\n' "$mods" | grep -qE 'net-lib|systemd-networkd'; then echo "no-initramfs-network.sh: $img still carries networking" >&2 exit 1 fi