Security
Difficulty: Intermediate
3 min read

AppArmor Utils: Managing Security Profiles

A complete guide to using AppArmor Utils to create, manage and harden the security profiles of your applications on Linux.

Back to tutorials
What is AppArmor Utils?
AppArmor Utils is a suite of command-line tools that makes managing AppArmor profiles easier. These utilities let you generate, refine and maintain the security policies that confine applications.

Why Use AppArmor Utils?

  • Simplified profile creation: The aa-genprof tool lets you generate a profile in "learning" mode.
  • Easy maintenance: aa-logprof analyzes the logs to help you update existing profiles.
  • State management: Easily switch a profile from complain mode (logging only) to enforce mode (active blocking).

Prerequisites

  • Operating system: A Linux distribution with AppArmor (Ubuntu, Debian, openSUSE...).
  • Privileges: Root access or sudo privileges.
  • AppArmor: The AppArmor service must be installed and enabled.

Installing AppArmor Utils

The apparmor-utils package is usually installed alongside AppArmor. If not, install it manually:

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

Creating a Profile with aa-genprof

This is the main tool for creating a new profile for an application that doesn't have one.

Step 1: Launch the Profile Generator

Suppose you want to confine the tcpdump utility. Run aa-genprof, pointing it to the binary:

sudo aa-genprof /usr/sbin/tcpdump

Step 2: Trigger the Application's Actions

In another terminal, run the application and perform the actions you want to allow. For example:

sudo tcpdump -i eth0 -c 5

Step 3: Scan the Logs and Build the Profile

Go back to the first terminal (the one running aa-genprof) and press the `S` key (Scan). The tool will analyze the system logs looking for events generated by `tcpdump`.

For each event, aa-genprof will ask whether you want to Allow it, Deny it, Ignore it, and so on. Answer the questions to progressively build your profile.

Step 4: Save and Activate the Profile

Once you have handled all the events, press `F` (Finish) to save the profile to /etc/apparmor.d/. The profile will automatically be set to enforce mode.

Profile created!
Your application is now confined by AppArmor. You can check its status with sudo aa-status.

Updating a Profile with aa-logprof

If a confined application needs new permissions (for example after an update), aa-logprof is the tool you need.

Simply run it:

sudo aa-logprof

Just like aa-genprof, it will scan the logs and offer to allow or deny the actions that were blocked by the existing profile.

Managing Profile Modes

You can easily change a profile's mode.

Switch to complain Mode (Non-Blocking)

sudo aa-complain /etc/apparmor.d/usr.sbin.tcpdump

In this mode, violations are logged but not blocked. This is useful for testing a profile without breaking the application.

Switch to enforce Mode (Blocking)

sudo aa-enforce /etc/apparmor.d/usr.sbin.tcpdump

This is the standard production mode, where the rules are strictly applied.

Disable a Profile

sudo aa-disable /etc/apparmor.d/usr.sbin.tcpdump
Profile Path
Note that the profile file name in /etc/apparmor.d/ replaces the `/` characters with `.` characters (e.g. /usr/sbin/tcpdump becomes usr.sbin.tcpdump).

Conclusion

The apparmor-utils tools are essential for working efficiently with AppArmor. They turn the potentially complex task of creating and maintaining profiles into an interactive, guided process. Mastering aa-genprof and aa-logprof is the key to securing your Linux applications effectively.

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

aa-genprof finds no events when I press S, why?
Almost always because the application was not exercised while aa-genprof was running. The tool guesses nothing: it scans the system logs for events actually produced by the binary. Leave aa-genprof open in a first terminal, run the application in a second one (for instance sudo tcpdump -i eth0 -c 5) performing every action you want to allow, then go back and press S.
My confined application broke after an update, how do I fix the profile cleanly?
Just run sudo aa-logprof: it scans the logs, finds the actions the existing profile blocked, and offers to allow or deny each of them one by one. That is the intended way to evolve a profile without rewriting it. If the service must stay available while you collect the events, first switch the profile with sudo aa-complain /etc/apparmor.d/<profile>, then put it back into aa-enforce once the new rules are validated.
aa-complain tells me the profile does not exist, what is wrong?
These commands expect the path of the profile file in /etc/apparmor.d/, not the path of the binary. The naming convention replaces / characters with .: to confine /usr/sbin/tcpdump, the profile is /etc/apparmor.d/usr.sbin.tcpdump. A quick ls /etc/apparmor.d/ gives you the exact name to pass to aa-complain, aa-enforce or aa-disable.
What is the difference between aa-complain, aa-enforce and aa-disable?
aa-complain puts the profile in permissive mode: violations are logged but nothing is blocked, which lets you test a profile without breaking the application. aa-enforce applies the rules strictly and blocks everything else, and is the standard production mode. aa-disable turns the profile off completely: the application is no longer confined at all, and violations are no longer logged either.
How do I verify that my new profile is actually loaded and active?
Run sudo aa-status: it lists the loaded profiles grouped by mode, so you can check at a glance that your profile is present and that it really is in enforce rather than complain. If the profile does not appear at all, it was either not saved into /etc/apparmor.d/ or never loaded.

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.