AppArmor
AppArmor profiles, complain vs enforce mode, aa-genprof, aa-logprof, and path-based MAC.
Overview
AppArmor is a Mandatory Access Control (MAC) system for Linux that confines programs to a limited set of resources. Mandatory means the rules come from a policy the program cannot change, on top of normal file permissions. Unlike SELinux which labels every file with a security context, AppArmor uses path-based profiles — rules that reference filesystem paths directly. This makes AppArmor significantly easier to write and audit than SELinux, at the cost of some flexibility.
AppArmor is the default MAC system on Ubuntu and Debian, and was long the default on SUSE distributions, while RHEL/Fedora use SELinux. Newer openSUSE and SUSE Linux Enterprise releases have moved to SELinux by default.
Profile Anatomy
A profile lives in /etc/apparmor.d/ and has this general structure:
Reading it from the top, the #include lines pull in shared rules, the capability lines grant root powers the program needs (binding ports below 1024, such as 80, with net_bind_service, and switching user and group with setuid and setgid), the path lines grant file access, and network tcp allows TCP sockets.
The path rules use globs. A path that ends in /, like /var/www/html/ r above, matches only the directory itself; * matches the files in one directory and ` matches everything below it, so each directory rule above is paired with a rule, such as /var/www/html/** r`, for the files.
Key concepts
- Profile
- Enforce mode
- Complain mode
- aa-genprof
- aa-logprof
- Abstractions
Interview questions
- How do you create an AppArmor profile for a new custom application?
- How does AppArmor compare to SELinux? When would you choose one over the other?
Sign up free to read the full topic
More Linux topics
Start free on Cariara · Coding problems · System design studio