summaryrefslogtreecommitdiff
path: root/libpod/oci.go
diff options
context:
space:
mode:
authorGiuseppe Scrivano <gscrivan@redhat.com>2018-08-24 12:15:34 +0200
committerAtomic Bot <atomic-devel@projectatomic.io>2018-08-26 07:22:42 +0000
commitc5753f57c1a929f80fb768ff62bd35f383584aed (patch)
treeece117393325d5a26d1fc7dfc23ad6b2c6f48631 /libpod/oci.go
parent720eb85ba55d8c825262e9b2e058ec8a8e0e4d9f (diff)
downloadpodman-c5753f57c1a929f80fb768ff62bd35f383584aed.tar.gz
podman-c5753f57c1a929f80fb768ff62bd35f383584aed.tar.bz2
podman-c5753f57c1a929f80fb768ff62bd35f383584aed.zip
rootless: exec handle processes that create an user namespace
Manage the case where the main process of the container creates and joins a new user namespace. In this case we want to join only the first child in the new hierarchy, which is the user namespace that was used to create the container. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com> Closes: #1331 Approved by: rhatdan
Diffstat (limited to 'libpod/oci.go')
-rw-r--r--libpod/oci.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/libpod/oci.go b/libpod/oci.go
index da054eceb..4f0fbe8e9 100644
--- a/libpod/oci.go
+++ b/libpod/oci.go
@@ -682,15 +682,23 @@ func (r *OCIRuntime) execContainer(c *Container, cmd, capAdd, env []string, tty
execCmd := exec.Command(r.path, args...)
if rootless.IsRootless() {
- args = append([]string{"--preserve-credentials", "-U", "-t", fmt.Sprintf("%d", c.state.PID), r.path}, args...)
- // using nsenter might not be correct if the target PID joined a different user namespace.
- // A better way would be to retrieve the parent ns (NS_GET_PARENT) until it is a child of the current namespace.
+ args = append([]string{"--preserve-credentials", "--user=/proc/self/fd/3", r.path}, args...)
+ f, err := rootless.GetUserNSForPid(uint(c.state.PID))
+ if err != nil {
+ return nil, err
+ }
execCmd = exec.Command("nsenter", args...)
+ execCmd.ExtraFiles = append(execCmd.ExtraFiles, f)
}
execCmd.Stdout = os.Stdout
execCmd.Stderr = os.Stderr
execCmd.Stdin = os.Stdin
execCmd.Env = append(execCmd.Env, fmt.Sprintf("XDG_RUNTIME_DIR=%s", runtimeDir))
+
+ if err := execCmd.Start(); err != nil {
+ return nil, errors.Wrapf(err, "cannot start container %s", c.ID())
+ }
+
return execCmd, nil
}