From e42e1c45ae761b203dd5312c22ee7992eef322dc Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Fri, 20 Sep 2019 14:45:20 +0200 Subject: container: make sure $HOME is always set If the HOME environment variable is not set, make sure it is set to the configuration found in the container /etc/passwd file. It was previously depending on a runc behavior that always set HOME when it is not set. The OCI runtime specifications do not require HOME to be set so move the logic to libpod. Closes: https://github.com/debarshiray/toolbox/issues/266 Signed-off-by: Giuseppe Scrivano --- libpod/container_internal_linux.go | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'libpod/container_internal_linux.go') diff --git a/libpod/container_internal_linux.go b/libpod/container_internal_linux.go index 4bbbef5db..355b9bea4 100644 --- a/libpod/container_internal_linux.go +++ b/libpod/container_internal_linux.go @@ -279,6 +279,17 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) { } } + 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", execUser.Home)) + } + if c.config.User != "" { // User and Group must go together g.SetProcessUID(uint32(execUser.Uid)) -- cgit v1.2.3-54-g00ecf