查看、比较和复制机器之间的 SELinux 配置?

查看、比较和复制机器之间的 SELinux 配置?

我有两台机器运行相同的 JBoss 和 HTTPD 设置。它们从完全相同的 RedHat 7 安装开始,并遵循相同的过程在两台机器上安装所有内容。

在一台机器上,SELinux 以默认设置运行,一切运行正常。我从未在这台机器上碰过 SELinux。

在另一台机器上,当我尝试在 Web 浏览器中访问它时,我收到 403 禁止错误消息。当我在网上搜索原因时,我发现有人建议我禁用它上面的 SELinux,然后看看它是否有效。所以我运行了setenforce 0,重新启动了 jboss 和 httpd,刷新了浏览器,禁止消息消失了,一切又恢复了正常。我用 重新打开 SELinux setenforce 1,重新启动应用程序,刷新浏览器,禁止消息又回来了。

因此,在我的第二台机器上,SELinux 似乎肯定出了问题。这很奇怪,因为我没有在任何一台机器上接触过 SELinux,直到我尝试在第二台机器上关闭它。我已经验证,在第一台机器上,当我运行 时getenforce,它确实返回Enforcing

我的问题是 - 如何查看每台机器上的 SELinux 配置?如何比较它们,找出它们之间的差异,并编辑或复制它们,以便我可以在第二台机器上运行 SELinux 而不会干扰我的应用程序,就像在第一台机器上一样?

编辑- 我运行此命令来搜索审计日志:

cat /var/log/audit/audit.log | grep httpd | grep denied

第一行重复了好几次。最后两行只在最后出现过一次。

type=AVC msg=audit(1468877854.297:22110): avc:  denied  { getattr } for  pid=5193 comm="httpd" path="/var/www/html/sfo/index.htm" dev="dm-0" ino=70334613 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file
type=AVC msg=audit(1468877854.297:22111): avc:  denied  { read } for  pid=5193 comm="httpd" name="index.htm" dev="dm-0" ino=70334613 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file
type=AVC msg=audit(1468877854.297:22111): avc:  denied  { open } for  pid=5193 comm="httpd" path="/var/www/html/sfo/index.htm" dev="dm-0" ino=70334613 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:var_t:s0 tclass=file

在运行 SELinux 且未错误阻止页面的机器上,我没有看到任何类似的消息。两台机器都为 /var、/var/www、/var/www/html、/var/www/html/sfo 和 /var/www/html/sfo/index.htm 设置了相同的权限标志

所有目录都有drwxr-xr-x,index.htm 文件有-rw-r--r--。所有这些都归用户 root 和组 root 所有。md5sum表示 /etc/sudoers 相同。两台机器上的 /etc/sudoers.d 中都没有任何内容。

两台机器的输出相同getsebool -a | grep httpd

httpd_anon_write --> off
httpd_builtin_scripting --> on
httpd_can_check_spam --> off
httpd_can_connect_ftp --> off
httpd_can_connect_ldap --> off
httpd_can_connect_mythtv --> off
httpd_can_connect_zabbix --> off
httpd_can_network_connect --> off
httpd_can_network_connect_cobbler --> off
httpd_can_network_connect_db --> off
httpd_can_network_memcache --> off
httpd_can_network_relay --> off
httpd_can_sendmail --> off
httpd_dbus_avahi --> off
httpd_dbus_sssd --> off
httpd_dontaudit_search_dirs --> off
httpd_enable_cgi --> on
httpd_enable_ftp_server --> off
httpd_enable_homedirs --> off
httpd_execmem --> off
httpd_graceful_shutdown --> on
httpd_manage_ipa --> off
httpd_mod_auth_ntlm_winbind --> off
httpd_mod_auth_pam --> off
httpd_read_user_content --> off
httpd_run_stickshift --> off
httpd_serve_cobbler_files --> off
httpd_setrlimit --> off
httpd_ssi_exec --> off
httpd_sys_script_anon_write --> off
httpd_tmp_exec --> off
httpd_tty_comm --> off
httpd_unified --> off
httpd_use_cifs --> off
httpd_use_fusefs --> off
httpd_use_gpg --> off
httpd_use_nfs --> off
httpd_use_openstack --> off
httpd_use_sasl --> off
httpd_verify_dns --> off

答案1

有了 SELinux,文件系统就拥有了超出常规 UNIX 权限的额外“权限”。如果您要在两台计算机上的文件上运行ls -Z ...-Z是 SELinux 的扩展),我猜您会看到以下内容:ls(1)/var/www/html

在服务器 A 上:

drwxr-xr-x root root system_u:object_r:httpd_sys_content_t /var/www/html/

在服务器 B 上:

drwxr-xr-x root root system_u:object_r:var_t /var/www/html/

ETC。

在服务器 A 上正确标记,以便 Apache 在 SELinux 处于活动状态时读取该目录。在服务器 B 上,目录不是当 SELinux 处于活动状态时,Apache 可以正确读取它。

为了修复它,请先尝试运行restorecon -Rvn /var/www/,它将向您展示文件系统将如何更改以匹配当前运行的 SELinux 策略。如果看起来正常,请删除该-n标志并重新运行。

还有一个很有用的httpd_selinux(8)手册页,其中记录了与 Apache 相关的 SELinux。

相关内容