在CentOS上共享使用Apache收集数据(SELinux)

我的CentOS 7 VPS启用了SELinux,由Collectd监控。 它使用rrdtool来logging报告的数据。 Pommi发布了一个很好的解决scheme,使我能够查看一个名为CGP的网页上的所有数据( http://pommi.nethuis.nl/collectd-graph-panel-v0-4/ )。

RRD数据存储在/var/lib/collectd/my.host.name中

drwxr-xr-x. root root system_u:object_r:collectd_var_lib_t:s0 my.host.name

当我打开CGP页面时,它指出Error: No Collectd hosts found in /var/lib/collectd/rrd但是当我禁用SELinux时,我的主机显示出来,并且正常工作。 审计日志显示:

audit.log包含以下条目

type=AVC msg=audit(1410524820.750:15750): avc: denied { getattr } for pid=10468 comm="httpd" path="/var/lib/collectd/rrd" dev="dm-0" ino=72430599 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:collectd_var_lib_t:s0 tclass=dir

type=SYSCALL msg=audit(1410524820.750:15750): arch=c000003e syscall=4 success=no exit=-13 a0=7f093426da68 a1=7fff4fa46ae0 a2=7fff4fa46ae0 a3=1 items=0 ppid=10461 pid=10468 auid=4294967295 uid=48 gid=48 euid=48 suid=48 fsuid=48 egid=48 sgid=48 fsgid=48 tty=(none) ses=4294967295 comm="httpd" exe="/usr/sbin/httpd" subj=system_u:system_r:httpd_t:s0 key=(null)

所以我认为将/ var / lib / collectd / rrd文件夹和内容的上下文更改为httpd_sys_content_thttpd_sys_content_t 。 现在CGP运行并显示主机和统计信息。 但是,当我重新启动collectd并检查状态它说:

 Sep 12 14:31:31 my.host.name collectd[17910]: stat(/var/lib/collectd/rrd/my.host.name/memory/memory-cached.rrd) failed: Permission denied Sep 12 14:31:31 my.host.name collectd[17910]: stat(/var/lib/collectd/rrd/my.host.name/memory/memory-free.rrd) failed: Permission denied Sep 12 14:31:31 my.host.name collectd[17910]: Filter subsystem: Built-in target `write': Dispatching value to all write plugins failed with status -1. Sep 12 14:31:31 my.host.name collectd[17910]: stat(/var/lib/collectd/rrd/my.host.name/interface-eth0/if_packets.rrd) failed: Permission denied Sep 12 14:31:31 my.host.name collectd[17910]: Filter subsystem: Built-in target `write': Dispatching value to all write plugins failed with status -1. Sep 12 14:31:31 my.host.name collectd[17910]: stat(/var/lib/collectd/rrd/my.host.name/interface-eth0/if_octets.rrd) failed: Permission denied Sep 12 14:31:31 my.host.name collectd[17910]: Filter subsystem: Built-in target `write': Dispatching value to all write plugins failed with status -1. Sep 12 14:31:31 my.host.name collectd[17910]: Filter subsystem: Built-in target `write': Dispatching value to all write plugins failed with status -1. Sep 12 14:31:31 my.host.name collectd[17910]: stat(/var/lib/collectd/rrd/my.host.name/cpu-1/cpu-softirq.rrd) failed: Permission denied Sep 12 14:31:31 my.host.name collectd[17910]: Filter subsystem: Built-in target `write': Dispatching value to all write plugins failed with status -1. 

如何设置安全上下文以便collectd AND httpd可以访问内容?

您需要按照文档中的描述设置selinux策略

要点是:

 [root@collectd ~]# audit2allow -a #============= httpd_t ============== allow httpd_t collectd_var_lib_t:dir read; allow httpd_t collectd_var_lib_t:file { read getattr open }; 

(这是运行下一个命令大约3次后在CGP中单击的最后一次迭代,因为每次迭代都需要更多的访问权限)

 [root@collectd ~]# audit2allow -a -M cgp ******************** IMPORTANT *********************** To make this policy package active, execute: semodule -i cgp.pp 

运行命令,冲洗并重复,直到你已经敲定了所有的权限问题。