FC6, SELinux and Nagios
I love Nagios, but have been having issues with it running under SELinux targeted. I’ve finally made it work with no more AVC’s or other errors (so far!). Here is what I have done to get it to work:
- Install nagios.
sudo yum install nagiossudo yum install 'nagios-plugins-*'- Make changes to nagios configuration to account for your situation.
- Make certain the permissions are correct.
- User apache needs read access to cfg files in /etc/nagios.
- User apache needs read access to web site files under /usr/share/nagios/html.
- If using resouces.cfg, only nagios needs access to read, not apache!
- For the nagios.cmd fifo pipe (under /var/spool/nagios/cmd), permissions are 660, owner = nagios, group = apache.
- cgi files need to be executable by apache
- plugins need to be executable by nagios
- Set security contexts on files (all sone with sudo, of course)
chcon -R -t httpd_sys_content_t /usr/share/nagios/htmlchcon -R -t nagios_etc_t /etc/nagioschcon -R -t nagios_log_t /var/log/nagioschcon -R -t var_spool_t /var/spool/nagioschcon -R -t bin_t /usr/lib/nagios/pluginschcon -t nagios_cgi_exec_t /usr/lib/nagios/cgi-bin/*.cgi- /usr/sbin/nagios has a security domain type of sbin_t
- Apache alias is in /etc/httpd/conf.d/nagios.conf. Inspect and make changes as necessary. Restart httpd service.
- The check_mem plugin was not working for me, it couldn’t find utils.pm. I had to add the following line to near the top of the script:
use lib "/usr/lib/nagios/plugins" ;- I needed to add some local security policy. Read on for details.
There seems to be some holes in the policy for nagios. These are easily corrected with a little help from checkmodule.
First, need to install the SELinux tools to create new policies. These are not installed by default.
sudo yum install checkpolicysudo yum install selinux-policy-devel
There is a nice tool for troubleshooting policy called setroubleshoot. It is available at Dan Walsh’s yum repo. See his blog entry for details. The setools are also quite helpful at inspecting policy (although I believe you need at least version 3 to inspect policy on fc6 where version 2.4 can inspect the audit logs).
I then went through the process of running/using nagios, inspecting the audit.log and taking the appropriate lines and running them through audit2allow -M
to generate the proper policy and then load the policy module. I had to do this process a number of times to make certain I captured all the AVC’s. I ended up with the following policy module (I’ve named it local, feel free to change its name if it conflicts. If you do, you need to make a change in the file, too).
module local 1.0.0;
require {
class fifo_file read;
class fifo_file getattr;
class fifo_file write;
class dir search;
class process { sigkill signal };
type httpd_t;
type nagios_cgi_t;
type ping_t;
type var_spool_t;
role system_r;
};
allow ping_t var_spool_t:fifo_file read;
allow httpd_t nagios_cgi_t:process { sigkill signal };
allow nagios_cgi_t var_spool_t:fifo_file getattr;
allow nagios_cgi_t var_spool_t:dir search;
allow nagios_cgi_t var_spool_t:fifo_file write;
After capturing this in the file local.te, make the policy package with:
% make -f /usr/share/selinux/devel/Makefile
This will ultimately create local.pp which then can be loaded by executing:
% sudo semodule -i local.pp
A good review of all of this can be found in the Red Hat SELinux FAQ.

February 26th, 2007 at 11:45 pm
Thanks for the article! I was pulling my hair out trying to get nagios to run under fedora 6. I was just about to ditch selinux when I found your post.
Your instructions worked flawlessly.
April 18th, 2007 at 9:34 am
Hi,
This worked great under FC6. Saved me loads of time. Many thanks for the post. Worked fine, only issue I had was creating the local.te file as root, this seemed to give a problem, so I created it as a normal user, and then did the sudo bit(I suppose it might be obvious in hind sight).
September 17th, 2007 at 3:11 am
Great! This one helped me a lot! I used it on RHEL 5 and using the EPEL nagios rpms which work flawless with your manual.
October 22nd, 2007 at 7:29 am
Hi,
I installed it in my CentOS5 system, via the Fedora 6 repository. Because I use lighttpd I had to configure it first. As soon as I did that it worked out of the box.
November 27th, 2007 at 3:13 pm
Thanks for the pointers. While this didn’t work for me step by step, I thought I’d share my how I overcame the differences.
I used the following to get the necessary classes and types:
cat /var/log/audit/audit.log | audit2allow >> my_nagios.teSAMPLE OUTPUT:
#============= httpd_nagios_script_t ==============
allow httpd_nagios_script_t var_spool_t:dir search;
This gave me the skeleton file that has the allows I needed to import. Make sure to look it over for anything that might actually be a violation of course and remove those lines. Then make sure to include all classes (those entries after the :’s) and types (those entries before the :’s) in the require block as shown above.
I named my policy my_nagios.te because nagios was already taken and giving errors:
libsepol.print_missing_requirements: nagios’s global requirements were not met: type/attribute nagios_etc_t
libsemanage.semanage_link_sandbox: Link packages failed
semodule: Failed!
Then I made and imported the my_nagios.pp file and now my SELinux is playing nicely with Nagios.
Thanks again for the help!
April 8th, 2008 at 9:02 pm
Under Fedora 7, it appears some mods must be made to the above. I had to add a couple of lines to the local policy module. Here’s what I ended up with, in order to get no errors listed from setroubleshoot. Not sure if the allow ping_t var_spool_t is still needed or not:
module local 1.0.0;
require {
class fifo_file read;
class fifo_file getattr;
class fifo_file write;
class dir search;
class process { sigkill signal };
type httpd_t;
type httpd_nagios_script_t;
type nagios_cgi_t;
type nagios_log_t;
type ping_t;
type var_spool_t;
role system_r;
};
allow ping_t var_spool_t:fifo_file read;
allow ping_t nagios_log_t:fifo_file read;
allow httpd_t nagios_cgi_t:process { sigkill signal };
allow nagios_cgi_t var_spool_t:fifo_file getattr;
allow nagios_cgi_t var_spool_t:dir search;
allow nagios_cgi_t var_spool_t:fifo_file write;
allow httpd_nagios_script_t nagios_log_t:fifo_file getattr;
allow httpd_nagios_script_t nagios_log_t:fifo_file write;
December 8th, 2008 at 1:26 am
I wish I had something exactly like this for OTRS, which is giving me fits on my centOS 5.2 machine runing Apache 2. I am getting this error:
[Sun Dec 07 22:00:56 2008] [error] [client 10.0.100.12] attempt to invoke directory as script: /opt/otrs/bin/cgi-bin/
Ut oh, sorry, I just realized that I can not tell if this from mod_suexec? or selinux? or what?