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

Move the initial osquery --version to using runsimple #1379

Merged
merged 1 commit into from
Oct 3, 2023
Merged
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
26 changes: 19 additions & 7 deletions cmd/launcher/launcher.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"bytes"
"context"
"crypto/tls"
"crypto/x509"
Expand All @@ -9,7 +10,6 @@ import (
"net"
"net/http"
"os"
"os/exec"
"os/signal"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -48,6 +48,7 @@ import (
"github.com/kolide/launcher/pkg/log/logshipper"
"github.com/kolide/launcher/pkg/log/teelogger"
"github.com/kolide/launcher/pkg/osquery"
"github.com/kolide/launcher/pkg/osquery/runsimple"
osqueryInstanceHistory "github.com/kolide/launcher/pkg/osquery/runtime/history"
"github.com/kolide/launcher/pkg/rungroup"
"github.com/kolide/launcher/pkg/service"
Expand Down Expand Up @@ -476,23 +477,34 @@ func writePidFile(path string) error {
// runOsqueryVersionCheck execs the osqueryd binary in the background when we're running
// on darwin. Operating on our theory that some startup delay issues for osquery might
// be due to the notarization check taking too long, we execute the binary here ahead
// of time in the hopes of getting the check out of the way.
// of time in the hopes of getting the check out of the way. This is expected to be called
// from a goroutine, and thus does not return an error.
func runOsqueryVersionCheck(ctx context.Context, logger log.Logger, osquerydPath string) {
if runtime.GOOS != "darwin" {
return
}

logger = log.With(logger, "component", "osquery-version-check")

var output bytes.Buffer

osq, err := runsimple.NewOsqueryProcess(osquerydPath, runsimple.WithStdout(&output))
if err != nil {
level.Error(logger).Log("msg", "unable to create process", "err", err)
return
}

// This has a somewhat long timeout, in case there's a notarization fetch
versionCtx, versionCancel := context.WithTimeout(ctx, 30*time.Second)
defer versionCancel()

versionCmd := exec.CommandContext(versionCtx, osquerydPath, "--version")

startTime := time.Now().UnixMilli()
out, err := versionCmd.CombinedOutput()

osqErr := osq.RunVersion(versionCtx)
executionTimeMs := time.Now().UnixMilli() - startTime
outTrimmed := strings.TrimSpace(string(out))
outTrimmed := strings.TrimSpace(output.String())

if err != nil {
if osqErr != nil {
level.Error(logger).Log("msg", "could not check osqueryd version", "output", outTrimmed, "err", err, "execution_time_ms", executionTimeMs)
return
}
Expand Down
Loading