mirror of
https://github.com/containers/podman.git
synced 2025-08-06 03:19:52 +08:00
libpod: support for cgroup namespace
allow a container to run in a new cgroup namespace. When running in a new cgroup namespace, the current cgroup appears to be the root, so that there is no way for the container to access cgroups outside of its own subtree. By default it uses --cgroup=host to keep the previous behavior. To create a new namespace, --cgroup=private must be provided. Signed-off-by: Giuseppe Scrivano <gscrivan@redhat.com>
This commit is contained in:
@ -63,6 +63,7 @@ type CreateConfig struct {
|
||||
CapDrop []string // cap-drop
|
||||
CidFile string
|
||||
ConmonPidFile string
|
||||
Cgroupns string
|
||||
CgroupParent string // cgroup-parent
|
||||
Command []string
|
||||
Detach bool // detach
|
||||
@ -101,6 +102,7 @@ type CreateConfig struct {
|
||||
NetworkAlias []string //network-alias
|
||||
PidMode namespaces.PidMode //pid
|
||||
Pod string //pod
|
||||
CgroupMode namespaces.CgroupMode //cgroup
|
||||
PortBindings nat.PortMap
|
||||
Privileged bool //privileged
|
||||
Publish []string //publish
|
||||
@ -268,6 +270,23 @@ func (c *CreateConfig) getContainerCreateOptions(runtime *libpod.Runtime, pod *l
|
||||
options = append(options, libpod.WithNetNS(portBindings, postConfigureNetNS, string(c.NetMode), networks))
|
||||
}
|
||||
|
||||
if c.CgroupMode.IsNS() {
|
||||
ns := c.CgroupMode.NS()
|
||||
if ns == "" {
|
||||
return nil, errors.Errorf("invalid empty user-defined network namespace")
|
||||
}
|
||||
_, err := os.Stat(ns)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
} else if c.CgroupMode.IsContainer() {
|
||||
connectedCtr, err := runtime.LookupContainer(c.CgroupMode.Container())
|
||||
if err != nil {
|
||||
return nil, errors.Wrapf(err, "container %q not found", c.CgroupMode.Container())
|
||||
}
|
||||
options = append(options, libpod.WithCgroupNSFrom(connectedCtr))
|
||||
}
|
||||
|
||||
if c.PidMode.IsContainer() {
|
||||
connectedCtr, err := runtime.LookupContainer(c.PidMode.Container())
|
||||
if err != nil {
|
||||
|
Reference in New Issue
Block a user