Course contentsShow
← Linux
Lesson 915 of 1,8199. Security Hardening and Mandatory Access ControlFree lesson

Determining the Enforcement Mode

Switch between enforcing, permissive, and disabled states to test system impact before applying restrictions.

In this lesson, you will learn how to safely transition between SELinux enforcement states to validate security policies without risking system instability.

Understanding Enforcement States

When working with Mandatory Access Control (MAC) systems like SELinux, you have three primary modes that dictate how the kernel handles security violations:

  • Enforcing: The kernel actively blocks actions that violate the loaded security policy and logs these denials. This is the goal for a production system.
  • Permissive: The kernel does not block any actions, but it continues to log what would have been blocked. This is your primary diagnostic tool.
  • Disabled: The security policy is not loaded. This is generally avoided, as it bypasses all MAC protections entirely.

Switching Modes for Testing

The safest way to harden a system is to start in Permissive mode. This allows you to observe how your applications interact with the policy without breaking functionality.

You can check your current mode using the getenforce command:

getenforce

If you need to switch to Permissive mode temporarily to debug a service startup or a file access issue, use the setenforce command:

# Switch to Permissive mode
setenforce 0

# Switch back to Enforcing mode
setenforce 1

Why Use Permissive Mode?

Imagine you are deploying a new web application. If you jump straight into Enforcing mode, your application might fail immediately due to a missing security label, making it difficult to pinpoint the cause. By running in Permissive mode first, the system allows the app to run while recording every violation in the audit logs (usually found in /var/log/audit/audit.log). Once the logs are clean—meaning no "denied" messages appear—you can confidently toggle back to Enforcing mode knowing your policies are tuned to your specific environment.

Remember that setenforce changes the mode for the current runtime only. To make persistent changes across reboots, you must edit the /etc/selinux/config file. Always test thoroughly in Permissive before moving to a fully Enforcing production state.

Key Takeaway: Use Permissive mode as a sandbox to audit security policy compliance without interrupting system operations before graduating to Enforcing mode.