diff --git a/cmd/launcher/launcher.go b/cmd/launcher/launcher.go index ecc7e2aa7..258337df9 100644 --- a/cmd/launcher/launcher.go +++ b/cmd/launcher/launcher.go @@ -373,7 +373,7 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl osqueryruntime.WithAugeasLensFunction(augeas.InstallLenses), ) runGroup.Add("osqueryRunner", osqueryRunner.Run, osqueryRunner.Interrupt) - k.SetInstanceQuerier(osqueryRunner) + k.SetInstanceRunner(osqueryRunner) versionInfo := version.Version() k.SystemSlogger().Log(ctx, slog.LevelInfo, diff --git a/ee/agent/knapsack/knapsack.go b/ee/agent/knapsack/knapsack.go index f52c63ce1..e28dad5b1 100644 --- a/ee/agent/knapsack/knapsack.go +++ b/ee/agent/knapsack/knapsack.go @@ -39,7 +39,7 @@ type knapsack struct { slogger, systemSlogger *multislogger.MultiSlogger - querier types.InstanceQuerier + osqRunner types.OsqRunner // This struct is a work in progress, and will be iteratively added to as needs arise. } @@ -87,9 +87,9 @@ func (k *knapsack) AddSlogHandler(handler ...slog.Handler) { k.systemSlogger.AddHandler(handler...) } -// Osquery instance querier -func (k *knapsack) SetInstanceQuerier(q types.InstanceQuerier) { - k.querier = q +// Osquery instance runner +func (k *knapsack) SetInstanceRunner(r types.OsqRunner) { + k.osqRunner = r } // RegistrationTracker interface methods @@ -97,13 +97,21 @@ func (k *knapsack) RegistrationIDs() []string { return []string{types.DefaultRegistrationID} } +func (k *knapsack) SetRegistrationIDs(registrationIDs []string) error { + if k.osqRunner == nil { + return nil + } + + return k.osqRunner.UpdateRegistrationIDs(registrationIDs) +} + // InstanceStatuses returns the current status of each osquery instance. // It performs a healthcheck against each existing instance. func (k *knapsack) InstanceStatuses() map[string]types.InstanceStatus { - if k.querier == nil { + if k.osqRunner == nil { return nil } - return k.querier.InstanceStatuses() + return k.osqRunner.InstanceStatuses() } // BboltDB interface methods diff --git a/ee/agent/types/knapsack.go b/ee/agent/types/knapsack.go index 45a441cb1..d00f7c602 100644 --- a/ee/agent/types/knapsack.go +++ b/ee/agent/types/knapsack.go @@ -11,7 +11,7 @@ type Knapsack interface { Slogger RegistrationTracker InstanceQuerier - SetInstanceQuerier(q InstanceQuerier) + SetInstanceRunner(r OsqRunner) // LatestOsquerydPath finds the path to the latest osqueryd binary, after accounting for updates. LatestOsquerydPath(ctx context.Context) string // ReadEnrollSecret returns the enroll secret value, checking in various locations. diff --git a/ee/agent/types/mocks/knapsack.go b/ee/agent/types/mocks/knapsack.go index 58bea406d..bfa7688dd 100644 --- a/ee/agent/types/mocks/knapsack.go +++ b/ee/agent/types/mocks/knapsack.go @@ -1,4 +1,4 @@ -// Code generated by mockery v2.45.0. DO NOT EDIT. +// Code generated by mockery v2.46.0. DO NOT EDIT. package mocks @@ -1570,9 +1570,9 @@ func (_m *Knapsack) SetInsecureTransportTLS(insecure bool) error { return r0 } -// SetInstanceQuerier provides a mock function with given fields: q -func (_m *Knapsack) SetInstanceQuerier(q types.InstanceQuerier) { - _m.Called(q) +// SetInstanceRunner provides a mock function with given fields: r +func (_m *Knapsack) SetInstanceRunner(r types.OsqRunner) { + _m.Called(r) } // SetKolideServerURL provides a mock function with given fields: url @@ -1760,6 +1760,24 @@ func (_m *Knapsack) SetPinnedOsquerydVersion(version string) error { return r0 } +// SetRegistrationIDs provides a mock function with given fields: registrationIDs +func (_m *Knapsack) SetRegistrationIDs(registrationIDs []string) error { + ret := _m.Called(registrationIDs) + + if len(ret) == 0 { + panic("no return value specified for SetRegistrationIDs") + } + + var r0 error + if rf, ok := ret.Get(0).(func([]string) error); ok { + r0 = rf(registrationIDs) + } else { + r0 = ret.Error(0) + } + + return r0 +} + // SetSystrayRestartEnabled provides a mock function with given fields: enabled func (_m *Knapsack) SetSystrayRestartEnabled(enabled bool) error { ret := _m.Called(enabled) diff --git a/ee/agent/types/registration.go b/ee/agent/types/registration.go index 979889e6c..0d8a91022 100644 --- a/ee/agent/types/registration.go +++ b/ee/agent/types/registration.go @@ -9,4 +9,5 @@ const ( // data may be provided by e.g. a control server subsystem. type RegistrationTracker interface { RegistrationIDs() []string -} + SetRegistrationIDs(registrationIDs []string) error +} \ No newline at end of file diff --git a/ee/agent/types/runner.go b/ee/agent/types/runner.go new file mode 100644 index 000000000..36768fba6 --- /dev/null +++ b/ee/agent/types/runner.go @@ -0,0 +1,13 @@ +package types + +type ( + // RegistrationChangeHandler is implemented by pkg/osquery/runtime/runner.go + RegistrationChangeHandler interface { + UpdateRegistrationIDs(registrationIDs []string) error + } + + OsqRunner interface { + RegistrationChangeHandler + InstanceQuerier + } +) diff --git a/pkg/osquery/runtime/runner.go b/pkg/osquery/runtime/runner.go index 3f926c46d..fe6493faf 100644 --- a/pkg/osquery/runtime/runner.go +++ b/pkg/osquery/runtime/runner.go @@ -333,3 +333,8 @@ func (r *Runner) InstanceStatuses() map[string]types.InstanceStatus { return instanceStatuses } + +func (r *Runner) UpdateRegistrationIDs(registrationIDs []string) error { + // TODO: detect any difference in reg IDs and shut down/spin up instances accordingly + return nil +}