Chapter 2. SELinux Contexts
ls -Z file1-rwxrw-r-- user1 group1 unconfined_u:object_r:user_home_t:s0 file1
- SELinux user
- The SELinux user identity is an identity known to the policy that is authorized for a specific set of roles, and for a specific MLS/MCS range. Each Linux user is mapped to an SELinux user using SELinux policy. This allows Linux users to inherit the restrictions placed on SELinux users. The mapped SELinux user identity is used in the SELinux context for processes in that session, in order to define what roles and levels they can enter. Enter the following command as root to view a list of mappings between SELinux and Linux user accounts (you need to have the policycoreutils-python package installed):
semanage login -lLogin Name SELinux User MLS/MCS Range Service __default__ unconfined_u s0-s0:c0.c1023 * root unconfined_u s0-s0:c0.c1023 * system_u system_u s0-s0:c0.c1023 *Output may differ slightly from system to system:
Login Namecolumn lists Linux users.
SELinux Usercolumn lists which SELinux user the Linux user is mapped to. For processes, the SELinux user limits which roles and levels are accessible.
MLS/MCS Rangecolumn, is the level used by Multi-Level Security (MLS) and Multi-Category Security (MCS).
Servicecolumn determines the correct SELinux context, in which the Linux user is supposed to be logged in to the system. By default, the asterisk (
*) character is used, which stands for any service.
- Part of SELinux is the Role-Based Access Control (RBAC) security model. The role is an attribute of RBAC. SELinux users are authorized for roles, and roles are authorized for domains. The role serves as an intermediary between domains and SELinux users. The roles that can be entered determine which domains can be entered; ultimately, this controls which object types can be accessed. This helps reduce vulnerability to privilege escalation attacks.
- The type is an attribute of Type Enforcement. The type defines a domain for processes, and a type for files. SELinux policy rules define how types can access each other, whether it be a domain accessing a type, or a domain accessing another domain. Access is only allowed if a specific SELinux policy rule exists that allows it.
- The level is an attribute of MLS and MCS. An MLS range is a pair of levels, written as lowlevel-highlevel if the levels differ, or lowlevel if the levels are identical (
s0-s0is the same as
s0). Each level is a sensitivity-category pair, with categories being optional. If there are categories, the level is written as sensitivity:category-set. If there are no categories, it is written as sensitivity.If the category set is a contiguous series, it can be abbreviated. For example,
c0.c3is the same as
/etc/selinux/targeted/setrans.conffile maps levels (
s0:c0) to human-readable form (that is
CompanyConfidential). In Red Hat Enterprise Linux, targeted policy enforces MCS, and in MCS, there is just one sensitivity,
s0. MCS in Red Hat Enterprise Linux supports 1024 different categories:
s0and authorized for all categories.MLS enforces the Bell-La Padula Mandatory Access Model, and is used in Labeled Security Protection Profile (LSPP) environments. To use MLS restrictions, install the selinux-policy-mls package, and configure MLS to be the default SELinux policy. The MLS policy shipped with Red Hat Enterprise Linux omits many program domains that were not part of the evaluated configuration, and therefore, MLS on a desktop workstation is unusable (no support for the X Window System); however, an MLS policy from the upstream SELinux Reference Policy can be built that includes all program domains. For more information on MLS configuration, see Section 4.13, “Multi-Level Security (MLS)”.
2.1. Domain Transitions
entrypointtype for the new domain. The
entrypointpermission is used in SELinux policy and controls which applications can be used to enter a domain. The following example demonstrates a domain transition:
Procedure 2.1. An Example of a Domain Transition
- A user wants to change their password. To do this, they run the
/usr/bin/passwdexecutable is labeled with the
ls -Z /usr/bin/passwd-rwsr-xr-x root root system_u:object_r:passwd_exec_t:s0 /usr/bin/passwdThe
/etc/shadow, which is labeled with the
ls -Z /etc/shadow-r--------. root root system_u:object_r:shadow_t:s0 /etc/shadow
- An SELinux policy rule states that processes running in the
passwd_tdomain are allowed to read and write to files labeled with the
shadow_ttype is only applied to files that are required for a password change. This includes
/etc/shadow, and their backup files.
- An SELinux policy rule states that the
entrypointpermission to the
- When a user runs the
passwdutility, the user's shell process transitions to the
passwd_tdomain. With SELinux, since the default action is to deny, and a rule exists that allows (among other things) applications running in the
passwd_tdomain to access files labeled with the
passwdapplication is allowed to access
/etc/shadow, and update the user's password.
passwd_tdomain to access objects labeled with the
shadow_tfile type, other SELinux policy rules must be met before the subject can transition to a new domain. In this example, Type Enforcement ensures:
passwd_tdomain can only be entered by executing an application labeled with the
passwd_exec_ttype; can only execute from authorized shared libraries, such as the
lib_ttype; and cannot execute any other applications.
- Only authorized domains, such as
passwd_t, can write to files labeled with the
shadow_ttype. Even if other processes are running with superuser privileges, those processes cannot write to files labeled with the
shadow_ttype, as they are not running in the
- Only authorized domains can transition to the
passwd_tdomain. For example, the
sendmailprocess running in the
sendmail_tdomain does not have a legitimate reason to execute
passwd; therefore, it can never transition to the
- Processes running in the
passwd_tdomain can only read and write to authorized types, such as files labeled with the
shadow_ttypes. This prevents the
passwdapplication from being tricked into reading or writing arbitrary files.