diff options
author | Matthew Heon <matthew.heon@gmail.com> | 2018-03-15 22:42:04 -0400 |
---|---|---|
committer | Atomic Bot <atomic-devel@projectatomic.io> | 2018-05-11 14:43:57 +0000 |
commit | 15ca5f26878e397056d31e84b4f0937ab173645b (patch) | |
tree | 27c61f991325a9c0a4f7e3b6d82b68bcb75451e5 /libpod/runtime_ctr.go | |
parent | 6756af386f68e003936d90e1f183fd5eebb47b92 (diff) | |
download | podman-15ca5f26878e397056d31e84b4f0937ab173645b.tar.gz podman-15ca5f26878e397056d31e84b4f0937ab173645b.tar.bz2 podman-15ca5f26878e397056d31e84b4f0937ab173645b.zip |
Add validation for CGroup parents. Pass CGroups path into runc
Signed-off-by: Matthew Heon <matthew.heon@gmail.com>
Closes: #507
Approved by: baude
Diffstat (limited to 'libpod/runtime_ctr.go')
-rw-r--r-- | libpod/runtime_ctr.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/libpod/runtime_ctr.go b/libpod/runtime_ctr.go index 4708e0c8f..f5d8e5704 100644 --- a/libpod/runtime_ctr.go +++ b/libpod/runtime_ctr.go @@ -3,6 +3,7 @@ package libpod import ( "context" "os" + "path" "path/filepath" "strings" "time" @@ -60,6 +61,24 @@ func (r *Runtime) NewContainer(ctx context.Context, rSpec *spec.Spec, options .. ctr.config.Name = name } + // Check CGroup parent sanity, and set it if it was not set + switch r.config.CgroupManager { + case CgroupfsCgroupsManager: + if ctr.config.CgroupParent == "" { + ctr.config.CgroupParent = CgroupfsDefaultCgroupParent + } else if strings.HasSuffix(path.Base(ctr.config.CgroupParent), ".slice") { + return nil, errors.Wrapf(ErrInvalidArg, "systemd slice received as cgroup parent when using cgroupfs") + } + case SystemdCgroupsManager: + if ctr.config.CgroupParent == "" { + ctr.config.CgroupParent = SystemdDefaultCgroupParent + } else if len(ctr.config.CgroupParent) < 6 || !strings.HasSuffix(path.Base(ctr.config.CgroupParent), ".slice") { + return nil, errors.Wrapf(ErrInvalidArg, "did not receive systemd slice as cgroup parent when using systemd to manage cgroups") + } + default: + return nil, errors.Wrapf(ErrInvalidArg, "unsupported CGroup manager: %s - cannot validate cgroup parent", r.config.CgroupManager) + } + // Set up storage for the container if err := ctr.setupStorage(ctx); err != nil { return nil, err |