【问题标题】:Docker Run With SELinux on ubuntu Constrain violationDocker 在 ubuntu 上使用 SELinux 运行 违反约束
【发布时间】:2015-08-10 14:16:12
【问题描述】:

在 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 的 Permissive 模式运行 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 DENIED mlsconstrain 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) 并发生此错误。

所以我的问题:

是容器的类型错误吗?如何关闭这个约束或者如何解决这个问题?

【问题讨论】:

    标签: ubuntu docker lxc selinux


    【解决方案1】:

    我不知道您的 container.te 文件的第 41 行。一般来说,“语法错误”表示缺少 selinux-type 或未知的 selinux-interface,这意味着问题出在不同的地方。

    但我注意到了一些事情:

    • Docker 守护进程必须使用--selinux-enabled=true 运行才能支持 SELinux
    • 要创建新的 selinux 策略模块,您需要所有这些文件:.te、.fc 和 .if。请参阅Debian how-to,了解最小 SELinux 策略的示例。
    • 通过使用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 策略。

    可能的解决方案:

    • 在 Ubuntu 中使用 AppArmor(但我不知道是否有现成的 Docker 配置文件)。
    • 为 Ubuntu 上的 SELinux 构建您自己的 Docker 策略。参见Fedora-Cloud Docker SELinux策略,但是有很多依赖,即svirt_lxc_net_t来自virt.te
    • 使用 Fedora,它可以与 SELinux 和 Docker 开箱即用,包括提到的文件 lxc_contexts

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-03
      • 1970-01-01
      • 2020-04-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多