From 47e5b5ae3262f140955abd57bbb13337c65a3497 Mon Sep 17 00:00:00 2001 From: =?utf8?q?C=C3=A9dric=20Bosdonnat?= Date: Fri, 18 Jul 2014 10:02:29 +0200 Subject: [PATCH] lxc: allow to keep or drop capabilities Added in the section of LXC domains configuration. This section can contain elements named after the capabilities like: , keep CAP_MKNOD capability drop CAP_SYS_CHROOT capability Users can restrict or give more capabilities than the default using this mechanism. --- docs/drvlxc.html.in | 47 ++++ docs/schemas/domaincommon.rng | 207 +++++++++++++++ src/conf/domain_conf.c | 126 ++++++++- src/conf/domain_conf.h | 56 ++++ src/libvirt_private.syms | 3 + src/lxc/lxc_cgroup.c | 8 + src/lxc/lxc_container.c | 241 ++++++++++++++++-- src/util/vircgroup.c | 57 ++++- src/util/vircgroup.h | 2 + .../domainschemadata/domain-caps-features.xml | 28 ++ 10 files changed, 755 insertions(+), 20 deletions(-) create mode 100644 tests/domainschemadata/domain-caps-features.xml diff --git a/docs/drvlxc.html.in b/docs/drvlxc.html.in index fc4bc207f4..403ce241d3 100644 --- a/docs/drvlxc.html.in +++ b/docs/drvlxc.html.in @@ -540,6 +540,53 @@ debootstrap, whatever) under /opt/vm-1-root: </domain> +

Altering the available capabilities

+ +

+By default the libvirt LXC driver drops some capabilities among which CAP_MKNOD. +However since 1.2.6 libvirt can be told to keep or +drop some capabilities using a domain configuration like the following: +

+
+...
+<features>
+  <capabilities policy='default'>
+    <mknod state='on'/>
+    <sys_chroot state='off'/>
+  </capabilities>
+</features>
+...
+
+

+The capabilities children elements are named after the capabilities as defined in +man 7 capabilities. An off state tells libvirt to drop the +capability, while an on state will force to keep the capability even though +this one is dropped by default. +

+

+The policy attribute can be one of default, allow +or deny. It defines the default rules for capabilities: either keep the +default behavior that is dropping a few selected capabilities, or keep all capabilities +or drop all capabilities. The interest of allow and deny is that +they guarantee that all capabilities will be kept (or removed) even if new ones are added +later. +

+

+The following example, drops all capabilities but CAP_MKNOD: +

+
+...
+<features>
+  <capabilities policy='deny'>
+    <mknod state='on'/>
+  </capabilities>
+</features>
+...
+
+

+Note that allowing capabilities that are normally dropped by default can seriously +affect the security of the container and the host. +

Container usage / management

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng index 835bd3c835..f6f697c855 100644 --- a/docs/schemas/domaincommon.rng +++ b/docs/schemas/domaincommon.rng @@ -3815,6 +3815,9 @@ + + + @@ -4387,6 +4390,200 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -4396,6 +4593,16 @@ + + + + default + allow + deny + + + +