无法将SELinux文件上下文应用于符号链接的path

我有一个在企业环境中安装的解决scheme。 该解决scheme及其部署指南旨在安装在启用了SELinux的RHEL7 / CentOS7服务器上,并根据文件系统层次结构标准将组件安装到位置。

然而,其中一个客户已经感到惊讶,我们说所有的第三方解决scheme必须安装到/apps目录,因为他们根据政策支持。

为了避免这个特定的客户端出现偏差,因为这需要对解决scheme进行重大的修改,所以我们决定最好的方法是在/opt/apps目录下创build一个新的目录,并在真正的/opt前面创build符号链接,相同的SELinux内容( usr_t )例如:

 ls -laZ /appl/opt drwxr-xr-x. root root unconfined_u:object_r:usr_t:s0 . drwxr-xr-x. root root unconfined_u:object_r:default_t:s0 .. drwxr-xr-x. product product unconfined_u:object_r:usr_t:s0 product la -laZ /opt drwxr-xr-x. root root system_u:object_r:usr_t:s0 . dr-xr-xr-x. root root system_u:object_r:root_t:s0 .. lrwxrwxrwx. root root unconfined_u:object_r:usr_t:s0 product -> /apps/opt/product/ 

产品的某些组件通过Apache HTTPD访问,并要求将httpd_sys_content_t上下文应用于它们。

这些文件位于/opt/product/wwwstatic/ (实际上是/apps/opt/product/wwwstatic/ )。

部署指南指定以下命令来运行:

 semanage fcontext -a -t httpd_sys_content_t "/opt/product/wwwstatic/*" restorecon -Rv /opt/product/wwwstatic 

它在一个标准的安装上恢复上下文,但在这个环境中,由于符号链接,它失败了。

如果修改这些命令以包含/apps目录,但它与一般方法有所不同。

/etc/selinux/targeted/contexts/files/file_contexts.local的内容是:

 # This file is auto-generated by libsemanage # Do not edit directly. /appl/opt/.* system_u:object_r:usr_t:s0 /appl/srv/.* system_u:object_r:var_t:s0 /opt/product/wwwstatic/* system_u:object_r:httpd_sys_content_t:s0 

有没有办法修改semanagerestorecon命令的参数,以便这将工作的符号链接(以及正常情况下),或者我有一个基本的SELinux如何应用文件上下文的误解?

我相信这个问题不同于我如何将SELinux标签分配给带有semanage的符号链接,所以它在重新绑定之后仍然存在? 因为它是将上下文应用于来自符号链接目录的子目录中的文件,而不是将上下文应用于符号链接文件本身。

您可以在部署指南中使用realpath命令,以确保指令是通用的,但将上下文应用于实际可能存在的真实文件系统位置。

 `realpath "/opt/product/wwwstatic"` 

SELinux文件上下文基于实际的文件系统path进行匹配。 没有“跟随符号链接”。 所以你的自定义上下文需要引用磁盘上的实际位置。

第三方应用程序的标准位置 /opt ,所以你在这里是正确的。 如果你有一个客户想要做一些非标准的事情,那么你应该向他们清楚他们做错了什么,以及额外的成本(时间和金钱)会是什么。

chcon使用-h标志:

chcon -h -v system_u:object_r:httpd_sys_content_t:s0 *