Repository navigation
fix(os): stop enabling the iSNS server and systemd-homed #702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jeefy
wants to merge
1
commit into
projectbluefin:main
Choose a base branch
from
jeefy:fix/disable-isnsd-homed
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+188
−17
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 { | ||
| 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 | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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) | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
21
files/os/systemd/system/bluefin-disable-unused-migrate.service
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.socketfor hardening),systemctl presetrefuses 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.Hostprovides;h.Outputis a placeholder. Add ahosttestcase whereis-enabledprintsmasked. Check that the case still writes the stamp. Not blocking: the failure is noisy but harmless.