docker will run the process(es) within the container with an SELinux label and will label all of the content within the container with mount label. Any temporary file systems created within the container need to be mounted with the same mount label. The user can override the process label by specifying -Z With a string of space separated options. -Z "user=unconfined_u role=unconfined_r type=unconfined_t level=s0" Would cause the process label to run with unconfined_u:unconfined_r:unconfined_t:s0" By default the processes will run execute within the container as svirt_lxc_net_t. All of the content in the container as svirt_sandbox_file_t. The process mcs level is based of the PID of the docker process that is creating the container. If you run the container in --priv mode, the labeling will be disabled. Docker-DCO-1.1-Signed-off-by: Dan Walsh <dwalsh@redhat.com> (github: rhatdan) Upstream-commit: 4c4356692580afb3971094e322aea64abe0e2500 Component: engine
108 lines
3.3 KiB
Go
108 lines
3.3 KiB
Go
package native
|
|
|
|
import (
|
|
"fmt"
|
|
"github.com/dotcloud/docker/pkg/cgroups"
|
|
"github.com/dotcloud/docker/pkg/libcontainer"
|
|
"github.com/dotcloud/docker/runtime/execdriver"
|
|
"os"
|
|
)
|
|
|
|
// createContainer populates and configures the container type with the
|
|
// data provided by the execdriver.Command
|
|
func createContainer(c *execdriver.Command) *libcontainer.Container {
|
|
container := getDefaultTemplate()
|
|
|
|
container.Hostname = getEnv("HOSTNAME", c.Env)
|
|
container.Tty = c.Tty
|
|
container.User = c.User
|
|
container.WorkingDir = c.WorkingDir
|
|
container.Env = c.Env
|
|
container.Context["mount_label"] = c.Context["mount_label"]
|
|
container.Context["process_label"] = c.Context["process_label"]
|
|
|
|
loopbackNetwork := libcontainer.Network{
|
|
Mtu: c.Network.Mtu,
|
|
Address: fmt.Sprintf("%s/%d", "127.0.0.1", 0),
|
|
Gateway: "localhost",
|
|
Type: "loopback",
|
|
Context: libcontainer.Context{},
|
|
}
|
|
|
|
container.Networks = []*libcontainer.Network{
|
|
&loopbackNetwork,
|
|
}
|
|
|
|
if c.Network.Interface != nil {
|
|
vethNetwork := libcontainer.Network{
|
|
Mtu: c.Network.Mtu,
|
|
Address: fmt.Sprintf("%s/%d", c.Network.Interface.IPAddress, c.Network.Interface.IPPrefixLen),
|
|
Gateway: c.Network.Interface.Gateway,
|
|
Type: "veth",
|
|
Context: libcontainer.Context{
|
|
"prefix": "veth",
|
|
"bridge": c.Network.Interface.Bridge,
|
|
},
|
|
}
|
|
container.Networks = append(container.Networks, &vethNetwork)
|
|
}
|
|
|
|
container.Cgroups.Name = c.ID
|
|
if c.Privileged {
|
|
container.CapabilitiesMask = nil
|
|
container.Cgroups.DeviceAccess = true
|
|
container.Context["apparmor_profile"] = "unconfined"
|
|
}
|
|
if c.Resources != nil {
|
|
container.Cgroups.CpuShares = c.Resources.CpuShares
|
|
container.Cgroups.Memory = c.Resources.Memory
|
|
container.Cgroups.MemorySwap = c.Resources.MemorySwap
|
|
}
|
|
// check to see if we are running in ramdisk to disable pivot root
|
|
container.NoPivotRoot = os.Getenv("DOCKER_RAMDISK") != ""
|
|
|
|
for _, m := range c.Mounts {
|
|
container.Mounts = append(container.Mounts, libcontainer.Mount{m.Source, m.Destination, m.Writable, m.Private})
|
|
}
|
|
|
|
return container
|
|
}
|
|
|
|
// getDefaultTemplate returns the docker default for
|
|
// the libcontainer configuration file
|
|
func getDefaultTemplate() *libcontainer.Container {
|
|
return &libcontainer.Container{
|
|
CapabilitiesMask: libcontainer.Capabilities{
|
|
libcontainer.GetCapability("SETPCAP"),
|
|
libcontainer.GetCapability("SYS_MODULE"),
|
|
libcontainer.GetCapability("SYS_RAWIO"),
|
|
libcontainer.GetCapability("SYS_PACCT"),
|
|
libcontainer.GetCapability("SYS_ADMIN"),
|
|
libcontainer.GetCapability("SYS_NICE"),
|
|
libcontainer.GetCapability("SYS_RESOURCE"),
|
|
libcontainer.GetCapability("SYS_TIME"),
|
|
libcontainer.GetCapability("SYS_TTY_CONFIG"),
|
|
libcontainer.GetCapability("MKNOD"),
|
|
libcontainer.GetCapability("AUDIT_WRITE"),
|
|
libcontainer.GetCapability("AUDIT_CONTROL"),
|
|
libcontainer.GetCapability("MAC_OVERRIDE"),
|
|
libcontainer.GetCapability("MAC_ADMIN"),
|
|
libcontainer.GetCapability("NET_ADMIN"),
|
|
},
|
|
Namespaces: libcontainer.Namespaces{
|
|
libcontainer.GetNamespace("NEWNS"),
|
|
libcontainer.GetNamespace("NEWUTS"),
|
|
libcontainer.GetNamespace("NEWIPC"),
|
|
libcontainer.GetNamespace("NEWPID"),
|
|
libcontainer.GetNamespace("NEWNET"),
|
|
},
|
|
Cgroups: &cgroups.Cgroup{
|
|
Parent: "docker",
|
|
DeviceAccess: false,
|
|
},
|
|
Context: libcontainer.Context{
|
|
"apparmor_profile": "docker-default",
|
|
},
|
|
}
|
|
}
|