SELinux:两台服务器,配置相同,但上下文不同

SELinux:两台服务器,配置相同,但上下文不同

我曾经在 SELinux 方面遇到过不少困难,但这是第一次它完全难倒我。我有两台 CentOS 8 生产服务器,它们的配置功能相同,托管一个 Web 应用程序。我有一个自定义类型执行模块,与这个问题相关的部分如下:

module my_app 1.0;
type my_app_rw_content_t;
files_type(my_app_rw_content_t);
require {
    type httpd_t;
    class file { getattr read write execute execute_no_trans open create unlink ioctl link rename };
    class dir { add_name remove_name read write create };
    class lnk_file { getattr read open };
}
allow httpd_t my_app_rw_content_t:file { getattr open read write create unlink ioctl };
allow httpd_t my_app_rw_content_t:dir { add_name remove_name read write };

我想将my_app_rw_content_t上下文分配给我的应用用于临时文件上传的目录,即 /data/www/my_app_tmp/。以下策略自定义在两个系统上均有效:

fcontext -a -f a -t httpd_sys_content_t -r 's0' '/data/www(/.*)?'
fcontext -a -f a -t my_app_rw_content_t -r 's0' '/data/www/my_app_tmp(/.*)?'

在服务器 1 上,它的行为符合预期:

[me@server1 ~]$ matchpathcon /data/www/my_app_tmp
/data/www/my_app_tmp    system_u:object_r:my_app_rw_content_t:s0

在服务器 2 上,它不会:

[me@server2 ~]$ matchpathcon /data/www/my_app_tmp
/data/www/my_app_tmp    system_u:object_r:httpd_sys_content_t:s0

我无论如何也想不出为什么。这是一个半无意义的问题,因为我很快就会迁移到其他发行版上的新系统,但我仍然想知道这里发生了什么。

相关内容