linux - 有谁知道 docker 中无新权限阻止 selinux 转换的解决方法?

标签 linux docker selinux

我正在尝试使用 no-new-privileges 标志并启用 Selinux 在 docker 下运行(任何)容器。

基本信息:

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

(我最初运行稳定,并切换到边缘版本希望修复)

我正在尝试做的事情:

docker run --security-opt "no-new-privileges" -it --rm busybox /bin/sh

发生了什么:

standard_init_linux.go:178: exec user process caused "operation not permitted"

支持所有功能 - Selinux 在未指定 no-new-privileges 时工作;当守护进程在没有 selinux 支持的情况下运行时,no-new-privileges 起作用。宽容模式与强制模式没有任何效果。

Docker 信息:

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 最近”

<no matches>

但是结果是“sudo ausearch -m SELINUX_ERR -ts 最近”

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

我认为这里的关键是

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

如果我没看错的话,没有新的权限会阻止 selinux 转换。有谁知道解决这个问题的方法,除了禁用其中一项安全功能之外?如果需要更多信息,请告诉我!

最佳答案

想通了;为其他有同样问题的人发帖。问题确实是没有新的权限阻止 selinux 转换。通过编译一个小的 selinux 策略,使容器类型显式地受容器运行时类型限制,任何新的权限都不会允许转换。我使用的是 docker-ce 边缘存储库中的默认 centos docker-ce-selinux 策略,因此我的容器运行时类型是 container_runtime_t,容器类型是 svirt_lxc_net_t。其他软件包/发行版可能使用不同的类型。

在空目录中创建了一个名为“dockersvirt.te”的策略文件。

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;

然后编译并安装新策略。

checkmodule -M -m -o dockersvirt.mod dockersvirt.te
semodule_package -o dockersvirt.pp -m dockersvirt.mod
sudo semodule -i dockersvirt.pp

请注意,理论上可能会产生副作用,但容器运行时是一个非常特权的域,因此不应对容器类型强加太多实际的新界限。对我来说没问题,但是 YMMV。

关于linux - 有谁知道 docker 中无新权限阻止 selinux 转换的解决方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44127247/

相关文章:

python - pycharm_helpers 的拉取访问被拒绝,存储库不存在或可能需要 'docker login'

linux - 即使 crond_disable_trans 被禁用,cron 也可以强制执行 SELinux

linux - 如何理解unix中的 `if [ ! -f $R_C_S_L/j_r_d* ] ...`?

python - 避免在 GTK 弹出菜单中滚动

linux - 多线程、阻塞和内存映射文件

linux - Podman (libpod) 在使用 SELinux 上下文挂载 shm 时无法运行

PHP 的配置设置 'error_log' 不起作用

mysql - OpenSuse - 在 mysql 上设置时区

docker 容器空间不足

docker - golang、docker、gradle的项目结构