APPARMOR(7)

๐Ÿ’– APPARMOR(7) ๐Ÿ’–

okay bestie, sit down, hydrate, and let me tell you about AppArmor โ€” it's a manual page from the AppArmor gang and honestly? she's iconic. ๐Ÿซถ


โœจ NAME โœจ

AppArmor โ€” a kernel enhancement that confines programs to a limited set of resources. no cap.


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

So AppArmor is a kernel enhancement to confine programs to a limited set of resources. And her whole thing โ€” her unique security model, her main character energy โ€” is that she binds access control attributes to programs rather than to users. programs, not people. periodt. ๐Ÿ’…

The confinement itself gets provided via profiles loaded into the kernel via apparmor_parser(8), typically through the apparmor.service systemd unit, which you use like this:

# systemctl start apparmor
# systemctl reload apparmor

AppArmor can operate in two modes: enforcement, and complain or learning. okay so:

  • enforcement โ€” profiles loaded in enforcement mode will result in enforcement of the policy defined in the profile, plus reporting policy violation attempts to syslogd. she's strict. she's locked in. ๐Ÿ”ฅ
  • complain โ€” profiles loaded in "complain" mode will not enforce policy. Instead, it will report policy violation attempts. This mode is convenient for developing profiles. To manage complain mode for individual profiles the utilities aa-complain(8) and aa-enforce(8) can be used. These utilities take a program name as an argument. ๐ŸŽ€

Profiles are traditionally stored in files in /etc/apparmor.d/ under filenames with the convention of replacing the / in pathnames with . (except for the root /) so profiles are easier to manage โ€” e.g. the /usr/sbin/nscd profile would be named usr.sbin.nscd. the way that's so much easier to read, I'm obsessed. ๐Ÿ“

Profiles are applied to a process at exec(3) time (as seen through the execve(2) system call): once a profile is loaded for a program, that program will be confined on the next exec(3). If a process is already running under a profile, when one replaces that profile in the kernel, the updated profile is applied immediately to that process. On the other hand โ€” and this is the sad part ๐Ÿ˜ญ โ€” a process that is already running unconfined cannot be confined.

AppArmor supports the Linux kernel's securityfs filesystem, and makes available the list of the profiles currently loaded. To mount the filesystem:

# mount -tsecurityfs securityfs /sys/kernel/security
$ cat /sys/kernel/security/apparmor/profiles
/usr/bin/mutt
/usr/bin/gpg
   ...

Normally, the initscript will mount securityfs if it has not already been done. she handles it, don't worry. ๐ŸŒธ

AppArmor also restricts what privileged operations a confined process may execute, even if the process is running as root. A confined process cannot call the following system calls:

create_module(2) delete_module(2) init_module(2) ioperm(2)
iopl(2) ptrace(2) reboot(2) setdomainname(2)
sethostname(2) swapoff(2) swapon(2) sysctl(2)

like, even as root? yeah. that's the vibe check. ๐Ÿ‘‘

๐ŸŒˆ Complain mode ๐ŸŒˆ

Instead of denying access to resources the profile does not have a rule for, AppArmor can "allow" the access and log a message for the operation that triggers it. This is called complain mode.

Important note bestie, don't skip this: rules that are present in the profile are still applied, so:

  • allow rules will still quiet or force audit messages
  • deny rules will still result in denials and quieting of denial messages (see Turn off deny audit quieting if this is a problem).

Complain mode can be used to develop profiles incrementally as an application is exercised. The logged accesses can be added to the profile and then can the application further exercised to discover further additions that are needed. Because AppArmor allows the accesses, the application will behave as it would if AppArmor was not confining it. it's literally just yapping in the logs, not blocking anything. ๐Ÿ’€

Warning โ€” complain mode does not provide any security, only auditing, while it is enabled. It should not be used in a hostile environment or bad behaviors may be logged and added to the profile as if they are resource accesses that should be used by the application. she is off duty. do not leave her in charge of the door. ๐Ÿ™ˆ

Note complain mode can be very noisy with new or empty profiles, but with developed profiles might not log anything if the profile covers the application behavior well. See Audit Rate Limiting if complain mode is generating too many log messages.

To set a profile and any children or hat profiles the profile may contain into complain mode, use:

aa-complain /etc/apparmor.d/<the-application>

To manually set a specific profile in complain mode, add the "complain" flag, and then manually reload the profile:

profile foo flags=(complain) { ... }

Note that the "complain" flag must also be added manually to any hats or children profiles of the profile or they will continue to use the previous mode. don't forget the babies!! ๐Ÿงš

To enable complain mode globally, run:

echo -n complain > /sys/module/apparmor/parameters/mode

or to set it on boot add:

apparmor.mode=complain

as a kernel boot parameter.

Warning โ€” setting complain mode globally disables all apparmor security protections. It can be useful during debugging or profile development, but setting it selectively on a per profile basis is safer. please don't do the global thing casually, I'm begging. ๐Ÿ˜ญ

๐Ÿ’€ ERRORS ๐Ÿ’€

When a confined process tries to access a file it does not have permission to access, the kernel will report a message through audit, similar to:

audit(1386511672.612:238): apparmor="DENIED" operation="exec"
  parent=7589 profile="/tmp/sh" name="/bin/uname" pid=7605
  comm="sh" requested_mask="x" denied_mask="x" fsuid=0 ouid=0

audit(1386511672.613:239): apparmor="DENIED" operation="open"
  parent=7589 profile="/tmp/sh" name="/bin/uname" pid=7605
  comm="sh" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

audit(1386511772.804:246): apparmor="DENIED" operation="capable"
  parent=7246 profile="/tmp/sh" pid=7589 comm="sh" pid=7589
  comm="sh" capability=2  capname="dac_override"

The permissions requested by the process are described in the operation= and denied_mask= (for files โ€” capabilities etc. use a slightly different log format). The "name" and process id of the running program are reported, as well as the profile name including any "hat" that may be active, separated by "//". ("Name" is in quotes, because the process name is limited to 15 bytes; it is the same as reported through the Berkeley process accounting.) ๐ŸŽ€

For confined processes running under a profile that has been loaded in complain mode, enforcement will not take place and the log messages reported to audit will be of the form:

audit(1386512577.017:275): apparmor="ALLOWED" operation="open"
  parent=8012 profile="/usr/bin/du" name="/etc/apparmor.d/tunables/"
  pid=8049 comm="du" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

audit(1386512577.017:276): apparmor="ALLOWED" operation="open"
  parent=8012 profile="/usr/bin/du" name="/etc/apparmor.d/tunables/"
  pid=8049 comm="du" requested_mask="r" denied_mask="r" fsuid=1000 ouid=0

If the userland auditd is not running, the kernel will send audit events to klogd; klogd will send the messages to syslog, which will log the messages with the KERN facility. Thus, DENIED and ALLOWED messages may go to either /var/log/audit/audit.log or /var/log/messages, depending upon local configuration. it's giving "where did my logs go" energy, so check both. ๐Ÿ”


๐Ÿ”ฅ DEBUGGING ๐Ÿ”ฅ

AppArmor provides a few facilities to log more information, which can help debugging profiles.

๐Ÿ› Enable debug mode ๐Ÿ›

When debug mode is enabled, AppArmor will log a few extra messages to dmesg (not via the audit subsystem). For example, the logs will state when ld.so(8) secure-execution mode has been applied in a profile transition.

To enable debug mode, run:

echo 1 > /sys/module/apparmor/parameters/debug

or to set it on boot add:

apparmor.debug=1

as a kernel boot parameter.

๐Ÿคซ Turn off deny audit quieting ๐Ÿคซ

By default, operations that trigger "deny" rules are not logged. This is called deny audit quieting.

To turn off deny audit quieting, run:

echo -n noquiet >/sys/module/apparmor/parameters/audit

or to set it on boot add:

apparmor.audit=noquiet

as a kernel boot parameter.

๐Ÿ“ข Force audit mode ๐Ÿ“ข

AppArmor can log a message for every operation that triggers a rule configured in the policy. This is called force audit mode.

Warning! Force audit mode can be extremely noisy even for a single profile, let alone when enabled globally. like, bring earplugs. ๐Ÿ˜ญ

To set a specific profile in force audit mode, add the "audit" flag:

profile foo flags=(audit) { ... }

To enable force audit mode globally, run:

echo -n all > /sys/module/apparmor/parameters/audit

or to set it on boot add:

apparmor.audit=all

as a kernel boot parameter.

โณ Audit Rate Limiting โณ

If auditd is not running, to avoid losing too many of the extra log messages, you will likely have to turn off rate limiting by doing:

echo 0 > /proc/sys/kernel/printk_ratelimit

But even then the kernel ring buffer may overflow and you might lose messages. ๐Ÿ’€

Else, if auditd is running, see auditd(8) and auditd.conf(5).


๐Ÿ“ FILES ๐Ÿ“

  • /etc/apparmor.d/
  • /var/cache/apparmor/
  • /var/log/audit/audit.log
  • /var/log/messages

๐Ÿ‘€ SEE ALSO ๐Ÿ‘€

apparmor_parser(8), aa_change_hat(2), apparmor.d(5), aa-autodep(1), clean(1), auditd(8), aa-unconfined(8), aa-enforce(1), aa-complain(1), and <https://wiki.apparmor.net>. go read them, I believe in you ๐Ÿซถ


and that's the whole page bestie!! this one's AppArmor 6.0.0~alpha1, dated 2026-10-05, and it lives under the name APPARMOR(7). mwah. ๐Ÿ’–โœจ๐ŸŽ€

๐Ÿ“ฆ where this page comes from