Skip to content

Commit

Permalink
Do not override root directory to point to another tenant
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Aug 26, 2024
1 parent e123f14 commit 39228c9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
30 changes: 22 additions & 8 deletions ee/tuf/library_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -156,6 +167,7 @@ func getAutoupdateConfig(args []string) (*autoupdateConfig, error) {
updateDirectory: flUpdateDirectory,
channel: flUpdateChannel,
localDevelopmentPath: flLocalDevelopmentPath,
identifier: flIdentifier,
}

return cfg, nil
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions pkg/launcher/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down

0 comments on commit 39228c9

Please sign in to comment.