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

os/user: godoc for Current does not mention caching #27659

Closed
dtrudg opened this issue Sep 13, 2018 · 3 comments
Closed

os/user: godoc for Current does not mention caching #27659

dtrudg opened this issue Sep 13, 2018 · 3 comments
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Suggested Issues that may be good for new contributors looking for work to do.
Milestone

Comments

@dtrudg
Copy link

dtrudg commented Sep 13, 2018

What version of Go are you using (go version)?

go version go1.10.1 linux/amd64

Does this issue reproduce with the latest release?

yes

What operating system and processor architecture are you using (go env)?

11:55 AM $ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dave/.cache/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dave/go"
GORACE=""
GOROOT="/usr/lib/go-1.10"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go-1.10/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
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 -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build611611681=/tmp/go-build -gno-record-gcc-switches"

What did you do?

godoc for user/os has

func Current() (*User, error)
    Current returns the current user.

There is no mention that caching is used... so if I run code looking at user.Current() around a uid change I see unexpected results:

11:53 AM $ cat main.go 
package main

import "runtime"
import "syscall"
import "os"
import "os/user"
import "log"
import "fmt"

func main() {

	runtime.LockOSThread()

	u, _ := user.Current()
	fmt.Printf("user.Current before priv drop: %v\n", u.Name)

	if os.Getuid() == 0 {
		if err := syscall.Setresuid(1000, 1000, 0); err != nil {
			log.Fatalf("failed to set user identity: %v", err)
		}

		u, _ = user.Current()
		fmt.Printf("user.Current after priv drop: %v\n", u.Name)

	}
}
dave@piran:~/currentuser_test.go
11:53 AM $ sudo go run main.go 
user.Current before priv drop: root
user.Current after priv drop: root

What did you expect to see?

godoc for user os mentions caching, e.g.

func Current() (*User, error)
    Current returns the current user.
    Note - the current user is cached at first call to Current().
    Subsequent calls will return the cached value and will not reflect changes
    to the EUID.
@dtrudg dtrudg changed the title godoc for os/user current does not mention caching godoc for os/user user.Current does not mention caching Sep 13, 2018
@dtrudg dtrudg changed the title godoc for os/user user.Current does not mention caching os/user: godoc for user.Current does not mention caching Sep 13, 2018
@ianlancetaylor ianlancetaylor added Suggested Issues that may be good for new contributors looking for work to do. Documentation NeedsFix The path to resolution is known, but the work has not been done. labels Sep 13, 2018
@ianlancetaylor ianlancetaylor added this to the Go1.12 milestone Sep 13, 2018
@odeke-em
Copy link
Member

/cc @kevinburke

@odeke-em odeke-em changed the title os/user: godoc for user.Current does not mention caching os/user: godoc for Current does not mention caching Sep 13, 2018
@gopherbot
Copy link

Change https://golang.org/cl/136315 mentions this issue: os/user: note in doc that user.Current is being cached

@dddent
Copy link
Contributor

dddent commented Sep 19, 2018

I added the note to the user.Current doc, but shouldn't there also be a way to invalidate or refresh the cache after changes were made to the current user?

@golang golang locked and limited conversation to collaborators Sep 25, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done. Suggested Issues that may be good for new contributors looking for work to do.
Projects
None yet
Development

No branches or pull requests

5 participants