Kahibaro
Discord Login Register

SELinux and AppArmor overview

Why Mandatory Access Control Exists

Traditional Unix permissions and ownership are discretionary: the owner of a file (or root) decides who can do what. If an application is compromised, it can usually do anything its user (or root) could do.

Mandatory Access Control (MAC) systems like SELinux and AppArmor add an extra, kernel‑enforced security layer:

On many enterprise or security‑focused distributions, SELinux or AppArmor is enabled by default.

This chapter gives you just enough to recognize both systems, understand what they do, and know where to look when they block something.

SELinux: The Basics

Security‑Enhanced Linux (SELinux) is a MAC system originally developed by the NSA and now widely used, especially in RHEL, CentOS Stream, Fedora, and Rocky/AlmaLinux.

Core Ideas

SELinux adds labels and policies on top of normal permissions:

  system_u:system_r:httpd_t:s0
  system_u:object_r:httpd_sys_content_t:s0

You’ll usually see the type field referenced most (e.g. httpd_t, ssh_t, httpd_sys_content_t).

Modes: Enforcing, Permissive, Disabled

You’ll commonly see SELinux in one of three modes:

To check mode:

getenforce
# or
sestatus

Typical outputs: Enforcing, Permissive, or Disabled.

Switching temporarily (runtime only, requires root and SELinux not disabled):

setenforce 0   # Permissive
setenforce 1   # Enforcing

Permanent mode changes are done in SELinux config files (distribution‑specific; usually /etc/selinux/config), not covered in detail here.

Types of SELinux Policies (High Level)

Distributions ship with a policy that defines how SELinux behaves. Common types:

For intermediate system administration, you will almost always deal with a targeted policy.

Common SELinux Tools You’ll Encounter

You don’t need to master them now, but recognize these names when you see them in documentation or troubleshooting guides:

Example showing file labels:

ls -Z /var/www/html
-rw-r--r--. root root system_u:object_r:httpd_sys_content_t:s0 index.html

SELinux in the Real World: Simple Scenarios

These are typical patterns you may see when SELinux is involved.

Example: Web Server Cannot Read Content

Symptom: httpd (Apache) is running, permissions look fine, but content under a non‑standard directory isn’t served.

Quick checks:

  ls -Zd /srv/myweb

The usual pattern to fix this (conceptually):

  1. Define the right file context mapping with semanage fcontext.
  2. Apply it with restorecon.

(Exact commands and deeper usage belong to troubleshooting‑focused material.)

Example: Denials in Logs

When SELinux denies something, it logs to:

You might see brief hints like:

SELinux is preventing /usr/sbin/httpd from read access on the file /srv/myweb/index.html.

Or a raw avc: denied line. Tools like sealert (when available) can interpret these messages and suggest policy or configuration changes.

AppArmor: The Basics

AppArmor is another MAC system, but with a different design philosophy. It’s used by Ubuntu, openSUSE, and some others.

Core Ideas

While SELinux is label‑based, AppArmor is primarily path‑based:

Example conceptual rule (not full syntax):

Modes: Enforce and Complain

Each AppArmor profile can be in its own mode:

AppArmor itself can be enabled or disabled at the system level (boot parameters, service state), but at the day‑to‑day level you often interact with profile modes.

On Ubuntu, typical tools:

AppArmor Profiles

Profiles are usually stored under:

You’ll see one file per confined application, such as:

Profiles:

SELinux vs AppArmor: Conceptual Differences

For an intermediate admin, you mainly need to recognize:

You normally don’t run both at the same time on the same system; distributions standardize on one.

Typical Beginner‑Level Interactions

As a beginner/intermediate system administrator, the ways you’ll most often touch these systems are:

When to Learn More

You don’t need to write policies or profiles at this stage, but it’s helpful to know:

Knowing that SELinux and AppArmor are the kernel‑level policy engines that may allow or block actions even when file permissions look correct is the key takeaway at this stage.

Views: 20

Comments

Please login to add a comment.

Don't have an account? Register now!