Sub topic 10
Diagnosing SELinux Denials with ausearch, audit2why, and sealert
Assume you are comfortable with sudo, systemctl, journalctl, Linux permissions, and basic Apache or nginx administration. This chapter focuses on diagnosis. It does not replace a correct file label, port label, or SELinux boolean.
Start with the AVC denial
SELinux records blocked actions as AVC denials. An AVC denial describes a decision made by the policy, such as an httpd_t process being denied read access to a file labeled default_t.
The most useful fields are:
| Field | Meaning |
|---|---|
| `scontext` | Security context of the source process |
| `tcontext` | Security context of the target object |
| `tclass` | Object category, such as `file` or `tcp_socket` |
| `{ read }` | Permission that was requested |
| `comm` | Program name that made the request |
A denial does not automatically mean that SELinux is wrong. First ask whether the service should perform the action. If the action is expected, fix the label, boolean, port label, or policy. If it is unexpected, investigate the service or request instead.
Search the audit log with ausearch
ausearch searches Linux audit records. Limit the search to AVC messages and a useful time range:
sudo ausearch -m avc -ts recentYou can narrow the results by executable, command, or service. For example:
sudo ausearch -m avc -c httpd -ts recentRead the denial as a relationship:
source process: httpd_t
target object: default_t
requested action: read
target class: fileThis often reveals a mislabeled custom web root. A web server normally reads content labeled httpd_sys_content_t, not an arbitrary type.
The audit record may repeat the same denial many times. Group repeated messages mentally by source type, target type, permission, and path. One root cause can create many records.
Explain records with audit2why
audit2why translates raw AVC records into a short explanation. Pass it raw audit output:
sudo ausearch -m avc -ts recent --raw | audit2whyThe result may identify a disabled SELinux boolean or explain that the target has an unsuitable type. Check the suggested fix against the intended service behavior. Do not enable a boolean merely because the tool mentions it.
For example, if Apache must connect to an application backend, confirm that this is required before enabling httpd_can_network_connect:
getsebool httpd_can_network_connect
sudo setsebool -P httpd_can_network_connect onThe -P option writes the change to policy configuration, so it survives a reboot. Without -P, the change is temporary.
Get reports with sealert
sealert provides a more detailed, human-oriented report. On RHEL-family systems, it is supplied by the setroubleshoot packages. Analyze the audit log:
sudo sealert -a /var/log/audit/audit.logReports commonly include the denied operation, an explanation, confidence-ranked suggestions, and commands. Treat those commands as proposals. Verify the path, process, and expected behavior before applying them.
A practical diagnosis path
After applying a fix, reproduce the original request and search again with a fresh time boundary. A successful command is not enough. Confirm that the expected service action works and that no unrelated access was opened.
Exercise
Apache cannot read /srv/web/index.html, and the AVC shows tcontext=system_u:object_r:default_t. Which diagnostic conclusion should you test first?
Show answer
Test whether the custom path has the wrong SELinux file type. Apache content commonly needs httpd_sys_content_t; inspect the path with ls -Z, then create a persistent semanage fcontext rule and apply it with restorecon.