SELinux

SELinux enforcing/permissive modes, contexts, audit2allow, chcon, semanage, and restorecon.

Overview

SELinux (Security-Enhanced Linux) is a Mandatory Access Control (MAC) system built into the Linux kernel. Unlike Discretionary Access Control (DAC — the traditional Unix permission model), SELinux enforces policy rules that even the root user cannot override. Every process and file is labeled with a security context, and the policy defines which process labels may access which file labels.

MAC vs DAC

DAC (traditional Unix permissions): the file owner decides who can access the file. Root can bypass all DAC restrictions. If a process is compromised, it inherits all the permissions of the user running it.

MAC (SELinux): the security policy — written by administrators and defined by the OS vendor — controls access. Even root cannot access a resource if the SELinux policy denies it. A compromised web server running as root cannot read /etc/shadow if the policy prohibits httpd_t from accessing shadow_t files.

Key concepts

  • Security context
  • AVC denial
  • chcon
  • semanage fcontext
  • restorecon
  • audit2allow
  • setsebool

Interview questions

  • Nginx fails to serve files from /srv/mysite. You see "Permission denied" in the error log. Walk through the SELinux diagnosis and fix.
  • What is audit2allow and when should you use it vs writing a proper policy?

Sign up free to read the full topic

More Linux topics

Start free on Cariara · Coding problems · System design studio