1 About Administering SELinux in Oracle Linux
This chapter describes the SELinux feature and provides tasks for administering SELinux on Oracle Linux systems.
Note:
The content in this document was tested against Oracle Linux 8 and Oracle Linux 9, but also applies to most Oracle Linux releases, and might also apply to other distributions.
Traditional Linux security is based on a Discretionary Access Control (DAC) policy, which
provides minimal protection from broken software or from malware that's running as a normal
user or as root
. Access to files and devices is based solely on user identity
and ownership. Malware or broken software can do anything with files and resources that the
user that started the process can do. If the user is root
or the application
is setuid
or setgid
to root
, the process
can have root
-access control over the entire file system.
The National Security Agency created Security Enhanced Linux (SELinux) to provide a finer-grained level of control over files, processes, users, and applications in the Linux OS. The SELinux enhancement to the Linux kernel implements the Mandatory Access Control (MAC) policy, which enables you to define a security policy that provides granular permissions for all users, programs, processes, files, and devices. The kernel's access control decisions are based on all the security relevant information available, and not solely on the authenticated user identity.
When security-relevant access occurs, such as when a process opens a file, SELinux intercepts the operation in the kernel. If a MAC policy rule allows the operation, it continues. Otherwise, SELinux blocks the operation and returns an error to the process. The kernel checks and enforces DAC policy rules before MAC rules, so it doesn't check SELinux policy rules if DAC rules have already denied access to a resource.
SELinux Package Descriptions
SELinux contains several packages, each of which contain specific utilities that you can use to administer SELinux on Oracle Linux systems. Some packages are installed by default, while other packages are optional.
The following table describes the SELinux packages that are installed by default with Oracle Linux.
Package | Description |
---|---|
|
Provides utilities such as load_policy, restorecon, secon, setfiles, semodule, sestatus, and setsebool for operating and managing SELinux. |
|
Provides the API that SELinux applications use to get and set process and file security contexts, and to obtain security policy decisions. |
|
Contains Python bindings for developing SELinux applications. |
|
Provides the SELinux Reference Policy, which is used as the basis for other policies, such as the SELinux targeted policy. |
|
Provides the SELinux targeted policy, where objects outside the targeted domains run under DAC. |
|
Provides the avcstat, getenforce, getsebool, matchpathcon, selinuxconlist, selinuxdefcon, selinuxenabled, setenforce, and togglesebool utilities. |
The following table describes useful SELinux packages that aren't installed by default.
Package | Description |
---|---|
|
Translates SELinux levels, such as
|
|
Provides Python utilities for operating SELinux, such as audit2allow, audit2why, chcat, and semanage. |
|
Provides a strict Multi-Level Security (MLS) policy as an alternative to the SELinux targeted policy. |
selinux-policy-doc
|
Provides manual pages for many SELinux policy elements. |
|
Enables you to view |
|
Translates access-denial messages from SELinux into detailed descriptions that you can view on the command line using the sealert command. |
|
Provides the Tresys Technology SETools distribution of tools and libraries, which you can use to analyze and query policies, monitor and report audit logs, and to manage file context. |
Use the dnf command or another suitable package manager to install SELinux packages that you require for the system.
For more information, see the
SELinux
Project Wiki, the selinux(8)
manual
page, and other manual pages for the SELinux commands.
Using SELinux Utilities
The following table describes the utilities that you can use to administer SELinux and information about the packages that contain each utility.
Utility | Package | Description |
---|---|---|
audit2allow |
|
Generates SELinux policy
|
audit2why |
|
Generates SELinux policy
|
avcstat |
|
Displays statistics for the SELinux Access Vector Cache (AVC). |
chcat |
|
Changes or removes the security category for a file or user. |
findcon |
|
Searches for file context. |
fixfiles |
|
Fixes the security context for file systems. |
getenforce |
|
Reports the current SELinux mode. |
getsebool |
|
Reports SELinux Boolean values. |
indexcon |
|
Indexes file context. |
load_policy |
|
Loads a new SELinux policy into the kernel. |
matchpathcon |
|
Queries the system policy and displays the default security context that's associated with the file path. |
replcon |
|
Replaces file context. |
restorecon |
|
Resets the security context on one or more files. |
restorecond |
|
Daemon that watches for file creation and sets the default file context. |
sandbox |
|
Runs a command in an SELinux sandbox. |
sealert |
|
Acts as the user interface to the |
sechecker |
|
Checks SELinux policies. |
secon |
|
Displays the SELinux context from a file, program, or user input. |
sediff |
|
Compares SELinux polices. |
seinfo |
|
Queries SELinux policies. |
selinuxconlist |
|
Displays all SELinux contexts that are reachable by a user. |
selinuxdefcon |
|
Displays the default SELinux context for a user. |
selinuxenabled |
|
Indicates whether SELinux is enabled. |
semanage |
|
Manages SELinux policies. |
semodule |
|
Manages SELinux policy modules. |
semodule_deps |
|
Displays the dependencies between SELinux policy packages. |
semodule_expand |
|
Expands a SELinux policy module package. |
semodule_link |
|
Links SELinux policy module packages together. |
semodule_package |
|
Creates a SELinux policy module package. |
sesearch |
|
Queries SELinux policies. |
sestatus |
|
Displays the SELinux mode and the SELinux policy that are in use. |
setenforce |
|
Changes the SELinux mode. |
setsebool |
|
Sets SELinux Boolean values. |
setfiles |
|
Sets the security context for one or more files. |
togglesebool |
|
Flips the current value of an SELinux Boolean. |
Setting SELinux Modes
SELinux runs in one of three modes:
-
Disabled
-
The kernel uses only DAC rules for access control. SELinux doesn't enforce any security policy because no policy is loaded into the kernel.
-
Enforcing
-
The kernel denies access to users and programs if they aren't granted permissions by SELinux security policy rules. All denial messages are logged as AVC (Access Vector Cache) denials. This is the default mode that enforces SELinux security policy.
-
Permissive
-
The kernel doesn't enforce security policy rules but SELinux sends denial messages to a log file. In this manner, you can see what actions would have been denied if SELinux were running in enforcing mode. This mode is intended to be used for diagnosing the behavior of SELinux.
To display current SELinux mode:
getenforce
Enforcing
:
sudo setenforce enforcing
Permissive
:
sudo setenforce permissive
The current value that you set for a mode using setenforce doesn't
persist across reboots. To configure the default SELinux mode, edit the configuration file for
SELinux, /etc/selinux/config
, and set the value of the
SELINUX
directive to disabled
, enforcing
,
or permissive
.
Getting More Information
SELinux is complex. You can obtain information about different policies more easily by
installing the selinux-policy-doc
package and then navigating the associated
manual pages.
- Install the package:
sudo dnf install -y selinux-policy-doc
- Update the manual page database:
sudo mandb
- Start searching through the new SELinux policy manual pages. To get a complete listing of
all the SELinux manual documentation, run:
man -k _selinux
The policy documentation contains information about users and roles. For example, you can
read more about the SELinux unprivileged user_u
user and the
user_r
role in the user_selinux(8)
manual page. The policy
documentation outlines the restrictions applied for different security contexts and what
Boolean options are available to you to customize the policy for an environment.