From dd5e8e02442710efe9426e080db34c21d1340ee3 Mon Sep 17 00:00:00 2001 From: Mrunal Patel Date: Mon, 5 Jan 2015 15:33:20 -0500 Subject: [PATCH] Rebases to master. Signed-off-by: Mrunal Patel (github: mrunalp) --- namespaces/exec.go | 36 ++++++++++++++++-------------------- sample_configs/userns.json | 12 ++++++------ 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/namespaces/exec.go b/namespaces/exec.go index 24ca210e5..86fa9c9b8 100644 --- a/namespaces/exec.go +++ b/namespaces/exec.go @@ -166,17 +166,15 @@ func hostIDFromMapping(containerID int, uMap []libcontainer.IDMap) (int, bool) { // when user namespaces are enabled. func GetHostRootUid(container *libcontainer.Config) (int, error) { hostRootUid := 0 - for _, v := range container.Namespaces { - if v.Name == "NEWUSER" { - if container.UidMappings == nil { - return -1, fmt.Errorf("User namespaces enabled, but no user mappings found.") - } - hostRootUid, found := hostIDFromMapping(0, container.UidMappings) - if !found { - return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.") - } else { - return hostRootUid, nil - } + if container.Namespaces.Contains(libcontainer.NEWUSER) { + if container.UidMappings == nil { + return -1, fmt.Errorf("User namespaces enabled, but no user mappings found.") + } + hostRootUid, found := hostIDFromMapping(0, container.UidMappings) + if !found { + return -1, fmt.Errorf("User namespaces enabled, but no root user mapping found.") + } else { + return hostRootUid, nil } } @@ -234,16 +232,14 @@ func DefaultCreateCommand(container *libcontainer.Config, console, dataPath, ini command.SysProcAttr.Pdeathsig = syscall.SIGKILL command.ExtraFiles = []*os.File{pipe} - for _, v := range container.Namespaces { - if v.Name == "NEWUSER" { - if container.UidMappings != nil || container.GidMappings != nil { - AddUidGidMappings(command.SysProcAttr, container) - } + if container.Namespaces.Contains(libcontainer.NEWUSER) { + if container.UidMappings != nil || container.GidMappings != nil { + AddUidGidMappings(command.SysProcAttr, container) + } - // Default to root user when user namespaces are enabled. - if command.SysProcAttr.Credential == nil { - command.SysProcAttr.Credential = &syscall.Credential{} - } + // Default to root user when user namespaces are enabled. + if command.SysProcAttr.Credential == nil { + command.SysProcAttr.Credential = &syscall.Credential{} } } diff --git a/sample_configs/userns.json b/sample_configs/userns.json index f4db1189a..8c9c841f1 100644 --- a/sample_configs/userns.json +++ b/sample_configs/userns.json @@ -182,12 +182,12 @@ ], "hostname": "koye", "namespaces": [ - {"name": "NEWIPC"}, - {"name": "NEWNET"}, - {"name": "NEWNS"}, - {"name": "NEWPID"}, - {"name": "NEWUTS"}, - {"name": "NEWUSER"} + {"type": "NEWIPC"}, + {"type": "NEWNET"}, + {"type": "NEWNS"}, + {"type": "NEWPID"}, + {"type": "NEWUTS"}, + {"type": "NEWUSER"} ], "networks": [ {