Sub topic 1
Why file permissions are not enough: DAC and MAC
Prerequisites
This chapter assumes that you can use the Linux command line, run commands with sudo, read file ownership and permission bits, and understand that a service runs as a user account such as apache or nginx. You should also know how to inspect a service with systemctl and its logs with journalctl.
The two access-control layers
Linux normally uses discretionary access control (DAC). DAC is the traditional permission system controlled by file owners and administrators. Each file has an owner, a group, and permission bits for the owner, group, and everyone else.
For example, these permissions allow the owner to read and write a file, allow the group to read it, and deny access to everyone else:
-rw-r----- 1 root web 1842 Nov 28 05:00 /srv/web/index.htmlThe process identity determines which DAC permissions apply. A web server running as apache may be denied because it is not the owner and is not in the web group.
Mandatory access control (MAC) adds another decision made by a system-wide security policy. On RHEL-family systems, SELinux provides MAC. The policy describes which confined processes may access which labeled files, directories, ports, and other resources.
A request succeeds only when both layers allow it:
| DAC result | SELinux result | Final result |
|---|---|---|
| Allow | Deny | Denied |
| Allow | Allow | Allowed |
| Deny | Allow | Denied |
The owner of a file cannot normally override a MAC rule by changing its permission bits. An administrator may change SELinux policy, but that is a separate policy action.
Why a compromised service needs MAC
Suppose an attacker exploits a web application. The application may already have DAC permission to read configuration files, write uploads, or connect to local resources. DAC cannot distinguish between every action that the same Unix user performs.
SELinux places the service in a domain, which is a label describing the security context of a process. Files also have labels called types. A policy can allow the httpd_t domain to read files of type httpd_sys_content_t, while denying it access to a database's private files, even when ordinary Unix permissions appear permissive.
This defense is useful because services often handle untrusted input. If the service is compromised, SELinux can limit the damage to the resources that the service policy explicitly permits.
A common troubleshooting mistake
A service failure does not prove that SELinux caused it. First check ordinary ownership and permission bits. Then inspect SELinux status and contexts:
ls -l /var/www/html/index.html
getenforce
ls -Z /var/www/html/index.html
ps -eZ | grep httpdA file can have correct DAC permissions but the wrong SELinux type. Conversely, a correctly labeled file still fails if its owner or mode denies the service account. Avoid “fixing” an SELinux denial by making every file world-readable or by running the service as root. Those changes weaken DAC without addressing the policy model.
Exercise
Exercise
A file is readable by the apache user according to ls -l, but Apache still receives “Permission denied.” What should you check next?
Show answer
Check whether SELinux is enforcing and inspect the file and Apache process contexts with getenforce, ls -Z, and ps -eZ. A policy denial may be blocking access even though DAC allows it.