AppArmor
Confine programs by path with AppArmor profiles on Ubuntu and Debian: check status, read denials, switch between complain and enforce, and write a profile.
AppArmor
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- AppArmor is mandatory access control like SELinux, but its profiles attach to programs by path and list the files, capabilities and network access each program may use.
- Ubuntu and Debian load AppArmor by default. `aa-status` shows which profiles are loaded and whether each is in enforce or complain mode.
- Enforce mode blocks and logs violations. Complain mode only logs them, which is how you test a new profile against real use.
- Profiles live in `/etc/apparmor.d/`, named after the binary's path with dots, such as `usr.sbin.foo`. Reload one after editing with `apparmor_parser -r`.
- Denials appear in the kernel log as `apparmor="DENIED"` lines. `aa-genprof` builds a new profile by watching a program, and `aa-logprof` turns logged denials into proposed rules.
The same problem, a different answer
The SELinux lesson started from one worry: a compromised service, even one running as root, should not be able to read everything on the machine. SELinux answers by labelling every process and file and writing policy about labels.
AppArmor answers the same question with a simpler model. Each confined program gets a profile, a plain-text list of the paths it may read, write or execute, the capabilities it may use, and whether it may open network sockets. Anything not listed is refused. Think of a contractor’s work order that says “kitchen and the back door only”. The rule names places, not badges.
Ubuntu, Debian and SUSE use AppArmor. The RHEL family uses SELinux. Each distribution enables one of the two by default, so in practice you learn whichever yours chose.
Is it on, and what is confined?
sudo aa-status
Ubuntu’s server documentation says AppArmor is installed and loaded by default. aa-status (also apparmor_status) lists the loaded profiles, how many are in each mode, and which running processes are confined. Packages often ship profiles for their own daemons. More are in the apparmor-profiles package, and the management tools are in apparmor-utils.
Complain and enforce
Each profile runs in one of two modes:
- Enforce blocks anything not allowed and logs it.
- Complain allows everything but logs what would have been blocked.
sudo aa-complain /usr/sbin/foo
sudo aa-enforce /usr/sbin/foo
Complain mode is the AppArmor equivalent of SELinux’s permissive mode, but per program. If a confined service breaks after an upgrade, putting just that profile in complain mode tells you within a minute whether AppArmor is the cause, without lowering protection for everything else.
Reading a denial
AppArmor logs through the kernel. The Ubuntu docs say denials appear as apparmor="DENIED" entries, with the profile, the operation and the resource requested:
sudo journalctl -k | grep 'apparmor="DENIED"'
A typical line names the operation, such as open, the profile, the path, and requested_mask="r". That tells you which rule is missing. Explicit deny rules are not logged, so a silent failure can still be AppArmor.
Writing a profile
Profiles live in /etc/apparmor.d/. The file is named after the program’s path with / turned into ., so /usr/sbin/foo is usr.sbin.foo. Here is a small profile I wrote for a hypothetical reporting tool. It is not from any package:
#include <tunables/global>
/usr/local/bin/report {
#include <abstractions/base>
/usr/local/bin/report mr,
/etc/report.conf r,
/var/lib/report/** rw,
network inet tcp,
deny /home/** rw,
}
Each rule is a path and permissions: r read, w write, m map as executable, and others. ** matches any depth. abstractions/base pulls in the shared libraries and device files nearly every program needs. network inet tcp allows IPv4 TCP sockets and nothing else. The explicit deny documents intent, and it wins even if a broader rule would allow the path.
Load or reload it with sudo apparmor_parser -r /etc/apparmor.d/usr.local.bin.report. -R unloads a profile. A symlink in /etc/apparmor.d/disable/ keeps it unloaded across boots.
Writing a profile by hand from nothing is slow. The tools do the first draft:
sudo aa-genprof /usr/local/bin/report # run the program in another terminal, then scan
sudo aa-logprof # turn new denials into proposed rules
aa-genprof puts the program in complain mode, watches what it does, and asks you, rule by rule, what to allow. Read each question. Accepting everything gives you a profile that allows whatever the program happened to do, including things it should not.
Paths are the strength and the weakness
Path rules are easy to read and need no relabelling when you move data. They also mean protection follows names, not objects. If the profile allows /srv/app/** and the same file is reachable through another allowed path, the profile cannot tell. SELinux’s labels travel with the file. For most servers AppArmor’s trade-off is reasonable, and a working AppArmor profile beats an SELinux policy someone has switched off.
AppArmor also pairs well with systemd’s own sandboxing from sandboxing services with systemd. systemd limits what the service’s environment looks like, and AppArmor limits what the program may touch within it.
Nothing here was run. AppArmor needs a Linux kernel. Commands and paths come from Ubuntu’s server documentation, read on 2026-11-28, and the example profile follows the syntax shown there.
About the video
The embed is all of ITPro Today’s “AppArmor Made Easy || Boost Your Linux Security”, January 2025, about eight minutes, presented by Grant Knoetze. Its chapters cover checking whether AppArmor is installed, installing it, configuration, profiles, creating and enforcing a profile, and switching to complain mode. It is a quick tour and does not go into reading denial lines or the path-versus-label trade-off. theurbanpenguin’s longer video in deeper builds a profile for a script step by step, though it uses Ubuntu 20.04 and I could not see a caption track to confirm the language beyond the channel being English-speaking. I judged the embed from its description and chapters, and English from its English caption track.
Where this fits
SELinux and AppArmor restrict what a process may touch. Linux also splits root’s own powers into pieces that can be handed out one at a time: Linux capabilities.
Check yourself
A service on Ubuntu fails to read a file in a new directory. Permissions look right. Where do you look first, and what for?
The kernel log or journal (`journalctl -k`, or `dmesg`) for `apparmor="DENIED"` lines naming the service's profile and the path. If one is there, the profile needs a rule for the new path.
What is the practical difference between complain and enforce mode?
Enforce blocks anything the profile does not allow and logs it. Complain allows it and only logs, so you can run the program normally and collect what a profile would need.
Why can AppArmor be easier to start with than SELinux, and what does that cost?
Rules are written as file paths, so there are no labels to manage and moving data does not need relabelling. The cost is that protection is tied to names. The same data reached through a different path the profile allows is not protected, whereas an SELinux label travels with the file.
You edited `/etc/apparmor.d/usr.sbin.foo`. What makes the change take effect?
`sudo apparmor_parser -r /etc/apparmor.d/usr.sbin.foo` reloads that profile into the kernel. Restarting the program is not enough on its own.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.