diff --git a/orbit/changes/11980-updates-panic b/orbit/changes/11980-updates-panic new file mode 100644 index 0000000000..11992611e4 --- /dev/null +++ b/orbit/changes/11980-updates-panic @@ -0,0 +1 @@ +* Fixed a crash that happened when updates where disabled and certain conditions (Nudge configuration set or host elegible for MDM migration) were met. diff --git a/orbit/pkg/update/nudge.go b/orbit/pkg/update/nudge.go index a45e1fe255..5f5ea4e85f 100644 --- a/orbit/pkg/update/nudge.go +++ b/orbit/pkg/update/nudge.go @@ -71,6 +71,11 @@ func (n *NudgeConfigFetcher) GetConfig() (*fleet.OrbitConfig, error) { return nil, nil } + if n.opt.UpdateRunner == nil { + log.Debug().Msg("NudgeConfigFetcher received nil UpdateRunner, this probably indicates that updates are turned off. Skipping any actions related to Nudge") + return cfg, nil + } + if cfg.NudgeConfig == nil { log.Debug().Msg("empty nudge config, removing nudge as target") // TODO(roberto): by early returning and removing the target from the diff --git a/orbit/pkg/update/nudge_test.go b/orbit/pkg/update/nudge_test.go index ece20f8b5c..61ca7bbe6b 100644 --- a/orbit/pkg/update/nudge_test.go +++ b/orbit/pkg/update/nudge_test.go @@ -25,6 +25,29 @@ type nudgeTestSuite struct { withTUF } +func (s *nudgeTestSuite) TestUpdatesDisabled() { + t := s.T() + var err error + cfg := &fleet.OrbitConfig{} + cfg.NudgeConfig, err = fleet.NewNudgeConfig(fleet.MacOSUpdates{MinimumVersion: optjson.SetString("11"), Deadline: optjson.SetString("2022-01-04")}) + require.NoError(t, err) + runNudgeFn := func(execPath, configPath string) error { + return nil + } + var f OrbitConfigFetcher = &dummyConfigFetcher{cfg: cfg} + f = ApplyNudgeConfigFetcherMiddleware(f, NudgeConfigFetcherOptions{ + UpdateRunner: nil, + RootDir: t.TempDir(), + Interval: time.Minute, + runNudgeFn: runNudgeFn, + }) + + // we used to get a panic if updates were disabled (see #11980) + gotCfg, err := f.GetConfig() + require.NoError(t, err) + require.Equal(t, cfg, gotCfg) +} + func (s *nudgeTestSuite) TestNudgeConfigFetcherAddNudge() { t := s.T() tmpDir := t.TempDir() @@ -69,6 +92,8 @@ func (s *nudgeTestSuite) TestNudgeConfigFetcherAddNudge() { // add nuge to the remote s.addRemoteTarget(nudgePath) + // nothing happens if a nil runner is provided + // nudge is added to targets when nudge config is present gotCfg, err = f.GetConfig() require.NoError(t, err) diff --git a/orbit/pkg/update/swift_dialog.go b/orbit/pkg/update/swift_dialog.go index a5f46d5639..ebd0543752 100644 --- a/orbit/pkg/update/swift_dialog.go +++ b/orbit/pkg/update/swift_dialog.go @@ -35,6 +35,11 @@ func (s *SwiftDialogDownloader) GetConfig() (*fleet.OrbitConfig, error) { return nil, nil } + if s.UpdateRunner == nil { + log.Debug().Msg("SwiftDialogDownloader received nil UpdateRunner, this probably indicates that updates are turned off. Skipping any actions related to swiftDialog") + return cfg, nil + } + if !cfg.Notifications.NeedsMDMMigration && !cfg.Notifications.RenewEnrollmentProfile { return cfg, nil } diff --git a/orbit/pkg/update/swift_dialog_test.go b/orbit/pkg/update/swift_dialog_test.go new file mode 100644 index 0000000000..871dc2e93c --- /dev/null +++ b/orbit/pkg/update/swift_dialog_test.go @@ -0,0 +1,21 @@ +package update + +import ( + "testing" + + "github.com/fleetdm/fleet/v4/server/fleet" + "github.com/stretchr/testify/require" +) + +func TestSwiftDialogUpdatesDisabled(t *testing.T) { + cfg := &fleet.OrbitConfig{} + cfg.Notifications.NeedsMDMMigration = true + cfg.Notifications.RenewEnrollmentProfile = true + var f OrbitConfigFetcher = &dummyConfigFetcher{cfg: cfg} + f = ApplySwiftDialogDownloaderMiddleware(f, nil) + + // we used to get a panic if updates were disabled (see #11980) + gotCfg, err := f.GetConfig() + require.NoError(t, err) + require.Equal(t, cfg, gotCfg) +}