-
Notifications
You must be signed in to change notification settings - Fork 2.9k
rootless: fix user lookup if USER= is not set #1217
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
rootless: fix user lookup if USER= is not set #1217
Conversation
pkg/rootless/rootless_linux.go
Outdated
| @@ -7,6 +7,7 @@ import ( | |||
| "io/ioutil" | |||
| "os" | |||
| "os/exec" | |||
| "os/user" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need blank line afterwards.
pkg/rootless/rootless_linux.go
Outdated
| @@ -97,6 +98,13 @@ func BecomeRootInUserNS() (bool, int, error) { | |||
|
|
|||
| var uids, gids []idtools.IDMap | |||
| username := os.Getenv("USER") | |||
| if username == "" { | |||
| user, err := user.LookupId(fmt.Sprintf("%d", os.Geteuid())) | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work with usernames not in /etc/passwd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no, it works only with users defined in /etc/passwd.
I've changed the error message with a pointer to the USER env variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do any go interfaces work with nsswitch?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from a quick search I didn't find anything, I'll look further if there is something available
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vbatts Do you know of anything?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@giuseppe @rhatdan You could use github.com/opencontainers/runc/libcontainer/user as we do in psgo (https://github.com/containers/psgo/blob/master/internal/process/process.go#L55).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vrothberg looking at the code, it seems it also just parses /etc/passwd
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RIght I think the libcontainer/user code is just for parsing the username inside of the container.
We need code to call into the gcc getpw library so that it will work with ldap and other providers of identity like freeipa.
6276761 to
309047a
Compare
pkg/rootless/rootless_linux.go
Outdated
| @@ -8,6 +8,7 @@ import ( | |||
| "os" | |||
| "os/exec" | |||
| gosignal "os/signal" | |||
| "os/user" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add line after
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need an extra line here? I thought we use it only to divide between std library and other packages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your right, my mistake, I thought the test was complaining about it.
Lookup the current username by UID if the USER env variable is not set. Reported in: containers#1092 Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
309047a to
4c814af
Compare
|
bot, retest this please |
2 similar comments
|
bot, retest this please |
|
bot, retest this please |
|
LGTM |
|
📌 Commit 4c814af has been approved by |
|
☀️ Test successful - status-papr |
Lookup the current username by UID if the USER env variable is not
set.
Reported in: #1092
Signed-off-by: Giuseppe Scrivano gscrivan@redhat.com