Dear Reader: Welcome to my third and not final installment on SELinux. The first two can be read here and here. They are exciting reads and are sure to have you on the edge of your seat.
Anyway, the best way to implement SELinux sucessfully is to know how to troubleshoot when things aren’t going your way. If you panic at the first sign of trouble, you are just going to end up turning off SELinux and not reap the rich rewards that it will bring you in life. Now that I have convinced you to run SELinux lets get started.
First install the package setroubleshoot, which will send SELinux messages to our messages file.
yum -y install setroubleshoot-server.x86_64
Now you can search the messages file for SELinux Violations. Use sealert -l UUID to find information on a specific incident, or sealert -a /var/log/audit.log to search an entire log file for violations.
In this specfic example, I created a test file and dropped it in /var/www/html, however I did not set the context to httpd_sys_content_t, then i attempted to view the file in a browser. Obviously access was denied. The output of sealert shows me the error and then tells me how to fix it.
Summary:
SELinux is preventing /usr/sbin/httpd “getattr” access to /var/www/html/file3.
Detailed Description:
SELinux denied access requested by httpd. /var/www/html/file3 may be a
mislabeled. /var/www/html/file3 default SELinux type is httpd_sys_content_t, but
its current type is admin_home_t. Changing this file back to the default type,
may fix your problem.…TRUNCATED…
Allowing Access:
You can restore the default system context to this file by executing the
restorecon command. restorecon ‘/var/www/html/file3’, if this file is a
directory, you can recursively restore using restorecon -R
‘/var/www/html/file3’.Fix Command:
/sbin/restorecon ‘/var/www/html/file3’
Boom goes the dynomite! Problem solved.