diff --git a/ee/tuf/library_lookup.go b/ee/tuf/library_lookup.go index 2f4713dcc1..876c2b16f4 100644 --- a/ee/tuf/library_lookup.go +++ b/ee/tuf/library_lookup.go @@ -28,6 +28,7 @@ type autoupdateConfig struct { channel string localDevelopmentPath string hostname string + identifier string } // CheckOutLatestWithoutConfig returns information about the latest downloaded executable for our binary, @@ -50,13 +51,22 @@ func CheckOutLatestWithoutConfig(binary autoupdatableBinary, slogger *slog.Logge // check for old root directories before returning final config in case we've stomped over with windows MSI install updatedRootDirectory := launcher.DetermineRootDirectoryOverride(cfg.rootDirectory, cfg.hostname) if updatedRootDirectory != cfg.rootDirectory { - slogger.Log(context.TODO(), slog.LevelInfo, - "old root directory contents detected, overriding for autoupdate config", - "opts_root_directory", cfg.rootDirectory, - "updated_root_directory", updatedRootDirectory, - ) - - cfg.rootDirectory = updatedRootDirectory + if cfg.identifier != "" && !strings.Contains(updatedRootDirectory, cfg.identifier) { + slogger.Log(context.TODO(), slog.LevelInfo, + "detected another root directory, but it does not match our identifier -- discarding", + "identifier", cfg.identifier, + "opts_root_directory", cfg.rootDirectory, + "non_matching_root_directory", updatedRootDirectory, + ) + } else { + slogger.Log(context.TODO(), slog.LevelInfo, + "old root directory contents detected, overriding for autoupdate config", + "opts_root_directory", cfg.rootDirectory, + "updated_root_directory", updatedRootDirectory, + ) + + cfg.rootDirectory = updatedRootDirectory + } } // Get update channel from startup settings @@ -125,13 +135,14 @@ func getAutoupdateConfig(args []string) (*autoupdateConfig, error) { pflagSet.ParseErrorsWhitelist = pflag.ParseErrorsWhitelist{UnknownFlags: true} // Extract the config flag plus the autoupdate flags - var flConfigFilePath, flRootDirectory, flUpdateDirectory, flUpdateChannel, flLocalDevelopmentPath, flHostname string + var flConfigFilePath, flRootDirectory, flUpdateDirectory, flUpdateChannel, flLocalDevelopmentPath, flHostname, flIdentifier string pflagSet.StringVar(&flConfigFilePath, "config", "", "") pflagSet.StringVar(&flRootDirectory, "root_directory", "", "") pflagSet.StringVar(&flUpdateDirectory, "update_directory", "", "") pflagSet.StringVar(&flUpdateChannel, "update_channel", "", "") pflagSet.StringVar(&flLocalDevelopmentPath, "localdev_path", "", "") pflagSet.StringVar(&flHostname, "hostname", "", "") + pflagSet.StringVar(&flIdentifier, "identifier", "", "") if err := pflagSet.Parse(argsToParse); err != nil { return nil, fmt.Errorf("parsing command-line flags: %w", err) @@ -156,6 +167,7 @@ func getAutoupdateConfig(args []string) (*autoupdateConfig, error) { updateDirectory: flUpdateDirectory, channel: flUpdateChannel, localDevelopmentPath: flLocalDevelopmentPath, + identifier: flIdentifier, } return cfg, nil @@ -187,6 +199,8 @@ func getAutoupdateConfigFromFile(configFilePath string) (*autoupdateConfig, erro cfg.localDevelopmentPath = value case "hostname": cfg.hostname = value + case "identifier": + cfg.identifier = value } return nil }); err != nil { diff --git a/pkg/launcher/paths.go b/pkg/launcher/paths.go index a1ad7af69c..b9ea21f19a 100644 --- a/pkg/launcher/paths.go +++ b/pkg/launcher/paths.go @@ -37,6 +37,8 @@ const ( ) var likelyWindowsRootDirPaths = []string{ + "C:\\ProgramData\\Kolide\\Launcher-kolide-nababe-k2\\data", + "C:\\Program Files\\Kolide\\Launcher-kolide-nababe-k2\\data", "C:\\ProgramData\\Kolide\\Launcher-kolide-k2\\data", "C:\\Program Files\\Kolide\\Launcher-kolide-k2\\data", }