查看,比较和复制机器之间的SELinuxconfiguration?

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

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

在另一台机器上,当我尝试在networking浏览器中访问它时,出现403条禁止的错误消息。 当我在网上search为什么时,我发现一个build议,我应该禁用SELinux,看看它是否工作。 所以我跑了setenforce 0 ,重新启动jbosshttpd,刷新我的浏览器,禁止的消息走了,一切都工作了。 我用setenforce 1重新打开SELinux setenforce 1 ,重新启动应用程序,刷新浏览器,禁止的消息回来。

所以在我的第二台机器上,SELinux肯定有些问题。 这很奇怪,因为我没有在任何一台机器上碰到SELinux,直到我试图在第二秒钟把它关掉。 我已经证实,在第一台机器上,当我运行getenforce ,它确实返回Enforcing

我的问题是 – 如何查看每台机器上的SELinuxconfiguration? 我怎么能比较它们,找出它们之间的差异,编辑或复制它们,以便我可以在不干扰我的应用的情况下在第二台机器上运行SELinux,就像在我的第一台机器上一样?

编辑 – 我运行这个命令来search审计日志:

 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都有相同的输出 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 

使用SELinux,文件系统具有超出常规UNIX的额外“权限”。 如果你要在两台机器上的/var/www/html文件上运行ls -Z ... (- -Z是对ls(1)的SELinux扩展),我怀疑你会看到以下内容:

在服务器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/

等等

在服务器A上,这标记为正确的,以使得在SELinux激活的情况下读取该目录。 在服务器B上,当SELinux处于活动状态时,目录没有正确标记以供Apache读取。

为了解决这个问题,首先运行restorecon -Rvn /var/www/它会告诉你如何改变文件系统以匹配当前运行的SELinux策略。 如果看起来很健全,请删除-n标志并重新运行。

还有一个有用的httpd_selinux(8)联机帮助页,它logging了SELinux与Apache的关系。