Skip to content

Commit

Permalink
Do not perform osquery healthchecks while system is sleeping
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaMahany committed Aug 7, 2023
1 parent b4b2646 commit 6dc940d
Show file tree
Hide file tree
Showing 12 changed files with 172 additions and 74 deletions.
1 change: 1 addition & 0 deletions cmd/launcher/extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ func commonRunnerOptions(logger log.Logger, k types.Knapsack) []runtime.OsqueryI
)

return []runtime.OsqueryInstanceOption{
runtime.WithKnapsack(k),
runtime.WithOsquerydBinary(k.OsquerydPath()),
runtime.WithRootDirectory(k.RootDirectory()),
runtime.WithOsqueryExtensionPlugins(ktable.LauncherTables(k)...),
Expand Down
9 changes: 9 additions & 0 deletions pkg/agent/flags/flag_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -491,3 +491,12 @@ func (fc *FlagController) DisableTraceIngestTLS() bool {
WithDefaultBool(fc.cmdLineOpts.DisableTraceIngestTLS),
).get(fc.getControlServerValue(keys.DisableTraceIngestTLS))
}

func (fc *FlagController) SetDisableOsqueryHealthchecks(enabled bool) error {
return fc.setControlServerValue(keys.DisableOsqueryHealthchecks, boolToBytes(enabled))
}
func (fc *FlagController) DisableOsqueryHealthchecks() bool {
return NewBoolFlagValue(
WithDefaultBool(false),
).get(fc.getControlServerValue(keys.DisableOsqueryHealthchecks))
}
1 change: 1 addition & 0 deletions pkg/agent/flags/keys/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ const (
LogIngestServerURL FlagKey = "log_ingest_url"
TraceIngestServerURL FlagKey = "trace_ingest_url"
DisableTraceIngestTLS FlagKey = "disable_trace_ingest_tls"
DisableOsqueryHealthchecks FlagKey = "disable_osquery_healthchecks"
)

func (key FlagKey) String() string {
Expand Down
7 changes: 7 additions & 0 deletions pkg/agent/knapsack/knapsack.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,3 +382,10 @@ func (k *knapsack) SetLogIngestServerURL(url string) error {
func (k *knapsack) LogIngestServerURL() string {
return k.flags.LogIngestServerURL()
}

func (k *knapsack) SetDisableOsqueryHealthchecks(enabled bool) error {
return k.flags.SetDisableOsqueryHealthchecks(enabled)
}
func (k *knapsack) DisableOsqueryHealthchecks() bool {
return k.flags.DisableOsqueryHealthchecks()
}
4 changes: 4 additions & 0 deletions pkg/agent/types/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,4 +188,8 @@ type Flags interface {
// DisableTraceIngestTLS disables TLS for observability ingest server communication
SetDisableTraceIngestTLS(enabled bool) error
DisableTraceIngestTLS() bool

// DisableOsqueryHealthchecks disables healthchecks for the osquery extension
SetDisableOsqueryHealthchecks(enabled bool) error
DisableOsqueryHealthchecks() bool
}
95 changes: 62 additions & 33 deletions pkg/agent/types/mocks/flags.go

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

91 changes: 53 additions & 38 deletions pkg/agent/types/mocks/knapsack.go

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

8 changes: 8 additions & 0 deletions pkg/osquery/runtime/osqueryinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/go-kit/kit/log"
"github.com/go-kit/kit/log/level"
"github.com/kolide/launcher/pkg/agent"
"github.com/kolide/launcher/pkg/agent/types"
"github.com/kolide/launcher/pkg/autoupdate"
"github.com/kolide/launcher/pkg/backoff"
"github.com/kolide/launcher/pkg/osquery/runtime/history"
Expand Down Expand Up @@ -209,6 +210,12 @@ func WithAutoloadedExtensions(extensions ...string) OsqueryInstanceOption {
}
}

func WithKnapsack(k types.Knapsack) OsqueryInstanceOption {
return func(i *OsqueryInstance) {
i.knapsack = k
}
}

// OsqueryInstance is the type which represents a currently running instance
// of osqueryd.
type OsqueryInstance struct {
Expand All @@ -227,6 +234,7 @@ type OsqueryInstance struct {
usingTempDir bool
stats *history.Instance
startFunc func(cmd *exec.Cmd) error
knapsack types.Knapsack
}

// Healthy will check to determine whether or not the osquery process that is
Expand Down
6 changes: 6 additions & 0 deletions pkg/osquery/runtime/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,12 @@ func (r *Runner) launchOsqueryInstance() error {
case <-o.doneCtx.Done():
return o.doneCtx.Err()
case <-ticker.C:
// If device is sleeping, we do not want to perform unnecessary healthchecks that
// may force an unnecessary restart.
if o.knapsack.DisableOsqueryHealthchecks() {
break
}

// Health check! Allow a couple
// failures before we tear everything
// down. This is pretty simple, it
Expand Down
Loading

0 comments on commit 6dc940d

Please sign in to comment.