Sub topic 10
Diagnosing denials with ausearch, audit2why and sealert
This chapter shows how to turn an AVC denial (an entry in the audit log recording that SELinux blocked an action) into a concrete fix. It assumes you can read security contexts, know the difference between enforcing and permissive mode, and have met file labels, booleans and port labels in earlier chapters. You should be comfortable with sudo, systemctl and journalctl, and you should be working on a RHEL-family system with SELinux enabled.
The diagnostic loop
A denial is a symptom. The cause is almost always one of four things:
- A file or directory has the wrong type label.
- A port has the wrong label.
- A boolean that the service needs is off.
- The policy lacks a rule for what you are doing.
The tools in this chapter help you decide which one applies. The order matters, because the first three have clean, supported fixes and the fourth needs a custom module.
Where denials are recorded
When auditd is running, SELinux denials are written to /var/log/audit/audit.log as records of type AVC. If auditd is not running, the kernel sends them to the kernel ring buffer, and you can read them with journalctl -k. On RHEL-family systems auditd is normally active, so start there.
Check that it is running before you debug:
systemctl is-active auditd
sudo ls -l /var/log/audit/audit.logA raw record looks like this:
type=AVC msg=audit(1764305932.114:482): avc: denied { read } for pid=2210 comm="httpd" name="index.html" dev="vda1" ino=394811 scontext=system_u:system_r:httpd_t:s0 tcontext=unconfined_u:object_r:user_home_t:s0 tclass=file permissive=0Read it from the left:
| Field | Meaning in the example |
|---|---|
| `denied { read }` | The permission that was refused. |
| `comm="httpd"` | The command that tried the action. |
| `name="index.html"` | The object involved. |
| `scontext` | The source context. The domain is `httpd_t`. |
| `tcontext` | The target context. The type is `user_home_t`. |
| `tclass=file` | The kind of object, here a regular file. |
| `permissive=0` | The domain was enforcing, so the action really was blocked. |
The pattern to look for is a source domain (httpd_t) trying to use a target type (user_home_t) that the policy does not allow. Here the file has the wrong type for web content, which is a labeling problem.
A permissive=1 value means the action was only logged and still succeeded. Denials in that state still tell you what enforcing mode would block.
Searching with ausearch
ausearch filters the audit log so you do not have to read it by hand.
sudo ausearch -m avc -ts recent
sudo ausearch -m avc -ts today
sudo ausearch -m avc -c httpd -ts bootThe useful options are:
-m avcselects AVC records. You can also use-m avc,user_avcto include denials from user-space object managers such as D-Bus.-tssets the start time. Accepted values includerecent(the last 10 minutes),today,boot,this-week, or an explicit time such as-ts 11/28/2026 04:00:00.-c httpdfilters by command name.-itranslates numeric values into readable names, for example user IDs and timestamps.
Compare the raw and interpreted forms:
sudo ausearch -m avc -ts recent -iWith -i, the timestamp becomes a date and the numeric fields become names. Use the interpreted form to read, and the raw form (without -i) when you pipe into audit2why or audit2allow, because those tools parse the raw format.
Get a clean reproduction
Old denials hide the one you care about. Before you reproduce a problem, note the time, then trigger the failure once, then search from that time:
date +"%m/%d/%Y %H:%M:%S"
sudo systemctl restart httpd
sudo ausearch -m avc -ts 11/28/2026 05:02:00Use the date format that matches your system locale. If ausearch complains about the time format, check locale, or use recent after reproducing the failure.
The dontaudit trap
The policy contains dontaudit rules that suppress logging for denials that are known to be harmless noise. If a service fails and you find no AVC, a dontaudit rule might be hiding it. You can disable these rules temporarily:
sudo semodule -DB
# reproduce the problem and search again
sudo ausearch -m avc -ts recent
sudo semodule -Bsemodule -DB rebuilds the policy with dontaudit rules disabled. semodule -B rebuilds it with the normal rules again. Always run the second command, because the disabled state produces a lot of log noise.
Explaining a denial with audit2why
audit2why reads raw AVC records on standard input and says why each one was denied. It also suggests a fix when one exists.
sudo ausearch -m avc -ts recent | audit2whyTypical output for a boolean problem:
type=AVC msg=audit(1764305990.201:490): avc: denied { name_connect } for pid=2301 comm="httpd" dest=8080 scontext=system_u:system_r:httpd_t:s0 tcontext=system_u:object_r:http_cache_port_t:s0 tclass=tcp_socket permissive=0
Was caused by:
The boolean httpd_can_network_connect was set incorrectly.
Description:
Allow HTTPD scripts and modules to connect to the network using TCP.
Allow access by executing:
# setsebool -P httpd_can_network_connect 1Here Apache tried to connect out to port 8080, and the policy only allows that when the boolean is on. The output names the boolean and gives the command.
For a denial that no boolean or label can fix, the output looks like this:
Was caused by:
Missing type enforcement (TE) allow rule.
You can use audit2allow to generate a loadable module to allow this access.This says the policy has no rule for the access. It does not say you should add one. First ask whether the access is legitimate and whether a mislabeled object explains it.
Reading the result critically
audit2why finds the cause but it cannot judge intent. Two cautions apply:
- A suggested boolean can be broader than you need.
httpd_can_network_connectlets Apache connect to any TCP port. If you only need one database port, a port or module change might be narrower. Read the boolean's description before enabling it. - A "Missing type enforcement rule" message for a file often means the file is mislabeled. Check
ls -Zon the target before you write any policy.
Using sealert for a readable report
sealert comes from the setroubleshoot packages. The setroubleshoot-server daemon watches the audit log, analyzes each denial with plugins, and writes a plain-language summary to the system log. sealert reads that analysis.
Install and use it:
sudo dnf install setroubleshoot-server
sudo sealert -a /var/log/audit/audit.logThe -a option analyzes a whole audit log file. Each report contains the source and target, a confidence score for each suggested fix, and the commands to apply it. A report might say:
SELinux is preventing /usr/sbin/httpd from read access on the file index.html.
***** Plugin restorecon (99.5 confidence) suggests ************************
If you want to fix the label.
/srv/web/index.html default label should be httpd_sys_content_t.
Then you can run restorecon.
Do
# /sbin/restorecon -v /srv/web/index.htmlWhen setroubleshoot-server is running, it also logs a message for each denial. Search the journal for it:
sudo journalctl -t setroubleshoot --since "10 minutes ago"Each message includes an ID, and you can look it up with sudo sealert -l <ID>.
Choosing between the tools
| Need | Tool |
|---|---|
| Find the raw records quickly | `ausearch` |
| Get a one-line cause and a boolean suggestion | `audit2why` |
| Get a full report with confidence scores and label advice | `sealert` |
| Work on a server with no extra packages | `ausearch` and `audit2why` |
Servers often skip setroubleshoot-server because it adds a daemon and dependencies. ausearch with audit2why covers most cases without it. You can also copy the audit log to a workstation and run sealert -a there.
A worked example
Apache serves pages from /srv/web, but requests return 403 Forbidden. Ownership and mode bits look right, so suspect SELinux.
- Confirm the mode and look at the label.
getenforce
ls -Zd /srv/web /srv/web/index.htmlEnforcing
unconfined_u:object_r:var_t:s0 /srv/web
unconfined_u:object_r:var_t:s0 /srv/web/index.html- Find the denial.
sudo ausearch -m avc -c httpd -ts recent | audit2whyThe output reports a denied read from httpd_t on a var_t file, and the cause is a missing type enforcement rule.
- Notice that
var_tis a generic type. The right move is to label the tree, not to write a rule. This label change uses the commands from the file labeling chapter:
sudo semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?"
sudo restorecon -Rv /srv/web- Retest and confirm that no new denial appears.
curl -I http://localhost/
sudo ausearch -m avc -ts recentIf the second command prints <no matches>, the denial is resolved.
Common errors
- Searching with the wrong time window.
-ts recentcovers only the last 10 minutes. Use-ts todayor-ts bootfor older failures. - Piping the
-ioutput toaudit2why. The tool expects raw records, so drop-i. - Assuming no AVC means no SELinux problem. A
dontauditrule or a stoppedauditdhides denials. Usesemodule -DBand checkauditd. - Fixing the first denial only. A service often hits several denials in sequence. After each fix, retest and search again, because the next denial appears only once the previous action succeeds.
- Running
restoreconwithout a rule. If the file context rule for the path does not exist,restoreconrestores the wrong default. Add the rule withsemanage fcontextfirst. - Blaming SELinux without evidence. Check
permissive=in the record and confirm the failure goes away in permissive mode before you change policy.
Exercise
A service fails after you reproduce a problem. ausearch -m avc -ts recent prints <no matches>, yet the service works when you run setenforce 0. What are two possible reasons that no AVC was shown, and what do you do for each?
Show answer
First, auditd might not be running, so denials go to the kernel log. Check systemctl is-active auditd and read journalctl -k. Second, a dontaudit rule might be hiding the denial. Run sudo semodule -DB, reproduce the failure, search again, and then restore the normal rules with sudo semodule -B. A third cause to check is the time window: recent covers only 10 minutes, so try -ts today.
Exercise
audit2why reports "Missing type enforcement (TE) allow rule" for httpd_t reading a file in /srv/web labeled var_t. Should you run audit2allow next? Give the better fix.
Show answer
No. The file has a generic type that is wrong for web content. Add a labeling rule with sudo semanage fcontext -a -t httpd_sys_content_t "/srv/web(/.*)?", apply it with sudo restorecon -Rv /srv/web, and retest. A custom module is a last resort for access that no label, port or boolean can fix.