Security
Difficulty: Intermediate
3 min read

AppArmor: Securing Linux Applications

Complete guide to install and configure AppArmor on a Linux system in order to harden application security with access control profiles.

Back to tutorials
What is AppArmor?
AppArmor (Application Armor) is a Mandatory Access Control (MAC) system for Linux, built into the kernel. It confines programs to a limited set of resources, thereby reducing the attack surface in the event of a compromise.

Why Use AppArmor?

  • Defense in depth: Adds a layer of security beyond traditional permissions (read, write, execute).
  • Simplicity: Considered easier to learn and manage than its alternative, SELinux. Profiles are based on file paths.
  • Pre-configured: Many distributions (such as Ubuntu) ship with AppArmor profiles pre-enabled for common services.

Prerequisites

  • Operating system: A Linux distribution that supports AppArmor (Ubuntu, Debian, openSUSE...).
  • Privileges: Root access or sudo privileges.

Installation and Activation

Step 1: Check the AppArmor status

AppArmor is often installed and enabled by default. Check its status:

sudo apparmor_status
# More modern alias: sudo aa-status

This command lists the loaded profiles and their mode (enforce or complain).

Step 2: Installation

If AppArmor is not installed, you can install it via your package manager:

# On Debian / Ubuntu
sudo apt-get update
sudo apt-get install -y apparmor apparmor-utils

Step 3: Enabling the service

Make sure the AppArmor service is enabled at boot:

sudo systemctl enable apparmor
sudo systemctl start apparmor
AppArmor is active!
The service is now running and the default profiles are being applied.

Managing AppArmor profiles

Profiles are text files located in /etc/apparmor.d/ that define the permissions for a specific application.

The two operating modes

  • enforce mode: The default mode. AppArmor strictly applies the profile rules and blocks any unauthorized action.
  • complain mode: Permissive mode. AppArmor does not block any action, but logs the violations in the system logs. This is ideal for testing and developing new profiles.

Changing a profile's mode

# Switch the Firefox profile to complain mode
sudo aa-complain /etc/apparmor.d/usr.bin.firefox

# Switch the profile back to enforce mode
sudo aa-enforce /etc/apparmor.d/usr.bin.firefox

Reloading profiles

After modifying a profile, you must reload it for the changes to take effect:

# -r for "replace"
sudo apparmor_parser -r /etc/apparmor.d/usr.bin.firefox

To reload all profiles:

sudo systemctl reload apparmor

Analyzing the logs

Violations of AppArmor rules are recorded in the kernel logs. This is the primary source of information for debugging a profile.

# Using journalctl
sudo journalctl -k | grep "apparmor="DENIED""

# Or directly in the log files
sudo grep "apparmor="DENIED"" /var/log/audit/audit.log
sudo grep "apparmor="DENIED"" /var/log/syslog

Each "DENIED" log line will give you valuable information about the denied operation, the profile concerned and the process.

Creating profiles
Creating a profile from scratch can be complex. It is recommended to use the tools from the apparmor-utils package, such as aa-genprof and aa-logprof, which greatly simplify this process.

Conclusion

AppArmor is a fundamental security building block for any modern Linux system. By confining applications, it drastically limits the potential damage of a security flaw. Although setting it up may seem intimidating, using existing profiles and utilities like aa-status and aa-complain makes it accessible and highly effective.

Written by

Morgann Riu

Cybersecurity and Linux administration expert. I share my knowledge through free tutorials and training to help system administrators and developers secure their infrastructures.

Frequently asked questions

My application stopped working after enabling AppArmor, how do I find the rule at fault?
Look for the denials in the kernel logs with sudo journalctl -k | grep 'apparmor="DENIED"', or directly in /var/log/audit/audit.log and /var/log/syslog. Every DENIED line names the denied operation, the profile involved and the process, which is enough to pinpoint the missing path or capability. To unblock the service immediately while you fix the profile, switch it to permissive mode with sudo aa-complain /etc/apparmor.d/<profile>.
I edited a profile but nothing changed, why?
Editing the file in /etc/apparmor.d/ is not enough: the kernel keeps the previously loaded version. Reload the profile with sudo apparmor_parser -r /etc/apparmor.d/usr.bin.firefox, or reload them all at once with sudo systemctl reload apparmor. Then confirm with sudo aa-status that the profile shows up in the expected mode.
What is the practical difference between enforce and complain mode?
In enforce, which is the default mode, AppArmor strictly applies the profile rules and blocks anything that is not explicitly allowed. In complain, nothing is blocked: violations are simply recorded in the system logs. You use complain to test or develop a profile without risking breaking the application, then switch back with sudo aa-enforce once the profile is complete.
Do I have to write a profile from scratch for every application?
No, and it is not even advisable: writing a complete profile by hand is slow and error-prone. Many distributions, Ubuntu among them, already ship pre-enabled profiles for common services. For an application that is not covered, use the tools from the apparmor-utils package — aa-genprof generates a profile by observing the application, and aa-logprof then extends it from the recorded denials.
AppArmor or SELinux, which one should I pick?
Both address the same mandatory access control need, but AppArmor is generally considered easier to learn and administer because its profiles are expressed as file paths rather than labels. It also ships pre-configured on Ubuntu, Debian and openSUSE, with profiles already active for widespread services. If your distribution already ships AppArmor, build on what is there rather than switching to SELinux.

Share this tutorial

Did you enjoy this article?

Comments

Checklist Sécurité Linux

30 points essentiels pour sécuriser un serveur Linux. Recevez aussi les nouveaux tutoriels par email.

Pas de spam. Désabonnement en 1 clic.