LogRotate和Apache的SELinux权限

与目录结构:

/www/live/website1/app/ /www/live/website1/files/ /www/live/website1/logs/ 

Apache至less需要以下访问权限:

 app: read-only access, but read-write is fine (files already chmod 0644) files: read-write access logs: read-write access 

通过以下两个规则设置的地方:

 /usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/www/live/.*/.*"; /usr/sbin/semanage fcontext -a -t httpd_log_t "/www/live/.*/logs(/.*)?"; /sbin/restorecon -vr "/www"; 

哪些应用,似乎工作正常…但是LogRotate不开心。

LogRotateconfiguration目前是:

 /www/live/*/logs/*access_log /www/live/*/logs/*access_log_443 { weekly rotate 52 missingok notifempty nodateext sharedscripts postrotate /usr/sbin/apachectl graceful > /dev/null endscript } 

但是,这似乎被SELinux阻止,在audit.log中出现条目,当它尝试点击与/www/live文件夹相关的inode(下面的示例中的262146)时…试图列出/ www / live /中的文件夹。

 type=AVC msg=audit(1396579563.324:316060): avc: denied { read } for pid=12336 comm="logrotate" name="live" dev=dm-0 ino=262146 scontext=system_u:system_r:logrotate_t:s0-s0:c0.c1023 tcontext=unconfined_u:object_r:default_t:s0 tclass=dir type=SYSCALL msg=audit(1396579563.324:316060): arch=c000003e syscall=2 success=no exit=-13 a0=7fff2cef68b0 a1=90800 a2=7fff2cef6b5a a3=8 items=0 ppid=12334 pid=12336 auid=0 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=(none) ses=35531 comm="logrotate" exe="/usr/sbin/logrotate" subj=system_u:system_r:logrotate_t:s0-s0:c0.c1023 key=(null) 

那么我应该设置哪个上下文父目录?

 /usr/sbin/semanage fcontext -a -t default_t "/www(/.*)"; 

在那里我知道default_t不工作,也不var_t …和参考我真的不在乎什么可以看到这些文件夹,因为它们已经是chmod 0755。


而对于奖励点…有一个简单的方法来查看一个程序的权限的完整列表? 我知道LogRotate必须能够访问httpd_log_tvar_log_t

令人讨厌的是,手动运行LogRotate似乎绕过了这些限制,因为我认为它inheritance了用户权限(与通过cron运行时不同)。

没有确认,如果这是正确的答案呢…

 /usr/sbin/semanage fcontext -a -t sysfs_t "/www(/.*)"; /usr/sbin/semanage fcontext -a -t httpd_sys_content_t "/www/live/.*/.*"; /usr/sbin/semanage fcontext -a -t httpd_log_t "/www/live/.*/logs(/.*)?"; /sbin/restorecon -vr "/www"; 

那里的sysfs_t是重要的一点。

我可以findLogRotate可以使用的域名:

 sesearch -s logrotate_t -SA 

快速search“dir”的“阅读”(而不是“打开”)权限:

 sesearch -s logrotate_t -SA -c dir -p read | sort 

然后扫描列表,我会说sysfs_t是最合适的。


我发现的一个问题是,如果我自己运行/usr/sbin/logrotate ,它会inheritanceroot帐户上下文:

 id -Z unconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023 

所以它会自动获得“无限制”的访问权限(即完全访问权限)……所以为了testing,我发现使用以下虽然不完美,但做了一些工作:

 sandbox /usr/sbin/logrotate -d /etc/logrotate.conf 

我也发现了newroleruncon ,两者都需要通过以下方式单独安装在RedHat / CentOS系统上:

 yum install policycoreutils-newrole newrole -r system_r -t logrotate_t runcon -r system_r -t logrotate_t /usr/sbin/logrotate -d /etc/logrotate.conf 

但是,这两个都给了我权限被拒绝的错误(可能是由于过渡不被允许):

http://wiki.gentoo.org/wiki/SELinux/Tutorials/How_does_a_process_get_into_a_certain_context


还有一些我觉得有用的东西:

 yum install setools-console seinfo -usystem_u -x seinfo -rsystem_r -x seinfo -tlogrotate_t -x seinfo -tsysfs_t -x 

并检查我在系统上创build的规则列表:

 cat /etc/selinux/targeted/contexts/files/file_contexts.local 

有关SELinux的更多信息,我发现这17个教程非常有帮助:

http://wiki.gentoo.org/wiki/SELinux/Tutorials


就我个人而言,我发现所有这些程序都非常不一致,可以理解为什么大多数人只是默认禁用SELinux

  • seinfo选项-u / r / t之后不能有空格
  • 你需要安装额外的软件包来获得seinfonewrole
  • 您不能在给定的上下文中轻松运行程序(用于testing目的)。
  • audit.log文件使用时间戳,所以现在试试ausearch -m avc --start today
  • 没有使用许多程序的命名约定(例如matchpathcon )。
  • 我不会说audit2allow的输出(或操作)是显而易见的。

这是一个耻辱,因为它似乎是一个非常强大的系统整体。