-
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
Ensure the consistent setting of the HOME env variable on container start #18492
Conversation
815d3ce
to
fd72b13
Compare
@n1hility @vrothberg @containers/podman-maintainers PTAL |
I don't think we want to honor the home folder of the user executing the command. The order should be:
The issue with using the current user home directory is that the same command would have different behaviors on different machines. If you want to override the home directory, just specify it on the command line |
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 agree with @giuseppe, it doesn't seem to make sense to set the home based on the user executing the command.
This seems to be a simple bug when the container is created with --userns keep-id -v $HOME:$HOME --user 0:0
so I think we should just fix that.
78bcbef
to
4892f7f
Compare
This indeed makes more sense. I've adjusted the PR to reflect this - the home directory of the caller is no longer considered. |
return execUser.Home, nil | ||
} | ||
|
||
// Ensure HOME is not already set in Env |
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 it make sense to move this and the stanza below "up"?
@@ -2432,6 +2426,46 @@ func (c *Container) generateCurrentUserPasswdEntry() (string, int, int, error) { | |||
return pwd, uid, rootless.GetRootlessGID(), nil | |||
} | |||
|
|||
// Sets the HOME Env variable with precedence: caller home, execUser home | |||
func (c *Container) setHomeEnvIfNeeded() error { |
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.
if this is only used once, can it just be inline?
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 think a separate function is better.
/approve LGTM, small nits identified |
@@ -2432,6 +2426,46 @@ func (c *Container) generateCurrentUserPasswdEntry() (string, int, int, error) { | |||
return pwd, uid, rootless.GetRootlessGID(), nil | |||
} | |||
|
|||
// Sets the HOME Env variable with precedence: caller home, execUser home | |||
func (c *Container) setHomeEnvIfNeeded() error { |
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 think a separate function is better.
…tart Signed-off-by: Dawid Kulikowski <git@dawidkulikowski.pl>
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.
/lgtm
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: baude, daw1012345, Luap99 The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
Kudos for adding the tests, @daw1012345 ! |
I arrived here from containers/toolbox#1296 Since this pull request explicitly mentions Toolbx, I thought that I would leave my doubt here as well for the sake of my future self and anybody else who might be following along.
I don't understand what home folder of the user executing the podman command means. Are we talking about the user on the host who invoked If so, wouldn't the Are you thinking of cases where someone might have (temporarily?) overridden
I don't understand this. |
Does this PR introduce a user-facing change?
Description
Podman sets the HOME environment variable to the home directory of the user executing the podman command (if it is mounted) only if a new passwd entry has to be added on start. After a container restart, HOME is set to the home directory of the user configured with the
--user
flag.Reproduction/Example
Impact
This impacts tools such as VSCode Dev Containers as they use this variable to decide where to place files (the vscode server in this case). This issue is particularly annoying for people using Dev Containers and toolbox as a restart causes VSCode to place the server in a different place, often
/root
where it does not have write permissions.Solution
Set the HOME env variable on container creation, prioritized in the following order:
--user
flag