详解SELinux故障排查和陷阱规避( 二 )


创建typeenforcement(.te)文件 , 拥有策略的必要权限:
#vimy_wicd.temodulemy_wicd1.0;require{typeNetworkManager_t;typeetc_t;classipx_socketcreate;classax25_socket{createioctl};classappletalk_socket{createioctl};classfilesetattr;}#=============NetworkManager_t==============allowNetworkManager_tetc_t:filesetattr;allowNetworkManager_tself:appletalk_socket{createioctl};allowNetworkManager_tself:ax25_socket{createioctl};allowNetworkManager_tself:ipx_socketcreate;要编译策略 , 安装软件包selinux-policy-devel , 并生成策略软件包:
#make-f/usr/share/selinux/devel/Makefilemy_wicd.pp要激活刚生成的模块 , 运行:
#semodule-imy_wicd.pp策略错误信息:试图访问我的网站时 , 我在日志中看到了SELinux错误 。
为SELinux错误信息排查故障时常见的陷阱之一是 , 根据发现的所有错误信息创建策略 。 在大多数情况下 , 如果setroubleshoot包已安装 , 同样的提醒会给出所有可能的变通选项 , 按最好到最差的顺序排列 。
要查看今天生成的setroubleshoot提醒 , 运行:
#journalctl-tsetroubleshoot--sincetodayDec0813:08:33lab.example.comsetroubleshoot[12013]:failedtoretrieverpminfofor/var/www/html/index.htmlDec0813:08:34lab.example.comsetroubleshoot[12013]:SELinuxispreventing/usr/sbin/httpdfromgetattraccessonthefile/var/www/html/index.html.ForcompleteSELinuxmessagesrun:sealert-l011df984-4eb6-4079-98ab-cba173c4342eDec0813:08:34lab.example.comsetroubleshoot[12013]:SELinuxispreventing/usr/sbin/httpdfromgetattraccessonthefile/var/www/html/index.html.*****Pluginrestorecon(99.5confidence)suggests************************Ifyouwanttofixthelabel/var/www/html/index.htmldefaultlabelshouldbehttpd_sys_content_t.Thenyoucanrunrestorecon.Theaccessattemptmayhavebeenstoppedduetoinsufficientpermissionstoaccessaparentdirectory,inwhichcasetrytochangethefollowingcommandaccordingly.Do#/sbin/restorecon-v/var/www/html/index.html*****Plugincatchall(1.49confidence)suggests**************************Ifyoubelievethathttpdshouldbeallowedgetattraccessontheindex.htmlfilebydefault.Thenyoushouldreportthisasabug.Youcangeneratealocalpolicymoduletoallowthisaccess.Doallowthisaccessfornowbyexecuting:#ausearch-c'httpd'--raw|audit2allow-Mmy-httpd#semodule-X300-imy-httpd.pp在这里 , 最好的解决办法就是修复文件的标签 。
小结
为SELinux排查故障可能很难 , 但如果运用这里介绍的几个概念 , 并了解服务的组成 , 您就可以处理它带来的各种难题 。
切记:SELinux是一种标签系统 。