mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
syscall: fix TestCloneNEWUSERAndRemapNoRootDisableSetgroups the right way
The problem was not the kernel version as I thought before, it was that the test used the same number for both the UID and the GID. Thanks to Chris Siebenmann for debugging this. Fixes #11220. Change-Id: Ib5077e182497155e84044683209590ee0f7c9dde Reviewed-on: https://go-review.googlesource.com/11124 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
4dab6d01f1
commit
6f0e427298
1 changed files with 8 additions and 15 deletions
|
|
@ -17,7 +17,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func whoamiCmd(t *testing.T, uid int, setgroups bool) *exec.Cmd {
|
func whoamiCmd(t *testing.T, uid, gid int, setgroups bool) *exec.Cmd {
|
||||||
if _, err := os.Stat("/proc/self/ns/user"); err != nil {
|
if _, err := os.Stat("/proc/self/ns/user"); err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
t.Skip("kernel doesn't support user namespaces")
|
t.Skip("kernel doesn't support user namespaces")
|
||||||
|
|
@ -31,15 +31,15 @@ func whoamiCmd(t *testing.T, uid int, setgroups bool) *exec.Cmd {
|
||||||
{ContainerID: 0, HostID: uid, Size: 1},
|
{ContainerID: 0, HostID: uid, Size: 1},
|
||||||
},
|
},
|
||||||
GidMappings: []syscall.SysProcIDMap{
|
GidMappings: []syscall.SysProcIDMap{
|
||||||
{ContainerID: 0, HostID: uid, Size: 1},
|
{ContainerID: 0, HostID: gid, Size: 1},
|
||||||
},
|
},
|
||||||
GidMappingsEnableSetgroups: setgroups,
|
GidMappingsEnableSetgroups: setgroups,
|
||||||
}
|
}
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func testNEWUSERRemap(t *testing.T, uid int, setgroups bool) {
|
func testNEWUSERRemap(t *testing.T, uid, gid int, setgroups bool) {
|
||||||
cmd := whoamiCmd(t, uid, setgroups)
|
cmd := whoamiCmd(t, uid, gid, setgroups)
|
||||||
out, err := cmd.CombinedOutput()
|
out, err := cmd.CombinedOutput()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
t.Fatalf("Cmd failed with err %v, output: %s", err, out)
|
||||||
|
|
@ -55,14 +55,14 @@ func TestCloneNEWUSERAndRemapRootDisableSetgroups(t *testing.T) {
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
t.Skip("skipping root only test")
|
t.Skip("skipping root only test")
|
||||||
}
|
}
|
||||||
testNEWUSERRemap(t, 0, false)
|
testNEWUSERRemap(t, 0, 0, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloneNEWUSERAndRemapRootEnableSetgroups(t *testing.T) {
|
func TestCloneNEWUSERAndRemapRootEnableSetgroups(t *testing.T) {
|
||||||
if os.Getuid() != 0 {
|
if os.Getuid() != 0 {
|
||||||
t.Skip("skipping root only test")
|
t.Skip("skipping root only test")
|
||||||
}
|
}
|
||||||
testNEWUSERRemap(t, 0, false)
|
testNEWUSERRemap(t, 0, 0, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// kernelVersion returns the major and minor versions of the Linux
|
// kernelVersion returns the major and minor versions of the Linux
|
||||||
|
|
@ -85,21 +85,14 @@ func TestCloneNEWUSERAndRemapNoRootDisableSetgroups(t *testing.T) {
|
||||||
if os.Getuid() == 0 {
|
if os.Getuid() == 0 {
|
||||||
t.Skip("skipping unprivileged user only test")
|
t.Skip("skipping unprivileged user only test")
|
||||||
}
|
}
|
||||||
|
testNEWUSERRemap(t, os.Getuid(), os.Getgid(), false)
|
||||||
// This test fails for some reason on Ubuntu Trusty.
|
|
||||||
major, minor := kernelVersion(t)
|
|
||||||
if major < 3 || (major == 3 && minor < 19) {
|
|
||||||
t.Skipf("skipping on kernel version before 3.19 (%d.%d)", major, minor)
|
|
||||||
}
|
|
||||||
|
|
||||||
testNEWUSERRemap(t, os.Getuid(), false)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestCloneNEWUSERAndRemapNoRootSetgroupsEnableSetgroups(t *testing.T) {
|
func TestCloneNEWUSERAndRemapNoRootSetgroupsEnableSetgroups(t *testing.T) {
|
||||||
if os.Getuid() == 0 {
|
if os.Getuid() == 0 {
|
||||||
t.Skip("skipping unprivileged user only test")
|
t.Skip("skipping unprivileged user only test")
|
||||||
}
|
}
|
||||||
cmd := whoamiCmd(t, os.Getuid(), true)
|
cmd := whoamiCmd(t, os.Getuid(), os.Getgid(), true)
|
||||||
err := cmd.Run()
|
err := cmd.Run()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Skip("probably old kernel without security fix")
|
t.Skip("probably old kernel without security fix")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue