1

对于我的 Docker 容器,Selinux 已启用并设置为“强制”模式。我们的系统中有 2 个容器正在运行。但是对于一个容器,“MountLabel”和“ProcessLabel”都配置了,如下图:

 docker inspect <container1_ID> | grep "Label"
    "MountLabel": "USER_u:ROLE_r:svirt_lxc_file_t:s0:c204,c558",
    "ProcessLabel": "USER_u:ROLE_r:svirt_lxc_net_t:s0:c204,c558",

对于另一个容器,缺少“ProcessLabel”配置 -

docker inspect <container2_ID> | grep "Label"
    "MountLabel": "USER_u:ROLE_r:svirt_lxc_file_t:s0:c212,c227",
    "ProcessLabel": "",  

   

您能否帮我了解一下,如何为 docker 容器配置进程标签以及此类别编号(c204,c558)表示什么?

4

1 回答 1

0

当容器启动时,包含该容器的进程将被标记为 SELinux 上下文。您可以运行 'ps -eZ' 或 'docker inspect ...' 来查看容器的上下文 为了让进程能够写入卷,卷需要使用进程上下文具有的 SELinux 上下文进行标记进入。这就是 '[zZ]' 标志的用途。如果您在没有 z 标志的情况下启动容器,您将收到权限被拒绝错误,因为 SELinux 卷级别和进程级别不匹配。

语法将类似于docker run --name yourcontainername --rm -it -v /foo:/foo:Z

哟可以在这里找到更详细的解释https://prefetch.net/blog/2017/09/30/using-docker-volumes-on-selinux-enabled-servers/

如果您想了解更多关于类别编号的信息,可以阅读以下文档https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/6/html/security-enhanced_linux/chap-security-enhanced_linux-selinux_contexts

于 2022-03-04T09:51:04.460 回答