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

Set all env vars on osquery process #1961

Merged
merged 2 commits into from
Nov 19, 2024
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
18 changes: 13 additions & 5 deletions pkg/osquery/runtime/osqueryinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ func (i *OsqueryInstance) createOsquerydCommand(osquerydBinary string, paths *os
fmt.Sprintf("--extensions_require=%s", KolideSaasExtensionName),
)

// We need environment variables to be set to ensure paths can be resolved appropriately.
cmd.Env = cmd.Environ()

// On darwin, run osquery using a magic macOS variable to ensure we
// get proper versions strings back. I'm not totally sure why apple
// did this, but reading SystemVersion.plist is different when this is set.
Expand All @@ -802,13 +805,18 @@ func (i *OsqueryInstance) createOsquerydCommand(osquerydBinary string, paths *os
// https://github.com/osquery/osquery/pull/6824
cmd.Env = append(cmd.Env, "SYSTEM_VERSION_COMPAT=0")

// On Windows, we want the `SystemDrive` environment variable to be set to ensure paths can be resolved appropriately.
// The cmd handles setting `SystemRoot` for us.
if runtime.GOOS == "windows" {
if systemDrive, found := os.LookupEnv("SystemDrive"); found {
cmd.Env = append(cmd.Env, fmt.Sprintf("SystemDrive=%s", systemDrive))
// On Windows, we need to ensure the `SystemDrive` environment variable is set to _something_,
// so if it isn't already set, we set it to an empty string.
systemDriveEnvVarFound := false
for _, e := range cmd.Env {
Copy link
Contributor

Choose a reason for hiding this comment

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

Things like this make me grumpy it's an array and not a hash

if strings.Contains(strings.ToLower(e), "systemdrive") {
systemDriveEnvVarFound = true
break
}
}
if !systemDriveEnvVarFound {
cmd.Env = append(cmd.Env, "SystemDrive=")
}

return cmd, nil
}
Expand Down
Loading