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 SystemDrive env var on osquery command #1960

Merged
merged 1 commit into from
Nov 18, 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
8 changes: 8 additions & 0 deletions pkg/osquery/runtime/osqueryinstance.go
Original file line number Diff line number Diff line change
Expand Up @@ -802,6 +802,14 @@ 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 {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably need to think hard about the !found case. It might be better to set this to "" than to leave it unset.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@directionless I tested and confirmed setting SystemDrive= helps, so I made that change in this follow-up PR: #1961

cmd.Env = append(cmd.Env, fmt.Sprintf("SystemDrive=%s", systemDrive))
}
}

return cmd, nil
}

Expand Down
50 changes: 50 additions & 0 deletions pkg/osquery/runtime/osqueryinstance_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
//go:build windows
// +build windows

package runtime

import (
"strings"
"testing"

typesMocks "github.com/kolide/launcher/ee/agent/types/mocks"
"github.com/kolide/launcher/pkg/log/multislogger"
"github.com/stretchr/testify/require"
)

func TestCreateOsqueryCommandEnvVars(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure this test adds much, but I don't feel that strongly

t.Parallel()

osquerydPath := testOsqueryBinaryDirectory

k := typesMocks.NewKnapsack(t)
k.On("WatchdogEnabled").Return(true)
k.On("WatchdogMemoryLimitMB").Return(150)
k.On("WatchdogUtilizationLimitPercent").Return(20)
k.On("WatchdogDelaySec").Return(120)
k.On("OsqueryVerbose").Return(true)
k.On("OsqueryFlags").Return([]string{})
k.On("Slogger").Return(multislogger.NewNopLogger())

i := newInstance(defaultRegistrationId, k, mockServiceClient())

cmd, err := i.createOsquerydCommand(osquerydPath, &osqueryFilePaths{
pidfilePath: "/foo/bar/osquery-abcd.pid",
databasePath: "/foo/bar/osquery.db",
extensionSocketPath: "/foo/bar/osquery.sock",
extensionAutoloadPath: "/foo/bar/osquery.autoload",
})
require.NoError(t, err)

systemDriveEnvVarFound := false
for _, envVar := range cmd.Env {
if strings.Contains(envVar, "SystemDrive") {
systemDriveEnvVarFound = true
break
}
}

require.True(t, systemDriveEnvVarFound, "SystemDrive env var missing from command")

k.AssertExpectations(t)
}
Loading