Directives
apparmor.d
supports build directives, they are processed at build time of the project. They are valid AppArmor comments, therefore, apparmor_parser
can be used on a profile even if the directives have not been processed. They should not end with a comma. Multiline directive is not supported.
The directives follow the format:
<name>
-
The name of the directive to apply
[options]
-
A (possibly empty) list or map of arguments. Exact format depend on the directive.
Dbus¶
See the dbus page.
Only, Exclude¶
The only
and exclude
directives can be used to filter individual rule or rule paragraphs depending on the target distribution or distribution family.
Format
<filter>
-
The filter to apply. Can be:
- A supported target distribution:
arch
,debian
,ubuntu
,opensuse
,whonix
. - A supported distribution family:
apt
,pacman
,zypper
. - A supported ABI:
abi3
,abi4
.
- A supported target distribution:
Example
Generate
#aa:only pacman
-
Remove the line/paragraph when the project is not compiled on the Arch Linux family.
Exec¶
The exec
directive is useful to allow executing transitions to a profile without having to manage the possible long list of profile attachments (it varies depending on the distribution). The directive parses and resolves the attachment variable (@{exec_path}
) of the target profile and includes it in the current profile.
Format
profiles...
-
List of profile files that can be executed from the current profile.
[transition]
-
Optional transition mode (default:
P
). Can be any of:P
,U
,p
,u
,PU
,pu
.
Example
Generate
#aa:exec baloo
Stack¶
Stacked profiles can be hard to maintain. The parent profile needs to manage its own rules as well as always including access from the child profile. In most profile using stacking, the child profile is often naturally included in the parent. However, sometime the child profile is fully different. This directive automatically include the stacked profile rules into the parent profile.
Format
profiles...
-
List a profile files to stack at the end of the current profile.
[X]
-
If
X
is set, the directive will conserve thex
file rules regardless of the transition. It is not enabled by default as it may conflict with the parent profile. Indeed, automatically addingPx
andix
transition in a profile is a very effective way to have conflict between transitions as you can automatically add rule already present in the profile but with another transition (you would then get the AppArmor error:profile has merged rule with conflicting x modifiers
).
Example
Generate
#aa:stack systemd-oomd
-
# Stacked profile: systemd-oomd include <abstractions/bus-system> include <abstractions/common/systemd> capability dac_override, capability kill, unix (bind) type=stream addr=@@{udbus}/bus/systemd-oomd/bus-api-oom, #aa:dbus own bus=system name=org.freedesktop.oom1 /etc/systemd/oomd.conf r, /etc/systemd/oomd.conf.d/{,**} r, @{run}/systemd/io.system.ManagedOOM rw, @{run}/systemd/io.systemd.ManagedOOM rw, @{run}/systemd/notify rw, @{sys}/fs/cgroup/cgroup.controllers r, @{sys}/fs/cgroup/memory.pressure r, @{sys}/fs/cgroup/user.slice/user-@{uid}.slice/user@@{uid}.service/memory.* r, @{PROC}/pressure/{cpu,io,memory} r, include if exists <local/systemd-oomd>