在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=false
和docker 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),这意味着问题出在其他地方。
但是我注意到一些事情:
--selinux-enabled=true
一起运行才能支持SELinux cat /var/log/audit/audit.log | audit2allow -M container
,您可以处理所有记录的线路。最好只将所需的行复制到新文件中。 s0
是级别而不是标签。而“重新标记”是指更改类型。参见labeling files。 默认情况下,Ubuntu预装了AppArmor,如果要使用SELinux,则必须先将其删除/禁用。 Ubuntu和Debian不提供SELinux的Docker策略。
可能的解决方案:
svirt_lxc_net_t
来自virt.te lxc_contexts
。