【发布时间】:2018-02-22 23:02:19
【问题描述】:
我有一个特定的容器,我需要在其中挂载 /proc 文件系统,出于可以理解的原因,SELinux 通常禁止该容器。我想创建一个对常规 SELinux 策略的修改,允许对特定标签进行此操作,然后让 Docker 使用我使用此策略创建的新上下文而不是正常的 system_u:system_r:container_t:s0:c540,c856 上下文运行特定容器。
这可能吗?如何?我什至找不到从system_u:system_r:container_t:s0:c540,c856 上下文中禁用/proc 挂载的策略文件的源代码。如何安装?
我现在有一个策略文件,它可以重新启用 all 容器的 /proc 挂载,这并不是我想要的。但我不知道如何写出我真正需要的东西。而且我也不知道如何让 Docker 在不同的上下文中运行。这是我拥有的过于宽泛的政策文件:
gen_require(`
type proc_t;
type tmpfs_t;
type container_t;
class filesystem unmount;
class filesystem mount;
class filesystem remount;
class dir mounton;
class dir proc_t;
')
#============= container_t ==============
allow container_t proc_t:filesystem unmount;
allow container_t proc_t:filesystem mount;
allow container_t proc_t:filesystem remount;
allow container_t tmpfs_t:filesystem unmount;
allow container_t proc_t:dir mounton;
具有不同缺点的不同答案是这样做:
docker run --security-opt label:disable
这将禁用该容器的所有 SELinux 检查。有一个section in the Docker manual that talks about the various valid arguments for --security-opt, including SELinux related ones。
所以,我目前的选择是,对所有容器禁用 /proc 相关检查,或者对特定容器禁用所有检查。使用label: 参数,您还可以为容器设置特定的 SELinux 上下文,所以如果我知道如何创建一个新的 SELinux 上下文,就像其他的一样,除了我指定的一些东西,我可以得到什么我想要。
此外,这个问题与我之前在 ServerFault 上提出的另一个问题有关:How do I mount a private /proc inside a namespace inside a Docker container?。
【问题讨论】: