Last active
March 31, 2016 14:56
-
-
Save jjo/ff32b08e48e4a52bfc36 to your computer and use it in GitHub Desktop.
apparmor profile to allow netns handling inside LXCs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# /etc/apparmor.d/lxc/lxc-default-with-netns | |
# Do not load this file. Rather, load /etc/apparmor.d/lxc-containers, which | |
# will source all profiles under /etc/apparmor.d/lxc | |
profile lxc-container-default-with-netns flags=(attach_disconnected,mediate_deleted) { | |
#include <abstractions/lxc/container-base> | |
#include <abstractions/lxc/start-container> | |
# - onetime mount, if /run/netns was not mounted yet: | |
# strace: mount("", "/var/run/netns", "none", MS_REC|MS_SHARED, NULL) = 0 | |
# fwiw fstype=none doesn't match, protect by denying mount with /dev argument | |
deny mount options=(rw, make-rshared) /** -> /run/netns/, | |
mount options=(rw, make-rshared) -> /run/netns/, | |
# strace: mount("/var/run/netns", "/var/run/netns", 0x43981d, MS_BIND, NULL) = 0 | |
mount options=(rw, bind) /run/netns/ -> /run/netns/, | |
# - one mount per each netns: ip netns add foo: | |
# strace: mount("/proc/self/ns/net", "/var/run/netns/foo", 0x43981d, MS_BIND, NULL) = 0 | |
mount options=(rw, bind) @{PROC} -> /run/netns/**, | |
# kernel 4.2 doesn't match above, needs this one: | |
mount options=(rw, bind) / -> /run/netns/**, | |
# - used by: ip netns exec foo ...: | |
# strace: mount("", "/", "none", MS_REC|MS_SLAVE, NULL) = 0 | |
# fwiw fstype=none doesn't match, protect by denying mount with /dev argument | |
deny mount options=(rw, make-rslave) /** -> /, | |
mount options=(rw, make-rslave) -> /, | |
} |
Nice. Would you mind submitting a patch to upstream lxc adding this as one of the sample profiles?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tested this aa profile with:
#1 create netns inside foo LXC, run cmd inside its netns
lxc-attach -n foo
ip netns add bar
ip netns exec bar ip a
#2 LXC'd openstack neutron-gateways deployed by
juju, requires hacking host's LXC templates to allow multinic
LXCs.