AppArmor only protects the programs that have a profile in enforce mode, and on most servers the services that face the network are the ones left unconfined. AppArmor is the mandatory access control module enabled by default on Ubuntu and Debian and documented for SUSE Linux Enterprise. This guide covers how profiles attach and decide access, how to author and tune a profile with complain mode, how AppArmor applies to containers and Kubernetes, what to log and alert on, and a rollout plan that moves services from unconfined to enforced. It is for Linux administrators, platform engineers and detection teams. For the host baseline see the Linux Server Hardening Guide; for label based confinement on RHEL family systems see the SELinux Guide.
This is an independent guide from NHI Mgmt Group, based on the AppArmor project's public documentation as of November 2026. It is not sponsored or reviewed by the AppArmor project. Product features change, so confirm settings against the AppArmor project's current documentation.
Key takeaways
- Unprofiled means unconfined. The kernel documentation is explicit: a task without a profile gets only standard discretionary permissions. Coverage of network facing services is the first metric to track.
- Complain mode is for learning, not production. It allows and logs everything a profile would deny; use it to build the profile, then enforce.
- Execute modes decide whether confinement survives.
uxdrops a child process out of confinement entirely; preferPx,Cxorix. - Local overrides survive upgrades. Put site changes in
/etc/apparmor.d/local/, not in the packaged profile, or the next package update reverts them. - Containers are only as confined as their run options. Docker applies
docker-default, but privileged containers with no explicit profile run unconfined.
How profiles attach and decide access
AppArmor is a Linux Security Module with a task centred policy: profiles are written in text, compiled by apparmor_parser and loaded into the kernel, and each profile attaches to a program by its executable path. Profiles live in /etc/apparmor.d/ and are named after the binary with / replaced by ., so /usr/sbin/ntpd uses /etc/apparmor.d/usr.sbin.ntpd. Inside a profile, rules grant file access by path with globbing, Linux capabilities, network socket types, signals, ptrace, mounts and user namespaces. Anything not granted is denied in enforce mode.
The path model is AppArmor's main difference from SELinux. There is no file labelling, so moving data to a new directory needs a profile change rather than a relabel, and profiles are readable by anyone who can read a file path. The trade-off is that hard links and bind mounts can present the same file under different paths, which is why the l (link) permission is restricted to a subset of the original file's rights.
| Rule element | Example | Meaning (from apparmor.d(5)) |
|---|---|---|
| File read / write | /srv/app/** r, /var/log/app/*.log w, | * matches within one directory level, ** matches across levels |
| Append only | /var/log/app/audit.log a, | Write only with O_APPEND; conflicts with w |
| Library mapping | /usr/lib/app/*.so m, | Allows mmap with PROT_EXEC |
| Execute, inherit | /usr/bin/gzip ix, | Child runs under the current profile |
| Execute, own profile | /usr/bin/curl Px, | Child must have its own profile; environment scrubbed (LD_PRELOAD removed) |
| Execute, child profile | /usr/bin/convert Cx -> convert, | Child runs in a subprofile defined inside this profile |
| Execute, unconfined | /usr/bin/helper Ux, | Child leaves confinement; the man page calls ux "use at your own risk" |
| Capability | capability net_bind_service, | Only the listed capabilities are allowed |
| Network | network inet tcp, | Socket family and type; finer ip= and port= conditions exist |
| Deny and audit | deny /etc/shadow r, audit /etc/app/** w, | deny blocks silently; audit logs allowed access |
| User namespace | userns create, | Allows creating user namespaces where creation is restricted |
Abstractions and tunables: #include <abstractions/base>, nameservice, authentication and similar files bundle common rules; <tunables/global> defines variables such as @{HOME}. Review what an abstraction grants before including it: authentication, for example, exists to give access to credential databases.
Profile modes and administrative control
Each profile is in one mode. Loading, unloading and changing modes needs root, so who can edit /etc/apparmor.d/ and run apparmor_parser is a privileged access question.
| Mode | Behaviour | When to use | Command |
|---|---|---|---|
| Enforce | Denies and logs violations | Production default | aa-enforce /path/to/bin |
| Complain | Allows and logs violations | Profile development and pilot | aa-complain /path/to/bin |
| Kill | Denies and signals the task | High assurance services where a violation should stop the process | flags=(kill) in the profile |
| Unconfined flag | Behaves as unconfined | Debugging only | flags=(unconfined) |
| Disabled profile | Not loaded | Temporary removal | symlink in /etc/apparmor.d/disable/ plus apparmor_parser -R |
- Status:
aa-statuslists loaded profiles by mode and processes confined or unconfined. - Reload:
apparmor_parser -r /etc/apparmor.d/<profile>after an edit, orsystemctl reload apparmor.servicefor all. - Disabling the whole module: from Ubuntu 24.04 LTS AppArmor is built into the kernel, so turning it off needs
apparmor=0on the kernel command line (GRUB_CMDLINE_LINUXin/etc/default/grub, thenupdate-grub). Treat that parameter on a production host as a finding. - Restart after loading: a process started before its profile was loaded keeps running unconfined, as the
aa-unconfinedman page notes. Restart the service after the first load.
Interactive users: AppArmor is mainly used to confine programs, not people. SUSE documents pam_apparmor for confining user sessions, and the change_hat interface lets a program such as a web server switch to a narrower subprofile per request. For limiting administrator rights, sudo policy and PAM do most of the work; see the sudo and sudoers Security Guide and the Linux PAM Guide.
Confining services, agents and containers
The highest value targets are network daemons, parsers that handle untrusted files, and agents that run as root with credentials. A backup or monitoring agent that holds an API token and runs unconfined as root gives an attacker who compromises it both the host and the token. Confining it limits the files and sockets the token can reach. The account side is covered in the Linux Service Accounts and Keytab Management Guide.
Authoring a profile
- Start from what ships: check
apparmor-profilesandapparmor-profiles-extra(the latter ships in complain mode) before writing your own. - Generate:
aa-genprof /usr/sbin/mydaemoncreates a skeleton and watches the program while you exercise it. - Exercise every path: start, reload, log rotation, backup, upgrade and error handling. Unused code paths become production denials later.
- Refine:
aa-logprofwalks the logged events and proposes rules. Replace broad suggestions such as/** r,with specific paths, and preferPxorCxoverux. - Add explicit denies for crown jewels:
deny /etc/shadow r,,deny @{HOME}/.ssh/** rw,. Deny rules override allows from abstractions. - Keep site changes local: distribution profiles usually include a file in
/etc/apparmor.d/local/; add rules there so upgrades keep them. - Enforce and watch:
aa-enforce, restart the service, and watch denials for a full business cycle.
Docker and Kubernetes
- Docker: the engine generates
docker-defaultand loads it for containers (not for the daemon). Use--security-opt apparmor=<profile>for a custom profile loaded withapparmor_parser -r -W. Privileged containers with no explicit profile run unconfined, and Docker warns that a custom default template can reduce isolation. - Kubernetes: AppArmor support is stable since Kubernetes 1.31. Profiles are set in the Pod or container
securityContext(RuntimeDefault,LocalhostorUnconfined), and aLocalhostprofile must already be loaded on every node that may run the Pod. BlockUnconfinedwith admission policy; see the Kubernetes Admission Control Guide and the Container Runtime Security Guide.
Unprivileged user namespaces
Ubuntu 23.10 introduced AppArmor control of unprivileged user namespace creation, citing a Google report that such namespaces featured in 44% of the exploits Google saw. With kernel.apparmor_restrict_unprivileged_userns=1, an unprivileged process can create a user namespace only if its profile has a userns rule or it holds CAP_SYS_ADMIN; kernel.apparmor_restrict_unprivileged_unconfined=1 applies the restriction to unconfined processes. Check both values on your release with sysctl before relying on them, and give browsers or rootless container tools that need namespaces a profile with userns, rather than turning the restriction off. Related kernel settings are in the Linux Kernel Hardening and sysctl Guide.
Logging and detection
Denials are kernel audit messages tagged apparmor="DENIED"; they appear in dmesg, the journal and, when auditd runs, /var/log/audit/audit.log. Each record carries the profile, operation, name (the path), requested_mask and denied_mask. Complain mode events are tagged apparmor="ALLOWED". Explicit deny rules do not log; add the audit qualifier (audit deny /etc/shadow r,) where you want an alert.
| Signal | Why it matters | Handling |
|---|---|---|
| DENIED from a web, mail or file parsing profile on exec, network connect or reads of credentials | Likely post exploitation activity after T1190, possibly heading for T1068 | High priority; investigate the service |
Profile switched to complain, removed, or symlinked into disable/ | Confinement reduced (T1685 Disable or Modify Tools) | Alert; require a change record |
apparmor=0 on kernel command line, or aa-status reports the module not loaded | Whole host unconfined | Critical configuration finding |
Container running unconfined or privileged | Escape to host risk (T1611) | Block at admission |
New listening process reported by aa-unconfined | Network service without a profile | Add to profiling backlog |
The aa-unconfined man page warns the tool is an aid for profiling in the lab and is unsuitable for forensics, so use EDR or audit data for investigation. See the Linux Logging and auditd for Defenders Guide and the Linux Detection and Response Guide.
Metrics
- Network service coverage: share of listening processes confined by an enforce mode profile.
- Complain mode debt: number of profiles in complain mode on production hosts, each with an owner and date.
- Unsafe transitions: count of
ux/Uxrules across custom profiles, trending to zero. - Module status: percentage of hosts with AppArmor loaded and no
apparmor=0. - Container confinement: percentage of running containers and Pods with a non unconfined profile.
Hardening baseline
Rollout plan
- Baseline: collect
aa-statusandaa-unconfinedoutput from every host; list network services and root agents without profiles. - Prioritise: internet facing daemons, parsers of untrusted content and credential holding agents first.
- Build in complain mode: author or adopt profiles on a staging host, store them in version control and deploy through configuration management.
- Pilot ring: enforce on a small set of production hosts; watch DENIED events and service health for at least one full cycle of scheduled jobs.
- Widen and lock: enforce estate wide, alert on mode changes, and add profile review to the change process for each application release.
- Rollback: per profile with
aa-complain(keeps logging), never by disabling the module. Restore enforce once the missing rule is added inlocal/.
Decision guidance
- AppArmor or SELinux: use what the distribution ships and supports; only one major LSM is active, and switching brings tooling and support costs. AppArmor is quicker to author for a single service; SELinux gives finer type separation and confined users across the whole system.
- Small estates: enable the shipped profiles, profile the two or three exposed services, and alert on mode changes.
- Large estates and Kubernetes: treat profiles as code, distribute them to nodes before workloads that reference them, and enforce
RuntimeDefaultas the floor through admission policy.
Framework mapping
| Framework | Reference | AppArmor contribution |
|---|---|---|
| NIST SP 800-53 Rev. 5 | AC-3(3) Mandatory Access Control; AC-6 Least Privilege; SC-39 Process Isolation | Enforced per-program limits independent of UID |
| NIST SP 800-53 Rev. 5 | CM-6, CM-7, AU-12 | Profiles and modes as configuration; DENIED events as audit records |
| NIST CSF 2.0 | PR.PS-01, PR.AA-05, DE.CM-09 | Configuration management, enforced permissions, runtime monitoring |
| CIS Controls v8.1 | Control 4 Secure Configuration | CIS Benchmarks for Ubuntu and Debian include AppArmor enablement and profile mode checks |
| ISO/IEC 27001:2022 | Annex A 8.9 Configuration management | Documented and version controlled profiles |
| MITRE ATT&CK v20 | T1190, T1068, T1611, T1685 | Reduces post exploitation reach; tampering is detectable |
Common misconfigurations
- Profiles left in complain mode: they log but block nothing, and dashboards that count "loaded profiles" hide the gap. Report by mode.
- Over-broad learned rules: accepting every
aa-logprofsuggestion, including/** rw,orcapability sys_admin,. The man page notes some capabilities can load kernel modules or bypass discretionary controls, which defeats confinement. - Escape through ux: a confined service allowed to run a shell or interpreter with
uxgives the attacker an unconfined process. Use a child profile. - Editing packaged profiles: upgrades overwrite them silently. Use
local/includes. - Service not restarted: the profile is loaded, but the running process predates it and stays unconfined.
- Privileged containers:
--privilegedwith no explicit profile runs unconfined, removing AppArmor and much else. Any credential mounted into that container is then one step from host level access.
Practitioner checklist
- Confirm AppArmor is loaded on every Ubuntu, Debian and SUSE host and that no kernel command line carries
apparmor=0. - Run
aa-unconfinedand give every network facing service an enforce mode profile. - Build profiles in complain mode on staging, then enforce in pilot rings before estate wide rollout.
- Replace
uxtransitions withPx,Cxorix, and review abstractions and capabilities in each profile. - Keep site rules in
/etc/apparmor.d/local/and all custom profiles in version control. - Restart services after loading a profile and verify with
aa-status. - Use
audit denyfor credential paths you want alerts on. - Forward DENIED events and profile mode changes to the SIEM.
- Enforce
RuntimeDefaultor a custom profile for containers and block unconfined Pods at admission.
Standards and references
- Linux kernel documentation: AppArmor
- Ubuntu manuals: apparmor.d(5), syntax of security profiles for AppArmor
- Ubuntu Server documentation: AppArmor
- Ubuntu manuals: aa-unconfined(8)
- Ubuntu: Restricted unprivileged user namespaces in Ubuntu 23.10
- Docker documentation: AppArmor security profiles for Docker
- Kubernetes documentation: Restrict a Container's Access to Resources with AppArmor
- NIST: SP 800-53 Rev. 5
Related NHI Mgmt Group resources: SELinux Guide · Reference Monitors and Mandatory Access Control Guide · Ubuntu Server Security Hardening Guide · Container Runtime Security Guide