Ubuntu 中定制 SELinux 的可操作步骤
一 前置说明与准备
二 启用与基础配置
sudo apt update && sudo apt install selinux-basics selinux-policy-default selinux-utils auditd audispd-plugins policycoreutilssudo rebootgetenforce、sestatussudo setenforce 1(强制)或 sudo setenforce 0(宽容)三 定制策略的三种常用方式
sudo ausearch -m avc -ts recent | audit2allow -M mypolsudo semodule -i mypol.ppmkdir -p ~/selinux-custom && cd ~/selinux-custom && nano custom_policy.tepolicy_module(custom_policy, 1.0)
require {
type httpd_t;
class file { read write open };
}
allow httpd_t httpd_sys_content_t:file { read write open };
make -f /usr/share/selinux/devel/Makefile 生成 custom_policy.pp,然后 sudo semodule -i custom_policy.ppsudo semanage fcontext -a -t httpd_sys_content_t "/var/www/myapp(/.*)?" && sudo restorecon -Rv /var/www/myappsudo semanage port -a -t http_port_t -p tcp 8080四 验证与排错
sudo ausearch -m avc -ts recentsudo ausearch -m avc -ts recent | audit2whysestatus、getenforce五 维护与最佳实践
semodule -i 加载。