.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "APPARMOR 7" .TH APPARMOR 7 2024-02-28 "AppArmor 3.0.13" AppArmor .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME AppArmor \- kernel enhancement to confine programs to a limited set of resources. .SH DESCRIPTION .IX Header "DESCRIPTION" AppArmor is a kernel enhancement to confine programs to a limited set of resources. AppArmor's unique security model is to bind access control attributes to programs rather than to users. .PP AppArmor confinement is provided via \fIprofiles\fR loaded into the kernel via \fBapparmor_parser\fR\|(8), typically through the \fI/etc/init.d/apparmor\fR SysV initscript, which is used like this: .PP .Vb 3 \& # /etc/init.d/apparmor start \& # /etc/init.d/apparmor stop \& # /etc/init.d/apparmor restart .Ve .PP AppArmor can operate in two modes: \fIenforcement\fR, and \fIcomplain or learning\fR: .IP \(bu 4 \&\fIenforcement\fR \- Profiles loaded in enforcement mode will result in enforcement of the policy defined in the profile as well as reporting policy violation attempts to syslogd. .IP \(bu 4 \&\fIcomplain\fR \- Profiles loaded in \f(CW\*(C`complain\*(C'\fR 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 \fBaa\-complain\fR\|(8) and \fBaa\-enforce\fR\|(8) can be used. These utilities take a program name as an argument. .PP Profiles are traditionally stored in files in \fI/etc/apparmor.d/\fR under filenames with the convention of replacing the \fB/\fR in pathnames with \fB.\fR (except for the root \fB/\fR) so profiles are easier to manage (e.g. the \fI/usr/sbin/nscd\fR profile would be named \fIusr.sbin.nscd\fR). .PP Profiles are applied to a process at \fBexec\fR\|(3) time (as seen through the \&\fBexecve\fR\|(2) system call): once a profile is loaded for a program, that program will be confined on the next \fBexec\fR\|(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, a process that is already running unconfined cannot be confined. .PP AppArmor supports the Linux kernel's securityfs filesystem, and makes available the list of the profiles currently loaded; to mount the filesystem: .PP .Vb 5 \& # mount \-tsecurityfs securityfs /sys/kernel/security \& $ cat /sys/kernel/security/apparmor/profiles \& /usr/bin/mutt \& /usr/bin/gpg \& ... .Ve .PP Normally, the initscript will mount securityfs if it has not already been done. .PP 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: .PP .Vb 3 \& 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) .Ve .SH ERRORS .IX Header "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: .PP .Vb 3 \& 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" .Ve .PP 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.) .PP 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: .PP .Vb 3 \& 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 .Ve .PP 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, REJECTING and PERMITTING messages may go to either \fI/var/log/audit/audit.log\fR or \fI/var/log/messages\fR, depending upon local configuration. .SH DEBUGGING .IX Header "DEBUGGING" AppArmor provides a few facilities to log more information, which can help debugging profiles. .SS "Enable debug mode" .IX Subsection "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 tell whether environment scrubbing has been applied. .PP To enable debug mode, run: .PP .Vb 1 \& echo 1 > /sys/module/apparmor/parameters/debug .Ve .SS "Turn off deny audit quieting" .IX Subsection "Turn off deny audit quieting" By default, operations that trigger \f(CW\*(C`deny\*(C'\fR rules are not logged. This is called \fIdeny audit quieting\fR. .PP To turn off deny audit quieting, run: .PP .Vb 1 \& echo \-n noquiet >/sys/module/apparmor/parameters/audit .Ve .SS "Force audit mode" .IX Subsection "Force audit mode" AppArmor can log a message for every operation that triggers a rule configured in the policy. This is called \fIforce audit mode\fR. .PP \&\fBWarning!\fR Force audit mode can be extremely noisy even for a single profile, let alone when enabled globally. .PP To set a specific profile in force audit mode, add the \f(CW\*(C`audit\*(C'\fR flag: .PP .Vb 1 \& profile foo flags=(audit) { ... } .Ve .PP To enable force audit mode globally, run: .PP .Vb 1 \& echo \-n all > /sys/module/apparmor/parameters/audit .Ve .PP 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: .PP .Vb 1 \& echo 0 > /proc/sys/kernel/printk_ratelimit .Ve .PP But even then the kernel ring buffer may overflow and you might lose messages. .PP Else, if auditd is running, see \fBauditd\fR\|(8) and \fBauditd.conf\fR\|(5). .SH FILES .IX Header "FILES" .IP \fI/etc/init.d/apparmor\fR 4 .IX Item "/etc/init.d/apparmor" .PD 0 .IP \fI/etc/apparmor.d/\fR 4 .IX Item "/etc/apparmor.d/" .IP \fI/var/lib/apparmor/\fR 4 .IX Item "/var/lib/apparmor/" .IP \fI/var/log/audit/audit.log\fR 4 .IX Item "/var/log/audit/audit.log" .IP \fI/var/log/messages\fR 4 .IX Item "/var/log/messages" .PD .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBapparmor_parser\fR\|(8), \fBaa_change_hat\fR\|(2), \fBapparmor.d\fR\|(5), \&\fBaa\-autodep\fR\|(1), \fBclean\fR\|(1), \&\fBauditd\fR\|(8), \&\fBaa\-unconfined\fR\|(8), \fBaa\-enforce\fR\|(1), \fBaa\-complain\fR\|(1), and .