Skip to content

Commit

Permalink
rework interfaces for runner change detection
Browse files Browse the repository at this point in the history
  • Loading branch information
zackattack01 committed Dec 17, 2024
1 parent dbb618a commit 6bb2b69
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
20 changes: 14 additions & 6 deletions ee/agent/knapsack/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
}
Expand Down Expand Up @@ -87,23 +87,31 @@ 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
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
Expand Down
2 changes: 1 addition & 1 deletion ee/agent/types/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 22 additions & 4 deletions ee/agent/types/mocks/knapsack.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion ee/agent/types/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
13 changes: 13 additions & 0 deletions ee/agent/types/runner.go
Original file line number Diff line number Diff line change
@@ -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
}
)
5 changes: 5 additions & 0 deletions pkg/osquery/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 6bb2b69

Please sign in to comment.