Skip to content

Commit

Permalink
run: unset any HOME variable after USER ran
Browse files Browse the repository at this point in the history
Running USER didn't reset HOME which had to be explicitly set.

Closes GoogleContainerTools#1072

Signed-off-by: Yoan Blanc <yoan@dosimple.ch>
  • Loading branch information
greut committed Feb 28, 2020
1 parent 700a917 commit fa0f9c1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion pkg/commands/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -56,8 +57,18 @@ 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
}

Expand Down

0 comments on commit fa0f9c1

Please sign in to comment.