Skip to content

Commit

Permalink
Don't run legacy autoupdater after transition
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Oct 11, 2023
1 parent 12a0a45 commit 6ad121c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
17 changes: 10 additions & 7 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
runGroup.Add("localserver", ls.Start, ls.Interrupt)
}

// If the autoupdater is enabled, enable it for both osquery and launcher
// If autoupdating is enabled, run the new autoupdater
if k.Autoupdate() {
// Create a new TUF autoupdater
metadataClient := http.DefaultClient
Expand All @@ -398,12 +398,15 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
tuf.WithOsqueryRestart(runnerRestart),
)
if err != nil {
// Log the error, but don't return it -- the new TUF autoupdater is not critical yet
level.Debug(logger).Log("msg", "could not create TUF autoupdater", "err", err)
} else {
runGroup.Add("tufAutoupdater", tufAutoupdater.Execute, tufAutoupdater.Interrupt)
return fmt.Errorf("creating TUF autoupdater updater: %w", err)
}

runGroup.Add("tufAutoupdater", tufAutoupdater.Execute, tufAutoupdater.Interrupt)
}

// Run the legacy autoupdater only if autoupdating is enabled and the given channel hasn't moved
// to the new autoupdater yet.
if k.Autoupdate() && !tuf.ChannelUsesNewAutoupdater(k.UpdateChannel()) {
osqueryUpdaterconfig := &updater.UpdaterConfig{
Logger: logger,
RootDirectory: rootDirectory,
Expand All @@ -413,7 +416,7 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
MirrorURL: k.MirrorServerURL(),
NotaryPrefix: k.NotaryPrefix(),
HTTPClient: httpClient,
InitialDelay: k.AutoupdateInitialDelay() + k.AutoupdateInterval()/2 + 5*time.Minute,
InitialDelay: k.AutoupdateInitialDelay() + k.AutoupdateInterval()/2,
SigChannel: sigChannel,
}

Expand All @@ -433,7 +436,7 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err
MirrorURL: k.MirrorServerURL(),
NotaryPrefix: k.NotaryPrefix(),
HTTPClient: httpClient,
InitialDelay: k.AutoupdateInitialDelay() + 5*time.Minute,
InitialDelay: k.AutoupdateInitialDelay(),
SigChannel: sigChannel,
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/autoupdate/tuf/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func (ta *TufAutoupdater) checkForUpdate() error {

// Only perform restarts if we're configured to use this new autoupdate library,
// to prevent performing unnecessary restarts.
if !usingNewAutoupdater(ta.channel) {
if !ChannelUsesNewAutoupdater(ta.channel) {
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/autoupdate/tuf/library_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func UsingNewAutoupdater() bool {
return false
}

return usingNewAutoupdater(cfg.channel)
return ChannelUsesNewAutoupdater(cfg.channel)
}

// getAutoupdateConfig reads launcher's config file to determine the configuration values
Expand Down Expand Up @@ -98,7 +98,7 @@ func getAutoupdateConfig() (*autoupdateConfig, error) {
// as its version.
func CheckOutLatest(binary autoupdatableBinary, rootDirectory string, updateDirectory string, channel string, logger log.Logger) (*BinaryUpdateInfo, error) {
// TODO: Remove this check once we decide to roll out the new autoupdater more broadly
if !usingNewAutoupdater(channel) {
if !ChannelUsesNewAutoupdater(channel) {
return nil, fmt.Errorf("not rolling out new TUF to channel %s that should still use legacy autoupdater", channel)
}

Expand All @@ -119,7 +119,7 @@ func CheckOutLatest(binary autoupdatableBinary, rootDirectory string, updateDire
return mostRecentVersion(binary, updateDirectory)
}

func usingNewAutoupdater(channel string) bool {
func ChannelUsesNewAutoupdater(channel string) bool {
_, ok := channelsUsingNewAutoupdater[channel]
return ok
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/autoupdate/tuf/library_lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func Test_mostRecentVersion_ReturnsErrorOnNoUpdatesDownloaded(t *testing.T) {
}
}

func Test_usingNewAutoupdater(t *testing.T) {
func TestChannelUsesNewAutoupdater(t *testing.T) {
t.Parallel()

channelsForTest := []struct {
Expand Down Expand Up @@ -210,6 +210,6 @@ func Test_usingNewAutoupdater(t *testing.T) {
}

for _, channel := range channelsForTest {
require.Equal(t, channel.usesNewAutoupdater, usingNewAutoupdater(channel.channelName))
require.Equal(t, channel.usesNewAutoupdater, ChannelUsesNewAutoupdater(channel.channelName))
}
}

0 comments on commit 6ad121c

Please sign in to comment.