在Ubuntu 14.04上,我使用SELinux运行Docker,众所周知,Docker将读取$ Selinux-Root-Dir / default / contexts / lxc_contexts。但是找不到此文件,因此我创建了该文件并放入了一些内容。 :

process = "system_u:system_r:svirt_lxc_net_t:s0"
content = "system_u:object_r:virt_var_lib_t:s0"
file = "system_u:object_r:svirt_lxc_file_t:s0"
sandbox_kvm_process = "system_u:system_r:svirt_qemu_net_t:s0"
sandbox_lxc_process = "system_u:system_r:svirt_lxc_net_t:s0"

然后我以Selinux的许可模式运行Docker,docker -dD --selinux-enabled=falsedocker run -it --rm ubuntu /bin/bash
最后,我想使用audit2allow生成一个* .te和* .pp文件,
我执行cat /var/log/audit/audit.log | audit2allow -M container,但它说compilation failed:container.te:41:ERROR 'syntax error' at token 'mlsconstrain' on line 41: #Constraint rule: mlsconstrain chr_file { create relabelto } ((h1 dom h2 -Fail-) and (l2 eq h2) ); Constraint DENIED/usr/bin/checkmodule: error(s) encountered while parsing configuration/usr/bin/checkmodule: loading policy configuration from container.te
我负责container.te的工作,其内容为: #!!!! This avc is a constraint violation. You would need to modify the attributes of either the source or target types to allow this access. #Constraint rule: mlsconstrain chr_file { create relabelto } ((h1 dom h2 -Fail-) and (l2 eq h2) ); Constraint DENIEDmlsconstrain chr_file { relabelfrom } ((h1 dom h2 -Fail-) ); Constraint DENIED.... # Possible cause is the source level (s0) and target level (s0:c96,c879) are different.我猜想docker以s0运行,但是它想将docker的rootfs文件系统重新标记为(s0:c96,c879),并且发生此错误。

所以我的问题:

容器的类型是否错误?如何关闭此约束或如何解决此问题?

最佳答案

我不知道您的container.te文件的第41行。通常,“语法错误”表示缺少selinux类型或未知的selinux接口(interface),这意味着问题出在其他地方。

但是我注意到一些事情:

  • Docker守护程序必须与--selinux-enabled=true一起运行才能支持SELinux
  • 要创建新的selinux策略模块,您需要所有以下文件:.te,.fc和.if。有关最小的SELinux策略的示例,请参见Debian how-to
  • 通过使用cat /var/log/audit/audit.log | audit2allow -M container,您可以处理所有记录的线路。最好只将所需的行复制到新文件中。
  • s0是级别而不是标签。而“重新标记”是指更改类型。参见labeling files
  • 在运行时,SELinux(不是docker本身)将重新标记docker守护程序类型(docker_t)和正在运行的容器(svirt_lxc_net_t)。
  • Docker默认更改文件的类别(即s0:c96,c879),以将运行中的容器彼此分开。

  • 默认情况下,Ubuntu预装了AppArmor,如果要使用SELinux,则必须先将其删除/禁用。 Ubuntu和Debian不提供SELinux的Docker策略。

    可能的解决方案:
  • 将AppArmor与Ubuntu结合使用(但我不知道是否有现成的Docker配置文件)。
  • 在Ubuntu上为SELinux构建自己的Docker策略。请参阅Fedora-Cloud Docker SELinux策略,但是有很多依赖性,即svirt_lxc_net_t来自virt.te
  • 使用Fedora,它可以直接与SELinux和Docker一起使用,包括提到的文件lxc_contexts
  • 08-28 05:00