Sub topic 3
Diagnosing denials with ausearch, audit2why and sealert
This chapter assumes you know the Linux command line and sudo, can read permission bits, and have used systemctl and journalctl. You need a RHEL-family system with SELinux in enforcing mode and httpd installed.
When SELinux blocks an action, the kernel writes an AVC denial to the audit log. Start there, then choose the fix.
Finding and explaining denials
sudo ausearch -m avc -ts recent
sudo ausearch -m avc -ts recent | audit2why
sealert -a /var/log/audit/audit.logausearch filters the audit log for AVC records. audit2why reads those records and names the likely cause, such as a missing boolean or a wrong label. sealert summarizes denials and suggests fixes.
Debugging with a permissive domain
Permissive mode logs denials without blocking them. Set it on one domain instead of disabling SELinux for the whole host:
sudo semanage permissive -a httpd_t
# reproduce the failure, then review the log
sudo ausearch -m avc -ts recent
sudo semanage permissive -d httpd_tRemove the exception when you finish. Otherwise httpd stays unconfined.
Querying the loaded policy with sesearch
sesearch lists the allow rules in the loaded policy:
sesearch -A -s httpd_t -t httpd_sys_content_t -c file -p readIf the output contains a rule, the policy grants httpdt read access to httpdsyscontentt files. No output means the policy does not grant that access.
Custom modules as a last resort
Use audit2allow only after booleans and labels fail. Review the generated rules before you install them:
sudo ausearch -m avc -c httpd --raw | audit2allow -M myhttpd
cat myhttpd.te
sudo semodule -i myhttpd.ppMCS categories and containers
Multi-Category Security (MCS) adds category labels such as s0:c100,c200 to processes and files. Processes can read only files whose categories they hold. Container runtimes give each container unique categories, so one container cannot read another container's files, even when both share a type.
A repeatable confinement workflow
- Confirm the mode with getenforce.
- Check the file and port labels.
- Reproduce the failure and read the denials with ausearch and audit2why.
- Apply the matching boolean or label fix.
- Use a permissive domain only while you gather more denials.
- Write and install a module only after you review it.
Exercise
A web server cannot read files you copied to /srv/web. What do you check first?
Show answer
Run ausearch and audit2why to confirm the denial, then label the path with semanage fcontext and apply it with restorecon -Rv /srv/web.