Merge pull request #403 from peter-evans/invalid-root-home

Invalid HOME for root user fix
This commit is contained in:
priyawadhwa 2018-10-18 10:25:39 -07:00 committed by GitHub
commit 5108ee3ee1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 1 deletions

View File

@ -21,6 +21,8 @@ USER testuser:1001
RUN echo "hey2" >> /tmp/foo
USER root
RUN echo "hi" > $HOME/file
COPY context/foo $HOME/foo
RUN useradd -ms /bin/bash newuser
USER newuser

View File

@ -127,7 +127,7 @@ func addDefaultHOME(u string, envs []string) []string {
}
// If user isn't set, set default value of HOME
if u == "" {
if u == "" || u == constants.RootUser {
return append(envs, fmt.Sprintf("%s=%s", constants.HOME, constants.DefaultHOMEValue))
}

View File

@ -62,6 +62,17 @@ func Test_addDefaultHOME(t *testing.T) {
"HOME=/",
},
},
{
name: "HOME isn't set, user is set to root",
user: "root",
initial: []string{
"PATH=/something/else",
},
expected: []string{
"PATH=/something/else",
"HOME=/root",
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

View File

@ -58,6 +58,7 @@ const (
HOME = "HOME"
// DefaultHOMEValue is the default value Docker sets for $HOME
DefaultHOMEValue = "/root"
RootUser = "root"
// Docker command names
Cmd = "cmd"