-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Setup HOME environment when using --userns=keep-id #8013
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1717,11 +1717,35 @@ func (c *Container) generateCurrentUserPasswdEntry() (string, int, int, error) { | |||||
// If the user's actual home directory exists, or was mounted in - use | ||||||
// that. | ||||||
homeDir := c.WorkingDir() | ||||||
if MountExists(c.config.Spec.Mounts, u.HomeDir) { | ||||||
homeDir = u.HomeDir | ||||||
hDir := u.HomeDir | ||||||
for hDir != "/" { | ||||||
if MountExists(c.config.Spec.Mounts, hDir) { | ||||||
homeDir = u.HomeDir | ||||||
break | ||||||
} | ||||||
hDir = filepath.Dir(hDir) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. me thinks
Suggested change
hDir doesn't seem to be referred to after this line otherwise. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If hDir is volume mounted into the container then
Is executed which sets the homeDir to the directory from the host as opposed to the CWD. |
||||||
} | ||||||
if homeDir != u.HomeDir { | ||||||
for _, hDir := range c.UserVolumes() { | ||||||
if hDir == u.HomeDir { | ||||||
homeDir = u.HomeDir | ||||||
break | ||||||
} | ||||||
} | ||||||
} | ||||||
// Set HOME environment if not already set | ||||||
hasHomeSet := false | ||||||
for _, s := range c.config.Spec.Process.Env { | ||||||
if strings.HasPrefix(s, "HOME=") { | ||||||
hasHomeSet = true | ||||||
break | ||||||
} | ||||||
} | ||||||
if !hasHomeSet { | ||||||
c.config.Spec.Process.Env = append(c.config.Spec.Process.Env, fmt.Sprintf("HOME=%s", homeDir)) | ||||||
} | ||||||
|
||||||
return fmt.Sprintf("%s:*:%s:%s:%s:%s:/bin/sh\n", u.Username, u.Uid, u.Gid, u.Username, homeDir), uid, rootless.GetRootlessGID(), nil | ||||||
return fmt.Sprintf("%s:*:%s:%s:%s:%s:/bin/sh\n", u.Username, u.Uid, u.Gid, u.Name, homeDir), uid, rootless.GetRootlessGID(), nil | ||||||
} | ||||||
|
||||||
// generateUserPasswdEntry generates an /etc/passwd entry for the container 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.
u.HomeDir is a string no?
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.
This code is attempting to walk up the directories to check if their is a mountpoint from the host that covers this directory.
For example if my homedir was /home/engineering/dwalsh.
I want to check if
/home/engineering/dwalsh
/home/engineering
/home
Is mounted into the container, if yes then I can use /home/engineering/dwalsh as the homedir, rather then CWD.
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, we want to look through the directories.
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.
I don't know if this is really wanted - when I originally wrote this, I wanted it to be specific to ensure that we didn't leak information about the user on the host into the container unless they were explicitly mounting their home