Sub topic 11
Debugging with a Permissive Domain Instead of Disabling SELinux
This chapter assumes that you understand Linux file permissions, sudo, systemctl, and basic SELinux contexts. You should also know the service you are debugging. The examples use Apache and its SELinux domain, httpd_t.
Why use a permissive domain?
SELinux has three system-wide modes:
- Enforcing blocks actions that the policy denies and records AVC denials.
- Permissive records denials but allows the actions.
- Disabled does not load SELinux policy.
Changing the whole system to permissive mode hides problems for every confined service. Disabling SELinux removes its protection and can require a full relabel when you enable it again.
A permissive domain is narrower. It makes one SELinux domain, such as httpd_t, log its denials without enforcing them. Other domains remain enforcing.
| Change | Scope | Protection for other domains |
|---|---|---|
| `setenforce 0` | Entire system | Reduced |
| `semanage permissive -a httpd_t` | One domain | Remains enforced |
| Disabling SELinux | Entire system | Removed |
Use a permissive domain only for a short, controlled debugging session. It tells you what the service attempts to do, but it does not prove that every logged denial is a required action.
A controlled debugging workflow
First confirm the current mode and check whether the domain is already permissive:
getenforce
sudo semanage permissive -lPut only the service domain into permissive mode:
sudo semanage permissive -a httpd_t
sudo systemctl restart httpdReproduce the failure once. For example, request the affected URL or run the operation that causes Apache to fail. Limiting the test makes the audit results easier to interpret.
Then inspect recent AVC records:
sudo ausearch -m avc -ts recent -c httpd
sudo ausearch -m avc -ts recent -c httpd --raw | audit2whyAn AVC record identifies the source context, target context, attempted class, and permission. Pay particular attention to the source type, such as httpd_t, and the target type, such as default_t or httpd_sys_content_t.
Remove the exception after collecting and reviewing the evidence:
sudo semanage permissive -d httpd_t
sudo systemctl restart httpd
sudo ausearch -m avc -ts recent -c httpdThe last command can confirm that later tests produce denials again when enforcement is restored. Existing audit records remain in the log, so use a time range or a fresh test to separate old and new events.
Choosing the next fix
Use the denial to select the least broad correction:
- A web file has the wrong type: add a persistent
semanage fcontextrule and runrestorecon. - The service needs an optional capability: inspect and enable the relevant SELinux Boolean.
- The service binds to an unusual port: label the port with
semanage port. - No label, Boolean, or port fix fits: inspect the proposed rules and consider a small custom module.
Exercise
Why is semanage permissive -a httpd_t safer for debugging than setenforce 0?
Show answer
It relaxes enforcement only for the Apache domain. SELinux continues enforcing policy for other domains, reducing the scope of the temporary exception.