From 1645c4c72d8ca873475d78be8ab220ab1773c464 Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Tue, 25 Jun 2024 11:15:44 -0400 Subject: [PATCH 1/4] Add store for Kolide ATC and prepare to use it in osquery runner --- cmd/launcher/launcher.go | 4 ++++ ee/agent/knapsack/knapsack.go | 4 ++++ ee/agent/storage/bbolt/stores_bbolt.go | 1 + ee/agent/storage/ci/stores_ci.go | 1 + ee/agent/storage/stores.go | 1 + ee/agent/types/mocks/knapsack.go | 27 ++++++++++++++++++++----- ee/agent/types/stores.go | 1 + pkg/osquery/interactive/interactive.go | 2 +- pkg/osquery/runtime/runner.go | 19 +++++++++++++++-- pkg/osquery/table/table.go | 28 +++++++++++++++++++++++++- 10 files changed, 79 insertions(+), 9 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index 0e5f4b433..ee7511e9c 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -71,6 +71,7 @@ const ( serverDataSubsystemName = "kolide_server_data" desktopMenuSubsystemName = "kolide_desktop_menu" authTokensSubsystemName = "auth_tokens" + atcConfigSubsystemName = "kolide_atc_config" ) // runLauncher is the entry point into running launcher. It creates a @@ -400,6 +401,9 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl controlService.RegisterConsumer(serverDataSubsystemName, keyvalueconsumer.New(k.ServerProvidedDataStore())) // agentFlagConsumer handles agent flags pushed from the control server controlService.RegisterConsumer(agentFlagsSubsystemName, keyvalueconsumer.New(flagController)) + // atcConfigConsumer handles updates to Kolide's custom ATC tables + controlService.RegisterConsumer(atcConfigSubsystemName, keyvalueconsumer.New(k.AtcConfigStore())) + controlService.RegisterSubscriber(atcConfigSubsystemName, osqueryRunner) runner, err = desktopRunner.New( k, diff --git a/ee/agent/knapsack/knapsack.go b/ee/agent/knapsack/knapsack.go index 20ee82468..b04f7ac2d 100644 --- a/ee/agent/knapsack/knapsack.go +++ b/ee/agent/knapsack/knapsack.go @@ -87,6 +87,10 @@ func (k *knapsack) AgentFlagsStore() types.KVStore { return k.getKVStore(storage.AgentFlagsStore) } +func (k *knapsack) AtcConfigStore() types.KVStore { + return k.getKVStore(storage.AtcConfigStore) +} + func (k *knapsack) AutoupdateErrorsStore() types.KVStore { return k.getKVStore(storage.AutoupdateErrorsStore) } diff --git a/ee/agent/storage/bbolt/stores_bbolt.go b/ee/agent/storage/bbolt/stores_bbolt.go index 97d6a0e5d..6942c6f80 100644 --- a/ee/agent/storage/bbolt/stores_bbolt.go +++ b/ee/agent/storage/bbolt/stores_bbolt.go @@ -20,6 +20,7 @@ func MakeStores(ctx context.Context, slogger *slog.Logger, db *bbolt.DB) (map[st var storeNames = []storage.Store{ storage.AgentFlagsStore, + storage.AtcConfigStore, storage.AutoupdateErrorsStore, storage.ConfigStore, storage.ControlStore, diff --git a/ee/agent/storage/ci/stores_ci.go b/ee/agent/storage/ci/stores_ci.go index c6b0d9061..66d93d753 100644 --- a/ee/agent/storage/ci/stores_ci.go +++ b/ee/agent/storage/ci/stores_ci.go @@ -18,6 +18,7 @@ import ( func MakeStores(t *testing.T, slogger *slog.Logger, db *bbolt.DB) (map[storage.Store]types.KVStore, error) { var storeNames = []storage.Store{ storage.AgentFlagsStore, + storage.AtcConfigStore, storage.AutoupdateErrorsStore, storage.ConfigStore, storage.ControlStore, diff --git a/ee/agent/storage/stores.go b/ee/agent/storage/stores.go index 84d770701..486709311 100644 --- a/ee/agent/storage/stores.go +++ b/ee/agent/storage/stores.go @@ -5,6 +5,7 @@ type Store string const ( AgentFlagsStore Store = "agent_flags" // The store used for agent control flags. + AtcConfigStore Store = "kolide_atc_config" // The store used for Kolide custom ATC configuration AutoupdateErrorsStore Store = "tuf_autoupdate_errors" // The store used for tracking new autoupdater errors. ConfigStore Store = "config" // The store used for launcher configuration. ControlStore Store = "control_service_data" // The store used for control service caching data. diff --git a/ee/agent/types/mocks/knapsack.go b/ee/agent/types/mocks/knapsack.go index 8be4fe74f..98dfce9e5 100644 --- a/ee/agent/types/mocks/knapsack.go +++ b/ee/agent/types/mocks/knapsack.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.34.2. DO NOT EDIT. +// Code generated by mockery v2.21.1. DO NOT EDIT. package mocks @@ -52,6 +52,22 @@ func (_m *Knapsack) AgentFlagsStore() types.GetterSetterDeleterIteratorUpdaterCo return r0 } +// AtcConfigStore provides a mock function with given fields: +func (_m *Knapsack) AtcConfigStore() types.GetterSetterDeleterIteratorUpdaterCounterAppender { + ret := _m.Called() + + var r0 types.GetterSetterDeleterIteratorUpdaterCounterAppender + if rf, ok := ret.Get(0).(func() types.GetterSetterDeleterIteratorUpdaterCounterAppender); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(types.GetterSetterDeleterIteratorUpdaterCounterAppender) + } + } + + return r0 +} + // Autoupdate provides a mock function with given fields: func (_m *Knapsack) Autoupdate() bool { ret := _m.Called() @@ -1692,12 +1708,13 @@ func (_m *Knapsack) WatchdogUtilizationLimitPercent() int { return r0 } -// NewKnapsack creates a new instance of Knapsack. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. -// The first argument is typically a *testing.T value. -func NewKnapsack(t interface { +type mockConstructorTestingTNewKnapsack interface { mock.TestingT Cleanup(func()) -}) *Knapsack { +} + +// NewKnapsack creates a new instance of Knapsack. It also registers a testing interface on the mock and a cleanup function to assert the mocks expectations. +func NewKnapsack(t mockConstructorTestingTNewKnapsack) *Knapsack { mock := &Knapsack{} mock.Mock.Test(t) diff --git a/ee/agent/types/stores.go b/ee/agent/types/stores.go index 417977ae5..b80d257da 100644 --- a/ee/agent/types/stores.go +++ b/ee/agent/types/stores.go @@ -5,6 +5,7 @@ import "github.com/kolide/launcher/ee/agent/storage" type Stores interface { Stores() map[storage.Store]KVStore AgentFlagsStore() KVStore + AtcConfigStore() KVStore AutoupdateErrorsStore() KVStore ConfigStore() KVStore ControlStore() KVStore diff --git a/pkg/osquery/interactive/interactive.go b/pkg/osquery/interactive/interactive.go index d10262214..dd9ba8942 100644 --- a/pkg/osquery/interactive/interactive.go +++ b/pkg/osquery/interactive/interactive.go @@ -56,7 +56,7 @@ func StartProcess(knapsack types.Knapsack, interactiveRootDir string) (*os.Proce } // start building list of osq plugins with the kolide tables - osqPlugins := table.PlatformTables(knapsack.Slogger(), knapsack.OsquerydPath()) + osqPlugins := table.PlatformTables(knapsack, knapsack.Slogger(), knapsack.OsquerydPath()) osqueryFlags := knapsack.OsqueryFlags() // if we were not provided a config path flag, try to add default config diff --git a/pkg/osquery/runtime/runner.go b/pkg/osquery/runtime/runner.go index 4ac24eb14..2349bbe85 100644 --- a/pkg/osquery/runtime/runner.go +++ b/pkg/osquery/runtime/runner.go @@ -183,6 +183,21 @@ func (r *Runner) FlagsChanged(flagKeys ...keys.FlagKey) { } } +// Ping satisfies the control.subscriber interface -- the runner subscribes to changes to +// the kolide_atc_config subsystem. +func (r *Runner) Ping() { + r.slogger.Log(context.TODO(), slog.LevelDebug, + "Kolide ATC configuration changed, restarting instance to apply", + ) + + if err := r.Restart(); err != nil { + r.slogger.Log(context.TODO(), slog.LevelError, + "could not restart osquery instance after Kolide ATC configuration changed", + "err", err, + ) + } +} + // Restart allows you to cleanly shutdown the current instance and launch a new // instance with the same configurations. func (r *Runner) Restart() error { @@ -469,7 +484,7 @@ func (r *Runner) launchOsqueryInstance() error { ) } - // Now spawn an extension manage to for the tables. We need to + // Now spawn an extension manager for the tables. We need to // start this one in the background, because the runner.Start // function needs to return promptly enough for osquery to use // it to enroll. Very racy @@ -482,7 +497,7 @@ func (r *Runner) launchOsqueryInstance() error { "errgroup", "kolide extension manager server launch", ) - plugins := table.PlatformTables(r.knapsack.Slogger().With("component", "platform_tables"), currentOsquerydBinaryPath) + plugins := table.PlatformTables(r.knapsack, r.knapsack.Slogger().With("component", "platform_tables"), currentOsquerydBinaryPath) if len(plugins) == 0 { return nil diff --git a/pkg/osquery/table/table.go b/pkg/osquery/table/table.go index a52f11324..51ec72e29 100644 --- a/pkg/osquery/table/table.go +++ b/pkg/osquery/table/table.go @@ -1,6 +1,7 @@ package table import ( + "context" "log/slog" "github.com/kolide/launcher/ee/agent/types" @@ -37,7 +38,7 @@ func LauncherTables(k types.Knapsack) []osquery.OsqueryPlugin { } // PlatformTables returns all tables for the launcher build platform. -func PlatformTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { +func PlatformTables(k types.Knapsack, slogger *slog.Logger, currentOsquerydBinaryPath string) []osquery.OsqueryPlugin { // Common tables to all platforms tables := []osquery.OsqueryPlugin{ ChromeLoginDataEmails(slogger), @@ -65,5 +66,30 @@ func PlatformTables(slogger *slog.Logger, currentOsquerydBinaryPath string) []os // add in the platform specific ones (as denoted by build tags) tables = append(tables, platformSpecificTables(slogger, currentOsquerydBinaryPath)...) + // Add in the Kolide custom ATC tables + tables = append(tables, kolideCustomAtcTables(k, slogger)...) + return tables } + +// kolideCustomAtcTables will handle indexeddb tables and others in the future. For now, +// it just logs the config. +func kolideCustomAtcTables(k types.Knapsack, slogger *slog.Logger) []osquery.OsqueryPlugin { + loggableConfig := make(map[string]string) + if err := k.AtcConfigStore().ForEach(func(k []byte, v []byte) error { + loggableConfig[string(k)] = string(v) + return nil + }); err != nil { + slogger.Log(context.TODO(), slog.LevelDebug, + "could not retrieve contents of Kolide ATC config store", + "err", err, + ) + return nil + } + + slogger.Log(context.TODO(), slog.LevelDebug, + "retrieved contents of Kolide ATC config store", + "config", loggableConfig, + ) + return nil +} From 7c4698a512f85f7cbb671de86fb348d6b5977ab8 Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Tue, 25 Jun 2024 11:50:12 -0400 Subject: [PATCH 2/4] Add config to startup_settings so interactive can access it as well --- cmd/launcher/launcher.go | 7 +-- ee/agent/startupsettings/writer.go | 37 ++++++++++++++++ pkg/osquery/table/table.go | 71 +++++++++++++++++++++++++----- 3 files changed, 101 insertions(+), 14 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index ee7511e9c..d06e88122 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -243,13 +243,13 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl startupSpan.AddEvent("log_shipper_init_completed") } - s, err := startupsettings.OpenWriter(ctx, k) + startupSettingsWriter, err := startupsettings.OpenWriter(ctx, k) if err != nil { return fmt.Errorf("creating startup db: %w", err) } - defer s.Close() + defer startupSettingsWriter.Close() - if err := s.WriteSettings(); err != nil { + if err := startupSettingsWriter.WriteSettings(); err != nil { slogger.Log(ctx, slog.LevelError, "writing startup settings", "err", err, @@ -404,6 +404,7 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl // atcConfigConsumer handles updates to Kolide's custom ATC tables controlService.RegisterConsumer(atcConfigSubsystemName, keyvalueconsumer.New(k.AtcConfigStore())) controlService.RegisterSubscriber(atcConfigSubsystemName, osqueryRunner) + controlService.RegisterSubscriber(atcConfigSubsystemName, startupSettingsWriter) runner, err = desktopRunner.New( k, diff --git a/ee/agent/startupsettings/writer.go b/ee/agent/startupsettings/writer.go index aeb3b04d3..4ec84f0ff 100644 --- a/ee/agent/startupsettings/writer.go +++ b/ee/agent/startupsettings/writer.go @@ -51,6 +51,17 @@ func OpenWriter(ctx context.Context, knapsack types.Knapsack) (*startupSettingsW return s, nil } +// Ping satisfies the control.subscriber interface -- the runner subscribes to changes to +// the kolide_atc_config subsystem. +func (s *startupSettingsWriter) Ping() { + if err := s.WriteSettings(); err != nil { + s.knapsack.Slogger().Log(context.TODO(), slog.LevelWarn, + "could not write updated settings", + "err", err, + ) + } +} + // WriteSettings updates the flags with their values from the agent flag data store. func (s *startupSettingsWriter) WriteSettings() error { updatedFlags := make(map[string]string) @@ -69,6 +80,15 @@ func (s *startupSettingsWriter) WriteSettings() error { updatedFlags["auto_table_construction"] = atcConfig } + if kolideAtcConfig, err := s.extractKolideAutoTableConstructionConfig(); err != nil { + s.knapsack.Slogger().Log(context.TODO(), slog.LevelDebug, + "extracting kolide_atc_config", + "err", err, + ) + } else { + updatedFlags["kolide_atc_config"] = kolideAtcConfig + } + if _, err := s.kvStore.Update(updatedFlags); err != nil { return fmt.Errorf("writing settings: %w", err) } @@ -119,3 +139,20 @@ func (s *startupSettingsWriter) extractAutoTableConstructionConfig() (string, er return string(atcJson), nil } + +func (s *startupSettingsWriter) extractKolideAutoTableConstructionConfig() (string, error) { + kolideCfg := make(map[string]string) + if err := s.knapsack.AtcConfigStore().ForEach(func(k []byte, v []byte) error { + kolideCfg[string(k)] = string(v) + return nil + }); err != nil { + return "", fmt.Errorf("could not get Kolide ATC config from store: %w", err) + } + + atcJson, err := json.Marshal(kolideCfg) + if err != nil { + return "", fmt.Errorf("could not marshal kolide_atc_config: %w", err) + } + + return string(atcJson), nil +} diff --git a/pkg/osquery/table/table.go b/pkg/osquery/table/table.go index 51ec72e29..b4d859819 100644 --- a/pkg/osquery/table/table.go +++ b/pkg/osquery/table/table.go @@ -2,8 +2,12 @@ package table import ( "context" + "encoding/json" + "errors" + "fmt" "log/slog" + "github.com/kolide/launcher/ee/agent/startupsettings" "github.com/kolide/launcher/ee/agent/types" "github.com/kolide/launcher/ee/allowedcmd" "github.com/kolide/launcher/ee/tables/cryptoinfotable" @@ -72,24 +76,69 @@ func PlatformTables(k types.Knapsack, slogger *slog.Logger, currentOsquerydBinar return tables } -// kolideCustomAtcTables will handle indexeddb tables and others in the future. For now, -// it just logs the config. +// kolideCustomAtcTables retrieves Kolide ATC config from the appropriate data store(s). +// For now, it just logs the configuration. In the future, it will handle indexeddb tables +// and others. func kolideCustomAtcTables(k types.Knapsack, slogger *slog.Logger) []osquery.OsqueryPlugin { - loggableConfig := make(map[string]string) - if err := k.AtcConfigStore().ForEach(func(k []byte, v []byte) error { - loggableConfig[string(k)] = string(v) - return nil - }); err != nil { + // Fetch tables from KVStore or from startup settings + config, err := kolideAtcConfigFromDb(k) + if err != nil { slogger.Log(context.TODO(), slog.LevelDebug, - "could not retrieve contents of Kolide ATC config store", + "could not retrieve Kolide ATC config from store, may not have access -- falling back to startup settings", "err", err, ) - return nil + + config, err = kolideAtcConfigFromStartupSettings(k) + if err != nil { + slogger.Log(context.TODO(), slog.LevelWarn, + "could not retrieve Kolide ATC config from startup settings", + "err", err, + ) + return nil + } } + // In the future, we would construct the plugins from the configuration here. + // For now, we just log. slogger.Log(context.TODO(), slog.LevelDebug, - "retrieved contents of Kolide ATC config store", - "config", loggableConfig, + "retrieved Kolide ATC config", + "config", config, ) + return nil } + +func kolideAtcConfigFromDb(k types.Knapsack) (map[string]string, error) { + if k == nil || k.AtcConfigStore() == nil { + return nil, errors.New("stores in knapsack not available") + } + loggableConfig := make(map[string]string) + if err := k.AtcConfigStore().ForEach(func(k []byte, v []byte) error { + loggableConfig[string(k)] = string(v) + return nil + }); err != nil { + return nil, fmt.Errorf("retrieving contents of Kolide ATC config store: %w", err) + } + + return loggableConfig, nil +} + +func kolideAtcConfigFromStartupSettings(k types.Knapsack) (map[string]string, error) { + r, err := startupsettings.OpenReader(context.TODO(), k.RootDirectory()) + if err != nil { + return nil, fmt.Errorf("error opening startup settings reader: %w", err) + } + defer r.Close() + + atcConfig, err := r.Get("kolide_atc_config") + if err != nil { + return nil, fmt.Errorf("error getting kolide_atc_config from startup settings: %w", err) + } + + var loggableConfig map[string]string + if err := json.Unmarshal([]byte(atcConfig), &loggableConfig); err != nil { + return nil, fmt.Errorf("unmarshalling kolide_atc_config: %w", err) + } + + return loggableConfig, nil +} From 5404575385240cd4694303312daf1e99f0db5fee Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Tue, 25 Jun 2024 12:35:48 -0400 Subject: [PATCH 3/4] Set up store for tests --- ee/agent/startupsettings/writer_test.go | 3 +++ pkg/osquery/interactive/interactive_test.go | 5 +++++ pkg/osquery/runtime/runtime_posix_test.go | 8 ++++++++ pkg/osquery/runtime/runtime_test.go | 18 ++++++++++++++++++ 4 files changed, 34 insertions(+) diff --git a/ee/agent/startupsettings/writer_test.go b/ee/agent/startupsettings/writer_test.go index b813fd233..f4cf4c746 100644 --- a/ee/agent/startupsettings/writer_test.go +++ b/ee/agent/startupsettings/writer_test.go @@ -34,6 +34,7 @@ func TestOpenWriter_NewDatabase(t *testing.T) { k.On("PinnedOsquerydVersion").Return("5.11.0") k.On("ConfigStore").Return(inmemory.NewStore()) k.On("Slogger").Return(multislogger.NewNopLogger()) + k.On("AtcConfigStore").Return(inmemory.NewStore()) // Set up storage db, which should create the database and set all flags s, err := OpenWriter(context.TODO(), k) @@ -82,6 +83,7 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) { // Set up dependencies k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) + k.On("AtcConfigStore").Return(inmemory.NewStore()) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion) @@ -126,6 +128,7 @@ func TestFlagsChanged(t *testing.T) { testRootDir := t.TempDir() k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) + k.On("AtcConfigStore").Return(inmemory.NewStore()) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion) diff --git a/pkg/osquery/interactive/interactive_test.go b/pkg/osquery/interactive/interactive_test.go index 5edba7600..baba3be9b 100644 --- a/pkg/osquery/interactive/interactive_test.go +++ b/pkg/osquery/interactive/interactive_test.go @@ -16,6 +16,8 @@ import ( "github.com/kolide/kit/fsutil" "github.com/kolide/kit/ulid" + "github.com/kolide/launcher/ee/agent/storage" + storageci "github.com/kolide/launcher/ee/agent/storage/ci" "github.com/kolide/launcher/ee/agent/types/mocks" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/kolide/launcher/pkg/packaging" @@ -97,6 +99,9 @@ func TestProc(t *testing.T) { mockSack.On("OsqueryFlags").Return(tt.osqueryFlags) mockSack.On("Slogger").Return(multislogger.NewNopLogger()) mockSack.On("RootDirectory").Maybe().Return("whatever_the_root_launcher_dir_is") + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + mockSack.On("AtcConfigStore").Return(store) proc, _, err := StartProcess(mockSack, rootDir) diff --git a/pkg/osquery/runtime/runtime_posix_test.go b/pkg/osquery/runtime/runtime_posix_test.go index f4d09d8c1..1753da0be 100644 --- a/pkg/osquery/runtime/runtime_posix_test.go +++ b/pkg/osquery/runtime/runtime_posix_test.go @@ -12,6 +12,8 @@ import ( "testing" "time" + "github.com/kolide/launcher/ee/agent/storage" + storageci "github.com/kolide/launcher/ee/agent/storage/ci" typesMocks "github.com/kolide/launcher/ee/agent/types/mocks" "github.com/kolide/launcher/pkg/log/multislogger" "github.com/kolide/launcher/pkg/threadsafebuffer" @@ -51,6 +53,9 @@ func TestOsquerySlowStart(t *testing.T) { slogger := multislogger.New(slog.NewJSONHandler(&logBytes, &slog.HandlerOptions{Level: slog.LevelDebug})) k.On("Slogger").Return(slogger.Logger) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner := New( k, @@ -95,6 +100,9 @@ func TestExtensionSocketPath(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) extensionSocketPath := filepath.Join(rootDirectory, "sock") runner := New( diff --git a/pkg/osquery/runtime/runtime_test.go b/pkg/osquery/runtime/runtime_test.go index 4e9dcbccd..7a350148b 100644 --- a/pkg/osquery/runtime/runtime_test.go +++ b/pkg/osquery/runtime/runtime_test.go @@ -336,6 +336,9 @@ func TestWithOsqueryFlags(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner := New( k, @@ -368,6 +371,9 @@ func TestFlagsChanged(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) // Start the runner runner := New( @@ -461,6 +467,9 @@ func TestSimplePath(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner := New( k, @@ -489,6 +498,9 @@ func TestMultipleShutdowns(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner := New( k, @@ -516,6 +528,9 @@ func TestOsqueryDies(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner := New( k, @@ -610,6 +625,9 @@ func setupOsqueryInstanceForTests(t *testing.T) (runner *Runner, teardown func() k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe() k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + require.NoError(t, err) + k.On("AtcConfigStore").Return(store) runner = New( k, From b2d7b96c623885b2ef4deba9d85e10e4ce2d7edd Mon Sep 17 00:00:00 2001 From: Rebecca Mahany-Horton Date: Tue, 25 Jun 2024 13:31:52 -0400 Subject: [PATCH 4/4] Rename to KATC --- cmd/launcher/launcher.go | 10 +++---- ee/agent/knapsack/knapsack.go | 4 +-- ee/agent/startupsettings/writer.go | 14 ++++----- ee/agent/startupsettings/writer_test.go | 6 ++-- ee/agent/storage/bbolt/stores_bbolt.go | 2 +- ee/agent/storage/ci/stores_ci.go | 2 +- ee/agent/storage/stores.go | 2 +- ee/agent/types/mocks/knapsack.go | 32 ++++++++++----------- ee/agent/types/stores.go | 2 +- pkg/osquery/interactive/interactive_test.go | 4 +-- pkg/osquery/runtime/runner.go | 2 +- pkg/osquery/runtime/runtime_posix_test.go | 8 +++--- pkg/osquery/runtime/runtime_test.go | 24 ++++++++-------- pkg/osquery/table/table.go | 20 ++++++------- 14 files changed, 66 insertions(+), 66 deletions(-) diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index d06e88122..e2701bccc 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -71,7 +71,7 @@ const ( serverDataSubsystemName = "kolide_server_data" desktopMenuSubsystemName = "kolide_desktop_menu" authTokensSubsystemName = "auth_tokens" - atcConfigSubsystemName = "kolide_atc_config" + katcSubsystemName = "katc_config" // Kolide ATC ) // runLauncher is the entry point into running launcher. It creates a @@ -401,10 +401,10 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl controlService.RegisterConsumer(serverDataSubsystemName, keyvalueconsumer.New(k.ServerProvidedDataStore())) // agentFlagConsumer handles agent flags pushed from the control server controlService.RegisterConsumer(agentFlagsSubsystemName, keyvalueconsumer.New(flagController)) - // atcConfigConsumer handles updates to Kolide's custom ATC tables - controlService.RegisterConsumer(atcConfigSubsystemName, keyvalueconsumer.New(k.AtcConfigStore())) - controlService.RegisterSubscriber(atcConfigSubsystemName, osqueryRunner) - controlService.RegisterSubscriber(atcConfigSubsystemName, startupSettingsWriter) + // katcConfigConsumer handles updates to Kolide's custom ATC tables + controlService.RegisterConsumer(katcSubsystemName, keyvalueconsumer.New(k.KatcConfigStore())) + controlService.RegisterSubscriber(katcSubsystemName, osqueryRunner) + controlService.RegisterSubscriber(katcSubsystemName, startupSettingsWriter) runner, err = desktopRunner.New( k, diff --git a/ee/agent/knapsack/knapsack.go b/ee/agent/knapsack/knapsack.go index b04f7ac2d..ee20e1010 100644 --- a/ee/agent/knapsack/knapsack.go +++ b/ee/agent/knapsack/knapsack.go @@ -87,8 +87,8 @@ func (k *knapsack) AgentFlagsStore() types.KVStore { return k.getKVStore(storage.AgentFlagsStore) } -func (k *knapsack) AtcConfigStore() types.KVStore { - return k.getKVStore(storage.AtcConfigStore) +func (k *knapsack) KatcConfigStore() types.KVStore { + return k.getKVStore(storage.KatcConfigStore) } func (k *knapsack) AutoupdateErrorsStore() types.KVStore { diff --git a/ee/agent/startupsettings/writer.go b/ee/agent/startupsettings/writer.go index 4ec84f0ff..e70b9e453 100644 --- a/ee/agent/startupsettings/writer.go +++ b/ee/agent/startupsettings/writer.go @@ -52,7 +52,7 @@ func OpenWriter(ctx context.Context, knapsack types.Knapsack) (*startupSettingsW } // Ping satisfies the control.subscriber interface -- the runner subscribes to changes to -// the kolide_atc_config subsystem. +// the katc_config subsystem. func (s *startupSettingsWriter) Ping() { if err := s.WriteSettings(); err != nil { s.knapsack.Slogger().Log(context.TODO(), slog.LevelWarn, @@ -80,13 +80,13 @@ func (s *startupSettingsWriter) WriteSettings() error { updatedFlags["auto_table_construction"] = atcConfig } - if kolideAtcConfig, err := s.extractKolideAutoTableConstructionConfig(); err != nil { + if katcConfig, err := s.extractKATCConstructionConfig(); err != nil { s.knapsack.Slogger().Log(context.TODO(), slog.LevelDebug, - "extracting kolide_atc_config", + "extracting katc_config", "err", err, ) } else { - updatedFlags["kolide_atc_config"] = kolideAtcConfig + updatedFlags["katc_config"] = katcConfig } if _, err := s.kvStore.Update(updatedFlags); err != nil { @@ -140,9 +140,9 @@ func (s *startupSettingsWriter) extractAutoTableConstructionConfig() (string, er return string(atcJson), nil } -func (s *startupSettingsWriter) extractKolideAutoTableConstructionConfig() (string, error) { +func (s *startupSettingsWriter) extractKATCConstructionConfig() (string, error) { kolideCfg := make(map[string]string) - if err := s.knapsack.AtcConfigStore().ForEach(func(k []byte, v []byte) error { + if err := s.knapsack.KatcConfigStore().ForEach(func(k []byte, v []byte) error { kolideCfg[string(k)] = string(v) return nil }); err != nil { @@ -151,7 +151,7 @@ func (s *startupSettingsWriter) extractKolideAutoTableConstructionConfig() (stri atcJson, err := json.Marshal(kolideCfg) if err != nil { - return "", fmt.Errorf("could not marshal kolide_atc_config: %w", err) + return "", fmt.Errorf("could not marshal katc_config: %w", err) } return string(atcJson), nil diff --git a/ee/agent/startupsettings/writer_test.go b/ee/agent/startupsettings/writer_test.go index f4cf4c746..a46e5ae2a 100644 --- a/ee/agent/startupsettings/writer_test.go +++ b/ee/agent/startupsettings/writer_test.go @@ -34,7 +34,7 @@ func TestOpenWriter_NewDatabase(t *testing.T) { k.On("PinnedOsquerydVersion").Return("5.11.0") k.On("ConfigStore").Return(inmemory.NewStore()) k.On("Slogger").Return(multislogger.NewNopLogger()) - k.On("AtcConfigStore").Return(inmemory.NewStore()) + k.On("KatcConfigStore").Return(inmemory.NewStore()) // Set up storage db, which should create the database and set all flags s, err := OpenWriter(context.TODO(), k) @@ -83,7 +83,7 @@ func TestOpenWriter_DatabaseAlreadyExists(t *testing.T) { // Set up dependencies k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) - k.On("AtcConfigStore").Return(inmemory.NewStore()) + k.On("KatcConfigStore").Return(inmemory.NewStore()) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion) @@ -128,7 +128,7 @@ func TestFlagsChanged(t *testing.T) { testRootDir := t.TempDir() k := typesmocks.NewKnapsack(t) k.On("RootDirectory").Return(testRootDir) - k.On("AtcConfigStore").Return(inmemory.NewStore()) + k.On("KatcConfigStore").Return(inmemory.NewStore()) k.On("RegisterChangeObserver", mock.Anything, keys.UpdateChannel) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedLauncherVersion) k.On("RegisterChangeObserver", mock.Anything, keys.PinnedOsquerydVersion) diff --git a/ee/agent/storage/bbolt/stores_bbolt.go b/ee/agent/storage/bbolt/stores_bbolt.go index 6942c6f80..f9fa42736 100644 --- a/ee/agent/storage/bbolt/stores_bbolt.go +++ b/ee/agent/storage/bbolt/stores_bbolt.go @@ -20,7 +20,7 @@ func MakeStores(ctx context.Context, slogger *slog.Logger, db *bbolt.DB) (map[st var storeNames = []storage.Store{ storage.AgentFlagsStore, - storage.AtcConfigStore, + storage.KatcConfigStore, storage.AutoupdateErrorsStore, storage.ConfigStore, storage.ControlStore, diff --git a/ee/agent/storage/ci/stores_ci.go b/ee/agent/storage/ci/stores_ci.go index 66d93d753..7e078ff1a 100644 --- a/ee/agent/storage/ci/stores_ci.go +++ b/ee/agent/storage/ci/stores_ci.go @@ -18,7 +18,7 @@ import ( func MakeStores(t *testing.T, slogger *slog.Logger, db *bbolt.DB) (map[storage.Store]types.KVStore, error) { var storeNames = []storage.Store{ storage.AgentFlagsStore, - storage.AtcConfigStore, + storage.KatcConfigStore, storage.AutoupdateErrorsStore, storage.ConfigStore, storage.ControlStore, diff --git a/ee/agent/storage/stores.go b/ee/agent/storage/stores.go index 486709311..56ca34420 100644 --- a/ee/agent/storage/stores.go +++ b/ee/agent/storage/stores.go @@ -5,7 +5,7 @@ type Store string const ( AgentFlagsStore Store = "agent_flags" // The store used for agent control flags. - AtcConfigStore Store = "kolide_atc_config" // The store used for Kolide custom ATC configuration + KatcConfigStore Store = "katc_config" // The store used for Kolide custom ATC configuration AutoupdateErrorsStore Store = "tuf_autoupdate_errors" // The store used for tracking new autoupdater errors. ConfigStore Store = "config" // The store used for launcher configuration. ControlStore Store = "control_service_data" // The store used for control service caching data. diff --git a/ee/agent/types/mocks/knapsack.go b/ee/agent/types/mocks/knapsack.go index 98dfce9e5..9a50c0a43 100644 --- a/ee/agent/types/mocks/knapsack.go +++ b/ee/agent/types/mocks/knapsack.go @@ -52,22 +52,6 @@ func (_m *Knapsack) AgentFlagsStore() types.GetterSetterDeleterIteratorUpdaterCo return r0 } -// AtcConfigStore provides a mock function with given fields: -func (_m *Knapsack) AtcConfigStore() types.GetterSetterDeleterIteratorUpdaterCounterAppender { - ret := _m.Called() - - var r0 types.GetterSetterDeleterIteratorUpdaterCounterAppender - if rf, ok := ret.Get(0).(func() types.GetterSetterDeleterIteratorUpdaterCounterAppender); ok { - r0 = rf() - } else { - if ret.Get(0) != nil { - r0 = ret.Get(0).(types.GetterSetterDeleterIteratorUpdaterCounterAppender) - } - } - - return r0 -} - // Autoupdate provides a mock function with given fields: func (_m *Knapsack) Autoupdate() bool { ret := _m.Called() @@ -510,6 +494,22 @@ func (_m *Knapsack) InsecureTransportTLS() bool { return r0 } +// KatcConfigStore provides a mock function with given fields: +func (_m *Knapsack) KatcConfigStore() types.GetterSetterDeleterIteratorUpdaterCounterAppender { + ret := _m.Called() + + var r0 types.GetterSetterDeleterIteratorUpdaterCounterAppender + if rf, ok := ret.Get(0).(func() types.GetterSetterDeleterIteratorUpdaterCounterAppender); ok { + r0 = rf() + } else { + if ret.Get(0) != nil { + r0 = ret.Get(0).(types.GetterSetterDeleterIteratorUpdaterCounterAppender) + } + } + + return r0 +} + // KolideHosted provides a mock function with given fields: func (_m *Knapsack) KolideHosted() bool { ret := _m.Called() diff --git a/ee/agent/types/stores.go b/ee/agent/types/stores.go index b80d257da..05acb9ae8 100644 --- a/ee/agent/types/stores.go +++ b/ee/agent/types/stores.go @@ -5,7 +5,7 @@ import "github.com/kolide/launcher/ee/agent/storage" type Stores interface { Stores() map[storage.Store]KVStore AgentFlagsStore() KVStore - AtcConfigStore() KVStore + KatcConfigStore() KVStore AutoupdateErrorsStore() KVStore ConfigStore() KVStore ControlStore() KVStore diff --git a/pkg/osquery/interactive/interactive_test.go b/pkg/osquery/interactive/interactive_test.go index baba3be9b..1b0b58aad 100644 --- a/pkg/osquery/interactive/interactive_test.go +++ b/pkg/osquery/interactive/interactive_test.go @@ -99,9 +99,9 @@ func TestProc(t *testing.T) { mockSack.On("OsqueryFlags").Return(tt.osqueryFlags) mockSack.On("Slogger").Return(multislogger.NewNopLogger()) mockSack.On("RootDirectory").Maybe().Return("whatever_the_root_launcher_dir_is") - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - mockSack.On("AtcConfigStore").Return(store) + mockSack.On("KatcConfigStore").Return(store) proc, _, err := StartProcess(mockSack, rootDir) diff --git a/pkg/osquery/runtime/runner.go b/pkg/osquery/runtime/runner.go index 2349bbe85..d96790bf8 100644 --- a/pkg/osquery/runtime/runner.go +++ b/pkg/osquery/runtime/runner.go @@ -184,7 +184,7 @@ func (r *Runner) FlagsChanged(flagKeys ...keys.FlagKey) { } // Ping satisfies the control.subscriber interface -- the runner subscribes to changes to -// the kolide_atc_config subsystem. +// the katc_config subsystem. func (r *Runner) Ping() { r.slogger.Log(context.TODO(), slog.LevelDebug, "Kolide ATC configuration changed, restarting instance to apply", diff --git a/pkg/osquery/runtime/runtime_posix_test.go b/pkg/osquery/runtime/runtime_posix_test.go index 1753da0be..e2ee780f0 100644 --- a/pkg/osquery/runtime/runtime_posix_test.go +++ b/pkg/osquery/runtime/runtime_posix_test.go @@ -53,9 +53,9 @@ func TestOsquerySlowStart(t *testing.T) { slogger := multislogger.New(slog.NewJSONHandler(&logBytes, &slog.HandlerOptions{Level: slog.LevelDebug})) k.On("Slogger").Return(slogger.Logger) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner := New( k, @@ -100,9 +100,9 @@ func TestExtensionSocketPath(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) extensionSocketPath := filepath.Join(rootDirectory, "sock") runner := New( diff --git a/pkg/osquery/runtime/runtime_test.go b/pkg/osquery/runtime/runtime_test.go index 7a350148b..68cfcc373 100644 --- a/pkg/osquery/runtime/runtime_test.go +++ b/pkg/osquery/runtime/runtime_test.go @@ -336,9 +336,9 @@ func TestWithOsqueryFlags(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner := New( k, @@ -371,9 +371,9 @@ func TestFlagsChanged(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) // Start the runner runner := New( @@ -467,9 +467,9 @@ func TestSimplePath(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner := New( k, @@ -498,9 +498,9 @@ func TestMultipleShutdowns(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner := New( k, @@ -528,9 +528,9 @@ func TestOsqueryDies(t *testing.T) { k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything) k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner := New( k, @@ -625,9 +625,9 @@ func setupOsqueryInstanceForTests(t *testing.T) (runner *Runner, teardown func() k.On("RegisterChangeObserver", mock.Anything, mock.Anything, mock.Anything, mock.Anything, mock.Anything).Maybe() k.On("Slogger").Return(multislogger.NewNopLogger()) k.On("LatestOsquerydPath", mock.Anything).Return(testOsqueryBinaryDirectory) - store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.AtcConfigStore.String()) + store, err := storageci.NewStore(t, multislogger.NewNopLogger(), storage.KatcConfigStore.String()) require.NoError(t, err) - k.On("AtcConfigStore").Return(store) + k.On("KatcConfigStore").Return(store) runner = New( k, diff --git a/pkg/osquery/table/table.go b/pkg/osquery/table/table.go index b4d859819..39f3edf6b 100644 --- a/pkg/osquery/table/table.go +++ b/pkg/osquery/table/table.go @@ -81,14 +81,14 @@ func PlatformTables(k types.Knapsack, slogger *slog.Logger, currentOsquerydBinar // and others. func kolideCustomAtcTables(k types.Knapsack, slogger *slog.Logger) []osquery.OsqueryPlugin { // Fetch tables from KVStore or from startup settings - config, err := kolideAtcConfigFromDb(k) + config, err := katcFromDb(k) if err != nil { slogger.Log(context.TODO(), slog.LevelDebug, "could not retrieve Kolide ATC config from store, may not have access -- falling back to startup settings", "err", err, ) - config, err = kolideAtcConfigFromStartupSettings(k) + config, err = katcFromStartupSettings(k) if err != nil { slogger.Log(context.TODO(), slog.LevelWarn, "could not retrieve Kolide ATC config from startup settings", @@ -108,12 +108,12 @@ func kolideCustomAtcTables(k types.Knapsack, slogger *slog.Logger) []osquery.Osq return nil } -func kolideAtcConfigFromDb(k types.Knapsack) (map[string]string, error) { - if k == nil || k.AtcConfigStore() == nil { +func katcFromDb(k types.Knapsack) (map[string]string, error) { + if k == nil || k.KatcConfigStore() == nil { return nil, errors.New("stores in knapsack not available") } loggableConfig := make(map[string]string) - if err := k.AtcConfigStore().ForEach(func(k []byte, v []byte) error { + if err := k.KatcConfigStore().ForEach(func(k []byte, v []byte) error { loggableConfig[string(k)] = string(v) return nil }); err != nil { @@ -123,21 +123,21 @@ func kolideAtcConfigFromDb(k types.Knapsack) (map[string]string, error) { return loggableConfig, nil } -func kolideAtcConfigFromStartupSettings(k types.Knapsack) (map[string]string, error) { +func katcFromStartupSettings(k types.Knapsack) (map[string]string, error) { r, err := startupsettings.OpenReader(context.TODO(), k.RootDirectory()) if err != nil { return nil, fmt.Errorf("error opening startup settings reader: %w", err) } defer r.Close() - atcConfig, err := r.Get("kolide_atc_config") + katcConfig, err := r.Get("katc_config") if err != nil { - return nil, fmt.Errorf("error getting kolide_atc_config from startup settings: %w", err) + return nil, fmt.Errorf("error getting katc_config from startup settings: %w", err) } var loggableConfig map[string]string - if err := json.Unmarshal([]byte(atcConfig), &loggableConfig); err != nil { - return nil, fmt.Errorf("unmarshalling kolide_atc_config: %w", err) + if err := json.Unmarshal([]byte(katcConfig), &loggableConfig); err != nil { + return nil, fmt.Errorf("unmarshalling katc_config: %w", err) } return loggableConfig, nil