-
Notifications
You must be signed in to change notification settings - Fork 18.4k
Description
What version of Go are you using (go version
)?
$ go version go version go1.13.4 darwin/amd64
Note: Even though I am developing on darwin, the code is targeted to windows/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
go env
Output
$ go env GO111MODULE="" GOARCH="amd64" GOBIN="/Users/liam/git/go_path/bin" GOCACHE="/Users/liam/Library/Caches/go-build" GOENV="/Users/liam/Library/Application Support/go/env" GOEXE="" GOFLAGS="" GOHOSTARCH="amd64" GOHOSTOS="darwin" GONOPROXY="" GONOSUMDB="" GOOS="darwin" GOPATH="/Users/liam/git/go_path" GOPRIVATE="" GOPROXY="https://proxy.golang.org,direct" GOROOT="/usr/local/Cellar/go/1.13.4/libexec" GOSUMDB="sum.golang.org" GOTMPDIR="" GOTOOLDIR="/usr/local/Cellar/go/1.13.4/libexec/pkg/tool/darwin_amd64" GCCGO="gccgo" AR="ar" CC="clang" CXX="clang++" CGO_ENABLED="1" GOMOD="" CGO_CFLAGS="-g -O2" CGO_CPPFLAGS="" CGO_CXXFLAGS="-g -O2" CGO_FFLAGS="-g -O2" CGO_LDFLAGS="-g -O2" PKG_CONFIG="pkg-config" GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jt/myl07nr11fb6_27x6k61xlzm0000gn/T/go-build237806154=/tmp/go-build -gno-record-gcc-switches -fno-common"
What did you do?
Launched a process with SysProcAttr
set that include a Token for the current active user.
What did you expect to see?
The process should have access to environment variables appropriate to the user it was launched for.
What did you see instead?
The launched process had environment variables originating from the service that started it, rather than those for the user it is running as.
Other comments:
When launching a process on Windows with a SysProcAttr
that includes a token, Go doesn't load the environment variables for that token, instead it uses the environment variables for the current process.
I can see in os/exec_posix.go
(on line 40) it does a check to see if the Env
is nil, if it is it will call environForSysProcAttr
which would load the appropriate environment variables if a token is supplied in the process attributes.
But in the calling method (os/exec/exec.go:416
) the Env
variable it set by addCriticalEnv(dedupEnv(c.envv()))
, of which c.envv()
will always return a value based on it's logic:
func (c *Cmd) envv() []string {
if c.Env != nil {
return c.Env
}
return os.Environ()
}
Ideally, this can probably be removed as environForSysProcAttr
for windows and other platforms always fallback to os.Environ()
if there is nothing to be done based on the process attributes.