详解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是一种标签系统 。
- 《明日方舟》新增六星干员“灰烬”正式公布,天赋技能详解!
- 官方发文详解Redmi K40如何打造一块旗舰屏幕
- 电缆故障测试仪的操作方法与步骤
- 发生故障赔偿100倍时长!京东云“百元上云”不玩虚的!
- 压力温度传感器故障!特斯拉Model 3/Y热泵空调或存质量问题
- 什么是浏览器 cookie?------------------------------------浏览器cookie详解
- 手把手教学,如何使用低代码快速构建应用程序步骤详解!
- 车辆|行车有大忌,如果制动系统出故障,这些前兆要提防
- 详解集成墙面一般要多少钱一平才合适
- 创业好项目——支付宝2021数字化经营转型2.0政策详解
