Join our Newsletter — 33% off our NHI Course
Home› Guides› AppArmor Guide: Write, Test and Enforce Profiles for…
Guide Endpoint Security

AppArmor Guide: Write, Test and Enforce Profiles for Linux Services

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 12 min read
On this page

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. ux drops a child process out of confinement entirely; prefer Px, Cx or ix.
  • 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 elementExampleMeaning (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"
Capabilitycapability net_bind_service,Only the listed capabilities are allowed
Networknetwork inet tcp,Socket family and type; finer ip= and port= conditions exist
Deny and auditdeny /etc/shadow r, audit /etc/app/** w,deny blocks silently; audit logs allowed access
User namespaceuserns 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.

ModeBehaviourWhen to useCommand
EnforceDenies and logs violationsProduction defaultaa-enforce /path/to/bin
ComplainAllows and logs violationsProfile development and pilotaa-complain /path/to/bin
KillDenies and signals the taskHigh assurance services where a violation should stop the processflags=(kill) in the profile
Unconfined flagBehaves as unconfinedDebugging onlyflags=(unconfined)
Disabled profileNot loadedTemporary removalsymlink in /etc/apparmor.d/disable/ plus apparmor_parser -R
  • Status: aa-status lists loaded profiles by mode and processes confined or unconfined.
  • Reload: apparmor_parser -r /etc/apparmor.d/<profile> after an edit, or systemctl reload apparmor.service for all.
  • Disabling the whole module: from Ubuntu 24.04 LTS AppArmor is built into the kernel, so turning it off needs apparmor=0 on the kernel command line (GRUB_CMDLINE_LINUX in /etc/default/grub, then update-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-unconfined man 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

  1. Start from what ships: check apparmor-profiles and apparmor-profiles-extra (the latter ships in complain mode) before writing your own.
  2. Generate: aa-genprof /usr/sbin/mydaemon creates a skeleton and watches the program while you exercise it.
  3. Exercise every path: start, reload, log rotation, backup, upgrade and error handling. Unused code paths become production denials later.
  4. Refine: aa-logprof walks the logged events and proposes rules. Replace broad suggestions such as /** r, with specific paths, and prefer Px or Cx over ux.
  5. Add explicit denies for crown jewels: deny /etc/shadow r,, deny @{HOME}/.ssh/** rw,. Deny rules override allows from abstractions.
  6. Keep site changes local: distribution profiles usually include a file in /etc/apparmor.d/local/; add rules there so upgrades keep them.
  7. Enforce and watch: aa-enforce, restart the service, and watch denials for a full business cycle.

Docker and Kubernetes

  • Docker: the engine generates docker-default and loads it for containers (not for the daemon). Use --security-opt apparmor=<profile> for a custom profile loaded with apparmor_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, Localhost or Unconfined), and a Localhost profile must already be loaded on every node that may run the Pod. Block Unconfined with 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.

SignalWhy it mattersHandling
DENIED from a web, mail or file parsing profile on exec, network connect or reads of credentialsLikely post exploitation activity after T1190, possibly heading for T1068High 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 loadedWhole host unconfinedCritical configuration finding
Container running unconfined or privilegedEscape to host risk (T1611)Block at admission
New listening process reported by aa-unconfinedNetwork service without a profileAdd 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/Ux rules 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

  1. Baseline: collect aa-status and aa-unconfined output from every host; list network services and root agents without profiles.
  2. Prioritise: internet facing daemons, parsers of untrusted content and credential holding agents first.
  3. Build in complain mode: author or adopt profiles on a staging host, store them in version control and deploy through configuration management.
  4. 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.
  5. Widen and lock: enforce estate wide, alert on mode changes, and add profile review to the change process for each application release.
  6. Rollback: per profile with aa-complain (keeps logging), never by disabling the module. Restore enforce once the missing rule is added in local/.

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 RuntimeDefault as the floor through admission policy.

Framework mapping

FrameworkReferenceAppArmor contribution
NIST SP 800-53 Rev. 5AC-3(3) Mandatory Access Control; AC-6 Least Privilege; SC-39 Process IsolationEnforced per-program limits independent of UID
NIST SP 800-53 Rev. 5CM-6, CM-7, AU-12Profiles and modes as configuration; DENIED events as audit records
NIST CSF 2.0PR.PS-01, PR.AA-05, DE.CM-09Configuration management, enforced permissions, runtime monitoring
CIS Controls v8.1Control 4 Secure ConfigurationCIS Benchmarks for Ubuntu and Debian include AppArmor enablement and profile mode checks
ISO/IEC 27001:2022Annex A 8.9 Configuration managementDocumented and version controlled profiles
MITRE ATT&CK v20T1190, T1068, T1611, T1685Reduces 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-logprof suggestion, including /** rw, or capability 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 ux gives 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: --privileged with 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-unconfined and 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 ux transitions with Px, Cx or ix, 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 deny for credential paths you want alerts on.
  • Forward DENIED events and profile mode changes to the SIEM.
  • Enforce RuntimeDefault or a custom profile for containers and block unconfined Pods at admission.

Standards and references

Related NHI Mgmt Group resources: SELinux Guide · Reference Monitors and Mandatory Access Control Guide · Ubuntu Server Security Hardening Guide · Container Runtime Security Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.