From 0faa4518ed2dad592bb238838b4df2b34d2171c3 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Fri, 26 Jun 2015 15:06:37 -0700 Subject: [PATCH] Default process user to container config user. Signed-off-by: David Calavera --- daemon/exec.go | 8 ++++++-- integration-cli/docker_cli_exec_test.go | 21 +++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/daemon/exec.go b/daemon/exec.go index 2b28ba1eef..340d9fa51c 100644 --- a/daemon/exec.go +++ b/daemon/exec.go @@ -109,7 +109,6 @@ func (d *Daemon) getActiveContainer(name string) (*Container, error) { } func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, error) { - // Not all drivers support Exec (LXC for example) if err := checkExecSupport(d.execDriver.Name()); err != nil { return "", err @@ -123,11 +122,16 @@ func (d *Daemon) ContainerExecCreate(config *runconfig.ExecConfig) (string, erro cmd := runconfig.NewCommand(config.Cmd...) entrypoint, args := d.getEntrypointAndArgs(runconfig.NewEntrypoint(), cmd) + user := config.User + if len(user) == 0 { + user = container.Config.User + } + processConfig := execdriver.ProcessConfig{ Tty: config.Tty, Entrypoint: entrypoint, Arguments: args, - User: config.User, + User: user, } execConfig := &execConfig{ diff --git a/integration-cli/docker_cli_exec_test.go b/integration-cli/docker_cli_exec_test.go index c12a6120fa..36d1e25965 100644 --- a/integration-cli/docker_cli_exec_test.go +++ b/integration-cli/docker_cli_exec_test.go @@ -445,7 +445,6 @@ func (s *DockerSuite) TestInspectExecID(c *check.C) { } func (s *DockerSuite) TestLinksPingLinkedContainersOnRename(c *check.C) { - var out string out, _ = dockerCmd(c, "run", "-d", "--name", "container1", "busybox", "top") idA := strings.TrimSpace(out) @@ -610,7 +609,6 @@ func (s *DockerSuite) TestRunMutableNetworkFiles(c *check.C) { } func (s *DockerSuite) TestExecWithUser(c *check.C) { - runCmd := exec.Command(dockerBinary, "run", "-d", "--name", "parent", "busybox", "top") if out, _, err := runCommandWithOutput(runCmd); err != nil { c.Fatal(out, err) @@ -635,3 +633,22 @@ func (s *DockerSuite) TestExecWithUser(c *check.C) { } } + +func (s *DockerSuite) TestExecWithImageUser(c *check.C) { + name := "testbuilduser" + _, err := buildImage(name, + `FROM busybox + RUN echo 'dockerio:x:1001:1001::/bin:/bin/false' >> /etc/passwd + USER dockerio`, + true) + if err != nil { + c.Fatalf("Could not build image %s: %v", name, err) + } + + dockerCmd(c, "run", "-d", "--name", "dockerioexec", name, "top") + + out, _ := dockerCmd(c, "exec", "dockerioexec", "whoami") + if !strings.Contains(out, "dockerio") { + c.Fatalf("exec with user by id expected dockerio user got %s", out) + } +}