Merge pull request #3858 from haircommander/exec-user
exec: run with user specified on container start
This commit is contained in:
commit
a3c46fcaf4
|
@ -274,6 +274,11 @@ func (c *Container) Exec(tty, privileged bool, env, cmd []string, user, workDir
|
|||
}
|
||||
}()
|
||||
|
||||
// if the user is empty, we should inherit the user that the container is currently running with
|
||||
if user == "" {
|
||||
user = c.config.User
|
||||
}
|
||||
|
||||
pid, attachChan, err := c.ociRuntime.execContainer(c, cmd, capList, env, tty, workDir, user, sessionID, streams, preserveFDs, resize, detachKeys)
|
||||
if err != nil {
|
||||
ec := define.ExecErrorCodeGeneric
|
||||
|
|
|
@ -146,6 +146,25 @@ var _ = Describe("Podman exec", func() {
|
|||
Expect(session2.OutputToString()).To(Equal(testUser))
|
||||
})
|
||||
|
||||
It("podman exec with user from run", func() {
|
||||
testUser := "guest"
|
||||
setup := podmanTest.Podman([]string{"run", "--user", testUser, "-d", ALPINE, "top"})
|
||||
setup.WaitWithDefaultTimeout()
|
||||
Expect(setup.ExitCode()).To(Equal(0))
|
||||
ctrID := setup.OutputToString()
|
||||
|
||||
session := podmanTest.Podman([]string{"exec", ctrID, "whoami"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring(testUser))
|
||||
|
||||
overrideUser := "root"
|
||||
session = podmanTest.Podman([]string{"exec", "--user", overrideUser, ctrID, "whoami"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session.ExitCode()).To(Equal(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring(overrideUser))
|
||||
})
|
||||
|
||||
It("podman exec simple working directory test", func() {
|
||||
setup := podmanTest.RunTopContainer("test1")
|
||||
setup.WaitWithDefaultTimeout()
|
||||
|
|
Loading…
Reference in New Issue