您的位置:首页 > 运维架构 > Linux

SELinux的应用

2013-10-12 00:00 127 查看
安装组件:

yum -y install policycoreutils-python


yum -y install setools-console


安装日志文件记录所需要的服务

yum -y install setroubleshoot setroubleshoot-server


echo "My first selinux check" > index.html


mv index.html /var/www/html/


现在我们在浏览器上访问,httpd服务器,如果不能访问查看iptables的给ACCEPT下

tail /var/log/messages


Aug 7 21:59:18 test auditd[1638]: Init complete, auditd 2.2 listening for events (startup state enable)

Aug 7 22:01:47 test setroubleshoot: SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/index.html. For complete SELinux messages. run sealert -l 91a19ae3-b982-41d1-bbf2-302cf2032064

Aug 7 22:01:47 test setroubleshoot: SELinux is preventing /usr/sbin/httpd from getattr access on the file /var/www/html/index.html. For complete SELinux messages. run sealert -l 91a19ae3-b982-41d1-bbf2-302cf2032064

这样就看到了好多的错误的信息

sealert -l b0332490-2505-4e1a-8a1a-b35f5041390a


SELinux is preventing /usr/sbin/httpd from open access on the file index.html.

***** Plugin catchall (100. confidence) suggests ***************************

If you believe that httpd should be allowed open access on the index.html file by default.

Then you should report this as a bug.

You can generate a local policy module to allow this access.

Do

allow this access for now by executing:

# grep httpd /var/log/audit/audit.log | audit2allow -M mypol

# semodule -i mypol.pp

grep httpd /var/log/audit/audit.log | audit2allow -M mypol


******************** IMPORTANT ***********************

To make this policy package active, execute:

semodule -i mypol.pp

semodule -i mypol.pp


执行这两个就可以访问了

让setroubleshoot主动发送产生的信息到E-mail:

vim /etc/setroubleshoot/setroubleshoot.conf


大约81行左右,这行要有才行

大约81行左右,这行要有才行

recipients_filepath = /var/lib/setroubleshoot/email_alert_recipients

大约在147行

# console: True|False, also log to the console

console = True

vim /var/lib/setroubleshoot/email_alert_recipients


root
@localhost

f91jty@163.com

service auditd restart


如果无法确定SELinux的问题出在哪里,建议这样处理:

一).在服务与RWX权限都没有问题,却无法成功的使用网络服务时,先使用setenforce 0设置为宽容模式。

二).再次使用该网络服务,如果这样就能用,表示SELinux出现问题,请往下继续处理;如果这样还不能使用,那问题就不是在SELinux上面,请再找其他解决方法,下面操作不适合你。

三).分析/var/log/messages内的信息,找到sealert -l 相关的信息并且执行。

四).找到Allow Access的关键词,按照里面的动作来进行SELinux的错误克服。

五).处理完重新setenforce 1,再次测试网络服务。

这样就能够很轻松的管理你的SELinux了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: