In this article, we’ll explore how SELinux manages file and process contexts, offering an extra layer of security that goes beyond standard Linux file permissions. Traditional permissions (read, write, execute) are essential, but they may not fully protect your system against sophisticated attacks. SELinux enhances system security by confining processes and applying strict mandatory access control policies. For example, imagine a web server running within a dedicated directory. If an attacker compromises the web server, they inherit its directory permissions, potentially exploiting system vulnerabilities. SELinux prevents this by isolating processes through detailed security contexts based on SELinux labels. On systems like CentOS Stream, SELinux is enabled by default, ensuring that even if a process is breached, its actions remain confined.Documentation Index
Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
Use this file to discover all available pages before exploring further.
Viewing Standard Permissions
The basic Linux commandls -l can be used to display the standard file and directory permissions:
Understanding SELinux Context Labels
SELinux introduces an additional security layer by assigning each file and process a security context label. This label comprises four components in the following order: user, role, type, and level. Consider the example label below:-
User:
unconfined_u
Represents the SELinux user defined within the SELinux policy, which may differ from the Linux login username. -
Role:
object_r
Specifies the role that helps determine permitted operations. -
Type:
user_home_t
Defines the allowed operations for the file or process and effectively serves as a security “jail.” -
Level:
s0
Often used for multi-level security in organizations, indicating the sensitivity level of the object.
Remember: In SELinux, only files with the correct type (e.g.,
sshd_exec_t for SSH daemon) can initiate a process that transitions into the corresponding security domain.Exploring Process Contexts
Processes also carry SELinux security contexts. You can check the SELinux labels for running processes using theps command with the -Z option:
sshd) runs within the sshd_t domain. Strict policies enforce that only files labeled with the correct type (in this case, often sshd_exec_t) can start a process that enters this domain. Conversely, processes running with the unconfined_t label operate with minimal restrictions.
Viewing the Current User’s SELinux Context
To determine your current SELinux security context, use theid command with the -Z option:
The default mapping assigns non-root users to the
unconfined_u SELinux user, ensuring that even root processes are subject to the same security policies.Checking SELinux Enforcement Status
To check if SELinux is actively enforcing its security policies, use thegetenforce command:
- Enforcing: SELinux policies are enforced, and unauthorized actions are blocked.
- Permissive: SELinux is not actively enforcing policies but logs actions that would have been denied.
- Disabled: SELinux is turned off, and no access control is performed.