USD ($)
$
United States Dollar
Euro Member Countries
India Rupee
د.إ
United Arab Emirates dirham
ر.س
Saudi Arabia Riyal

Mandatory Access Control (SELinux/AppArmor Detailed Configuration)

Lesson 9/31 | Study Time: 20 Min

Mandatory Access Control (MAC) is an essential component of Linux security that supplements traditional discretionary access controls (DAC) by enforcing strict, system-wide security policies.

Unlike DAC, where the owner controls access, MAC enforces predefined rules that all subjects and objects must follow, reducing the risk of unauthorized access and privilege escalation. Two major MAC implementations on Linux are Security-Enhanced Linux (SELinux) and AppArmor. 

Overview of Mandatory Access Control (MAC)

MAC systems enforce security policies centrally by controlling how processes (subjects) access files, sockets, devices, and other resources (objects) based on security labels or profiles. The goal of MAC is to confine processes to the minimum required permissions, limiting potential damage from compromised applications.

SELinux Detailed Configuration

SELinux uses a policy-driven security model in which security contexts are assigned to files, processes, and network ports to control access. Each context is represented as a label consisting of user, role, type, and level components (for example, system_u:system_r:sshd_t:s0), and these labels determine what actions an entity is permitted to perform.

SELinux policies define granular allow or deny rules based on these contexts, making the system highly customizable and capable of enforcing strong, fine-grained access control.


Core SELinux Components


1. Targeted policy: Focuses on confining specific services (default in many distros).

2. MLS (Multi-Level Security) policy: Enforces hierarchical security levels, often for government use.

3. Booleans: Runtime toggles to enable/disable specific rules without recompiling policy.


Configuring SELinux


1. Configuration file: /etc/selinux/config


Set mode: SELINUX=enforcing|permissive|disabled

Set policy: SELINUXTYPE=targeted|mls|strict


2. Modify file contexts with semanage fcontext -a -t [type] [file]

3. Apply context changes with restorecon -Rv [path]

4. Manage booleans with getsebool and setsebool

5. Audit logs for violations found in /var/log/audit/audit.log; use ausearch and sealert for analysis.


Example: Allowing Apache to Communicate


1. Enable HTTPD network connection:

text
setsebool -P httpd_can_network_connect on


2. Allow writing to specific directories:

text
semanage fcontext -a -t httpd_sys_rw_content_t "/var/www/html(/.*)?"
restorecon -Rv /var/www/html

AppArmor Detailed Configuration

AppArmor implements mandatory access control (MAC) by using per-application profiles that define path-based access permissions. These profiles specify which files, capabilities, and network resources a confined program is allowed to access, thereby limiting its behavior even if it is compromised.

Compared to SELinux, AppArmor is generally easier for many administrators to create, understand, and maintain due to its simpler, more intuitive policy structure.


Configuring AppArmor


1. Profiles are stored in /etc/apparmor.d/.

2. Profiles define:


File access permissions (r, w, m, etc.).

Network permissions.

Capability rules.


3. Use aa-status to check current enforcement.

4. Load/unload profiles using apparmor_parser.

5. Put a profile into complain mode:

text
aa-complain /etc/apparmor.d/profile_name


6. Switch to enforce mode:

text
aa-enforce /etc/apparmor.d/profile_name


Example: Tightening a Profile for an Application


1. Edit profile to restrict access to only necessary files.

2. Add network or capability restrictions as needed.

3. Reload profile after changes.

SELinux vs. AppArmor

Andrew Foster

Andrew Foster

Product Designer
Profile

Class Sessions

1- Linux Security Model Overview 2- Kernel-Level Security Features (Namespaces, Capabilities, SELinux, AppArmor) 3- Linux File System Permissions and Extended Attributes (Xattr) 4- Secure User and Group Management Fundamentals 5- Best Practices for Sudo Configuration and Privilege Escalation Control 6- Disabling Unneeded Services and Configuring Secure Boot 7- Firewall Setup: Iptables/Nftables Basics and Advanced Rule Creation 8- Securing SSH: Key Management, Configuration, and Tunneling 9- Mandatory Access Control (SELinux/AppArmor Detailed Configuration) 10- Deployment of PAM for Enhanced Authentication 11- Linux Network Namespaces and Container Isolation Basics 12- TLS/SSL Configuration for Linux Services 13- VPN Setup for Secure Remote Access (OpenVPN, WireGuard) 14- Cryptographic Tools: GPG Encryption, Hashing Utilities, and Key Management 15- Intrusion Detection Systems and Log Monitoring Tools Overview 16- Linux Audit Framework (Auditd) Configuration and Log Analysis 17- Using Syslog, Journald, and Centralized Logging Solutions 18- File Integrity Monitoring with AIDE And Tripwire 19- Compliance Frameworks Introduction (PCI DSS, GDPR, HIPAA) 20- Incident Response Preparation and Forensic Readiness Basics 21- Bash Scripting Best Practices for Security and Automation 22- Conditional Logic, Loops, and Functions for Modular Scripts 23- Handling Errors, Signals, and Debugging Scripts Effectively 24- Automating User and Permission Audits with Scripts 25- Integrating Shell Scripts with System Tools (Cron Jobs, Systemd Timers) 26- Automating Log Analysis and Alerting Via Scripting 27- Writing Scripts for Automated Patch and Vulnerability Management 28- Automating Firewall and SSH Key Rotation Policies 29- Integrating Shell Scripts with Security Scanning Tools (Lynis, OpenVAS) 30- Case Studies on Automated Incident Detection and Response 31- Using Open-Source Tools for Orchestration with Scripting

Sales Campaign

Sales Campaign

We have a sales campaign on our promoted courses and products. You can purchase 1 products at a discounted price up to 15% discount.