rootless: check uid with Geteuid() instead of Getuid()

change the tests to use chroot to set a numeric UID/GID.

Go syscall.Credential doesn't change the effective UID/GID of the
process.

Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>

Closes: #1372
Approved by: mheon
This commit is contained in:
Giuseppe Scrivano
2018-08-31 09:31:34 +02:00
committed by Atomic Bot
parent bdee681409
commit 807f6f8d8f
10 changed files with 21 additions and 16 deletions

View File

@ -10,7 +10,6 @@ import (
"os/exec"
"path/filepath"
"strings"
"syscall"
"testing"
"time"
@ -190,11 +189,13 @@ func (p *PodmanTest) PodmanAsUser(args []string, uid, gid uint32, env []string)
} else {
fmt.Printf("Running: (env: %v) %s %s\n", env, p.PodmanBinary, strings.Join(podmanOptions, " "))
}
command := exec.Command(p.PodmanBinary, podmanOptions...)
var command *exec.Cmd
if uid != 0 || gid != 0 {
command.SysProcAttr = &syscall.SysProcAttr{}
command.SysProcAttr.Credential = &syscall.Credential{Uid: uid, Gid: gid}
nsEnterOpts := append([]string{"--userspec", fmt.Sprintf("%d:%d", uid, gid), "/", p.PodmanBinary}, podmanOptions...)
command = exec.Command("chroot", nsEnterOpts...)
} else {
command = exec.Command(p.PodmanBinary, podmanOptions...)
}
if env != nil {
command.Env = env