AppArmor applies a set of rules (known as “profile”) on each program. The profile applied by the kernel depends on the installation path of the program being executed. Contrary to SELinux (discussed in ), the rules applied do not depend on the user. All users face the same set of rules when they are executing the same program (but traditional user permissions still apply and might result in different behaviour!).
AppArmor profiles are stored in and they contain a list of access control rules on resources that each program can make use of. The profiles are compiled and loaded into the kernel by the apparmor_parser
command. Each profile can be loaded either in enforcing or complaining mode. The former enforces the policy and reports violation attempts, while the latter does not enforce the policy but still logs the system calls that would have been denied.
AppArmor support is built into the standard kernels provided by Debian. Enabling AppArmor is thus just a matter of installing a few packages and adding some parameters to the kernel command line:
After a reboot, AppArmor is now functional and aa-status
will confirm it quickly:
#
注意 更多的 AppArmor 配置文件
The state of each profile can be switched between enforcing and complaining with calls to aa-enforce
and aa-complain
giving as parameter either the path of the executable or the path to the policy file. Additionaly a profile can be entirely disabled with aa-disable
or put in audit mode (to log accepted system calls too) with .
Even though creating an AppArmor profile is rather easy, most programs do not have one. This section will show you how to create a new profile from scratch just by using the target program and letting AppArmor monitor the system call it makes and the resources it accesses.
The most important programs that need to be confined are the network facing programs as those are the most likely targets of remote attackers. That is why AppArmor conveniently provides an aa-unconfined
command to list the programs which have no associated profile and which expose an open network socket. With the --paranoid
option you get all unconfined processes that have at least one active network connection.
#
In the following example, we will thus try to create a profile for /sbin/dhclient
. For this we will use aa-genprof dhclient
. It will invite you to use the application in another window and when done to come back to aa-genprof
to scan for AppArmor events in the system logs and convert those logs into access rules. For each logged event, it will make one or more rule suggestions that you can either approve or further edit in multiple ways:
Note that the program does not display back the control characters that you type but for the clarity of the explanation I have included them in the previous transcript.
aa-genprof
is in fact only a smart wrapper around aa-logprof
: it creates an empty profile, loads it in complain mode and then run aa-logprof
which is a tool to update a profile based on the profile violations that have been logged. So you can re-run that tool later to improve the profile that you just created.
- # Last Modified: Tue Sep 8 21:40:02 2015
- #include <tunables/global>
- /sbin/dhclient {
- #include <abstractions/base>
- #include <abstractions/nameservice>
- capability net_bind_service,
- /bin/dash r,
- /etc/dhcp/* r,
- /etc/dhcp/dhclient-enter-hooks.d/* r,
- /etc/dhcp/dhclient-exit-hooks.d/* r,
- /etc/resolv.conf.* w,
- /etc/samba/dhcp.conf.* w,
- /proc/*/net/dev r,
- /proc/filesystems r,
- /run/dhclient*.pid w,
- /sbin/dhclient mr,
- /sbin/dhclient-script rCx,
- /usr/lib/NetworkManager/nm-dhcp-helper Px,
- /var/lib/NetworkManager/*.lease rw,
- /var/lib/dhcp/*.leases rw,
- profile /sbin/dhclient-script flags=(complain) {
- #include <abstractions/base>
- #include <abstractions/bash>
- /bin/dash rix,
- /etc/dhcp/dhclient-enter-hooks.d/* r,
- /etc/dhcp/dhclient-exit-hooks.d/* r,
- /sbin/dhclient-script r,
- }