Signed-off-by: Antonis Kalipetis <akalipetis@gmail.com>
| ... | ... |
@@ -7,11 +7,13 @@ import ( |
| 7 | 7 |
"io/ioutil" |
| 8 | 8 |
"os" |
| 9 | 9 |
"os/exec" |
| 10 |
+ "path" |
|
| 10 | 11 |
"path/filepath" |
| 11 | 12 |
"strconv" |
| 12 | 13 |
"strings" |
| 13 | 14 |
|
| 14 | 15 |
"github.com/docker/docker/pkg/integration/checker" |
| 16 |
+ "github.com/docker/docker/pkg/stringid" |
|
| 15 | 17 |
"github.com/docker/docker/pkg/system" |
| 16 | 18 |
"github.com/go-check/check" |
| 17 | 19 |
) |
| ... | ... |
@@ -29,6 +31,10 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
| 29 | 29 |
|
| 30 | 30 |
defer os.RemoveAll(tmpDir) |
| 31 | 31 |
|
| 32 |
+ // Set a non-existent path |
|
| 33 |
+ tmpDirNotExists := path.Join(os.TempDir(), "userns"+stringid.GenerateRandomID()) |
|
| 34 |
+ defer os.RemoveAll(tmpDirNotExists) |
|
| 35 |
+ |
|
| 32 | 36 |
// we need to find the uid and gid of the remapped root from the daemon's root dir info |
| 33 | 37 |
uidgid := strings.Split(filepath.Base(s.d.root), ".") |
| 34 | 38 |
c.Assert(uidgid, checker.HasLen, 2, check.Commentf("Should have gotten uid/gid strings from root dirname: %s", filepath.Base(s.d.root)))
|
| ... | ... |
@@ -40,11 +46,17 @@ func (s *DockerDaemonSuite) TestDaemonUserNamespaceRootSetting(c *check.C) {
|
| 40 | 40 |
// writable by the remapped root UID/GID pair |
| 41 | 41 |
c.Assert(os.Chown(tmpDir, uid, gid), checker.IsNil) |
| 42 | 42 |
|
| 43 |
- out, err := s.d.Cmd("run", "-d", "--name", "userns", "-v", tmpDir+":/goofy", "busybox", "sh", "-c", "touch /goofy/testfile; top")
|
|
| 43 |
+ out, err := s.d.Cmd("run", "-d", "--name", "userns", "-v", tmpDir+":/goofy", "-v", tmpDirNotExists+":/donald", "busybox", "sh", "-c", "touch /goofy/testfile; top")
|
|
| 44 | 44 |
c.Assert(err, checker.IsNil, check.Commentf("Output: %s", out))
|
| 45 | 45 |
user := s.findUser(c, "userns") |
| 46 | 46 |
c.Assert(uidgid[0], checker.Equals, user) |
| 47 | 47 |
|
| 48 |
+ // check that the created directory is owned by remapped uid:gid |
|
| 49 |
+ statNotExists, err := system.Stat(tmpDirNotExists) |
|
| 50 |
+ c.Assert(err, checker.IsNil) |
|
| 51 |
+ c.Assert(statNotExists.UID(), checker.Equals, uint32(uid), check.Commentf("Created directory not owned by remapped root UID"))
|
|
| 52 |
+ c.Assert(statNotExists.GID(), checker.Equals, uint32(gid), check.Commentf("Created directory not owned by remapped root GID"))
|
|
| 53 |
+ |
|
| 48 | 54 |
pid, err := s.d.Cmd("inspect", "--format={{.State.Pid}}", "userns")
|
| 49 | 55 |
c.Assert(err, checker.IsNil, check.Commentf("Could not inspect running container: out: %q", pid))
|
| 50 | 56 |
// check the uid and gid maps for the PID to ensure root is remapped |