E Eric W. Biederman #
Message details and related content
Aditya Kali [off-list ref] writes:
Second take at the Cgroup Namespace patch-set. Major changes form RFC (V0): 1. setns support for cgroupns 2. 'mount -t cgroup cgroup <mntpt>' from inside a cgroupns now mounts the cgroup hierarcy with cgroupns-root as the filesystem root. 3. writes to cgroup files outside of cgroupns-root are not allowed 4. visibility of /proc/<pid>/cgroup is further restricted by not showing anything if the <pid> is in a sibling cgroupns and its cgroup falls outside your cgroupns-root. More details in the writeup below.
This definitely looks like the right direction to go, and something that in some form or another I had been asking for since cgroups were merged. So I am very glad to see this work moving forward. I had hoped that we might just be able to be clever with remounting cgroupfs but 2 things stand in the way. 1) /proc/<pid>/cgroups (but proc could capture that). 2) providing a hard guarnatee that tasks stay within a subset of the cgroup hierarchy. So I think this clearly meets the requirements for a new namespace. We need to have the discussion on chmod of files on cgroupfs. There is a notion that has floated around that only systemd or only root (with the appropriate capabilities) should be allowed to set resource limits in cgroupfs. In a practical reality that is nonsense. If an atribute is properly bound in it's hiearchy it should be safe to change. Not all attributes are properly bound to hierarchy and some are or at least were dangerous for anyone except root to set. So I suggest that a CFTYPE flag perhaps CFTYPE_UNPRIV be added for attributes that are safe to allow anyone to set, and require CFTYPE_UNPRIV be set before we chmod a cgroup attribute from root. That would be complimentary work, and not strictly tied the cgroup namespaces but unprivileged cgroup namespaces don't make much sense without that work. Eric
Background
Cgroups and Namespaces are used together to create “virtual”
containers that isolates the host environment from the processes
running in container. But since cgroups themselves are not
“virtualized”, the task is always able to see global cgroups view
through cgroupfs mount and via /proc/self/cgroup file.
$ cat /proc/self/cgroup
0:cpuset,cpu,cpuacct,memory,devices,freezer,hugetlb:/batchjobs/c_job_id1
This exposure of cgroup names to the processes running inside a
container results in some problems:
(1) The container names are typically host-container-management-agent
(systemd, docker/libcontainer, etc.) data and leaking its name (or
leaking the hierarchy) reveals too much information about the host
system.
(2) It makes the container migration across machines (CRIU) more
difficult as the container names need to be unique across the
machines in the migration domain.
(3) It makes it difficult to run container management tools (like
docker/libcontainer, lmctfy, etc.) within virtual containers
without adding dependency on some state/agent present outside the
container.
Note that the feature proposed here is completely different than the
“ns cgroup” feature which existed in the linux kernel until recently.
The ns cgroup also attempted to connect cgroups and namespaces by
creating a new cgroup every time a new namespace was created. It did
not solve any of the above mentioned problems and was later dropped
from the kernel. Incidentally though, it used the same config option
name CONFIG_CGROUP_NS as used in my prototype!
Introducing CGroup Namespaces
With unified cgroup hierarchy
(Documentation/cgroups/unified-hierarchy.txt), the containers can now
have a much more coherent cgroup view and its easy to associate a
container with a single cgroup. This also allows us to virtualize the
cgroup view for tasks inside the container.
The new CGroup Namespace allows a process to “unshare” its cgroup--- fs/kernfs/dir.c | 53 +++++++++--- fs/kernfs/mount.c | 48 +++++++++++ fs/proc/namespaces.c | 3 + include/linux/cgroup.h | 41 +++++++++- include/linux/cgroup_namespace.h | 62 +++++++++++++++ include/linux/kernfs.h | 5 ++ include/linux/nsproxy.h | 2 + include/linux/proc_ns.h | 4 + include/uapi/linux/sched.h | 3 +- init/Kconfig | 9 +++ kernel/Makefile | 1 + kernel/cgroup.c | 139 ++++++++++++++++++++++++++------ kernel/cgroup_namespace.c | 168 +++++++++++++++++++++++++++++++++++++++ kernel/fork.c | 2 +- kernel/nsproxy.c | 19 ++++- 15 files changed, 518 insertions(+), 41 deletions(-) create mode 100644 include/linux/cgroup_namespace.h create mode 100644 kernel/cgroup_namespace.c [PATCHv1 1/8] kernfs: Add API to generate relative kernfs path [PATCHv1 2/8] sched: new clone flag CLONE_NEWCGROUP for cgroup [PATCHv1 3/8] cgroup: add function to get task's cgroup on default [PATCHv1 4/8] cgroup: export cgroup_get() and cgroup_put() [PATCHv1 5/8] cgroup: introduce cgroup namespaces [PATCHv1 6/8] cgroup: restrict cgroup operations within task's cgroupns [PATCHv1 7/8] cgroup: cgroup namespace setns support [PATCHv1 8/8] cgroup: mount cgroupns-root when inside non-init cgroupns _______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/containers
_______________________________________________ Containers mailing list Containers@lists.linux-foundation.org https://lists.linuxfoundation.org/mailman/listinfo/containers