Skip to content

os/user: Current fails when the current thread is impersonated #68647

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

Closed
qmuntal opened this issue Jul 30, 2024 · 4 comments
Closed

os/user: Current fails when the current thread is impersonated #68647

qmuntal opened this issue Jul 30, 2024 · 4 comments
Assignees
Labels
NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Milestone

Comments

@qmuntal
Copy link
Member

qmuntal commented Jul 30, 2024

Go version

go version go1.22.0 windows/amd64

Output of go env in your module/workspace:

set GO111MODULE=
set GOARCH=amd64
set GOBIN=
set GOCACHE=C:\Users\qmuntaldiaz\AppData\Local\go-build
set GOENV=C:\Users\qmuntaldiaz\AppData\Roaming\go\env
set GOEXE=.exe
set GOEXPERIMENT=
set GOFLAGS=
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOINSECURE=
set GOMODCACHE=C:\Users\qmuntaldiaz\go\pkg\mod
set GONOPROXY=github.com/microsoft/*,dev.azure.com/*
set GONOSUMDB=github.com/microsoft/*,dev.azure.com/*
set GOOS=windows
set GOPATH=C:\Users\qmuntaldiaz\go
set GOPRIVATE=github.com/microsoft/*,dev.azure.com/*
set GOPROXY=https://proxy.golang.org,direct
set GOROOT=C:\Program Files\Go
set GOSUMDB=sum.golang.org
set GOTMPDIR=
set GOTOOLCHAIN=auto
set GOTOOLDIR=C:\Program Files\Go\pkg\tool\windows_amd64
set GOVCS=
set GOVERSION=go1.22.0
set GCCGO=gccgo
set GOAMD64=v1
set AR=ar
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set GOWORK=
set CGO_CFLAGS=-O2 -g
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-O2 -g
set CGO_FFLAGS=-O2 -g
set CGO_LDFLAGS=-O2 -g
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m64 -mthreads -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=C:\Users\QMUNTA~1\AppData\Local\Temp\go-build3241524281=/tmp/go-build -gno-record-gcc-switches

What did you do?

Call user.Current() on an impersonated thread:

func main() {
	runtime.LockOSThread()
	defer runtime.UnlockOSThread()

	err := windows.ImpersonateSelf(windows.SecurityIdentification)
	if err != nil {
		panic(err)
	}
	defer windows.RevertToSelf()

	_, err = user.Current()
	if err != nil {
		panic(err)
	}
}

What did you see happen?

user.Current reports an error instead of returning the current process user. Same happens when using ImpersonateLoggedOnUser to impersonate the thread.

What did you expect to see?

user.Current should be able to return the current process user even if the thread is impersonated.

@qmuntal qmuntal self-assigned this Jul 30, 2024
@qmuntal
Copy link
Member Author

qmuntal commented Jul 30, 2024

@golang/windows

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/602415 mentions this issue: os/user: support calling Current on impersonated threads

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/604395 mentions this issue: os/user: document Current improvements

@dmitshur dmitshur added this to the Go1.24 milestone Aug 21, 2024
@dmitshur dmitshur added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 21, 2024
gopherbot pushed a commit that referenced this issue Aug 21, 2024
Update #21867.
Update #68312.
Update #68647.

Change-Id: Ic41d6747c5a54ba28c1292258aa4d318ccb9fe40
Reviewed-on: https://go-review.googlesource.com/c/go/+/604395
Reviewed-by: Cherry Mui <[email protected]>
Reviewed-by: Dmitri Shuralyov <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
Reviewed-by: Alex Brainman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsFix The path to resolution is known, but the work has not been done. OS-Windows
Projects
None yet
Development

No branches or pull requests

4 participants