run: unset any HOME variable after USER ran

Running USER didn't reset HOME which had to be explicitly set.

Closes #1082

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
This commit is contained in:
Yoan Blanc
2020-03-04 14:12:42 -08:00
committed by Tejal Desai
parent 0c6571a1fc
commit 52acd798f8
2 changed files with 14 additions and 1 deletions
+1
View File
@@ -77,6 +77,7 @@ func (r *RunCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bui
}
cmd.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
}
cmd.Env = addDefaultHOME(userStr, replacementEnvs)
if err := cmd.Start(); err != nil {
+13 -1
View File
@@ -20,6 +20,7 @@ import (
"fmt"
"strings"
"github.com/GoogleContainerTools/kaniko/pkg/constants"
"github.com/GoogleContainerTools/kaniko/pkg/dockerfile"
"github.com/GoogleContainerTools/kaniko/pkg/util"
v1 "github.com/google/go-containerregistry/pkg/v1"
@@ -55,8 +56,19 @@ func (r *UserCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu
}
userStr = userStr + ":" + groupStr
}
config.User = userStr
// Remove any HOME environment variable previously set.
env := make([]string, 0, len(config.Env))
for _, v := range config.Env {
if strings.HasPrefix(v, constants.HOME+"=") {
continue
}
env = append(env, v)
}
config.Env = env
return nil
}