Administering SELinux in Oracle Linux
Describes SELinux and provides guidance on administering SELinux in Oracle Linux.
Traditional Linux security is based on a Discretionary Access Control (DAC) policy. In the
DAC model of system security, access to resources such as files and processes is based solely
on user identity and ownership. If malware or broken software is present on the system, it can
do anything with files and resources that the user that started the process has permission to
do. If the user is root or the application is running with elevated
privileges (setuid or setgid to root), the
process has root-access control over the entire file system.
To address this problem, the National Security Agency created Security Enhanced Linux (SELinux) to provide a greater 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 lets you define a security policy that configures granular permissions for all users, programs, processes, files, and devices. The kernel's access control decisions are based on how sensitive the resources are from a security perspective, 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 lists the SELinux packages installed by default with Oracle Linux.
|
Package |
Description |
|---|---|
|
|
Provides utilities such as |
|
|
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 |
The following table lists useful SELinux packages that aren't installed by default.
Install any required packages using the dnf command.
|
Package |
Description |
|---|---|
|
|
Translates SELinux levels, such as |
|
|
Provides Python utilities for operating SELinux, such as
|
|
|
Provides the sandbox utility for creating SELinux sandboxes to run commands in a tightly confined SELinux domain. |
|
|
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. |
|
|
Lets you view |
|
|
Translates access-denial messages from SELinux into detailed descriptions that you
can view on the command line using the |
|
|
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 manage file context. |
For more information, see the SELinux Project Wiki for community documentation and the
selinux(8) and other SELinux command manual pages.
SELinux Utilities
The following table describes the main utilities that you can use to administer SELinux and the packages that contain them.
|
Utility |
Package |
Description |
|---|---|---|
|
|
|
Generates SELinux policy |
|
|
|
Analyzes denial logs to explain why access was blocked and recommends relevant SELinux adjustments. |
|
|
|
Displays statistics for the SELinux Access Vector Cache (AVC). |
|
|
|
Changes or removes the security category for a file or user. |
|
|
|
Changes the SELinux context of files and directories. |
|
|
|
Fixes the security context for file systems. |
|
|
|
Reports the current SELinux mode. |
|
|
|
Reports SELinux Boolean values. |
|
|
|
Loads a new SELinux policy into the kernel. |
|
|
|
Queries the system policy and displays the default security context that's associated with the file path. |
|
|
|
Resets the security context on one or more files. |
|
|
|
Daemon that watches for file creation and sets the default file context. |
|
|
|
Runs a command within the specified context. |
|
|
|
Runs a command within an SELinux sandbox. |
|
|
|
Acts as the user interface to the |
|
|
|
Checks SELinux policies. |
|
|
|
Displays the SELinux context from a file, program, or user input. |
|
|
|
Compares SELinux polices. |
|
|
|
Queries SELinux policies. |
|
|
|
Displays all SELinux contexts that are reachable by a user. |
|
|
|
Displays the default SELinux context for a user. |
|
|
|
Indicates whether SELinux is enabled. |
|
|
|
Manages SELinux policies. |
|
|
|
Manages SELinux policy modules. |
|
|
|
Displays the dependencies between SELinux policy packages. |
|
|
|
Expands a SELinux policy module package. |
|
|
|
Links SELinux policy module packages together. |
|
|
|
Creates a SELinux policy module package. |
|
|
|
Queries SELinux policies. |
|
|
|
Displays the SELinux mode and the SELinux policy that are in use. |
|
|
|
Changes the SELinux mode. |
|
|
|
Sets SELinux Boolean values. |
|
|
|
Sets the security context for one or more files. |
Setting SELinux Modes
SELinux runs in either enforcing or permissive mode:
-
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.
-
permissive -
The kernel doesn't enforce security policy rules but SELinux sends denial messages to a log file. This lets you see what actions would be denied if SELinux is running in
enforcingmode. Use this mode to help you implement SELinux in a system effectively.
To display the current SELinux mode, run the following command:
getenforce
To set the current mode to enforcing, run the following command:
sudo setenforce enforcing
To set the current mode to permissive, run the following command:
sudo setenforce permissive
The 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 enforcing, or
permissive.
Disabling SELinux
You can fully disable SELinux by setting the selinux kernel
parameter to zero.
Oracle doesn't recommend disabling SELinux in production systems. Use
permissive mode instead.
Installing Policy Documentation
SELinux is complex, with many options for configuring access, using policies. You can obtain
detailed information about the available policies from the manual pages that the
selinux-policy-doc package provides. This task shows you how to access
this information.
The policy documentation also 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 that apply for different security contexts
and what Boolean options are available to customize the policy for an environment.