AppArmor
AppArmor is a Linux security module that confines programs to a limited set of resources using per-program profiles. Each profile specifies which files, network access, and capabilities a process may use, reducing the damage a compromised application can cause.
itLinux | OpenSkills.info
Course pathWalk it in order
Look it upDip in anytime
Go furtherLeaves this page
Don't Panic
Don't Panic — AppArmor
AppArmor does not protect a system from its users. It protects a system from a program the system runs on purpose.
The observation underneath is that a Unix process inherits the entire authority of the account it runs as, which for a background service is wildly more than the job calls for — a few config files, a socket, one state directory, and nothing else on the machine is its business. A profile writes down that shorter list, and the kernel enforces it after the ordinary file permissions have already said yes.
That "after" is the whole posture. Nothing here replaces file ownership, permission bits, capabilities or patching: every applicable layer must permit an operation before it happens, and this one only ever subtracts.
The mechanism is short: a process asks the kernel for an operation, the kernel finds the profile attached to that program's path, and a rule either permits it or does not. Policy is allow-list shaped, so an enforcing profile with no matching rule denies by default.
Complain mode records the operation and permits it anyway — how a profile gets developed, and not a form of protection.
Rules match paths. r for read, w for write, m to map a file as executable
memory, then the execution rules: ix keeps the current profile, px switches
to another, cx enters a child profile, ux drops confinement altogether.
Those four decide what confines the next program, so they deserve more
scrutiny than anything else in the file. Treat ux as an exit, not an
option.
Two things will surprise you. The first is that path-based policy is only as stable as the filesystem beneath it. Hard links and bind mounts — a second name for one file, a directory grafted into a second location — can present the same file at a path no profile mentioned.
Upstream concedes the shape of this: where reading the source and writing the destination are both allowed, a rename restriction can be sidestepped by copying the contents. Systems that tag objects themselves rather than their paths have no such problem — but what AppArmor buys in exchange is legibility, since a competent administrator reads one of these profiles in a minute and will not read the equivalent SELinux policy in an hour. Spend the effort on the layers underneath instead.
The second surprise is that confinement assumes those layers hold. The
CAP_SYS_ADMIN privilege includes mounting filesystems, and path rules are
evaluated against whatever the process currently sees mounted — so anything able
to remount can change what a path resolves to and walk around its own profile
without ever violating it. Production workloads drop that privilege for exactly
this reason.
One habit worth taking away: run aa-status and read the complain count rather
than the loaded count. A profile parked in complain mode breaks nothing and
alerts nobody, so it stays there for years after the incident that moved it.
Broad coverage with a large complaining share gives all the audit noise of
confinement and none of the protection.
The Cheatsheet is the reference for rule syntax and tooling, and the Intro walks the profile lifecycle end to end. Save Field Notes for last: it covers what changed in 2024, since when this denies things on hosts where nobody wrote a rule.
Where this skill leads
Relevant careers
See how this topic contributes to broader role-level skill maps.
Sources
- https://apparmor.net/
Supports
- AppArmor as mandatory access control for individual programs
- Kernel enforcement of per-application profiles
- Mediation of files, capabilities, sockets, D-Bus, and IPC
- Denial event fields and journal inspection example
- https://documentation.ubuntu.com/security/security-features/privilege-restriction/apparmor/
Supports
- AppArmor integration with the Linux Security Module framework
- Relationship between discretionary and mandatory access control
- Kernel profile lookup and policy decision sequence
- Capability, D-Bus, Unix-socket, and user-namespace restrictions
- Distribution version differences and AppArmor integration
- https://apparmor.net/profiles/profile-types-and-syntax/
Supports
- Profile headers, attachments, flags, and rule blocks
- Attached and unattached profile behavior
- Enforce as default mode and complain-mode behavior
- Runtime mode changes with `aa-complain` and `aa-enforce`
- Includes, abstractions, variables, and common mediated resource classes
- https://apparmor.net/reference/profiles-quick-reference/
Supports
- Implicit denial when no rule grants access
- Child profiles, hats, and variables
- Capability, network, signal, and ptrace rules
- File globbing and directory matching
- File permissions and execution transitions
- AppArmor file access as an additional control beyond DAC
- https://apparmor.net/profiles/Policy_Layout/
Supports
- Conventional `/etc/apparmor.d` policy layout
- Cache, disable, force-complain, local, abstractions, tunables, and namespaces directories
- Profile filename conventions for executable attachments
- https://ubuntu.com/server/docs/how-to/security/apparmor/
Supports
- Ubuntu package and profile locations
- `aa-status`, `aa-complain`, `aa-enforce`, and parser reload operations
- Profile creation with `aa-genprof`
- Profile updates with `aa-logprof`
- Audit denial interpretation and local customization
- Explicit-deny logging behavior
- https://apparmor.net/man/5.0/apparmor.d/
Supports
- Complete AppArmor profile grammar and rule classes
- File permissions, execution transitions, and rule qualifiers
- D-Bus mediation in cooperation with the D-Bus daemon
- Policy variables and feature-dependent rule syntax
- https://apparmor.net/man/master/apparmor_parser/
Supports
- Policy compilation and kernel loading
- Add, replace, and remove commands
- Namespace, cache, validation, and skip-kernel-load controls
- Privilege requirement for kernel policy administration
- https://apparmor.net/man/4.1/aa-status/
Supports
- Reporting loaded profiles, modes, and confined processes
- JSON output and script-oriented status options
- Exit-status meanings and root visibility limitation
- https://apparmor.net/man/master/aa-genprof/
Supports
- Interactive initial profile generation
- Complain-mode observation and log scanning cycle
- Transition to enforce mode after review completion
- https://apparmor.net/man/4.0/aa-logprof/
Supports
- Interactive audit-event review and profile updates
- File, execution, capability, and change-hat decisions
- Execute-transition choices and refusal to default to unconfined execution
- https://apparmor.net/monitoring/
Supports
- Audit records through auditd, kernel logs, and the system journal
- Denial monitoring for troubleshooting and policy maintenance
- Application changes as a trigger for profile review
