Reputation: 71
I'm trying to run (any) container under docker with the no-new-privileges flag and Selinux enabled.
Basic Info:
CentOS 7.3 on bare metal
docker-ce 17.05.0-ce (edge) from official repo
docker-ce-selinux 17.05.0-ce (edge) from official repo
(I was originally running stable, and switched to the edge release hoping for a fix)
What I'm trying to do:
docker run --security-opt "no-new-privileges" -it --rm busybox /bin/sh
What happens:
standard_init_linux.go:178: exec user process caused "operation not permitted"
All features are supported - Selinux works when no-new-privileges is not specified; no-new-privileges works when the daemon is running without selinux support. Permissive vs enforcing mode has no effect.
Docker info:
Containers: 0
Running: 0
Paused: 0
Stopped: 0
Images: 40
Server Version: 17.05.0-ce
Storage Driver: btrfs
Build Version: Btrfs v4.4.1
Library Version: 101
Logging Driver: journald
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: bridge host macvlan null overlay
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 9048e5e50717ea4497b757314bad98ea3763c145
runc version: 9c2d8d184e5da67c95d601382adf14862e4f2228
init version: 949e6fa
Security Options:
seccomp
Profile: default
selinux
Operating System: CentOS Linux 7 (Core)
OSType: linux
Architecture: x86_64
CPUs: 2
Total Memory: 3.536GiB
Name: localhost.localdomain
ID: EAGL:4QBW:GYM3:XY3U:YOSJ:7NBJ:O5OB:6HWY:S255:2X7D:MFHN:ZOYS
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Username: -----
Registry: https://index.docker.io/v1/
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
'sudo ausearch -m avc -ts recent' turns out
<no matches>
But 'sudo ausearch -m SELINUX_ERR -ts recent' turns out
time->Tue May 23 02:07:55 2017
type=PROCTITLE msg=audit(1495519675.981:996345): proctitle=2F70726F632F73656C662F65786500696E6974
type=PATH msg=audit(1495519675.981:996345): item=0 name="/bin/sh" inode=260 dev=00:22 mode=0100755 ouid=0 ogid=0 rdev=00:00 obj=system_u:object_r:svirt_sandbox_file_t:s0:c7,c132 nametype=NORMAL
type=CWD msg=audit(1495519675.981:996345): cwd="/"
type=BPRM_FCAPS msg=audit(1495519675.981:996345): fver=0 fp=0000000000000000 fi=0000000000000000 fe=0 old_pp=00000000a80425fb old_pi=00000000a80425fb old_pe=00000000a80425fb new_pp=00000000a80425fb new_pi=00000000a80425fb new_pe=00000000a80425fb
type=SYSCALL msg=audit(1495519675.981:996345): arch=c000003e syscall=59 success=no exit=-1 a0=c420142260 a1=c420142270 a2=c420122960 a3=0 items=1 ppid=30894 pid=30910 auid=4294967295 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts1 ses=4294967295 comm="runc:[2:INIT]" exe="/usr/bin/docker-runc" subj=system_u:system_r:container_runtime_t:s0 key=(null)
type=SELINUX_ERR msg=audit(1495519675.981:996345): op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:container_runtime_t:s0 newcontext=system_u:system_r:svirt_lxc_net_t:s0:c7,c132
I think the key here is the
type=SELINUX_ERR msg=audit(1495519675.981:996345): op=security_bounded_transition seresult=denied oldcontext=system_u:system_r:container_runtime_t:s0 newcontext=system_u:system_r:svirt_lxc_net_t:s0:c7,c132
If I'm reading it right, no new privileges is blocking the selinux transition. Does anyone know a way around this, short of disabling one of the security features? Please let me know if more info is needed!
Upvotes: 2
Views: 5356
Reputation: 71
Figured it out; posting for anyone else having the same problem. The problem was indeed no new privileges blocking the selinux transition. By compiling a small selinux policy making the container type explicitly bounded by the container runtime type, no new privileges will allow the transition. I am using the default centos docker-ce-selinux policy from the docker-ce edge repository, so my container runtime type is container_runtime_t, and my container type is svirt_lxc_net_t. Other packages/distributions may use different types.
Created a policy file called "dockersvirt.te" in an empty directory.
module dockersvirt 1.0;
require {
type container_runtime_t;
type svirt_lxc_net_t;
role system_r;
};
typebounds container_runtime_t svirt_lxc_net_t;
Then compiled and installed the new policy.
checkmodule -M -m -o dockersvirt.mod dockersvirt.te
semodule_package -o dockersvirt.pp -m dockersvirt.mod
sudo semodule -i dockersvirt.pp
Please note that there can theoretically be side effects, but the container runtime is a very privileged domain, so should not impose too many actual new bounds on the container type. No issues for me, but YMMV.
Upvotes: 3