Merge pull request #403 from peter-evans/invalid-root-home
Invalid HOME for root user fix
This commit is contained in:
commit
5108ee3ee1
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue