prc*_*jac 2 linux redhat selinux centos symlink
我有一个正在企业环境中安装的解决方案。该解决方案及其部署指南旨在安装在启用了 SELinux 的 RHEL7/CentOS7 服务器上,并根据文件系统层次结构标准将组件安装到位置。
然而,其中一位客户让我们感到惊讶,他指出所有第三方解决方案都必须安装到一个/apps目录中,因为他们根据策略对此进行了备份。
为了避免这个特定客户端的偏差,因为它需要对解决方案进行重大修改,我们决定最好的方法是在目录中创建一个新目录,/apps并/opt从真实的目录中预先创建符号链接/opt,并将相同的 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/
Run Code Online (Sandbox Code Playgroud)
产品的某些组件是通过 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
Run Code Online (Sandbox Code Playgroud)
它恢复标准安装上的上下文,但在这种环境中,由于符号链接,它会失败。
如果您修改命令以包含该/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
Run Code Online (Sandbox Code Playgroud)
是否有一种方法可以修改命令的参数,semanage以便restorecon这适用于符号链接(以及正常情况下),或者我对 SELinux 如何应用文件上下文有根本的误解?
我相信这个问题不同于How do I allocate an SELinux label to a symlink with semanage so it persists after a relabel? 因为它是将上下文应用于符号链接目录中子目录中的文件,而不是将上下文应用于符号链接文件本身。
小智 5
您可以使用realpath部署指南中的命令来确保说明是通用的,但将上下文应用到实际的文件系统位置(无论实际位置如何)。
`realpath "/opt/product/wwwstatic"`
Run Code Online (Sandbox Code Playgroud)