Stop playing whackmole with SELinux denials by auditing context transitions
By Saket Jain Published Linux/Unix
Stop playing whack-a-mole with SELinux denials by auditing context transitions
Technical Briefing | 11/23/2026
Every time I see someone set SELinux to permissive mode because they cannot get a service to talk to a file, a little part of my sysadmin soul dies. We have all been there. You deploy a custom binary or move a directory, and suddenly everything throws a 13 permission denied error. Most people start hacking at policies they do not understand, or worse, they permanently drop their security posture to keep the app running. The fix is rarely making the policy more permissive; it is usually just fixing the file context.
Why your custom files inherit the wrong labels
The kernel tracks file contexts via extended attributes. If you create a file or move it from a temporary location like /tmp, it often carries a default label that your production service is forbidden to read. Trying to force a policy change to allow that access is exactly how you open security holes you will forget about in six months. Instead, you need to verify if the file context actually matches what the policy expects for that directory structure.
matchpathcon -v /var/www/html/my-app/config.json
- Use matchpathcon to compare the current context with the system default
- Run restorecon -vR to force the filesystem to apply correct labels recursively
- Check /var/log/audit/audit.log specifically for scontext and tcontext pairs
- Stop running setenforce 0 unless you are actively debugging a specific trace
The real trap is thinking that policy modules are the only way to manage access. If you find yourself writing custom interface definitions for basic file operations, you are likely working harder, not smarter. Always check if the files are labeled correctly first. If the labels are right and you still get a denial, then check your booleans. If that still fails, then and only then should you think about building a custom policy. Most of the time, the fix is just one restorecon command away.
