Skip to content

Commit 48a8e91

Browse files
committed
libcontainer: check cpt/rst for containers with userns
Signed-off-by: Andrei Vagin <[email protected]>
1 parent 3425f73 commit 48a8e91

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

libcontainer/integration/checkpoint_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"bytes"
66
"io/ioutil"
77
"os"
8+
"os/exec"
89
"path/filepath"
910
"strings"
1011
"syscall"
@@ -38,7 +39,22 @@ func showFile(t *testing.T, fname string) error {
3839
return nil
3940
}
4041

42+
func TestUsernsCheckpoint(t *testing.T) {
43+
if _, err := os.Stat("/proc/self/ns/user"); os.IsNotExist(err) {
44+
t.Skip("userns is unsupported")
45+
}
46+
cmd := exec.Command("criu", "check", "--feature", "userns")
47+
if err := cmd.Run(); err != nil {
48+
t.Skip("Unable to c/r a container with userns")
49+
}
50+
testCheckpoint(t, true)
51+
}
52+
4153
func TestCheckpoint(t *testing.T) {
54+
testCheckpoint(t, false)
55+
}
56+
57+
func testCheckpoint(t *testing.T, userns bool) {
4258
if testing.Short() {
4359
return
4460
}
@@ -62,6 +78,12 @@ func TestCheckpoint(t *testing.T) {
6278
Flags: defaultMountFlags | syscall.MS_RDONLY,
6379
})
6480

81+
if userns {
82+
config.UidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
83+
config.GidMappings = []configs.IDMap{{HostID: 0, ContainerID: 0, Size: 1000}}
84+
config.Namespaces = append(config.Namespaces, configs.Namespace{Type: configs.NEWUSER})
85+
}
86+
6587
factory, err := libcontainer.New(root, libcontainer.Cgroupfs)
6688

6789
if err != nil {

0 commit comments

Comments
 (0)