diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index e44d08f91..fdcee4f52 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -3,7 +3,6 @@ package main import ( "bytes" "context" - "crypto/tls" "crypto/x509" "errors" "fmt" @@ -20,11 +19,9 @@ import ( "github.com/apache/thrift/lib/go/thrift" "github.com/go-kit/kit/log" "github.com/kolide/kit/fsutil" - "github.com/kolide/kit/logutil" "github.com/kolide/kit/ulid" "github.com/kolide/kit/version" "github.com/kolide/launcher/cmd/launcher/internal" - "github.com/kolide/launcher/cmd/launcher/internal/updater" "github.com/kolide/launcher/ee/agent" "github.com/kolide/launcher/ee/agent/flags" "github.com/kolide/launcher/ee/agent/knapsack" @@ -45,7 +42,6 @@ import ( "github.com/kolide/launcher/ee/powereventwatcher" "github.com/kolide/launcher/ee/tuf" "github.com/kolide/launcher/pkg/augeas" - "github.com/kolide/launcher/pkg/autoupdate" "github.com/kolide/launcher/pkg/backoff" "github.com/kolide/launcher/pkg/contexts/ctxlog" "github.com/kolide/launcher/pkg/debug" @@ -251,18 +247,6 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl } defer s.Close() - // construct the appropriate http client based on security settings - httpClient := http.DefaultClient - if k.InsecureTLS() { - httpClient = &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: &tls.Config{ - InsecureSkipVerify: true, - }, - }, - } - } - // If we have successfully opened the DB, and written a pid, // we expect we're live. Record the version for osquery to // pickup @@ -528,65 +512,6 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl } } - // Run the legacy autoupdater only if autoupdating is enabled and the new autoupdater - // is not yet in use. - if k.Autoupdate() && !k.UseTUFAutoupdater() { - osqueryUpdaterconfig := &updater.UpdaterConfig{ - Logger: logger, - RootDirectory: rootDirectory, - AutoupdateInterval: k.AutoupdateInterval(), - UpdateChannel: autoupdate.UpdateChannel(k.UpdateChannel()), - NotaryURL: k.NotaryServerURL(), - MirrorURL: k.MirrorServerURL(), - NotaryPrefix: k.NotaryPrefix(), - HTTPClient: httpClient, - InitialDelay: k.AutoupdateInitialDelay() + k.AutoupdateInterval()/2, - SigChannel: sigChannel, - } - - // create an updater for osquery - osqueryLegacyUpdater, err := updater.NewUpdater(ctx, opts.OsquerydPath, osqueryRunner.Restart, osqueryUpdaterconfig) - if err != nil { - return fmt.Errorf("create osquery updater: %w", err) - } - runGroup.Add("osqueryLegacyAutoupdater", osqueryLegacyUpdater.Execute, osqueryLegacyUpdater.Interrupt) - - launcherUpdaterconfig := &updater.UpdaterConfig{ - Logger: logger, - RootDirectory: rootDirectory, - AutoupdateInterval: k.AutoupdateInterval(), - UpdateChannel: autoupdate.UpdateChannel(k.UpdateChannel()), - NotaryURL: k.NotaryServerURL(), - MirrorURL: k.MirrorServerURL(), - NotaryPrefix: k.NotaryPrefix(), - HTTPClient: httpClient, - InitialDelay: k.AutoupdateInitialDelay(), - SigChannel: sigChannel, - } - - // create an updater for launcher - launcherPath, err := os.Executable() - if err != nil { - logutil.Fatal(logger, "err", err) - } - launcherLegacyUpdater, err := updater.NewUpdater( - ctx, - launcherPath, - updater.UpdateFinalizer(logger, func() error { - // stop desktop on auto updates - if runner != nil { - runner.Interrupt(nil) - } - return osqueryRunner.Shutdown() - }), - launcherUpdaterconfig, - ) - if err != nil { - return fmt.Errorf("create launcher updater: %w", err) - } - runGroup.Add("launcherLegacyAutoupdater", launcherLegacyUpdater.Execute, launcherLegacyUpdater.Interrupt) - } - startupSpan.End() if err := runGroup.Run(); err != nil { diff --git a/cmd/launcher/main.go b/cmd/launcher/main.go index aa670f42c..d8d7750bf 100644 --- a/cmd/launcher/main.go +++ b/cmd/launcher/main.go @@ -58,28 +58,7 @@ func main() { // fork-bombing itself. This is an ENV, because there's no // good way to pass it through the flags. if !env.Bool("LAUNCHER_SKIP_UPDATES", false) { - if tuf.ShouldUseNewAutoupdater(ctx) { - runNewerLauncherIfAvailable(ctx, logger) - } else { - newerBinary, err := autoupdate.FindNewestSelf(ctx) - if err != nil { - logutil.Fatal(logger, err, "checking for updated version") - } - - if newerBinary != "" { - level.Debug(logger).Log( - "msg", "preparing to exec new binary", - "oldVersion", version.Version().Version, - "newBinary", newerBinary, - ) - if err := execwrapper.Exec(ctx, newerBinary, os.Args, os.Environ()); err != nil { - logutil.Fatal(logger, err, "exec") - } - panic("how") - } - - level.Debug(logger).Log("msg", "Nothing new") - } + runNewerLauncherIfAvailable(ctx, logger) } // if the launcher is being ran with a positional argument, diff --git a/ee/agent/flags/flag_controller.go b/ee/agent/flags/flag_controller.go index 86d094d00..f39c099f2 100644 --- a/ee/agent/flags/flag_controller.go +++ b/ee/agent/flags/flag_controller.go @@ -500,15 +500,6 @@ func (fc *FlagController) UpdateDirectory() string { ).get(fc.getControlServerValue(keys.UpdateDirectory)) } -func (fc *FlagController) SetUseTUFAutoupdater(enabled bool) error { - return fc.setControlServerValue(keys.UseTUFAutoupdater, boolToBytes(enabled)) -} -func (fc *FlagController) UseTUFAutoupdater() bool { - return NewBoolFlagValue( - WithDefaultBool(false), - ).get(fc.getControlServerValue(keys.UseTUFAutoupdater)) -} - func (fc *FlagController) SetExportTraces(enabled bool) error { return fc.setControlServerValue(keys.ExportTraces, boolToBytes(enabled)) } diff --git a/ee/agent/flags/keys/keys.go b/ee/agent/flags/keys/keys.go index 40a3553cf..faee4f0cc 100644 --- a/ee/agent/flags/keys/keys.go +++ b/ee/agent/flags/keys/keys.go @@ -43,7 +43,6 @@ const ( MirrorServerURL FlagKey = "mirror_url" AutoupdateInterval FlagKey = "autoupdate_interval" UpdateChannel FlagKey = "update_channel" - UseTUFAutoupdater FlagKey = "use_tuf_autoupdater" NotaryPrefix FlagKey = "notary_prefix" AutoupdateInitialDelay FlagKey = "autoupdater_initial_delay" UpdateDirectory FlagKey = "update_directory" diff --git a/ee/agent/startupsettings/writer.go b/ee/agent/startupsettings/writer.go index d8f11bb25..3b96af25b 100644 --- a/ee/agent/startupsettings/writer.go +++ b/ee/agent/startupsettings/writer.go @@ -8,7 +8,6 @@ import ( "fmt" "log/slog" - "github.com/kolide/launcher/ee/agent/flags" "github.com/kolide/launcher/ee/agent/flags/keys" agentsqlite "github.com/kolide/launcher/ee/agent/storage/sqlite" "github.com/kolide/launcher/ee/agent/types" @@ -38,8 +37,7 @@ func OpenWriter(ctx context.Context, knapsack types.Knapsack) (*startupSettingsW kvStore: store, knapsack: knapsack, storedFlags: map[keys.FlagKey]func() string{ - keys.UpdateChannel: func() string { return knapsack.UpdateChannel() }, - keys.UseTUFAutoupdater: func() string { return flags.BoolToString(knapsack.UseTUFAutoupdater()) }, + keys.UpdateChannel: func() string { return knapsack.UpdateChannel() }, }, } diff --git a/ee/agent/startupsettings/writer_test.go b/ee/agent/startupsettings/writer_test.go index e828a9443..4d87a8a9c 100644 --- a/ee/agent/startupsettings/writer_test.go +++ b/ee/agent/startupsettings/writer_test.go @@ -5,7 +5,6 @@ import ( "testing" _ "github.com/golang-migrate/migrate/v4/database/sqlite" - "github.com/kolide/launcher/ee/agent/flags" "github.com/kolide/launcher/ee/agent/flags/keys" agentsqlite "github.com/kolide/launcher/ee/agent/storage/sqlite" typesmocks "github.com/kolide/launcher/ee/agent/types/mocks" @@ -22,10 +21,8 @@ func TestOpenWriter_NewDatabase(t *testing.T) { k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) - k.On("RegisterChangeObserver", mock.Anything, keys.UseTUFAutoupdater) updateChannelVal := "stable" k.On("UpdateChannel").Return(updateChannelVal) - k.On("UseTUFAutoupdater").Return(false) // Set up storage db, which should create the database and set all flags s, err := OpenWriter(context.TODO(), k) @@ -35,9 +32,6 @@ func TestOpenWriter_NewDatabase(t *testing.T) { v1, err := s.kvStore.Get([]byte(keys.UpdateChannel.String())) require.NoError(t, err, "getting startup value") require.Equal(t, updateChannelVal, string(v1), "incorrect flag value") - v2, err := s.kvStore.Get([]byte(keys.UseTUFAutoupdater.String())) - require.NoError(t, err, "getting startup value") - require.False(t, flags.StringToBool(string(v2)), "incorrect flag value") require.NoError(t, s.Close(), "closing startup db") } @@ -50,15 +44,11 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) { store, err := agentsqlite.OpenRW(context.TODO(), testRootDir, agentsqlite.StartupSettingsStore) require.NoError(t, err, "getting connection to test db") require.NoError(t, store.Set([]byte(keys.UpdateChannel.String()), []byte("some_old_value")), "setting key") - require.NoError(t, store.Set([]byte(keys.UseTUFAutoupdater.String()), []byte(flags.BoolToString(false))), "setting key") // Confirm flags were set v1, err := store.Get([]byte(keys.UpdateChannel.String())) require.NoError(t, err, "getting startup value") require.Equal(t, "some_old_value", string(v1), "incorrect flag value") - v2, err := store.Get([]byte(keys.UseTUFAutoupdater.String())) - require.NoError(t, err, "getting startup value") - require.False(t, flags.StringToBool(string(v2)), "incorrect flag value") require.NoError(t, store.Close(), "closing setup connection") @@ -66,12 +56,10 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) { k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) - k.On("RegisterChangeObserver", mock.Anything, keys.UseTUFAutoupdater) // Set up flag updateChannelVal := "alpha" k.On("UpdateChannel").Return(updateChannelVal) - k.On("UseTUFAutoupdater").Return(true) // Set up storage db, which should create the database and set all flags s, err := OpenWriter(context.TODO(), k) @@ -81,9 +69,6 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) { v1, err = s.kvStore.Get([]byte(keys.UpdateChannel.String())) require.NoError(t, err, "getting startup value") require.Equal(t, updateChannelVal, string(v1), "incorrect flag value") - v2, err = s.kvStore.Get([]byte(keys.UseTUFAutoupdater.String())) - require.NoError(t, err, "getting startup value") - require.True(t, flags.StringToBool(string(v2)), "incorrect flag value") require.NoError(t, s.Close(), "closing startup db") } @@ -96,11 +81,8 @@ func TestFlagsChanged(t *testing.T) { k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) - k.On("RegisterChangeObserver", mock.Anything, keys.UseTUFAutoupdater) updateChannelVal := "beta" k.On("UpdateChannel").Return(updateChannelVal).Once() - useTufAutoupdaterVal := true - k.On("UseTUFAutoupdater").Return(useTufAutoupdaterVal).Once() // Set up storage db, which should create the database and set all flags s, err := OpenWriter(context.TODO(), k) @@ -110,24 +92,16 @@ func TestFlagsChanged(t *testing.T) { v1, err := s.kvStore.Get([]byte(keys.UpdateChannel.String())) require.NoError(t, err, "getting startup value") require.Equal(t, updateChannelVal, string(v1), "incorrect flag value") - v2, err := s.kvStore.Get([]byte(keys.UseTUFAutoupdater.String())) - require.NoError(t, err, "getting startup value") - require.Equal(t, useTufAutoupdaterVal, flags.StringToBool(string(v2)), "incorrect flag value") // Now, prepare for flag changes newFlagValue := "alpha" k.On("UpdateChannel").Return(newFlagValue).Once() - newUseTufAutoupdaterVal := false - k.On("UseTUFAutoupdater").Return(newUseTufAutoupdaterVal).Once() // Call FlagsChanged and expect that all flag values are updated s.FlagsChanged(keys.UpdateChannel) v1, err = s.kvStore.Get([]byte(keys.UpdateChannel.String())) require.NoError(t, err, "getting startup value") require.Equal(t, newFlagValue, string(v1), "incorrect flag value") - v2, err = s.kvStore.Get([]byte(keys.UseTUFAutoupdater.String())) - require.NoError(t, err, "getting startup value") - require.Equal(t, newUseTufAutoupdaterVal, flags.StringToBool(string(v2)), "incorrect flag value") require.NoError(t, s.Close(), "closing startup db") } diff --git a/ee/agent/types/flags.go b/ee/agent/types/flags.go index 483256b42..78843f47f 100644 --- a/ee/agent/types/flags.go +++ b/ee/agent/types/flags.go @@ -185,10 +185,6 @@ type Flags interface { SetUpdateDirectory(directory string) error UpdateDirectory() string - // UseTUFAutoupdater controls whether launcher uses the new TUF autoupdater instead of the legacy autoupdater - SetUseTUFAutoupdater(enabled bool) error - UseTUFAutoupdater() bool - // ExportTraces enables exporting our traces SetExportTraces(enabled bool) error SetExportTracesOverride(value bool, duration time.Duration) diff --git a/ee/agent/types/mocks/flags.go b/ee/agent/types/mocks/flags.go index 5ca514983..63a4bfad0 100644 --- a/ee/agent/types/mocks/flags.go +++ b/ee/agent/types/mocks/flags.go @@ -1160,20 +1160,6 @@ func (_m *Flags) SetUpdateDirectory(directory string) error { return r0 } -// SetUseTUFAutoupdater provides a mock function with given fields: enabled -func (_m *Flags) SetUseTUFAutoupdater(enabled bool) error { - ret := _m.Called(enabled) - - var r0 error - if rf, ok := ret.Get(0).(func(bool) error); ok { - r0 = rf(enabled) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // SetWatchdogDelaySec provides a mock function with given fields: sec func (_m *Flags) SetWatchdogDelaySec(sec int) error { ret := _m.Called(sec) @@ -1328,20 +1314,6 @@ func (_m *Flags) UpdateDirectory() string { return r0 } -// UseTUFAutoupdater provides a mock function with given fields: -func (_m *Flags) UseTUFAutoupdater() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - // WatchdogDelaySec provides a mock function with given fields: func (_m *Flags) WatchdogDelaySec() int { ret := _m.Called() diff --git a/ee/agent/types/mocks/knapsack.go b/ee/agent/types/mocks/knapsack.go index dccf1559b..0638960b8 100644 --- a/ee/agent/types/mocks/knapsack.go +++ b/ee/agent/types/mocks/knapsack.go @@ -1370,20 +1370,6 @@ func (_m *Knapsack) SetUpdateDirectory(directory string) error { return r0 } -// SetUseTUFAutoupdater provides a mock function with given fields: enabled -func (_m *Knapsack) SetUseTUFAutoupdater(enabled bool) error { - ret := _m.Called(enabled) - - var r0 error - if rf, ok := ret.Get(0).(func(bool) error); ok { - r0 = rf(enabled) - } else { - r0 = ret.Error(0) - } - - return r0 -} - // SetWatchdogDelaySec provides a mock function with given fields: sec func (_m *Knapsack) SetWatchdogDelaySec(sec int) error { ret := _m.Called(sec) @@ -1618,20 +1604,6 @@ func (_m *Knapsack) UpdateDirectory() string { return r0 } -// UseTUFAutoupdater provides a mock function with given fields: -func (_m *Knapsack) UseTUFAutoupdater() bool { - ret := _m.Called() - - var r0 bool - if rf, ok := ret.Get(0).(func() bool); ok { - r0 = rf() - } else { - r0 = ret.Get(0).(bool) - } - - return r0 -} - // WatchdogDelaySec provides a mock function with given fields: func (_m *Knapsack) WatchdogDelaySec() int { ret := _m.Called() diff --git a/ee/tuf/autoupdate.go b/ee/tuf/autoupdate.go index 18742253e..daa5e6c31 100644 --- a/ee/tuf/autoupdate.go +++ b/ee/tuf/autoupdate.go @@ -418,12 +418,6 @@ func (ta *TufAutoupdater) checkForUpdate(binariesToCheck []autoupdatableBinary) return fmt.Errorf("could not download updates: %+v", updateErrors) } - // Only perform restarts if we're configured to use this new autoupdate library, - // to prevent performing unnecessary restarts. - if !ta.knapsack.UseTUFAutoupdater() { - return nil - } - // If launcher was updated, we want to exit and reload if updatedVersion, ok := updatesDownloaded[binaryLauncher]; ok { // Only reload if we're not using a localdev path diff --git a/ee/tuf/autoupdate_test.go b/ee/tuf/autoupdate_test.go index 5d722c165..612761fe0 100644 --- a/ee/tuf/autoupdate_test.go +++ b/ee/tuf/autoupdate_test.go @@ -80,7 +80,6 @@ func TestExecute_launcherUpdate(t *testing.T) { mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") mockKnapsack.On("LocalDevelopmentPath").Return("") - mockKnapsack.On("UseTUFAutoupdater").Return(true) mockQuerier := newMockQuerier(t) // Set logger so that we can capture output @@ -155,80 +154,6 @@ func TestExecute_launcherUpdate(t *testing.T) { mockKnapsack.AssertExpectations(t) } -func TestExecute_launcherUpdate_noRestartIfUsingLegacyAutoupdater(t *testing.T) { - t.Parallel() - - testRootDir := t.TempDir() - testReleaseVersion := "1.2.3" - tufServerUrl, rootJson := tufci.InitRemoteTufServer(t, testReleaseVersion) - s := setupStorage(t) - mockKnapsack := typesmocks.NewKnapsack(t) - mockKnapsack.On("RootDirectory").Return(testRootDir) - mockKnapsack.On("UpdateChannel").Return("stable") - mockKnapsack.On("AutoupdateInterval").Return(100 * time.Millisecond) // Set the check interval to something short so we can make a couple requests to our test metadata server - mockKnapsack.On("AutoupdateInitialDelay").Return(0 * time.Second) - mockKnapsack.On("AutoupdateErrorsStore").Return(s) - mockKnapsack.On("TufServerURL").Return(tufServerUrl) - mockKnapsack.On("UpdateDirectory").Return("") - mockKnapsack.On("MirrorServerURL").Return("https://example.com") - mockKnapsack.On("UseTUFAutoupdater").Return(false) - mockQuerier := newMockQuerier(t) - - // Set logger so that we can capture output - var logBytes threadsafebuffer.ThreadSafeBuffer - slogger := multislogger.New(slog.NewJSONHandler(&logBytes, &slog.HandlerOptions{Level: slog.LevelDebug})) - mockKnapsack.On("Slogger").Return(slogger.Logger) - - // Set up autoupdater - autoupdater, err := NewTufAutoupdater(context.TODO(), mockKnapsack, http.DefaultClient, http.DefaultClient, mockQuerier) - require.NoError(t, err, "could not initialize new TUF autoupdater") - - // Update the metadata client with our test root JSON - require.NoError(t, autoupdater.metadataClient.Init(rootJson), "could not initialize metadata client with test root JSON") - - // Get metadata for each release - _, err = autoupdater.metadataClient.Update() - require.NoError(t, err, "could not update metadata client to fetch target metadata") - osquerydMetadata, err := autoupdater.metadataClient.Target(fmt.Sprintf("%s/%s/%s/%s-%s.tar.gz", binaryOsqueryd, runtime.GOOS, PlatformArch(), binaryOsqueryd, testReleaseVersion)) - require.NoError(t, err, "could not get test metadata for osqueryd") - launcherMetadata, err := autoupdater.metadataClient.Target(fmt.Sprintf("%s/%s/%s/%s-%s.tar.gz", binaryLauncher, runtime.GOOS, PlatformArch(), binaryLauncher, testReleaseVersion)) - require.NoError(t, err, "could not get test metadata for launcher") - - // Expect that we attempt to tidy the library first before running execute loop - mockLibraryManager := NewMocklibrarian(t) - autoupdater.libraryManager = mockLibraryManager - currentLauncherVersion := "" // cannot determine using version package in test - currentOsqueryVersion := "1.1.1" - mockQuerier.On("Query", mock.Anything).Return([]map[string]string{{"version": currentOsqueryVersion}}, nil) - mockLibraryManager.On("TidyLibrary", binaryOsqueryd, mock.Anything).Return().Once() - - // Expect that we attempt to update the library - mockLibraryManager.On("Available", binaryOsqueryd, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion)).Return(false) - mockLibraryManager.On("Available", binaryLauncher, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion)).Return(false) - mockLibraryManager.On("AddToLibrary", binaryOsqueryd, currentOsqueryVersion, fmt.Sprintf("osqueryd-%s.tar.gz", testReleaseVersion), osquerydMetadata).Return(nil) - mockLibraryManager.On("AddToLibrary", binaryLauncher, currentLauncherVersion, fmt.Sprintf("launcher-%s.tar.gz", testReleaseVersion), launcherMetadata).Return(nil) - - // Let the autoupdater run for a bit -- it will shut itself down after a launcher update - go autoupdater.Execute() - time.Sleep(500 * time.Millisecond) - - // Assert expectation that we added the expected `testReleaseVersion` to the updates library - mockLibraryManager.AssertExpectations(t) - - // Check log lines to confirm that we DO NOT see the log `received interrupt to restart launcher after update, stopping` - logLines := strings.Split(strings.TrimSpace(logBytes.String()), "\n") - for _, line := range logLines { - require.NotContains(t, line, "received interrupt to restart launcher after update, stopping") - } - - // The autoupdater won't stop on its own, so stop it - autoupdater.Interrupt(errors.New("test error")) - time.Sleep(100 * time.Millisecond) - - // Confirm we pulled all config items as expected - mockKnapsack.AssertExpectations(t) -} - func TestExecute_osquerydUpdate(t *testing.T) { t.Parallel() @@ -245,7 +170,6 @@ func TestExecute_osquerydUpdate(t *testing.T) { mockKnapsack.On("TufServerURL").Return(tufServerUrl) mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") - mockKnapsack.On("UseTUFAutoupdater").Return(true) mockQuerier := newMockQuerier(t) // Set logger so that we can capture output @@ -320,7 +244,6 @@ func TestExecute_downgrade(t *testing.T) { mockKnapsack.On("TufServerURL").Return(tufServerUrl) mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") - mockKnapsack.On("UseTUFAutoupdater").Return(true) mockQuerier := newMockQuerier(t) // Set logger so that we can capture output @@ -406,7 +329,6 @@ func TestExecute_withInitialDelay(t *testing.T) { mockKnapsack.On("TufServerURL").Return(tufServerUrl) mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") - mockKnapsack.On("UseTUFAutoupdater").Return(true).Maybe() mockQuerier := newMockQuerier(t) // Set logger so that we can capture output @@ -472,7 +394,6 @@ func TestInterrupt_Multiple(t *testing.T) { mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") mockKnapsack.On("Slogger").Return(multislogger.New().Logger) - mockKnapsack.On("UseTUFAutoupdater").Return(true).Maybe() mockQuerier := newMockQuerier(t) // Set up autoupdater @@ -596,7 +517,6 @@ func TestDo(t *testing.T) { mockKnapsack.On("TufServerURL").Return(tufServerUrl) mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") - mockKnapsack.On("UseTUFAutoupdater").Return(true) mockKnapsack.On("LocalDevelopmentPath").Return("").Maybe() mockQuerier := newMockQuerier(t) mockKnapsack.On("Slogger").Return(multislogger.New().Logger) @@ -664,7 +584,6 @@ func TestDo_HandlesSimultaneousUpdates(t *testing.T) { mockKnapsack.On("UpdateDirectory").Return("") mockKnapsack.On("MirrorServerURL").Return("https://example.com") mockKnapsack.On("LocalDevelopmentPath").Return("") - mockKnapsack.On("UseTUFAutoupdater").Return(true) mockQuerier := newMockQuerier(t) mockKnapsack.On("Slogger").Return(multislogger.New().Logger) diff --git a/ee/tuf/library_lookup.go b/ee/tuf/library_lookup.go index e177b499d..81a31c061 100644 --- a/ee/tuf/library_lookup.go +++ b/ee/tuf/library_lookup.go @@ -11,9 +11,6 @@ import ( "github.com/Masterminds/semver" "github.com/go-kit/kit/log" "github.com/go-kit/kit/log/level" - "github.com/kolide/launcher/ee/agent/flags" - "github.com/kolide/launcher/ee/agent/flags/keys" - "github.com/kolide/launcher/ee/agent/startupsettings" "github.com/kolide/launcher/pkg/autoupdate" "github.com/kolide/launcher/pkg/launcher" "github.com/kolide/launcher/pkg/traces" @@ -51,18 +48,6 @@ func CheckOutLatestWithoutConfig(binary autoupdatableBinary, logger log.Logger) return CheckOutLatest(context.Background(), binary, cfg.rootDirectory, cfg.updateDirectory, cfg.channel, logger) } -// ShouldUseNewAutoupdater retrieves the root directory from the command-line args -// (either set via command-line arg, or set in the config file indicated by the --config arg), -// and then looks up whether the new autoupdater has been enabled for this installation. -func ShouldUseNewAutoupdater(ctx context.Context) bool { - cfg, err := getAutoupdateConfig(os.Args[1:]) - if err != nil { - return false - } - - return usingNewAutoupdater(ctx, cfg.rootDirectory) -} - // getAutoupdateConfig pulls the configuration values necessary to work with the autoupdate library // from either the given args or from the config file. func getAutoupdateConfig(args []string) (*autoupdateConfig, error) { @@ -155,37 +140,12 @@ func getAutoupdateConfigFromFile(configFilePath string) (*autoupdateConfig, erro return cfg, nil } -// usingNewAutoupdater reads from the shared startup settings db to see whether the -// UseTUFAutoupdater flag has been set for this installation. -func usingNewAutoupdater(ctx context.Context, rootDirectory string) bool { - r, err := startupsettings.OpenReader(ctx, rootDirectory) - if err != nil { - // For now, default to not using the new autoupdater - return false - } - defer r.Close() - - enabledStr, err := r.Get(keys.UseTUFAutoupdater.String()) - if err != nil { - // For now, default to not using the new autoupdater - return false - } - - return flags.StringToBool(enabledStr) -} - // CheckOutLatest returns the path to the latest downloaded executable for our binary, as well // as its version. func CheckOutLatest(ctx context.Context, binary autoupdatableBinary, rootDirectory string, updateDirectory string, channel string, logger log.Logger) (*BinaryUpdateInfo, error) { ctx, span := traces.StartSpan(ctx, "binary", string(binary)) defer span.End() - // TODO: Remove this check once we decide to roll out the new autoupdater more broadly - if !usingNewAutoupdater(ctx, rootDirectory) { - span.AddEvent("not_using_new_autoupdater") - return nil, errors.New("not using new autoupdater yet") - } - if updateDirectory == "" { updateDirectory = DefaultLibraryDirectory(rootDirectory) } diff --git a/ee/tuf/library_lookup_test.go b/ee/tuf/library_lookup_test.go index 91d906fd6..ccbcbae30 100644 --- a/ee/tuf/library_lookup_test.go +++ b/ee/tuf/library_lookup_test.go @@ -8,8 +8,6 @@ import ( "testing" "github.com/go-kit/kit/log" - "github.com/kolide/launcher/ee/agent/flags/keys" - agentsqlite "github.com/kolide/launcher/ee/agent/storage/sqlite" tufci "github.com/kolide/launcher/ee/tuf/ci" "github.com/stretchr/testify/require" ) @@ -46,12 +44,6 @@ func TestCheckOutLatest_withTufRepository(t *testing.T) { tufci.CopyBinary(t, tooRecentPath) require.NoError(t, os.Chmod(tooRecentPath, 0755)) - // Ensure we actually use the new autoupdater - store, err := agentsqlite.OpenRW(context.TODO(), rootDir, agentsqlite.StartupSettingsStore) - require.NoError(t, err, "setting up db connection") - require.NoError(t, store.Set([]byte(keys.UseTUFAutoupdater.String()), []byte("enabled")), "setting key") - require.NoError(t, store.Close(), "closing test db") - // Check it latest, err := CheckOutLatest(context.TODO(), binary, rootDir, "", "nightly", log.NewNopLogger()) require.NoError(t, err, "unexpected error on checking out latest") @@ -79,12 +71,6 @@ func TestCheckOutLatest_withoutTufRepository(t *testing.T) { _, err := os.Stat(executablePath) require.NoError(t, err, "did not make test binary") - // Ensure we actually use the new autoupdater - store, err := agentsqlite.OpenRW(context.TODO(), rootDir, agentsqlite.StartupSettingsStore) - require.NoError(t, err, "setting up db connection") - require.NoError(t, store.Set([]byte(keys.UseTUFAutoupdater.String()), []byte("enabled")), "setting key") - require.NoError(t, store.Close(), "closing test db") - // Check it latest, err := CheckOutLatest(context.TODO(), binary, rootDir, "", "nightly", log.NewNopLogger()) require.NoError(t, err, "unexpected error on checking out latest") @@ -94,28 +80,6 @@ func TestCheckOutLatest_withoutTufRepository(t *testing.T) { } } -func TestCheckOutLatest_NotAvailableWhenNewAutoupdaterNotEnabled(t *testing.T) { - t.Parallel() - - for _, binary := range binaries { - binary := binary - t.Run(string(binary), func(t *testing.T) { - t.Parallel() - - rootDir := t.TempDir() - - // Ensure we do not use the new autoupdater - store, err := agentsqlite.OpenRW(context.TODO(), rootDir, agentsqlite.StartupSettingsStore) - require.NoError(t, err, "setting up db connection") - require.NoError(t, store.Set([]byte(keys.UseTUFAutoupdater.String()), []byte("")), "setting key") - require.NoError(t, store.Close(), "closing test db") - - _, err = CheckOutLatest(context.TODO(), binary, rootDir, "", "stable", log.NewNopLogger()) - require.Error(t, err, "expected error when using new TUF lookup on channel that should be using legacy") - }) - } -} - func Test_mostRecentVersion(t *testing.T) { t.Parallel() @@ -231,37 +195,6 @@ func Test_mostRecentVersion_acceptsLauncher_v1_4_1(t *testing.T) { require.Equal(t, firstVersionPath, latest.Path) } -func Test_usingNewAutoupdater_DatabaseNotExist(t *testing.T) { - t.Parallel() - - require.Equal(t, false, usingNewAutoupdater(context.TODO(), t.TempDir())) -} - -func Test_usingNewAutoupdater_FlagNotSet(t *testing.T) { - t.Parallel() - - tempRootDir := t.TempDir() - - store, err := agentsqlite.OpenRW(context.TODO(), tempRootDir, agentsqlite.StartupSettingsStore) - require.NoError(t, err, "setting up db connection") - require.NoError(t, store.Close(), "closing test db") - - require.Equal(t, false, usingNewAutoupdater(context.TODO(), tempRootDir)) -} - -func Test_usingNewAutoupdater_FlagSet(t *testing.T) { - t.Parallel() - - tempRootDir := t.TempDir() - - store, err := agentsqlite.OpenRW(context.TODO(), tempRootDir, agentsqlite.StartupSettingsStore) - require.NoError(t, err, "setting up db connection") - require.NoError(t, store.Set([]byte(keys.UseTUFAutoupdater.String()), []byte("enabled")), "setting key") - require.NoError(t, store.Close(), "closing test db") - - require.Equal(t, true, usingNewAutoupdater(context.TODO(), tempRootDir)) -} - func Test_getAutoupdateConfig_ConfigFlagSet(t *testing.T) { t.Parallel()