From 7283e2cfeb7d9e64c0f51d10ad142e5008dc1c27 Mon Sep 17 00:00:00 2001 From: Jeffrey Sica Date: Thu, 19 Nov 2026 22:42:50 -0600 Subject: [PATCH] fix(os): stop enabling the iSNS server and systemd-homed FSDK has no catch-all "disable *", so units without a preset line are enabled on first boot. The dogfood boot log shows isnsd.socket, isnsd.service and systemd-homed.service all started. isnsd is open-isns's iSNS server and listens on TCP 3205 on every interface; the iSCSI initiator does not need it. Nothing here uses homed (root ships locked, accounts come from sysusers and Ignition). 80-bluefin-unused.preset disables them. Presets apply on first boot only, so bluefin-disable-unused-migrate runs `systemctl preset --now` on exactly those four units once on installed nodes that updated into this image; a preset that enables one (Ignition's) still wins. Assisted-by: Claude via Claude Code Co-Authored-By: Claude Code --- docs/skills/kubeadm-sysext.md | 4 +- elements/bluefin-server/os-host.bst | 9 ++-- elements/oci/bluefin-server-usr.bst | 3 ++ .../homelab/cluster/cmd/bluefin-host/main.go | 26 +++++----- .../cluster/internal/host/unused/unused.go | 50 ++++++++++++++++++ .../internal/host/unused/unused_test.go | 52 +++++++++++++++++++ .../system-preset/80-bluefin-unused.preset | 13 +++++ .../bluefin-disable-unused-migrate.service | 21 ++++++++ tests/unit/conftest.py | 1 + tests/unit/test_os_contracts.py | 26 ++++++++++ 10 files changed, 188 insertions(+), 17 deletions(-) create mode 100644 files/homelab/cluster/internal/host/unused/unused.go create mode 100644 files/homelab/cluster/internal/host/unused/unused_test.go create mode 100644 files/os/systemd/system-preset/80-bluefin-unused.preset create mode 100644 files/os/systemd/system/bluefin-disable-unused-migrate.service diff --git a/docs/skills/kubeadm-sysext.md b/docs/skills/kubeadm-sysext.md index 25ab579f..9293b8b3 100644 --- a/docs/skills/kubeadm-sysext.md +++ b/docs/skills/kubeadm-sysext.md @@ -249,7 +249,9 @@ and `iscsid`, with `iscsid.socket` enabled by `80-bluefin-iscsi.preset` so iscsid starts on first use. `iscsid.service` requires `iscsi-init.service`, which writes `/etc/iscsi/initiatorname.iscsi` only if absent (a fresh name per diskless boot; an Ignition-written file wins). `iscsi.service` auto-login is -off. `/etc/iscsi/iscsid.conf` comes from the factory `/etc` +off, and so is `isnsd`, open-isns's iSNS server (TCP 3205), which the +initiator does not need (`80-bluefin-unused.preset`, with systemd-homed). +`/etc/iscsi/iscsid.conf` comes from the factory `/etc` (`30-bluefin-iscsi.conf` restores it and creates `/var/lib/iscsi`), which is what democratic-csi's `chroot /host ... iscsiadm` node plugin needs. diff --git a/elements/bluefin-server/os-host.bst b/elements/bluefin-server/os-host.bst index 03ae4bcd..d89c9ff6 100644 --- a/elements/bluefin-server/os-host.bst +++ b/elements/bluefin-server/os-host.bst @@ -8,6 +8,7 @@ description: | /usr/libexec/bluefin-hostname keep working: - update path: bluefin-update-status, bluefin-update-status-migrate, bluefin-update-pending, bluefin-reboot-lock (FleetLock client), + bluefin-disable-unused-migrate, bluefin-boot-deadline, bluefin-diskless-update-check, bluefin-sysext-fetch, bluefin-boot-origin; - first boot: bluefin-hostname, bluefin-firstboot-credentials, @@ -56,9 +57,9 @@ config: set -eu install -D -m 0755 bluefin-host "%{install-root}/usr/bin/bluefin-host" mkdir -p "%{install-root}/usr/libexec" - for helper in boot-deadline boot-origin diskless-update-check \ - firstboot-credentials hostname reboot-lock repair-etc-modes \ - sysext-fetch sysext-modules update-pending update-status \ - update-status-migrate; do + for helper in boot-deadline boot-origin disable-unused-migrate \ + diskless-update-check firstboot-credentials hostname reboot-lock \ + repair-etc-modes sysext-fetch sysext-modules update-pending \ + update-status update-status-migrate; do ln -s ../bin/bluefin-host "%{install-root}/usr/libexec/bluefin-${helper}" done diff --git a/elements/oci/bluefin-server-usr.bst b/elements/oci/bluefin-server-usr.bst index d580c7ef..df31dc98 100644 --- a/elements/oci/bluefin-server-usr.bst +++ b/elements/oci/bluefin-server-usr.bst @@ -168,6 +168,9 @@ config: # does, once per installed node (projectbluefin/server#367). ln -sf ../bluefin-update-status-migrate.service \ /sysroot/usr/lib/systemd/system/multi-user.target.wants/bluefin-update-status-migrate.service + # The same for 80-bluefin-unused.preset (isnsd, systemd-homed). + ln -sf ../bluefin-disable-unused-migrate.service \ + /sysroot/usr/lib/systemd/system/multi-user.target.wants/bluefin-disable-unused-migrate.service # Enabled in /usr, not by preset: a node that updated into this image # must still give its FleetLock slot back once an operator configures a # server, or its group stops rebooting. Inert without a server. diff --git a/files/homelab/cluster/cmd/bluefin-host/main.go b/files/homelab/cluster/cmd/bluefin-host/main.go index 0aba8b64..41316f76 100644 --- a/files/homelab/cluster/cmd/bluefin-host/main.go +++ b/files/homelab/cluster/cmd/bluefin-host/main.go @@ -22,6 +22,7 @@ import ( "github.com/projectbluefin/server/files/homelab/cluster/internal/host/kube" "github.com/projectbluefin/server/files/homelab/cluster/internal/host/sys" "github.com/projectbluefin/server/files/homelab/cluster/internal/host/sysextfetch" + "github.com/projectbluefin/server/files/homelab/cluster/internal/host/unused" "github.com/projectbluefin/server/files/homelab/cluster/internal/host/updatepending" "github.com/projectbluefin/server/files/homelab/cluster/internal/host/updatestatus" ) @@ -40,18 +41,19 @@ var cLocale = map[string]bool{ // helpers are installed as /usr/libexec/bluefin- symlinks. var helpers = map[string]command{ - "boot-deadline": bootdeadline.Main, - "boot-origin": bootorigin.Main, - "diskless-update-check": diskless.Check, - "firstboot-credentials": firstboot.Main, - "hostname": hostname.Main, - "reboot-lock": fleetlock.Main, - "repair-etc-modes": etcmodes.Main, - "sysext-fetch": sysextfetch.Main, - "sysext-modules": kmods.Main, - "update-pending": updatepending.Main, - "update-status": updatestatus.Main, - "update-status-migrate": updatestatus.Migrate, + "boot-deadline": bootdeadline.Main, + "boot-origin": bootorigin.Main, + "diskless-update-check": diskless.Check, + "disable-unused-migrate": unused.Migrate, + "firstboot-credentials": firstboot.Main, + "hostname": hostname.Main, + "reboot-lock": fleetlock.Main, + "repair-etc-modes": etcmodes.Main, + "sysext-fetch": sysextfetch.Main, + "sysext-modules": kmods.Main, + "update-pending": updatepending.Main, + "update-status": updatestatus.Main, + "update-status-migrate": updatestatus.Migrate, } // units are run by unit files as /usr/bin/bluefin-host . diff --git a/files/homelab/cluster/internal/host/unused/unused.go b/files/homelab/cluster/internal/host/unused/unused.go new file mode 100644 index 00000000..e7ce5d66 --- /dev/null +++ b/files/homelab/cluster/internal/host/unused/unused.go @@ -0,0 +1,50 @@ +// Package unused is bluefin-disable-unused-migrate: on a node that first +// booted an image without 80-bluefin-unused.preset, apply its lines once. +// +// Presets apply on first boot only, so isnsd and systemd-homed, which FSDK's +// implicit "enable" turned on there, stay enabled across A/B updates. This +// runs `systemctl preset --now` on exactly those units: the shipped preset +// disables and stops them, and a node whose own preset (e.g. Ignition's +// 20-ignition.preset) enables one keeps it. It runs once; a stamp in /var +// suppresses later boots. +package unused + +import "github.com/projectbluefin/server/files/homelab/cluster/internal/host/sys" + +const Stamp = "/var/lib/bluefin/disable-unused-migrate.stamp" + +// Units are the units 80-bluefin-unused.preset disables. +var Units = []string{ + "isnsd.socket", + "isnsd.service", + "systemd-homed-activate.service", + "systemd-homed.service", +} + +// Migrate is bluefin-disable-unused-migrate. +// Test overrides: BLUEFIN_SYSTEMCTL, BLUEFIN_DISABLE_UNUSED_STAMP. +func Migrate(h *sys.Host, _ []string) int { + systemctl := h.Env("BLUEFIN_SYSTEMCTL", "systemctl") + stamp := h.Env("BLUEFIN_DISABLE_UNUSED_STAMP", Stamp) + failed := false + for _, unit := range Units { + if h.Exec(systemctl, "preset", "--now", unit) != 0 { + h.Eprintf("bluefin-disable-unused-migrate: systemctl preset --now %s failed\n", unit) + failed = true + } + } + if failed { + // No stamp: try again next boot. + return 1 + } + if err := sys.MkdirP(sys.Dir(stamp)); err != nil { + h.Eprintf("bluefin-disable-unused-migrate: %v\n", err) + return 1 + } + if err := sys.Truncate(stamp); err != nil { + h.Eprintf("bluefin-disable-unused-migrate: %v\n", err) + return 1 + } + h.Printf("bluefin-disable-unused-migrate: applied the preset to %d unit(s)\n", len(Units)) + return 0 +} diff --git a/files/homelab/cluster/internal/host/unused/unused_test.go b/files/homelab/cluster/internal/host/unused/unused_test.go new file mode 100644 index 00000000..c9e46eae --- /dev/null +++ b/files/homelab/cluster/internal/host/unused/unused_test.go @@ -0,0 +1,52 @@ +package unused + +import ( + "os" + "path/filepath" + "strings" + "testing" + + "github.com/projectbluefin/server/files/homelab/cluster/internal/host/hosttest" +) + +func TestMigrateAppliesThePresetToEachUnitOnce(t *testing.T) { + stamp := filepath.Join(t.TempDir(), "var", "lib", "bluefin", "disable-unused-migrate.stamp") + h := hosttest.New(map[string]string{"BLUEFIN_SYSTEMCTL": "sc", "BLUEFIN_DISABLE_UNUSED_STAMP": stamp}, nil) + if code := Migrate(h.Host, nil); code != 0 { + t.Fatalf("exit %d: %s", code, h.Err.String()) + } + var want []string + for _, u := range Units { + want = append(want, "sc preset --now "+u) + } + if got := h.Fake.Calls(); strings.Join(got, "\n") != strings.Join(want, "\n") { + t.Errorf("calls %q; want %q", got, want) + } + for _, c := range h.Fake.Calls() { + if strings.Contains(c, "preset-all") || strings.Contains(c, " enable") { + t.Errorf("must only preset its own units: %q", c) + } + } + if _, err := os.Stat(stamp); err != nil { + t.Errorf("stamp: %v", err) + } +} + +func TestMigrateRetriesNextBootWhenAPresetFails(t *testing.T) { + stamp := filepath.Join(t.TempDir(), "stamp") + h := hosttest.New(map[string]string{"BLUEFIN_SYSTEMCTL": "sc", "BLUEFIN_DISABLE_UNUSED_STAMP": stamp}, func(argv []string) (string, int) { + if argv[len(argv)-1] == "isnsd.service" { + return "", 1 + } + return "", 0 + }) + if code := Migrate(h.Host, nil); code != 1 { + t.Fatalf("exit %d; want 1", code) + } + if len(h.Fake.Calls()) != len(Units) { + t.Errorf("a failure must not skip the other units: %q", h.Fake.Calls()) + } + if _, err := os.Stat(stamp); !os.IsNotExist(err) { + t.Errorf("stamp written after a failure: %v", err) + } +} diff --git a/files/os/systemd/system-preset/80-bluefin-unused.preset b/files/os/systemd/system-preset/80-bluefin-unused.preset new file mode 100644 index 00000000..a24d28b4 --- /dev/null +++ b/files/os/systemd/system-preset/80-bluefin-unused.preset @@ -0,0 +1,13 @@ +# Daemons FSDK ships that a server node does not use. FSDK has no catch-all +# "disable *", so without these lines systemd enables them on first boot: +# - isnsd: open-isns's iSNS *server*, which listens on TCP 3205 on every +# interface. The iSCSI initiator (80-bluefin-iscsi.preset) does not need +# it; a node that should run an iSNS server enables it per node. +# - systemd-homed: portable home directories; this image has no homed users +# (root ships locked, accounts come from sysusers and Ignition). +# bluefin-disable-unused-migrate.service applies these lines once on nodes +# that first booted an image without them. +disable isnsd.service +disable isnsd.socket +disable systemd-homed.service +disable systemd-homed-activate.service diff --git a/files/os/systemd/system/bluefin-disable-unused-migrate.service b/files/os/systemd/system/bluefin-disable-unused-migrate.service new file mode 100644 index 00000000..1184fe00 --- /dev/null +++ b/files/os/systemd/system/bluefin-disable-unused-migrate.service @@ -0,0 +1,21 @@ +[Unit] +Description=Disable Unused Daemons on Nodes That Updated from an Older Image +Documentation=file:/usr/libexec/bluefin-disable-unused-migrate +# Presets apply on first boot only, so a node that first booted an image +# without 80-bluefin-unused.preset keeps isnsd and systemd-homed enabled. +# This applies that preset to those units once. Enabled in /usr +# (elements/oci/bluefin-server-usr.bst), so updated nodes run it. Installed +# nodes only: a diskless node's /etc starts empty, so its first-boot presets +# already include the new file. +ConditionPathExists=!/var/lib/bluefin/disable-unused-migrate.stamp +ConditionPathExists=!/run/machines/rootdisk.raw +ConditionKernelCommandLine=!root=tmpfs +After=systemd-tmpfiles-setup.service + +[Service] +Type=oneshot +RemainAfterExit=yes +ExecStart=/usr/libexec/bluefin-disable-unused-migrate + +[Install] +WantedBy=multi-user.target diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py index 9abd0b1f..192c3ca4 100644 --- a/tests/unit/conftest.py +++ b/tests/unit/conftest.py @@ -67,6 +67,7 @@ def pytest_runtest_setup(item: pytest.Item) -> None: HOST_HELPERS = ( "boot-deadline", "boot-origin", + "disable-unused-migrate", "diskless-update-check", "firstboot-credentials", "hostname", diff --git a/tests/unit/test_os_contracts.py b/tests/unit/test_os_contracts.py index 8b980888..71ac4c56 100644 --- a/tests/unit/test_os_contracts.py +++ b/tests/unit/test_os_contracts.py @@ -90,3 +90,29 @@ def test_no_base_image_preset_enables_zfs() -> None: # The ZFS sysext's own 50-zfs.preset enables its units; a preset in a # sysext does nothing until the admin runs `systemctl preset`. assert not enable_lines(BASE_PRESETS, "zfs") + + +UNUSED_PRESET = ROOT / "files" / "os" / "systemd" / "system-preset" / "80-bluefin-unused.preset" +UNUSED_UNITS = ("isnsd.service", "isnsd.socket", "systemd-homed.service", "systemd-homed-activate.service") + + +@pytest.mark.parametrize("unit", UNUSED_UNITS) +def test_unused_fsdk_daemons_are_disabled_by_preset(unit: str) -> None: + # FSDK's implicit "enable" turned on the iSNS server (TCP 3205 on every + # interface) and homed; nothing on a node uses either. + lines = [line.split() for line in UNUSED_PRESET.read_text(encoding="utf-8").splitlines() if line and not line.startswith("#")] + assert ["disable", unit] in lines + assert not enable_lines(PRESETS, unit) + + +def test_nodes_that_updated_apply_the_unused_preset_once() -> None: + # Presets apply on first boot only; the migration presets exactly the + # preset's units, so an Ignition preset that enables one still wins. + unit = (ROOT / "files" / "os" / "systemd" / "system" / "bluefin-disable-unused-migrate.service").read_text(encoding="utf-8") + assert "ExecStart=/usr/libexec/bluefin-disable-unused-migrate" in unit + assert "ConditionPathExists=!/var/lib/bluefin/disable-unused-migrate.stamp" in unit + usr = (ROOT / "elements" / "oci" / "bluefin-server-usr.bst").read_text(encoding="utf-8") + assert "multi-user.target.wants/bluefin-disable-unused-migrate.service" in usr + go = (ROOT / "files" / "homelab" / "cluster" / "internal" / "host" / "unused" / "unused.go").read_text(encoding="utf-8") + listed = go.split("var Units = []string{", 1)[1].split("}", 1)[0] + assert sorted(u.strip().strip('",') for u in listed.split() if u.strip()) == sorted(UNUSED_UNITS)