Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/skills/kubeadm-sysext.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 5 additions & 4 deletions elements/bluefin-server/os-host.bst
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
3 changes: 3 additions & 0 deletions elements/oci/bluefin-server-usr.bst
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 14 additions & 12 deletions files/homelab/cluster/cmd/bluefin-host/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -40,18 +41,19 @@ var cLocale = map[string]bool{

// helpers are installed as /usr/libexec/bluefin-<name> 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 <name>.
Expand Down
50 changes: 50 additions & 0 deletions files/homelab/cluster/internal/host/unused/unused.go
Original file line number Diff line number Diff line change
@@ -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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

correctness (low, advisory): I could not test this against FSDK's systemd. If an operator has already masked one of these units (for example systemctl mask isnsd.socket for hardening), systemctl preset refuses it: systemd reports that the unit file is masked and exits non-zero. Every boot then marks this unit failed, writes no stamp (lines 36-39), and tries again. A masked unit is already off, which is what this migration wants, so it can count as done:

 	for _, unit := range Units {
+		// A masked unit is already off; preset refuses masked units.
+		if out, _ := h.Output(systemctl, "is-enabled", unit); strings.TrimSpace(out) == "masked" {
+			continue
+		}
 		if h.Exec(systemctl, "preset", "--now", unit) != 0 {

Use whatever capture-output helper sys.Host provides; h.Output is a placeholder. Add a hosttest case where is-enabled prints masked. Check that the case still writes the stamp. Not blocking: the failure is noisy but harmless.

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
}
52 changes: 52 additions & 0 deletions files/homelab/cluster/internal/host/unused/unused_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
13 changes: 13 additions & 0 deletions files/os/systemd/system-preset/80-bluefin-unused.preset
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions files/os/systemd/system/bluefin-disable-unused-migrate.service
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions tests/unit/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
26 changes: 26 additions & 0 deletions tests/unit/test_os_contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Loading