Q: An application runs fine, but SELinux denies a critical system call with "Permission Denied" (avc denial). Standard Unix permissions show the file is readable. How do you diagnose and temporarily allow the access?
SELinux is a Mandatory Access Control (MAC) layer that sits *above* traditional Unix permissions (DAC). Even if a file is 644, SELinux can block access if the policy says the process's domain is not allowed.
Want to master this scenario in a live sandbox? The Linux Foundation's Certified System Administrator (LFCS) & SRE Track covers this exact problem with hands-on terminal drills.
🛠️ Production Runbook & Step-by-Step Resolution
Direct Answer: "Never reboot a server blindly; always capture top process telemetry, lsof descriptors, and thread dumps first. The interviewer is testing: Mandatory Access Control (MAC) vs Discretionary Access Control (DAC), SELinux policy debugging.. I structure my answer around systematic triage first, root cause analysis second, and permanent remediation third."
Initial Diagnostics & Root Cause Analysis
SELinux is a Mandatory Access Control (MAC) layer that sits *above* traditional Unix permissions (DAC). Even if a file is 644, SELinux can block access if the policy says the process's domain is not allowed.
- Check the audit log:
audit2whyorgrep AVC /var/log/audit/audit.logshows the exact denial. Example: - Temporary fix (debug mode): Set SELinux to Permissive mode for the domain:
- Permanent fix: Either:
Remediation & Permanent Safeguards
When a denial occurs: This shows httpd_t domain trying to read a user_home_t file—denied by policy. This logs denials but allows the process to operate, helping identify which accesses are actually needed.
type=AVC msg=... avc: denied { read } for pid=1234 comm="apache" name="config.txt" scontext=system_u:system_r:httpd_t:s0 tcontext=staff_u:object_r:user_home_t:s0
- Change the file's SELinux context:
chcon -t httpd_sys_rw_content_t /var/www/config.txt - Write a custom policy module using
audit2allowto automatically generate rules from audit logs.
- Check the audit log: audit2why or grep AVC /var/log/audit/audit.log shows the exact denial. Example:
- Temporary fix (debug mode): Set SELinux to Permissive mode for the domain:
- Permanent fix: Either:
Senior hiring managers and bar raisers evaluate how you prioritize during outages. Avoid these common anti-patterns:
- Issuing immediate kill -9 (SIGKILL) commands rather than allowing graceful termination via kill -15 (SIGTERM) when configuring application runs fine SIGKILL immediately halts execution without allowing processes to flush memory buffers, commit database transactions, or remove stale PID locks.
-
Overlooking file system inode exhaustion (df -i) when diagnosing 'No space left on device' errors when configuring application runs fine
Millions of small files or unrotated session tokens can exhaust available file system inodes even when standard disk storage (
df -h) shows ample free space. - Exhausting open file descriptor allocations (ulimit -n) under intensive concurrent socket connections when configuring application runs fine Reaching file descriptor exhaustion throws 'Too many open files' errors, preventing services from accepting new TCP client socket connections.
-
Permitting defunct zombie processes to accumulate without fixing parent process SIGCHLD waitpid reaping when configuring application runs fine
Zombie processes consume process table entries; accumulating zombies can exhaust the system maximum PID limit (
pid_max).