在Red Hat系统安全加固实践中,SELinux策略优化是保障系统安全的关键环节。本文将通过具体案例演示如何配置并调试SELinux策略。
场景描述: 某企业Linux服务器需要限制Apache HTTP服务的访问权限,确保其只能读取特定目录内容。默认情况下,Apache运行在httpd_t域中,但默认策略可能过于宽松。
具体配置步骤:
- 首先检查当前SELinux状态和策略配置
sestatus
getenforce
- 创建自定义SELinux策略文件(/etc/selinux/targeted/policy/custom.te)
module custom_httpd 1.0;
require {
type httpd_t;
type httpd_sys_content_t;
class dir search;
class file read;
}
# 只允许Apache访问特定目录
allow httpd_t httpd_sys_content_t:dir { search };
allow httpd_t httpd_sys_content_t:file { read getattrattr };
- 编译并加载策略
checkmodule -M -m -o custom_httpd.mod custom.te
semodule_package -o custom_httpd.pp -i custom_httpd.mod
sudo semodule -i custom_httpd.pp
故障排除技巧: 当配置后服务无法启动时,可通过以下命令排查:
# 查看SELinux相关日志
journalctl | grep avc
# 或使用sealert分析问题
sealert -a /var/log/audit/audit.log
通过以上策略优化,系统安全性和访问控制得到显著增强。

讨论