2007-04-11 08:12:51 +00:00
|
|
|
# ----------------------------------------------------------------------
|
2010-12-20 13:47:09 -06:00
|
|
|
# Copyright (c) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
|
|
|
|
# 2008, 2009
|
2007-04-11 08:12:51 +00:00
|
|
|
# NOVELL (All rights reserved)
|
|
|
|
#
|
2010-12-20 13:47:09 -06:00
|
|
|
# Copyright (c) 2010
|
|
|
|
# Canonical Ltd. (All rights reserved)
|
|
|
|
#
|
2013-12-12 03:07:37 +01:00
|
|
|
# Copyright (c) 2013
|
|
|
|
# Christian Boltz (All rights reserved)
|
|
|
|
#
|
2007-04-11 08:12:51 +00:00
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of version 2 of the GNU General Public
|
|
|
|
# License published by the Free Software Foundation.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, contact Novell, Inc.
|
|
|
|
# ----------------------------------------------------------------------
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
|
|
|
|
=pod
|
|
|
|
|
|
|
|
=head1 NAME
|
|
|
|
|
2007-03-27 03:50:21 +00:00
|
|
|
AppArmor - kernel enhancement to confine programs to a limited set of resources.
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
=head1 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.
|
|
|
|
|
|
|
|
AppArmor confinement is provided via I<profiles> loaded into the kernel
|
2024-03-03 18:18:12 +01:00
|
|
|
via apparmor_parser(8), typically through the F<apparmor.service>
|
|
|
|
systemd unit, which is used like this:
|
2006-04-11 21:52:54 +00:00
|
|
|
|
2024-03-03 18:18:12 +01:00
|
|
|
# systemctl start apparmor
|
|
|
|
# systemctl reload apparmor
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
AppArmor can operate in two modes: I<enforcement>, and I<complain or learning>:
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
I<enforcement> - 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.
|
|
|
|
|
|
|
|
=item *
|
|
|
|
|
|
|
|
I<complain> - Profiles loaded in C<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
|
2006-11-03 09:47:55 +00:00
|
|
|
utilities aa-complain(8) and aa-enforce(8) can be used.
|
2006-04-11 21:52:54 +00:00
|
|
|
These utilities take a program name as an argument.
|
|
|
|
|
|
|
|
|
|
|
|
=back
|
|
|
|
|
|
|
|
Profiles are traditionally stored in files in F</etc/apparmor.d/>
|
|
|
|
under filenames with the convention of replacing the B</> in pathnames
|
|
|
|
with B<.> (except for the root B</>) so profiles are easier to manage
|
2006-11-03 09:47:55 +00:00
|
|
|
(e.g. the F</usr/sbin/nscd> profile would be named F<usr.sbin.nscd>).
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
Profiles are applied to a process at exec(3) time (as seen through the
|
2018-01-29 11:27:13 +00:00
|
|
|
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, a process that is already running unconfined cannot
|
|
|
|
be confined.
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
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)
|
2013-12-12 03:07:37 +01:00
|
|
|
iopl(2) ptrace(2) reboot(2) setdomainname(2)
|
2006-04-11 21:52:54 +00:00
|
|
|
sethostname(2) swapoff(2) swapon(2) sysctl(2)
|
|
|
|
|
2021-03-14 04:27:24 -07:00
|
|
|
=head2 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 I<complain mode>. It is important to
|
|
|
|
note that rules that are present in the profile are still applied, so
|
|
|
|
allow rules will still quiet or force audit messages, and deny rules
|
|
|
|
will still result in denials and quieting of denial messages (see
|
|
|
|
I<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
|
2024-03-29 10:56:19 +01:00
|
|
|
profile and then can the application further exercised to discover further
|
2021-03-14 04:27:24 -07:00
|
|
|
additions that are needed. Because AppArmor allows the accesses the
|
|
|
|
application will behave as it would if AppArmor was not confining it.
|
|
|
|
|
|
|
|
B<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.
|
|
|
|
|
|
|
|
B<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 I<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
|
|
|
|
C<complain> flag, and then manually reload the profile:
|
|
|
|
|
|
|
|
profile foo flags=(complain) { ... }
|
|
|
|
|
|
|
|
Note that the C<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.
|
|
|
|
|
|
|
|
To enable complain mode globally, run:
|
|
|
|
|
|
|
|
echo -n complain > /sys/module/apparmor/parameters/mode
|
|
|
|
|
|
|
|
or to set it on boot add:
|
|
|
|
|
|
|
|
apparmor.mode=complain
|
|
|
|
|
2024-03-29 10:56:41 +01:00
|
|
|
as a kernel boot parameter.
|
2021-03-14 04:27:24 -07:00
|
|
|
|
2024-03-29 10:56:56 +01:00
|
|
|
B<Warning> Setting complain mode globally disables all apparmor
|
2021-03-14 04:27:24 -07:00
|
|
|
security protections. It can be useful during debugging or profile
|
|
|
|
development, but setting it selectively on a per profile basis is
|
|
|
|
safer.
|
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
=head1 ERRORS
|
|
|
|
|
|
|
|
When a confined process tries to access a file it does not have permission
|
2006-11-03 09:47:55 +00:00
|
|
|
to access, the kernel will report a message through audit, similar to:
|
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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
|
2006-11-03 09:47:55 +00:00
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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
|
2006-04-11 21:52:54 +00:00
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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"
|
2006-04-11 21:52:54 +00:00
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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"
|
2006-04-11 21:52:54 +00:00
|
|
|
is in quotes, because the process name is limited to 15 bytes; it is the
|
2013-12-12 03:07:37 +01:00
|
|
|
same as reported through the Berkeley process accounting.)
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
For confined processes running under a profile that has been loaded in
|
|
|
|
complain mode, enforcement will not take place and the log messages
|
2006-11-03 09:47:55 +00:00
|
|
|
reported to audit will be of the form:
|
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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
|
2006-11-03 09:47:55 +00:00
|
|
|
|
2013-12-12 03:07:37 +01:00
|
|
|
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
|
2006-11-03 09:47:55 +00:00
|
|
|
|
|
|
|
|
|
|
|
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 F</var/log/audit/audit.log> or F</var/log/messages>,
|
|
|
|
depending upon local configuration.
|
2006-04-11 21:52:54 +00:00
|
|
|
|
2018-10-30 10:52:18 +00:00
|
|
|
=head1 DEBUGGING
|
|
|
|
|
|
|
|
AppArmor provides a few facilities to log more information,
|
|
|
|
which can help debugging profiles.
|
|
|
|
|
|
|
|
=head2 Enable debug mode
|
|
|
|
|
|
|
|
When debug mode is enabled, AppArmor will log a few extra messages to
|
2024-08-28 11:22:08 -07:00
|
|
|
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.
|
2018-10-30 10:52:18 +00:00
|
|
|
|
|
|
|
To enable debug mode, run:
|
|
|
|
|
|
|
|
echo 1 > /sys/module/apparmor/parameters/debug
|
|
|
|
|
2021-03-14 04:27:24 -07:00
|
|
|
or to set it on boot add:
|
|
|
|
|
|
|
|
apparmor.debug=1
|
|
|
|
|
2024-03-29 10:56:41 +01:00
|
|
|
as a kernel boot parameter.
|
2021-03-14 04:27:24 -07:00
|
|
|
|
2018-10-30 10:52:18 +00:00
|
|
|
=head2 Turn off deny audit quieting
|
|
|
|
|
|
|
|
By default, operations that trigger C<deny> rules are not logged.
|
|
|
|
This is called I<deny audit quieting>.
|
|
|
|
|
|
|
|
To turn off deny audit quieting, run:
|
|
|
|
|
|
|
|
echo -n noquiet >/sys/module/apparmor/parameters/audit
|
|
|
|
|
2021-03-14 04:27:24 -07:00
|
|
|
or to set it on boot add:
|
|
|
|
|
|
|
|
apparmor.audit=noquiet
|
|
|
|
|
2024-03-29 10:56:41 +01:00
|
|
|
as a kernel boot parameter.
|
2021-03-14 04:27:24 -07:00
|
|
|
|
2018-10-30 10:52:18 +00:00
|
|
|
=head2 Force audit mode
|
|
|
|
|
|
|
|
AppArmor can log a message for every operation that triggers a rule
|
|
|
|
configured in the policy. This is called I<force audit mode>.
|
|
|
|
|
|
|
|
B<Warning!> Force audit mode can be extremely noisy even for a single profile,
|
|
|
|
let alone when enabled globally.
|
|
|
|
|
|
|
|
To set a specific profile in force audit mode, add the C<audit> flag:
|
|
|
|
|
|
|
|
profile foo flags=(audit) { ... }
|
|
|
|
|
|
|
|
To enable force audit mode globally, run:
|
|
|
|
|
|
|
|
echo -n all > /sys/module/apparmor/parameters/audit
|
|
|
|
|
2021-03-14 04:27:24 -07:00
|
|
|
or to set it on boot add:
|
|
|
|
|
|
|
|
apparmor.audit=all
|
|
|
|
|
2024-03-29 10:56:41 +01:00
|
|
|
as a kernel boot parameter.
|
2021-03-14 04:27:24 -07:00
|
|
|
|
|
|
|
B<Audit Rate Limiting>
|
|
|
|
|
2018-10-30 10:52:18 +00:00
|
|
|
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).
|
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
=head1 FILES
|
|
|
|
|
|
|
|
=over 4
|
|
|
|
|
|
|
|
=item F</etc/apparmor.d/>
|
|
|
|
|
2024-03-03 18:18:12 +01:00
|
|
|
=item F</var/cache/apparmor/>
|
2006-04-11 21:52:54 +00:00
|
|
|
|
2006-11-03 09:47:55 +00:00
|
|
|
=item F</var/log/audit/audit.log>
|
|
|
|
|
|
|
|
=item F</var/log/messages>
|
|
|
|
|
2006-04-11 21:52:54 +00:00
|
|
|
=back
|
|
|
|
|
|
|
|
=head1 SEE ALSO
|
|
|
|
|
2010-12-20 13:47:09 -06:00
|
|
|
apparmor_parser(8), aa_change_hat(2), apparmor.d(5),
|
2018-11-03 16:39:49 -07:00
|
|
|
aa-autodep(1), clean(1),
|
2006-11-03 09:47:55 +00:00
|
|
|
auditd(8),
|
2010-12-20 13:47:09 -06:00
|
|
|
aa-unconfined(8), aa-enforce(1), aa-complain(1), and
|
2018-09-13 16:28:22 +00:00
|
|
|
L<https://wiki.apparmor.net>.
|
2006-04-11 21:52:54 +00:00
|
|
|
|
|
|
|
=cut
|