查看自定义的selinux策略

有没有办法查看所有适用于SELinux的自定义策略,最好将它们全部整合到一个策略“包”中?

我刚刚花了一个星期左右的时间,通过一系列的SELinux错误,当一个特定的进程(从logrotate脚本,FWIW awstats更新)试图运行。 在SELinux处于许可模式下,我会等待logrotate运行,查看审计日志中的SELinux块,运行audit2allow创build一个允许策略,然后在第二天重复这个过程,并提供一个全新的相关错误列表。 最后,今天上午,审计日志变得干净了,所以我认为我有所有必要的规则来允许脚本正常运行。

当然,我没有考虑到这个过程,所以我没有创build所有的.pp / .te文件。 所以我想要做的就是将所有当前活动的自定义策略从SELinux中取出,这样我就可以拥有一个用于其他机器或恢复的备份副本。 这可能吗?

编辑:这是在运行CentOS 6.7的机器上,如果这有所作为

这个答案是从这个问题借来的。 虽然它不能完全回答将所有自定义SELinux策略应用于计算机的问题,但它确实提供了您希望用来查看任何自定义策略的工具集或将其缩小一点点。


一些获取这些信息的命令是(例子使用httpd_log_t ):

  1. seinfo

     # seinfo -x --type=httpd_log_t /etc/selinux/default/policy/policy.26 httpd_log_t file_type non_security_file_type logfile 
  2. sesearch

     # sesearch --dontaudit -t httpd_log_t /etc/selinux/default/policy/policy.26 | head Found 35 semantic av rules: dontaudit run_init_t file_type : dir { getattr search open } ; dontaudit staff_t non_security_file_type : file getattr ; dontaudit staff_t non_security_file_type : dir { ioctl read getattr lock search open } ; dontaudit staff_t non_security_file_type : lnk_file getattr ; dontaudit staff_t non_security_file_type : sock_file getattr ; dontaudit staff_t non_security_file_type : fifo_file getattr ; dontaudit unconfined_t non_security_file_type : file getattr ; dontaudit unconfined_t non_security_file_type : dir { ioctl read getattr lock search open } ; dontaudit unconfined_t non_security_file_type : lnk_file getattr ; 
  3. semanage

     # semanage fcontext -l | grep httpd_log_t /etc/httpd/logs all files system_u:object_r:httpd_log_t:s0 /var/log/apache(2)?(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/apache-ssl(2)?(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/cacti(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/cgiwrap\.log.* regular file system_u:object_r:httpd_log_t:s0 /var/log/horde2(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/httpd(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/lighttpd(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/log/piranha(/.*)? all files system_u:object_r:httpd_log_t:s0 /var/www(/.*)?/logs(/.*)? all files system_u:object_r:httpd_log_t:s0 

参考文献: RHEL6 SELinux手册