Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download osqueryd when missing on startup #1788

Merged
merged 1 commit into from
Jul 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,33 @@ func runLauncher(ctx context.Context, cancel func(), multiSlogger, systemMultiSl
if actionsQueue != nil {
actionsQueue.RegisterActor(tuf.AutoupdateSubsystemName, tufAutoupdater)
}

// in some cases, (e.g. rolling back a windows installation to a previous osquery version) it is possible that
// the installer leaves us in a situation where there is no osqueryd on disk.
// we can detect this and attempt to download the correct version into the TUF update library to run from that.
// This must be done as a blocking operation before the rungroups start, because the osquery runner will fail to
// launch and trigger a restart immediately
currentOsquerydBinaryPath := k.LatestOsquerydPath(ctx)
if _, err = os.Stat(currentOsquerydBinaryPath); os.IsNotExist(err) {
slogger.Log(ctx, slog.LevelInfo,
"detected missing osqueryd executable, will attempt to download",
)

// simulate control server request for immediate update, noting to bypass the initial delay window
actionReader := strings.NewReader(`{
"bypass_initial_delay": true,
"binaries_to_update": [
{ "name": "osqueryd" }
]
}`)

if err = tufAutoupdater.Do(actionReader); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very elegant. I might suggest exposing tufAutoupdater.DoNow or something, because hardcoding the wireprotocol here will totally come back to bite us. But this is very tidy.

slogger.Log(ctx, slog.LevelError,
"failure triggering immediate osquery update",
"err", err,
)
}
}
}

startupSpan.End()
Expand Down
23 changes: 12 additions & 11 deletions ee/tuf/autoupdate.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ const AutoupdateSubsystemName = "autoupdate"

type (
controlServerAutoupdateRequest struct {
BinariesToUpdate []binaryToUpdate `json:"binaries_to_update"`
BinariesToUpdate []binaryToUpdate `json:"binaries_to_update"`
BypassInitialDelay bool `json:"bypass_initial_delay,omitempty"`
RebeccaMahany marked this conversation as resolved.
Show resolved Hide resolved
}

// In the future, we may allow for setting a particular version here as well
Expand Down Expand Up @@ -278,16 +279,6 @@ func (ta *TufAutoupdater) Interrupt(_ error) {
// Do satisfies the actionqueue.actor interface; it allows the control server to send
// requests down to autoupdate immediately.
func (ta *TufAutoupdater) Do(data io.Reader) error {
if time.Now().Before(ta.initialDelayEnd) {
ta.slogger.Log(context.TODO(), slog.LevelWarn,
"received update request during initial delay, discarding",
"initial_delay_end", ta.initialDelayEnd.UTC().Format(time.RFC3339),
)
// We don't return an error because there's no need for the actionqueue to retry this request --
// we're going to perform an autoupdate check as soon as we exit the delay anyway.
return nil
}

var updateRequest controlServerAutoupdateRequest
if err := json.NewDecoder(data).Decode(&updateRequest); err != nil {
ta.slogger.Log(context.TODO(), slog.LevelWarn,
Expand All @@ -298,6 +289,16 @@ func (ta *TufAutoupdater) Do(data io.Reader) error {
return nil
}

if time.Now().Before(ta.initialDelayEnd) && !updateRequest.BypassInitialDelay {
ta.slogger.Log(context.TODO(), slog.LevelWarn,
"received update request during initial delay, discarding",
"initial_delay_end", ta.initialDelayEnd.UTC().Format(time.RFC3339),
)
// We don't return an error because there's no need for the actionqueue to retry this request --
// we're going to perform an autoupdate check as soon as we exit the delay anyway.
return nil
}

RebeccaMahany marked this conversation as resolved.
Show resolved Hide resolved
binariesToUpdate := make([]autoupdatableBinary, 0)
for _, b := range updateRequest.BinariesToUpdate {
if val, ok := autoupdatableBinaryMap[b.Name]; ok {
Expand Down
Loading