Lion Cipher Lab

Confine a service with SELinux: break nginx twice, then fix the labels properly

Why it matters

Ordinary Linux permissions answer the question "which USER is allowed to touch this file?" That model collapses the moment an attacker exploits your web server, because the attacker is now running AS the web server's user and inherits everything that user may read. Mandatory access control answers a different question — "is this PROGRAM allowed to do this specific thing, ever?" — and the kernel enforces the answer even against a fully compromised process. SELinux is the mandatory access control system on Fedora, RHEL, AlmaLinux, Rocky, CentOS Stream, Android and a large slice of the servers…

What you'll learn

Steps in this lab

  1. The one idea: permissions ask WHO, SELinux asks WHAT PROGRAM
  2. Get a real Fedora-family VM — and why a container will not do
  3. Confirm SELinux is enforcing, and install the tools
  4. Read the labels: ls -Z, ps -Z, id -Z
  5. Break it #1: serve from /srv/mysite with flawless permissions
  6. Hunt the denial: AVC lines in the audit log
  7. Fix it the right way: semanage fcontext, then restorecon
  8. Break it #2: SELinux labels PORTS too
  9. Booleans: the switches policy already ships for you
  10. audit2allow — the tool that will get you in trouble
  11. The judgment: labels vs paths, permissive vs disabled, and what MAC is not

Open the full interactive lab →