-
Notifications
You must be signed in to change notification settings - Fork 18k
os/exec: $HOME not updated when running command as a different UID #33788
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
Comments
some properties doesn't set? |
Per http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap08.html#tag_08_03 (emphasis mine):
You can set both explicitly for the command using something like: cmd.Env = append(os.Environ(), "USER="+user.Username, "HOME="+user.HomeDir) We probably need clearer documentation about it either way. |
CC @bradfitz @kevinburke @ianlancetaylor; see previously #26463. |
I don't think os/exec should be in the business of adjusting the environment too much. We do a bit on Windows to make sure there's a minimally functional environment for loading DLLs, but I don't think we should do much more than that. |
we hope it can simulate working of shell, as we specified the user. like |
when Current User is root run shell as another User like flow
output like
as @bcmills says we can code
os.Environ() is current User root 's ENV , May be cmd.Env should set like follow:
|
I think the most we'll do here is add a small bit of documentation to SysProcAttr or syscall.Credential to say that advanced users are on their own in this regard and we don't do this automatically. Even setting USER and HOME may not be sufficient for all cases. It might be both too much and not enough magic. Better to stay out of it and let advanced users choose exactly what happens without surprises. |
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
there is testfile asynccmd .go
there is file : /home/www/.bash_profile
in /root dir run follow command:
What did you expect to see?
What did you see instead?
out is:
The text was updated successfully, but these errors were encountered: