APPARMOR.D(5)

๐Ÿ’– apparmor.d(5) โ€” AppArmor profile syntax (bestie edition) ๐Ÿ’–


๐ŸŒธ NAME ๐ŸŒธ

apparmor.d โ€” it's literally the syntax of security profiles for AppArmor. No cap.


โœจ DESCRIPTION โœจ

Okay so AppArmor profiles? They describe the mandatory access rights that get handed to specific programs, and you feed them to the AppArmor policy enforcement module using apparmor_parser(8). This man page is all about the format of the AppArmor configuration files โ€” if you want the big-picture overview of AppArmor itself, go peek at apparmor(7).


๐Ÿฆ‹ FORMAT ๐Ÿฆ‹

AppArmor policy? Written in a declarative language, which means the order of rules inside any given section or block does NOT matter โ€” it's giving chaos-friendly. By convention policy lives in multiple files, but that's not a requirement at all; you could absolutely write it all in a single file. The policy language gets compiled to an architecture-independent binary format that then gets loaded into the kernel for enforcement. Periodt.

AppArmor compiled policy is stored in a cross-platform container format. When it's loaded into the kernel, it gets verified and converted into the best format for the host. Technically you can convert host policy back to the load format, but recreating the exact format, layout, and sha256sum is not feasible. So if userspace wants to obtain the currently enforced policy from the kernel (for example, criu support needs to do this), AppArmor has to hold onto the originally loaded policy. To reduce the memory that the loaded policy uses, AppArmor compresses the policy with two different types of compression: an internal state layout compression, and a policy container level compression.

The policy state layout compression? That one is only done in the compiler, and the kernel doesn't change it during the unpack โ€” it's natively part of the state machine used for mediation. The policy container compression can be done by the kernel or by the policy compiler to reduce how much memory the policy container uses, all to support CRIU and policy introspection. If you disable introspection of policy and CRIU support, the kernel will not retain the compressed container data. Goodbye, data ๐Ÿ’€.

The policy compiler gives you the option to pre-compress the policy container, so the kernel won't have to do it after the policy is loaded. That gives better control over the compression level used, letting userspace make speed/size trade-offs. Plus, policy only gets compressed once at compile time instead of every single time it's loaded. So subsequent policy loads that rely just on the cache are faster: the kernel only needs to decompress (which is 4-5x faster) at the start of the load, instead of compressing at the end. Efficiency? Slay ๐Ÿ’….

When enabled, the default compression level for userspace compression of the policy is higher than the level the kernel uses. That can make the first load slightly slower, for a better compression. However subsequent loads will be faster. Wanna adjust the default compression level? Set the zstd-compress-level parameter in parser.conf.

The base unit of AppArmor confinement is the profile. It contains a set of rules that are enforced when the profile is associated with a running program. Those rules are basically a whitelist of different permissions that are allowed, plus a few other special rules. Main character energy, honestly ๐Ÿ‘‘.

AppArmor policy text is split into two sections: the preamble and the profile definitions. The preamble must be at the head of the file, and once profile definitions begin, no more preamble rules are allowed (even in files that get included into the profile โ€” sorry bestie). When AppArmor policy (a set of profiles) is split across multiple files, each file can have its own preamble section, which may be the same or different from other files' preambles. But files included within a profile section cannot have a preamble section. Blocked ๐Ÿ™ˆ.

Okay, the following is a BNF-style description of AppArmor policy configuration files; there's an example AppArmor policy file further down. AppArmor config files are line-oriented; # introduces a comment, just like in shell scripting languages. The one exception is that #include will include the contents of a file inline to the policy โ€” that behaviour is modelled after cpp(1).

Here's the whole grammar, verbatim, because we do not skip details in this house:

           PROFILE FILE = ( [ PREAMBLE ] [ PROFILE ] )*

           PREAMBLE = ( COMMENT | VARIABLE ASSIGNMENT | ALIAS RULE | INCLUDE |
           ABI )*
             Variable assignment and alias rules must come before the profile.

           VARIABLE ASSIGNMENT = ( VARIABLE | BOOL_VAR ) ('=' | '+=' | '?=' |
           ':=' ) (space separated values)

           VARIABLE = '@{' ALPHA [ ( ALPHANUMERIC | '_' ) ... ] '}'

           BOOL_VAR = '${' ALPHA [ ( ALPHANUMERIC | '_' ) ... ] '}'

           ALIAS RULE = 'alias' ABS PATH '->' REWRITTEN ABS PATH ','

           INCLUDE = ( '#include' | 'include' ) [ 'if exists' ] ( ABS PATH |
           MAGIC PATH )

           ABI = ( 'abi' ) ( ABS PATH | MAGIC PATH | '<kernel>' | '<default>' )
           ','

           ABS PATH = '"' path '"' (the path is passed to open(2))

           MAGIC PATH = '<' relative path '>'
             The path is relative to /etc/apparmor.d/.

           COMMENT = '#' TEXT [ '\r' ] '\n'

           TEXT = any characters

           PROFILE = ( PROFILE HEAD ) [ ATTACHMENT SPECIFICATION ] [ PROFILE
           FLAG CONDS ] '{' ( RULES )* '}'

           PROFILE HEAD = [ 'profile' ] FILEGLOB | 'profile' PROFILE NAME

           PROFILE NAME ( UNQUOTED PROFILE NAME | QUOTED PROFILE NAME )

           QUOTED PROFILE NAME = '"' UNQUOTED PROFILE NAME '"'

           UNQUOTED PROFILE NAME = (must start with alphanumeric character
           (after variable expansion), or '/' AARE have special meanings; see
           below. May include VARIABLE. Rules with embedded spaces or tabs must
           be quoted.)

           ATTACHMENT SPECIFICATION = [ PROFILE_EXEC_COND ] [ PROFILE XATTR
           CONDS ]

           PROFILE_EXEC_COND = FILEGLOB

           PROFILE XATTR CONDS =  [ 'xattrs=' ] '(' comma or white space
           separated list of PROFILE XATTR ')'

           PROFILE XATTR = extended attribute name '=' XATTR VALUE FILEGLOB

           XATTR VALUE FILEGLOB = FILEGLOB

           PROFILE FLAG CONDS =  [ 'flags=' ] '(' comma or white space
           separated list of PROFILE FLAGS ')'

           PROFILE FLAGS = PROFILE MODE | AUDIT_MODE | 'mediate_deleted' |
           'attach_disconnected' | 'attach_disconnected.path='ABS PATH |
           'chroot_relative' | 'attach_disconnected.ipc' |
           'attach_disconnected.ipc='ABS PATH | 'debug' | 'interruptible' |
           'kill.signal='SIGNAL | 'error='ERROR CODE

           ERROR CODE = (case insensitive error code name starting with 'E';
           see errno(3))

           PROFILE MODE = 'enforce' | 'complain' | 'kill' | 'default_allow' |
           'unconfined' | 'prompt'

           AUDIT MODE = 'audit'

           RULES = [ ( LINE RULES | COMMA RULES ',' | BLOCK RULES )

           LINE RULES = ( COMMENT | INCLUDE ) [ '\r' ] '\n'

           COMMA RULES = ( CAPABILITY RULE | NETWORK RULE | MOUNT RULE | PIVOT
           ROOT RULE | UNIX RULE | FILE RULE | LINK RULE | CHANGE_PROFILE RULE
           | RLIMIT RULE | DBUS RULE | MQUEUE RULE | IO_URING RULE | USERNS
           RULE | ALL RULE)

           BLOCK RULES = ( SUBPROFILE | HAT | QUALIFIER BLOCK | IF_BLOCK )

           SUBPROFILE = 'profile' PROFILE NAME [ ATTACHMENT SPECIFICATION ] [
           PROFILE FLAG CONDS ] '{' ( RULES )* '}'

           HAT = ('hat' | '^') HATNAME [ PROFILE FLAG CONDS ] '{' ( RULES )*
           '}'

           HATNAME = (must start with alphanumeric character. See
           aa_change_hat(2) for a description of how this "hat" is used. If '^'
           is used to start a hat then there is no space between the '^' and
           HATNAME)

           QUALIFIER BLOCK = QUALIFIERS BLOCK

           INTEGER = (+ | -)? [[:digit:]]+

           IF_BLOCK = 'if' EXPR BLOCK [ ( 'else' 'if'  EXPR BLOCK )* ] [ 'else'
           BLOCK ]

           EXPR = ( EXPR ( 'and' | 'or' ) EXPR | 'not' EXPR | '(' EXPR ')' |
           FACTOR )

           FACTOR = ( 'defined' VARIABLE | [ 'defined' ] BOOL_VAR | ( TEXT |
           VARIABLE ) OPERATOR ( TEXT | VARIABLE ) )

           OPERATOR = ( 'in' | '==' | '!=' | '>' | '>=' | '<' | '<=' )

           BLOCK = '{' ( RULES )* '}'

           ACCESS TYPE = ( 'allow' | 'deny' )

           QUALIFIERS = [ 'priority' '=' <INTEGER> ] [ 'audit' ] [ ACCESS TYPE
           ]

           CAPABILITY RULE = [ QUALIFIERS ] 'capability' [ CAPABILITY LIST ]

           CAPABILITY LIST = ( CAPABILITY )+

           CAPABILITY = (lowercase capability name without 'CAP_' prefix; see
           capabilities(7))

           NETWORK RULE = [ QUALIFIERS ] 'network' [ NETWORK ACCESS EXPR ] [
           DOMAIN ] [ TYPE | PROTOCOL ] [ NETWORK LOCAL EXPR ] [ NETWORK PEER
           EXPR ]

           NETWORK ACCESS EXPR = ( NETWORK ACCESS | NETWORK ACCESS LIST )

           NETWORK ACCESS = ( 'create' | 'bind' | 'listen' | 'accept' |
           'connect' | 'shutdown' | 'getattr' | 'setattr' | 'getopt' | 'setopt'
           | 'send' | 'receive' | 'r' | 'w' | 'rw' )
             Some access modes are incompatible with some rules.

           NETWORK ACCESS LIST = '(' NETWORK ACCESS ( [','] NETWORK ACCESS )*
           ')'

           DOMAIN = ( 'unix' | 'inet' | 'ax25' | 'ipx' | 'appletalk' | 'netrom'
           | 'bridge' | 'atmpvc' | 'x25' | 'inet6' | 'rose' | 'netbeui' |
           'security' | 'key' | 'netlink' | 'packet' | 'ash' | 'econet' |
           'atmsvc' | 'rds' | 'sna' | 'irda' | 'pppox' | 'wanpipe' | 'llc' |
           'ib' | 'mpls' | 'can' | 'tipc' | 'bluetooth' | 'iucv' | 'rxrpc' |
           'isdn' | 'phonet' | 'ieee802154' | 'caif' | 'alg' | 'nfc' | 'vsock'
           | 'kcm' | 'qipcrtr' | 'smc' | 'xdp' | 'mctp' ) ','

           TYPE = ( 'stream' | 'dgram' | 'seqpacket' |  'rdm' | 'raw' |
           'packet' )

           PROTOCOL = ( 'tcp' | 'udp' | 'icmp' )

           NETWORK LOCAL EXPR = ( NETWORK IP COND | NETWORK PORT COND |
           INTERFACE COND | LABEL_COND | LABEL ASSIGN )*
             Each cond can appear at most once.

           NETWORK PEER EXPR = 'peer' '=' '(' ( NETWORK IP COND | NETWORK PORT
           COND )+ | LABEL COND | LABEL ASSIGN ')'
             Each cond can appear at most once.

           NETWORK IP COND = 'ip' '=' ( 'none' | NETWORK IPV4 | NETWORK IPV6 )

           NETWORK PORT COND = 'port' '=' ( NETWORK PORT | NETWORK PORT '-'
           NETWORK PORT )

           NETWORK IPV4 = IPv4, represented by four 8-bit decimal numbers
           separated by '.'

           NETWORK IPV6 = IPv6, represented by eight groups of four hexadecimal
           numbers separated by ':'. Shortened representation of contiguous
           zeros is allowed by using '::'

           NETWORK PORT = 16-bit number ranging from 0 to 65535

           INTERFACE COND = 'interface' '=' '(' '"' AARE '"' | AARE ')'

           LABEL COND = 'label' '=' '(' '"' AARE '"' | AARE ')'

           LABEL ASSIGN = 'label' ':=' LABEL NAME

           MOUNT RULE = ( MOUNT | REMOUNT | UMOUNT )

           MOUNT = [ QUALIFIERS ] 'mount' [ MOUNT CONDITIONS ] [ SOURCE
           FILEGLOB ] [ '->' [ MOUNTPOINT FILEGLOB ]

           REMOUNT = [ QUALIFIERS ] 'remount' [ MOUNT CONDITIONS ] MOUNTPOINT
           FILEGLOB

           UMOUNT = [ QUALIFIERS ] 'umount' [ MOUNT CONDITIONS ] MOUNTPOINT
           FILEGLOB

โ€ฆand that's the grammar for part 1! More parts incoming, don't go anywhere ๐Ÿ’…โœจ

okay so back to the grammar tea โ˜•๏ธ first up, the mount rules. they're giving conditional energy:

MOUNT CONDITIONS = [ ( 'fstype' | 'vfstype' ) ( '=' | 'in' ) MOUNT
FSTYPE EXPRESSION ] [ 'options' ( '=' | 'in' ) MOUNT FLAGS
EXPRESSION ]

MOUNT FSTYPE EXPRESSION = ( MOUNT FSTYPE LIST | MOUNT EXPRESSION )

MOUNT FSTYPE LIST = Comma separated list of valid filesystem and
virtual filesystem types (eg ext4, debugfs, devfs, etc)

MOUNT FLAGS EXPRESSION = ( MOUNT FLAGS LIST | MOUNT EXPRESSION )

MOUNT FLAGS LIST = Comma separated list of MOUNT FLAGS.

MOUNT FLAGS = ( 'ro' | 'rw' | 'nosuid' | 'suid' | 'nodev' | 'dev' |
'noexec' | 'exec' | 'sync' | 'async' | 'remount' | 'mand' | 'nomand'
| 'dirsync' | 'noatime' | 'atime' | 'nodiratime' | 'diratime' |
'bind' | 'rbind' | 'move' | 'verbose' | 'silent' | 'loud' | 'acl' |
'noacl' | 'unbindable' | 'runbindable' | 'private' | 'rprivate' |
'slave' | 'rslave' | 'shared' | 'rshared' | 'relatime' |
'norelatime' | 'iversion' | 'noiversion' | 'strictatime' |
'nostrictatime' | 'lazytime' | 'nolazytime' | 'nouser' | 'user' |
'symfollow' | 'nosymfollow' )

MOUNT EXPRESSION = ( ALPHANUMERIC | AARE ) ...

so MOUNT CONDITIONS is like, "hey, check the fstype or vfstype and optionally the options" โ€” it's giving conditional queen ๐Ÿ’…. MOUNT FSTYPE LIST is just a comma-separated list of valid filesystem types like ext4, debugfs, devfs, etc. MOUNT FLAGS LIST is a comma-separated list of MOUNT FLAGS. and MOUNT FLAGS is a whole vibe with all those flags โ€” it's literally every mount flag you can think of. MOUNT EXPRESSION is just alphanumeric or AARE, so you know it's flexible. periodt.

next up, mqueue rules for all your message queue needs:

MQUEUE_RULE = [ QUALIFIERS ] 'mqueue' [ MQUEUE ACCESS PERMISSIONS ]
[ MQUEUE TYPE ] [ LABEL_COND ] [ MQUEUE NAME ]

MQUEUE ACCESS PERMISSIONS = MQUEUE ACCESS | MQUEUE ACCESS LIST

MQUEUE ACCESS LIST = '(' Comma or space separated list of MQUEUE
ACCESS ')'

MQUEUE ACCESS = ( 'r' | 'w' | 'rw' | 'read' | 'write' | 'create' |
'open' | 'delete' | 'getattr' | 'setattr' )

MQUEUE TYPE = 'type' '=' ( 'posix' | 'sysv' )

MQUEUE NAME = AARE

mqueue is all about message queues. MQUEUE ACCESS is the tea โ˜•๏ธ โ€” you can read, write, create, open, delete, getattr, setattr, or the shorthand r/w/rw. MQUEUE TYPE is either posix or sysv. and MQUEUE NAME is just an AARE. got it? ๐Ÿ’–

then userns, which is simple:

USERNS RULE = [ QUALIFIERS ] 'userns' [ USERNS ACCESS PERMISSIONS ]

USERNS ACCESS PERMISSIONS = ( 'create' )

userns is simple โ€” you just need create permission. that's it. iconic.

io_uring is next, giving async energy:

IO_URING RULE = [ QUALIFIERS ] 'io_uring' [ IO_URING ACCESS
PERMISSIONS [ LABEL COND ]

IO_URING ACCESS PERMISSIONS = ( 'sqpoll' | 'override_creds' )

you can have sqpoll or override_creds. (and yes, the bracket situation is a little unhinged, but we copy exactly. no cap.)

pivot_root is for changing the root filesystem:

PIVOT ROOT RULE = [ QUALIFIERS ] pivot_root [ oldroot=OLD PUT
FILEGLOB ] [ NEW ROOT FILEGLOB ] [ '->' PROFILE NAME ]

SOURCE FILEGLOB = FILEGLOB

MOUNTPOINT FILEGLOB = FILEGLOB

OLD PUT FILEGLOB = FILEGLOB

you can specify oldroot, new root, and a profile name to transition to. slay.

ptrace is for debugging and tracing:

PTRACE_RULE = [ QUALIFIERS ] 'ptrace' [ PTRACE ACCESS PERMISSIONS ]
[ PTRACE PEER ]

PTRACE ACCESS PERMISSIONS = PTRACE ACCESS | PTRACE ACCESS LIST

PTRACE ACCESS LIST = '(' Comma or space separated list of PTRACE
ACCESS ')'

PTRACE ACCESS = ( 'r' | 'w' | 'rw' | 'read' | 'readby' | 'trace' |
'tracedby' )

PTRACE PEER = 'peer' '=' AARE

you can read, write, readby, tracedby, or the shorthand. PTRACE PEER lets you specify a peer with an AARE. big brother vibes ๐Ÿ‘€.

signal rules are for sending signals:

SIGNAL_RULE = [ QUALIFIERS ] 'signal' [ SIGNAL ACCESS PERMISSIONS ]
[ SIGNAL SET ] [ SIGNAL PEER ]

SIGNAL ACCESS PERMISSIONS = SIGNAL ACCESS | SIGNAL ACCESS LIST

SIGNAL ACCESS LIST = '(' Comma or space separated list of SIGNAL
ACCESS ')'

SIGNAL ACCESS = ( 'r' | 'w' | 'rw' | 'read' | 'write' | 'send' |
'receive' )

SIGNAL SET = 'set' '=' '(' SIGNAL LIST ')'

SIGNAL LIST = Comma or space separated list of SIGNALs

SIGNAL = ( 'hup' | 'int' | 'quit' | 'ill' | 'trap' | 'abrt' | 'bus'
| 'fpe' | 'kill' | 'usr1' | 'segv' | 'usr2' | 'pipe' | 'alrm' |
'term' | 'stkflt' | 'chld' | 'cont' | 'stop' | 'stp' | 'ttin' |
'ttou' | 'urg' | 'xcpu' | 'xfsz' | 'vtalrm' | 'prof' | 'winch' |
'io' | 'pwr' | 'sys' | 'emt' | 'exists' | 'rtmin+0' ... 'rtmin+32' )

SIGNAL PEER = 'peer' '=' AARE

you can read, write, send, receive. SIGNAL SET lets you list specific signals, and there are a ton of them โ€” from hup to rtmin+32. that's a whole alphabet of signals, bestie. SIGNAL PEER is just an AARE.

dbus rules are next, and they're giving communication energy:

DBUS RULE = ( DBUS MESSAGE RULE | DBUS SERVICE RULE | DBUS EAVESDROP
RULE | DBUS COMBINED RULE )

DBUS MESSAGE RULE = [ QUALIFIERS ] 'dbus' [ DBUS ACCESS EXPRESSION ]
[ DBUS BUS ] [ DBUS PATH ] [ DBUS INTERFACE ] [ DBUS MEMBER ] [ DBUS
PEER ]

DBUS SERVICE RULE = [ QUALIFIERS ] 'dbus' [ DBUS ACCESS EXPRESSION ]
[ DBUS BUS ] [ DBUS NAME ]

DBUS EAVESDROP RULE = [ QUALIFIERS ] 'dbus' [ DBUS ACCESS EXPRESSION
] [ DBUS BUS ]

DBUS COMBINED RULE = [ QUALIFIERS ] 'dbus' [ DBUS ACCESS EXPRESSION
] [ DBUS BUS ]

DBUS ACCESS EXPRESSION = ( DBUS ACCESS | '(' DBUS ACCESS LIST ')' )

DBUS BUS = 'bus' '=' '(' 'system' | 'session' | '"' AARE '"' | AARE
')'

DBUS PATH = 'path' '=' '(' '"' AARE '"' | AARE ')'

DBUS INTERFACE = 'interface' '=' '(' '"' AARE '"' | AARE ')'

DBUS MEMBER = 'member' '=' '(' '"' AARE '"' | AARE ')'

DBUS PEER = 'peer' '=' '(' [ DBUS NAME ] [ LABEL COND ] ')'

DBUS NAME = 'name' '=' '(' '"' AARE '"' | AARE ')'

DBUS ACCESS LIST = Comma separated list of DBUS ACCESS

DBUS ACCESS = ( 'send' | 'receive' | 'bind' | 'eavesdrop' | 'r' |
'read' | 'w' | 'write' | 'rw' )
also, bestie, some accesses are incompatible with some rules; see below ๐Ÿ’….

unix rules are for UNIX domain sockets:

UNIX RULE = [ QUALIFIERS ] 'unix' [ UNIX ACCESS EXPR ] [ UNIX RULE
CONDS ] [ UNIX LOCAL EXPR ] [ UNIX PEER EXPR ]

UNIX ACCESS EXPR = ( UNIX ACCESS | UNIX ACCESS LIST )

UNIX ACCESS = ( 'create' | 'bind' | 'listen' | 'accept' | 'connect'
| 'shutdown' | 'getattr' | 'setattr' | 'getopt' | 'setopt' | 'send'
| 'receive' | 'r' | 'w' | 'rw' )

UNIX ACCESS LIST = '(' UNIX ACCESS ( [','] UNIX ACCESS )* ')'

UNIX RULE CONDS = ( TYPE COND | PROTO COND )

TYPE COND = 'type' '='  ( AARE | '(' ( '"' AARE '"' | AARE )+ ')' )

PROTO COND = 'protocol' '='  ( AARE | '(' ( '"' AARE '"' | AARE )+
')' )

UNIX LOCAL EXPR = ( UNIX ADDRESS COND | LABEL COND | UNIX ATTR COND
| UNIX OPT COND )*

UNIX PEER EXPR = 'peer' '=' ( UNIX ADDRESS COND | UNIX LABEL COND )+

UNIX ADDRESS COND 'addr' '=' ( AARE | '(' '"' AARE '"' | AARE ')' )

UNIX ATTR COND 'attr' '=' ( AARE | '(' '"' AARE '"' | AARE ')' )

UNIX OPT COND 'opt' '=' ( AARE | '(' '"' AARE '"' | AARE ')' )
ngl, some access modes don't vibe with certain rules or need extra parameters, so watch out ๐Ÿซฃ. Also, each cond can show up at most once, periodt. That goes for UNIX RULE CONDS, UNIX LOCAL EXPR, and UNIX PEER EXPR.

rlimit rules are for setting resource limits:

RLIMIT RULE = 'set' 'rlimit' [RLIMIT '<=' RLIMIT VALUE ]

RLIMIT = ( 'cpu' | 'fsize' | 'data' | 'stack' | 'core' | 'rss' |
'nofile' | 'ofile' | 'as' | 'nproc' | 'memlock' | 'locks' |
'sigpending' | 'msgqueue' | 'nice' | 'rtprio' | 'rttime' )

RLIMIT VALUE = ( RLIMIT SIZE | RLIMIT NUMBER | RLIMIT TIME | RLIMIT
NICE )

RLIMIT SIZE = NUMBER ( 'K' | 'M' | 'G' )

RLIMIT NUMBER = number from 0 to max rlimit value.

RLIMIT TIME = NUMBER ( 'us' | 'microsecond' | 'microseconds' | 'ms'
| 'millisecond' | 'milliseconds' | 's' | 'sec' | 'second' |
'seconds' | 'min' | 'minute' | 'minutes' | 'h' | 'hour' | 'hours' |
'd' | 'day' | 'days' | 'week' | 'weeks' )

RLIMIT NICE = a number between -20 and 19.

RLIMIT SIZE only applies to RLIMIT of 'fsize', 'data', 'stack', 'core', 'rss', 'as', 'memlock', 'msgqueue'. RLIMIT NUMBER only applies to RLIMIT of 'ofile', 'nofile', 'locks', 'sigpending', 'nproc', 'rtprio'. RLIMIT TIME only applies to RLIMIT of 'cpu' and 'rttime'. RLIMIT 'cpu' only allows units >= 'seconds'. RLIMIT NICE only applies to RLIMIT of 'nice'. got all that? ๐Ÿ’–

file rules are the big ones:

FILE RULE = [ QUALIFIERS ] [ 'owner' ] ( 'file' | [ 'file' ] (
FILEGLOB ACCESS  | ACCESS FILEGLOB ) [ '->' EXEC TARGET ] )

FILEGLOB = ( QUOTED FILEGLOB | UNQUOTED FILEGLOB )

QUOTED FILEGLOB = '"' UNQUOTED FILEGLOB '"'

UNQUOTED FILEGLOB = (must start with '/' (after variable expansion),
AARE have special meanings; see below. May include VARIABLE. Rules
with embedded spaces or tabs must be quoted. Rules must end with '/'
to apply to directories.)

AARE = ?*[]{}^

ACCESS = ( 'r' | 'w' | 'a' | 'l' | 'k' | 'm' | EXEC TRANSITION )+

EXEC TRANSITION =  ( 'ix' | 'ux' | 'Ux' | 'px' | 'Px' | 'cx' | 'Cx'
| 'pix' | 'Pix' | 'cix' | 'Cix' | 'pux' | 'PUx' | 'cux' | 'CUx' |
'x' )

EXEC TARGET = name

LINK RULE = QUALIFIERS [ 'owner' ] 'link' [ 'subset' ] FILEGLOB '->'
FILEGLOB

ALPHA = ('a', 'b', 'c', ... 'z', 'A', 'B', ... 'Z')

ALPHANUMERIC = ('0', '1', '2', ... '9', 'a', 'b', 'c', ... 'z', 'A',
'B', ... 'Z')

CHANGE_PROFILE RULE = 'change_profile' [ [ EXEC MODE ] EXEC COND ] [
'->' PROFILE NAME ]

EXEC_MODE = ( 'safe' | 'unsafe' )

EXEC COND = FILEGLOB

ALL RULE = 'all'

so UNQUOTED FILEGLOB must start with '/' after variable expansion, AARE have special meanings (see below), may include VARIABLE, rules with spaces or tabs must be quoted, and rules must end with '/' to apply to directories. AARE is just ?*[]{}^ โ€” check the "Globbing (AARE)" section below for meanings. ACCESS is r, w, a, l, k, m, or an EXEC TRANSITION. not all combinations are allowed; see below. EXEC TRANSITION has a ton of options, and a bare 'x' is only allowed in rules with the deny qualifier, everything else only without the deny qualifier. EXEC TARGET requires EXEC TRANSITION. LINK RULE is for linking. ALPHA and ALPHANUMERIC are just character sets. CHANGE_PROFILE RULE is for changing profiles. EXEC_MODE is safe or unsafe. EXEC COND is a FILEGLOB. and ALL RULE is just 'all'. iconic.

now, the tea on subprofiles: All resources and programs need a full path. There may be any number of subprofiles (aka child profiles) in a profile, limited only by kernel memory. Subprofile names are limited to 974 characters. Child profiles can be used to confine an application in a special way, or when you want the child to be unconfined on the system, but confined when called from the parent. Hats are a special child profile that can be used with the aa_change_hat(2) API call. Applications written or modified to use aa_change_hat(2) can take advantage of subprofiles to run under different confinements, dependent on program logic. Several aa_change_hat(2)-aware applications exist, including an Apache module, mod_apparmor(5); a PAM module, pam_apparmor; and a Tomcat valve, tomcat_apparmor. Applications written or modified to use aa_change_profile(2) transition permanently to the specified profile. libvirt is one such application.

Profile Head

The profile head consists of a required name that is unique and optional attachment conditionals and control flags.

Name

The name of the profile is its identifier. It is what is displayed during introspection (eg. ps -Z), and defines how the profile is referenced by policy rules for any policy interaction via ipc or domain changes. It is recommended that the name be kept short and have meaning for the application it is being applied eg. firefox for the firefox web browser or its functional role eg. log_admin.

If the name is an applications full absolute path name eg. /usr/bin/firefox and an exec attachment conditional is not specified the name is also used as the profile's exec attachment conditional. This use however has been deprecated and is discouraged as it makes for long names that can make profile rules difficult to understand, and may not be fully displayed by some introspection tools.

Attachment Conditionals

The attachment conditionals are used during profile changes to determine whether a profile is a match for the proposed profile transition. The attachment conditionals are optional, how and when they are applied is determined by the specific condition(s) used.

When you're rolling with attachment conditionals, the conditionals for every profile in the namespace get evaluated, bestie. The profile with the set of attachments that results in the best match becomes the new profile after a transition operation. And attachments that don't match? That profile just isn't available for transition, sorry babe. ๐Ÿ’…

If no conditionals are specified at all, then the profile only gets used if a transition explicitly specifies the profile name. That's the whole vibe.

Exec Attachment Conditional

The exec attachment conditional is the one that governs how closely your profile matches an executable program. It's only used during an exec operation when the matching exec rule specifies either a px or a cx transition type (or their derivatives). It'll also be used by tasks that are unconfined, because those roll with a pix transition rule. ๐Ÿซถ

And if there are no attachment matches, then it's up to the exec rule to decide what happens โ€” fail, or a fallback option. No attachment match, no opinion, the exec rule runs the show.

Note: see profile Name for all the info around using the profile name as an attachment conditional. ๐Ÿ’–

Exec attachment conditionals can contain variable names and pattern matching. They use a longest left match heuristic to decide the winner when there are multiple matches at run time. The exact implementation of this resolution is kernel specific and has improved over time, all while retaining backwards compatibility. And if the heuristic can't determine a winner between multiple matches? Then the exec is denied. Periodt. ๐Ÿ’€

Extended Attributes Attachment Conditional

AppArmor profiles have the ability to target files based on their xattr(7) values in addition to their path. Like, obsessed. For example, this profile matches files in /usr/bin with the attribute "security.apparmor" and value "trusted":

/usr/bin/* xattrs=(security.apparmor="trusted") {
  # ...
}

See apparmor_xattrs(7) for further details. ๐ŸŒธ

Flags

The profile flags let you modify the behavior of the profile. And if a profile flag is specified, it takes priority over any conflicting flags that have been specified by rules in the profile body. Flags beat rules, no cap. โœจ

Profile Mode

The profile mode lets you control the enforcement behavior of the profile rules.

If no mode is specified, the profile defaults to enforce mode.

  • enforce โ€” For a given action, if the profile rules don't grant permission, the action is denied, with an EACCES or EPERM error code returned to userspace, and the violation gets logged with a tag of the access being DENIED.
  • kill โ€” This is a variant of enforce mode where, on top of returning EACCES or EPERM for a violation, the task is also sent a signal to kill it. ๐Ÿ’€
  • complain โ€” For a given action, if the profile rules don't grant permission, the action is allowed, but the violation still gets logged with a tag of the access being ALLOWED.
    • It is important to understand that complain mode does not allow everything. It only allows policy violations that are not covered by a rule in the confining profile. This means that errors caused by non-policy violations, permissions being denied by interactions with other subsystems, or actions denied due to none policy based restrictions will not be allowed.
    • The set of what can be allowed may change with the kernel version, either because new mediation hooks have been added, policy has been extended to cover cases that were hardcoded restrictions, ABI mismatch, or new failure possibilities have been introduced.
    • A non-complete list of places where complain mode will not convert an error into an allowed operation follows. ๐Ÿ‘‡
      • explicit denials โ€” If the kernel is carrying explicit denial information (generated by deny rules), the access will not be allowed. complain mode will only convert implicit denials to ALLOWED.
        • It is important to note that a kernel may not have the ability to carry explicit denial information, and that even if the kernel does carry explicit denial information, the compiler may choose to strip explicit denial information (-O filter-deny).
      • stacked denials โ€” Denials from other profiles that are not in complain but are in a mediation stack with a profile in complain mode can cause mediation to fail. These failures will be reported against those profiles and not the profile in complain mode.
      • Peer profiles interaction โ€” In mediation that involves a peer profile (eg. ipc or ptrace), the peer profile can cause an operation to be denied even though the current task's profile is in complain mode.
        • This is because these interactions require both profiles to allow the action, and there is a cross check that gets done. If the peer profile does not allow the requested action, and it is not in complain mode, the cross check will fail and the requested action will be denied. Such a denial will be logged against the peer profile, but the requesting task will receive the denial error.
      • Memory allocations errors (ENOMEM) โ€” If mediation requires allocation of memory and the allocation of memory fails, AppArmor will fail closed, returning an ENOMEM error. This prevents attackers from trying to use memory DOS attacks to by-pass policy. ๐Ÿ›ก๏ธ
      • Interrupts โ€” Interrupts that may cause a syscall restart, break locks, or otherwise result in interrupting mediation will result in the appropriate error being returned (eg. ERESTART).
      • disconnected objects โ€” Objects (files, paths, sockets, mounts) that do not have sufficient mediation information may be denied. Examples include file objects opened in a different mount namespace that have not been delegated to the task being mediated, sockets in a different network namespace, users from a different user namespace.
        • It may also include mount objects without sufficient tracking information, file objects that have been deleted/removed, sockets that have been shutdown, controlling terminals that have been removed, etc.
      • Permissions denied by another subsystem โ€” If AppArmor queries the capabilities subsystem, and it denies the access, depending on why the query was made the access may be denied, instead of converted to an ALLOWED operation. Similarly this may be done for unix DAC permissions.
      • No-new-privs โ€” The no-new-privs restriction occurs when a task indicates to the kernel that no new privileges should be granted. It is a way for userspace to request an explicit security barrier. AppArmor respects the no-new-privs request and will not allow adding permissions or changing policy unless the change can be proven to be a subset of the existing confinement.
        • no-new-privs in particular affects profile transitions.
      • Restrictions not covered by policy โ€” AppArmor has a few hardcoded restrictions that are not covered by policy, and thus can not be allowed by policy. Hence they are not covered by complain mode. When these restrictions are applied they will return EPERM instead of EACCES. An example of this is trying to disable AppArmor via the module enabled parameter, after AppArmor has been initialized during kernel initialization in early boot. This parameter is restricted to use as a kernel parameters set in the boot loader.
        • The full set of these restrictions can change based on kernel version.
      • ABI mismatch โ€” If the ABI of policy does not match the ABI of the kernel, complain mode may be affected in non-intuitive ways. Generally the ABI mismatch will not result in failures that result in an error that could be converted to an ALLOWED message by complain mode. Instead, ABI mismatches usually result in rules not being enforced, resulting in no mediation or allowed messages even though a kernel may support a given feature.
        • eg. the kernel may support fine grained network ip mediation, but the policy was declared under an ABI that does not specify support for fine grained network mediation. In this scenario the profile will not deny based on fine grained network access and there may not be any complain mode ALLOWED messages or denied messages.
        • ABI mismatches can cause rule downgrades instead of rules not being mediated. Generally this means rules are broader, resulting in the same issue seen with rules not being enforced, ie. what is being allowed by the kernel is more generic than what the rule specified, but it is still not allowing everything that a full rule not enforced would.
        • An example of this would be a fine grained ip address rule being downgraded to a coarser, socket level rule. Eg.
allow network rw stream ip=127.0.0.1 port=5555,

being downgraded to

allow network inet stream,

The downgraded rule can result in denials. The above example will result in denials for inet dgram that can be converted into ALLOWED messages by complain mode. However it will allow inet stream access to ports that are not 5555, and to addresses that are not 127.0.0.1. Neither of these broader accesses will result in denial messages that can be converted to ALLOWED messages by complain mode.

  • There is a case where rule downgrades can result in ALLOWED messages for mediation covered by a rule in policy. When deny rules are downgraded, they get narrower (to avoid denying more than what was specified in policy) and rely on default deny to cover gaps between the explicit deny rule and the allow rules in policy. This however means that a downgrade of a deny rule may result in complain mode ALLOWED messages for accesses that are already explicitly denied by policy. ๐Ÿ˜ญ
  • null-XXX profiles โ€” okay so these are the kernel's special null profiles, and their whole job is tracking the execution of child processes that a program in complain mode execs. Here's the tea tho: depending on which kernel you're on, these null profiles might have a different ABI than the parent profile in complain mode, which gives you weird behavior that looks exactly like an ABI mismatch. Not a vibe. ๐Ÿ˜ญ
  • default_allow โ€” bestie, this mode flips AppArmor's whole default from default deny to default allow. So when default_allow is specified, the resulting profile will just allow operations that it doesn't even have a rule for. It's giving unconfined, but it still lets you do allow rules, deny rules, specify audit, and domain transitions. One little thing: profiles in this mode may be reported as being in enforce mode or allow mode when introspected from the kernel, so don't panic.
Note: default_allow is similar to โ€” and for many profiles will be equivalent to โ€” specifying an allow all, rule in the profile. But the default_allow flag does not provide all the same options that the allow all, rule provides. Close, but not the same, iykyk.
  • unconfined โ€” this mode lets a task confined by the profile behave as though it is unconfined. You can flip that unconfined behavior back to confinement later using profile replacement. Do not use this under regular deployment, for real โ€” it's for debugging and some system initialization scenarios only. ๐ŸŽ€

This mode is similar to default_allow, and on kernels that no longer support a true unconfined mode it may be emulated by default_allow. It does not generally allow for specifying deny rules, or allow rules that override the default behavior โ€” except in a few custom kernels where unconfined restricts a few operations. It relies on special customized behavior of the unconfined profile in the kernel, so likeโ€ฆ it should only be used for debugging.

Note: true unconfined is being phased out ๐Ÿ˜ญ, with unconfined becoming a replaceable profile. As such, unconfined mode will be emulated by a special profile compiled with the default_allow flag in newer kernels.
  • prompt โ€” this mode lets task mediation send an up call to userspace to ask for a decision whenever there isn't a rule covering the permission request. And if userspace doesn't respond? The access will be denied. No response, no entry. ๐Ÿ’…

๐ŸŒˆ Audit Mode ๐ŸŒˆ

The audit mode is all about controlling how AppArmor messages get logged to the audit system.

  • audit โ€” this flag causes all actions, whether allowed or denied, to be logged. Every. Single. One. ๐Ÿ‘‘

๐Ÿฆ‹ Misc modes ๐Ÿฆ‹

  • mediate_deleted โ€” forces AppArmor to mediate deleted files as if they still exist in the file system. Ghost files, but make it policy.
  • attach_disconnected โ€” forces AppArmor to attach disconnected objects to the task's namespace and mediate them as though they are part of the namespace. โš ๏ธ WARNING this mode is unsafe and can result in aliasing and access to objects that should not be allowed. Its intent is a debug and policy development tool.
  • attach_disconnected.path=ABS PATH โ€” like attach_disconnected, but it attaches disconnected objects to the supplied path instead of the root of the namespace.
  • attach_disconnected.ipc โ€” a subset of attach_disconnected, but specific for IPC namespaces. It allows attaching disconnected IPC paths without having to allow attaching all types of files.
  • attach_disconnected.ipc=ABS PATH โ€” like attach_disconnected.ipc, but attach disconnected posix mqueue to the supplied path instead of the root of the namespace.
  • chroot_relative โ€” forces file names to be relative to a chroot and behave as if the chroot is a mount namespace.
  • debug โ€” this flag turns on kernel debug messages on a per-profile basis. It works in conjunction with other kernel debug flags to control what messages will be output. Its effect is kernel dependent, and it should never appear in policy except when you're trying to debug kernel or policy problems.
  • interruptible โ€” enables interrupts for prompt upcall to userspace.
  • kill.signal=SIGNAL โ€” changes the signal that AppArmor will send when it's in kill mode or a kill rule has been violated.
  • error=ERROR CODE โ€” changes the error code returned by AppArmor when a rule has been violated.

โœจ Access Modes โœจ

File permission access modes are made of combinations of these:

  • r โ€” read
  • w โ€” write โ€” conflicts with append
  • a โ€” append โ€” conflicts with write
  • ux โ€” unconfined execute
  • Ux โ€” unconfined execute โ€” use ld.so(8) secure-execution mode
  • px โ€” discrete profile execute
  • Px โ€” discrete profile execute โ€” use ld.so(8) secure-execution mode
  • cx โ€” transition to subprofile on execute
  • Cx โ€” transition to subprofile on execute โ€” use ld.so(8) secure-execution mode
  • ix โ€” inherit execute
  • pix โ€” discrete profile execute with inherit fallback
  • Pix โ€” discrete profile execute with inherit fallback โ€” use ld.so(8) secure-execution mode
  • cix โ€” transition to subprofile on execute with inherit fallback
  • Cix โ€” transition to subprofile on execute with inherit fallback โ€” use ld.so(8) secure-execution mode
  • pux โ€” discrete profile execute with fallback to unconfined
  • PUx โ€” discrete profile execute with fallback to unconfined โ€” use ld.so(8) secure-execution mode
  • cux โ€” transition to subprofile on execute with fallback to unconfined
  • CUx โ€” transition to subprofile on execute with fallback to unconfined โ€” use ld.so(8) secure-execution mode
  • deny x โ€” disallow execute (in rules with the deny qualifier)
  • m โ€” allow PROT_EXEC with mmap(2) calls
  • l โ€” link
  • k โ€” lock

๐Ÿ’– Access Modes Details ๐Ÿ’–

๐Ÿ“ r - Read mode

Allows the program to have read access to the file or directory listing. Read access is required for shell scripts and other interpreted content. Yes bestie, your shell scripts need this one.

๐Ÿ“ w - Write mode

Allows the program to have write access to the file. Files and directories must have this permission if they are to be unlinked (removed). Write mode is not required on a directory to rename or create files within the directory.

This mode conflicts with append mode.

๐Ÿ“ a - Append mode

Allows the program to have a limited appending only write access to the file. Append mode will prevent an application from opening the file for write unless it passes the O_APPEND parameter flag on open.

The mode conflicts with Write mode.

๐Ÿ“ ux - Unconfined execute mode

Allows the program to execute the program without any AppArmor profile being applied to the program.

This mode is useful when a confined program needs to be able to perform a privileged operation, such as rebooting the machine. By placing the privileged section in another executable and granting unconfined execution rights, it is possible to bypass the mandatory constraints imposed on all confined processes. For more information on what is constrained, see the apparmor(7) man page.

โš ๏ธ WARNING ux should only be used in very special cases. It enables the designated child processes to be run without any AppArmor protection. ux does not use ld.so(8) secure-execution mode to clear variables such as LD_PRELOAD; as a result, the calling domain may have an undue amount of influence over the callee. Use this mode only if the child absolutely must be run unconfined and LD_PRELOAD must be used. Any profile using this mode provides negligible security. Use at your own risk. ๐Ÿ’€

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ Ux - unconfined execute -- use ld.so(8) secure-execution mode

Ux allows the named program to run in ux mode, but AppArmor will invoke the Linux Kernel's unsafe_exec routines to set ld.so(8) secure-execution mode and clear environment variables such as LD_PRELOAD, similar to setuid programs. (See ld.so(8) for more information.)

โš ๏ธ WARNING Ux should only be used in very special cases. It enables the designated child processes to be run without any AppArmor protection. Use this mode only if the child absolutely must be run unconfined. Use at your own risk.

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ px - Discrete Profile execute mode

This mode requires that a discrete security profile is defined for a program executed and forces an AppArmor domain transition. If there is no profile defined then the access will be denied.

โš ๏ธ WARNING px does not use ld.so(8) secure-execution mode to clear variables such as LD_PRELOAD; as a result, the calling domain may have an undue amount of influence over the callee.

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ Px - Discrete Profile execute mode -- use ld.so(8) secure-execution mode

Px allows the named program to run in px mode, but AppArmor will invoke the Linux Kernel's unsafe_exec routines to set ld.so(8) secure-execution mode and clear environment variables such as LD_PRELOAD, similar to setuid programs. (See ld.so(8) for more information.)

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ cx - Transition to Subprofile execute mode

This mode requires that a local security profile is defined and forces an AppArmor domain transition to the named profile. If there is no profile defined then the access will be denied.

โš ๏ธ WARNING cx does not use ld.so(8) secure-execution mode to clear variables such as LD_PRELOAD; as a result, the calling domain may have an undue amount of influence over the callee.

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ Cx - Transition to Subprofile execute mode -- use ld.so(8) secure-execution mode

Cx allows the named program to run in cx mode, but AppArmor will invoke the Linux Kernel's unsafe_exec routines to set ld.so(8) secure-execution mode and clear environment variables such as LD_PRELOAD, similar to setuid programs. (See ld.so(8) for more information.)

Incompatible with other exec transition modes and the deny qualifier.

๐Ÿ“ ix - Inherit execute mode

Prevent the normal AppArmor domain transition on execve(2) when the profiled program executes the named program. Instead, the executed resource will inherit the current profile.

This mode is useful when a confined program needs to call another confined program without gaining the permissions of the target's profile, or losing the permissions of the current profile. There is no version to set secure-execution mode because ix executions don't change privileges.

okay so that mode we were just talking about? yeah โ€” incompatible with other exec transition modes and the deny qualifier. Periodt. Don't mix them ๐Ÿ’…


Profile transition with inheritance fallback execute mode ๐Ÿงฌ

These modes are โœจgiversโœจ: they attempt to do a domain transition exactly as the matching permission says (list below, bestie), and if that transition fails to find the matching profile, the domain transition just carries on using the ix transition mode instead. Fallback queen behavior, honestly.

'Pix' == 'Px' with fallback to 'ix'
'pix' == 'px' with fallback to 'ix'
'Cix' == 'Cx' with fallback to 'ix'
'cix' == 'cx' with fallback to 'ix'

Incompatible with other exec transition modes and the deny qualifier.


Profile transition with unconfined fallback execute mode ๐Ÿฆ‹

Same idea, different fallback: these attempt the domain transition as specified by the matching permission (shown below ๐Ÿซถ), and if it fails to find the matching profile, the transition proceeds using the ux transition mode if pux, cux is used, or the Ux transition mode if PUx, CUx is used. It's giving "plan B is unconfined" energy and we respect it ๐ŸŒˆ

'PUx' == 'Px' with fallback to 'Ux'
'pux' == 'px' with fallback to 'ux'
'CUx' == 'Cx' with fallback to 'Ux'
'cux' == 'cx' with fallback to 'ux'

Incompatible with other exec transition modes and the deny qualifier.


deny x โ€” Deny execute ๐Ÿšซ

For rules that include the deny modifier, only x is allowed to deny execute. No other letters invited to that party, sorry not sorry.

And listen: the ix, Px, px, Cx, cx and the fallback modes conflict with the deny modifier. They cannot be in the same room. ๐Ÿ’€


Directed profile transitions ๐ŸŽฏ

So the directed (px, Px, pix, Pix, pux, PUx) profile and subprofile (cx, Cx, cix, Cix, cux, CUx) transitions normally figure out which profile to transition to from the executable name. Lowkey automatic. BUT ๐Ÿซข it is however possible to specify the name of the profile that the transition should use, because we're main character planners around here.

You specify the profile to transition to using -> followed by the name of the profile to transition to. Eg.

/bin/** px -> profile,

Incompatible with other exec transition modes.


m โ€” Allow executable mapping ๐Ÿง 

This mode lets a file be mapped into memory using mmap(2)'s PROT_EXEC flag. That flag marks the pages executable; it's used on some architectures to provide non-executable data pages, which can complicate exploit attempts. Slay security. AppArmor uses this mode to limit which files a well-behaved program (or all programs on architectures that enforce non-executable memory access controls) may use as libraries, to limit the effect of invalid -L flags given to ld(1) and LD_PRELOAD, LD_LIBRARY_PATH, given to ld.so(8). That's the whole point, iykyk ๐Ÿ’…


Allows the program to be able to create a link with this name. When a link is created, the new link MUST have a subset of permissions as the original file (with the exception that the destination does not have to have link access.) And if there is an x rule on the new link, it must match the original file exactly. No vibes-based matching, bestie โœจ


k โ€” lock mode ๐Ÿ”

Allows the program to be able lock a file with this name. This permission covers both advisory and mandatory locking. Yes queen, both ๐Ÿ’œ


leading OR trailing access permissions ๐ŸŒธ

File rules can be specified with the access permission either leading or trailing the file glob. Eg.

rw /**,               # leading permissions

/** rw,               # trailing permissions

When leading permissions are used further rule options and context may be allowed, Eg.

l /foo -> /bar,       # lead 'l' link permission is equivalent to link rules

Link rules allow specifying permission to form a hard link as a link target pair. If the subset condition is specified then the permissions to access the link file must be a subset of the profiles permissions to access the target file. And if there is an x rule on the new link, it must match the original file exactly. (Yes, again. It's a whole theme.)

Eg.

/file1  r,
/file2  rwk,
/link*  rw,
link subset /link* -> /**,

The link rule allows linking of /link to both /file1 or /file2 by name, however because the /link file has rw permissions it is not allowed to link to /file1 because that would grant an access path to /file1 with more permissions than the r permissions the profile specifies. Greedy behavior = denied ๐Ÿ™ˆ

A link of /link to /file2 would be allowed because the rw permissions of /link are a subset of the rwk permissions for /file1. See how that works? Chef's kiss ๐Ÿ‘‘

The link rule is equivalent to specifying the l link permission as a leading permission with no other file access permissions. When this is done the link rule options can be specified.

The following link rule is equivalent to the l permission file rule

link /foo -> bar,
l /foo -> /bar,

File rules that specify the l permission and don't specify the extend link permissions map to link rules as follows.

/foo l,
l /foo,
link subset /foo -> /**,

Comments ๐Ÿ’ฌ

Comments start with # and may begin at any place within a line. The comment ends when the line ends. This is the same comment style as shell scripts. Simple, iconic, we love a consistent girlie โœจ


Capabilities ๐ŸŒˆ

The only capabilities a confined process may use may be enumerated; for the complete list, please refer to capabilities(7).

๐Ÿšจ okay this is the important bit: granting some capabilities renders AppArmor confinement for that domain advisory; while open(2), read(2), write(2), etc., will still return error when access is not granted, some capabilities allow loading kernel modules, arbitrary access to IPC, ability to bypass discretionary access controls, and other operations that are typically reserved for the root user. That is a LOT of power. Be careful bestie, fr fr ๐Ÿ˜ญ

Network Rules ๐Ÿ•ธ๏ธ

AppArmor supports simple coarse grained network mediation. The network rule rest

  • audit: bestie, this profile flag is lowkey shy โ€” it may not trigger unless your profile has rules that assign the profile label, or rules that match an interface. The thing is, the audit prefix on a rule with the interface conditional? Not limited like that. She's free. ๐Ÿ’…
  • complain: same energy, unfortunately โ€” the complain profile flag may not trigger unless the profile has rules assigning the profile label, or rules matching the interface. But again, the complain prefix on a rule with the interface conditional does not have this limitation. slay.
  • prompt: the interface conditional is โœจincompatibleโœจ with the prompt rule prefix, and the prompt flag will not trigger for interface failures. so that's just not happening.
  • kill: the interface conditional is incompatible with the kill rule prefix, and also with the profile flag for inbound packets. ๐Ÿ’€
  • halt: the interface conditional is incompatible with the halt rule prefix, and the profile flag for inbound packets. same vibe, different casualty.

The outbound interface conditional interacts with โ€” and potentially conflicts with โ€” explicit firewall packet labeling that uses the SecMark. Why tho? Because the interface conditional uses the label on the outbound packet to mediate which interface the packet is allowed to be sent to. ๐Ÿ˜ญ

So if you explicitly set the label via a firewall rule, you can change the label on the packet, and that can potentially cause the interface conditional to not be applied at all, or even cause the wrong interface mediation to be applied. not cute.

Where possible, when multiple labels are specified, AppArmor will assign a label stack to the packet ensuring the interface conditional is applied โ€” and if it can't do that, it will raise a policy compilation error. she'd rather scream than lie to you fr fr. ๐Ÿซถ

See the SecMark section for information on how the interface restrictions interact with NetFilter and firewall rules.

The interface mediation may be done via SecMark packet labeling in the NetFilter LOCAL_OUTPUT hook. And if it is done via SecMark, any other firewall rule that runs before the AppArmor hook in the LOCAL_OUTPUT hook may result in interface mediation not working correctly. ๐Ÿ‘‘

Interface mediation is done in the LOCAL_OUTPUT netfilter hook, and is subject to any changes a previous hook may have done to packet routing information. That is to say, it is possible that some firewall rule type applications could interfere with AppArmor interface mediation.


๐ŸŒธ Label Match Conditional ๐ŸŒธ

The label match conditional lets you specify the label that a received packet is allowed to have โ€” or, for socket based operations, the label that the socket has. The label match is performed by matching the specified label pattern against the SecMark (or any other future supported type of label) on the packet, or in the case of socket operations, the label on the socket.

The local label match conditional is the conditional used for socket label matching.

network label=foo,

The peer label match conditional is the conditional used when matching incoming network packet labels.

network receive peer=(label=foo),
network inet peer=(label=httpd),
network ip=127.0.0.1 peer=(label=httpd),

The label on a socket is set by the confinement of the task that opened the socket, and is potentially extended if the socket is passed to other tasks with different confinement. shared socket, shared label energy โœจ

The label on a packet (currently just the SecMark) can be set by an AppArmor rule (interface or explicit assignment), or by system firewalls like iptables. For the purposes of network packet label matching, if a packet does not have a label (SecMark) it will be associated with the special label of unlabeled.

AppArmor will only do packet label matching when profiles have explicit rules supporting it. Otherwise AppArmor will short circuit label match mediation, reducing the overhead. she's efficient like that ๐Ÿ’…

For packet label matching, the socket label is used as a proxy for the receiving task. Generally this does not affect mediation โ€” however, if a socket is shared between tasks with different confinement, what is allowed will be the intersection of what is allowed by all profiles in the socket label.

Why? Because AppArmor does not control which task will receive the packet, and so it can only allow what is allowed by all tasks that could potentially receive the packet. intersection not union, periodt.

Similarly, unless the interface match conditional is used or an explicit label assignment rule is used, AppArmor does not set the label on packets, to avoid any overhead when it is not necessary.


๐ŸŽ€ Specifying Socket and Packet Labeling ๐ŸŽ€

AppArmor by default will label sockets with the creating task's confinement. This labeling may be extended to a label stack when the socket is shared between tasks of different confinement.

AppArmor by default does not label network packets, because that can have performance implications, and it is not always needed. Instead AppArmor tries to be smart about packet labeling on applying and matching labels when needed to support the specified rules. smart queen behavior fr fr.

Some rules will result in a packet being given the label of the sending task. e.g. the interface conditional will implicitly label outgoing packets with the task's confinement (note: in some cases the socket's label may be used as a proxy).

Implicitly labeling packets works if you are only considering AppArmor network rules. However, if the admin would like to also be able to control packets based on AppArmor labeling at the firewall, then implicit labeling controls are not sufficient, and explicit labeling must be used.

AppArmor allows specifying an explicit label for both the socket and the packet, using the assignment conditional.

For the socket, the local assignment conditional is used.

network label:=@{profile_name},

In this case, the use of @{profile_name} is equivalent to the implicit labeling that AppArmor already does.

For packet labels, the peer assignment condition is used.

network send inet peer=(label:=@{profile_name}),

In this case the label set is the same label that implied labeling set โ€” except that it will be set on every network packet, not just the ones implied by the interface conditional. ๐Ÿ’–

Explicit labeling can interact with and conflict with implied labeling, so current AppArmor only supports setting the explicit label to the same label that implied labeling would provide โ€” thus avoiding the conflict.

There are plans to extend explicit labeling to allow specifying any label, but that is not available yet. soonโ„ข ๐Ÿฆ‹

Packets sent by the kernel may either have the type of kernel_t or unlabeled, dependent on whether AppArmor is configured to label kernel packets or not.

If labeling of kernel packets is enabled, AppArmor will label all kernel packets. This can have a small impact on network performance, so for those systems that need it, kernel socket labeling can be disabled.


๐ŸŒˆ SecMark, NetFilter, and Firewalls ๐ŸŒˆ

When AppArmor profiles are attached to processes, the network rules can be thought of as an application level firewall, handling network traffic in the context of the application. System level firewalling is generally left to existing firewalls that admins are already familiar with.

However, the AppArmor application firewall can and will interact with the system firewall, and it is important to understand how and where this interaction can occur. ๐Ÿ‘‘

In Linux, firewalls are built on top of the kernel's NetFilter subsystem, which provides five different hook points to manage the flow of packets in the system: PRE_ROUTING, LOCAL_IN, FORWARD, LOCAL_OUT, and POST_ROUTING. In addition it provides some fields for the firewall, network, and security subsystems to store data on the packet as it traverses through the system.

   +-------------------------Loop Back<------------------------+
   |                                                           |
   v                                                           ^
  Dev -->PRE_ROUTING--->[ROUTE]--->FWD-------->POST_ROTUING--> Dev
         |               |         |      ^       |
         Conntrack       |       Mangle   |       Mangle
         Mangle          |       Filter   |       NAT (Src)
         NAT (Dst)       |                |       Conntrack
         (QDisc)         |             [ROUTE]    AppArmor Interface
                         |                |       AppArmor Label Match
                         V                |
        Conntrack----LOCAL_IN         LOCAL OUT---AppArmor SecMark
        Mangle           |                ^       Conntrack
        AppArmor SecMark |                |       Mangle
                         |                |       NAT (Dst)
                         v                |       Filter
               apparmor_sock_rcv_skb      |
             apparmor_inet_conn_request   |
                         |                |
                         |                |
                         v                ^
                      Process          Process

AppArmor uses SecMark, and ConnSecMark, to pass state information with the packet as it is passed through the system. In addition it uses several of the hook points to make mediation decisions.

The interface conditional does not allow explicitly setting the SecMark. Instead it is set based on the confining label of the sending task. More specifically, in a stacking situation it's set based on the subset of profiles in the label with matching interface conditionals. It may be possible to set the SecMark explicitly in the future, but it is not supported at this time.

AppArmor does not currently support explicitly specifying a SecMark match conditional (label=) match at this time either. Though that ability will be made available in a future patch. ๐Ÿ™ˆ

However firewalls are free to match the SecMark if AppArmor sets it.

AppArmor's SecMark support has several restrictions, and limitations. AppArmor must be built with SecMark support enabled, and it shares the SecMark with all other LSMs on the system โ€” as such AppArmor must be able to claim the SecMark interface on boot. This means AppArmor must be in the LSM= security module list before any other LSM that may try to claim the interface.

AppArmor netfilter hooks are executed with a SELINUX_FISRT priority, so they will be executed before most firewall rules. However it is possible to create hook filters that will compete with and may fire before the AppArmor code.

AppArmor will set the secmark to the subject label in the LOCAL_OUTPUT hook. It will filter interfaces based on the secmark in the POST_ROUTING and security_sock_rcv_skb hook (roughly the same as LOCAL_INPUT for firewalls).


๐Ÿงš Medidation of the unix family ๐Ÿงš

(yes bestie, that's how it's spelled, i don't make the rules ๐Ÿ’€)

See Unix socket rules for both socket and fs based unix socket mediation.


๐Ÿ’œ Unix socket rules ๐Ÿ’œ

AppArmor supports fine grained mediation of unix domain abstract and anonymous sockets. Unix domain sockets with file system paths are mediated via file access rules. โœจ

Abstract unix domain sockets are literally a nonportable Linux extension of unix domain sockets, okay? See unix(7) if you want the lore. ๐Ÿฆ‹


๐ŸŒธ Unix socket address paths ๐ŸŒธ

The sun_path component (aka the socket address) of a unix domain socket gets specified by the

addr=

conditional. And here's the tea: if an address conditional is not specified as part of a rule, then that rule matches both abstract and anonymous sockets. Both. No cap. ๐Ÿ’…

In AppArmor, the address of an abstract unix domain socket starts with the @ character, similar to how they get reported (as paths) by netstat -x. Then the address follows and it may contain pattern matching and any characters including the null character. In AppArmor, null characters must be specified by using an escape sequence \000 or \x00. The pattern matching is the same as what file path matching uses, so * will not match / even though it has no special meaning within an abstract socket name. Eg.

unix addr=@*,

Autobound unix domain sockets have a unix sun_path assigned to them by the kernel, so specifying a policy based address is just not possible, bestie. The autobinding of sockets can be controlled by specifying the special auto keyword. Eg.

unix addr=auto,

That's to indicate the rule only applies to auto binding of unix domain sockets. It is important to note this only applies to the bind permission โ€” because once the socket is bound to an address it is indistinguishable from a socket that have an addr bound with a specified name. When the auto keyword is used with other permissions or as part of a peer addr, it will be replaced with a pattern that can match an autobound socket. Eg. For some kernels

unix rw addr=auto,

is transformed to

unix rw addr=@[a-f0-9][a-f0-9][a-f0-9][a-f0-9][a-f0-9],

It is important to note, this pattern may match abstract sockets that were not autobound but have an addr that fits what is generated by the kernel when autobinding a socket. ๐Ÿ‘€

Anonymous unix domain sockets have no sun_path associated with the socket address, however it can be specified with the special none keyword to indicate the rule only applies to anonymous unix domain sockets. Eg.

unix addr=none,

If the address component of a rule is not specified, then the rule applies to autobind, abstract and anonymous sockets. All three. Slay. โœจ


๐Ÿ’– Unix socket permissions ๐Ÿ’–

Unix domain socket rules are accumulated so that the granted unix socket permissions are the union of all the listed unix rule permissions. Union, bestie. Everyone eats. ๐Ÿ“

Unix domain socket rules are broad and general, and they become more restrictive as further information is specified. Policy may be specified down to the socket address (aka sun_path) and label level. The content of the communication is not examined. We are not reading your DMs. ๐Ÿ™ˆ

Unix socket rule permissions are implied when a rule does not explicitly state an access list. By default, if a rule does not have an access list, all permissions that are compatible with the specified set of local and peer conditionals are implied.

The create, bind, listen, shutdown, getattr, setattr, getopt, and setopt permissions are local socket permissions. They are only applied to the local socket and can't be specified in rules that have a peer component. The accept permission applies to the combination of a local and peer socket. The connect, send, and receive permissions are peer socket permissions.

Only the peer socket permissions will be applied to rules that don't specify permissions and contain a peer component.

Example Unix domain socket rules:

# Allow all permissions to unix sockets
unix,

# Explicitly allow all unix permissions
unix (create, listen, accept, connect, send, receive, getattr, setattr, setopt, getopt),

# Explicitly deny unix socket access
deny unix,

# Allow create and use of abstract and anonymous sockets for profile_name
unix peer=(label=@{profile_name}),

# Allow receiving via unix sockets from unconfined
unix (receive) peer=(label=unconfined),

# Allow getattr and shutdown on anonymous sockets
unix (getattr, shutdown) addr=none,

# Allow SOCK_STREAM connect, receive and send on an abstract socket @bar
# with peer running under profile '/foo'
unix (connect, receive, send) type=stream peer=(label=/foo,addr="@bar"),

# Allow accepting connections from and receiving from peer running under
# profile '/bar' on abstract socket '@foo'
unix (accept, receive) addr=@foo peer=(label=/bar),

๐ŸŽ€ Abstract unix domain sockets autobind ๐ŸŽ€

Abstract unix domain sockets can autobind to an address. The autobind address is a unique 5 digit string of decimal numbers, eg. @00001. There is nothing that prevents a task from manually binding to addresses with a similar pattern, so it is impossible to reliably identify autobind addresses from a regular address. The vibes are ambiguous. ๐Ÿ’€


๐ŸŒˆ Interaction of network rules and fine grained unix domain socket rules ๐ŸŒˆ

The coarse grained networking rules can be used to control unix domain sockets as well. When fine grained unix domain socket mediation is available, the coarse grained network rule is mapped into the equivalent unix socket rule.

E.G.

network unix,  =>  unix,

network unix stream,   =>  unix stream,

Fine grained mediation rules however can not be losslessly converted back to the coarse grained network rule; e.g.

unix bind addr=@example,

Has no exact match under coarse grained network rules, the closest match is the much wider permission rule of

network unix,

๐Ÿ‘‘ Mount Rules ๐Ÿ‘‘

AppArmor supports mount mediation and allows specifying filesystem types and mount flags. The syntax of mount rules in AppArmor is based on the mount(8) command syntax. Mount rules must contain one of the mount, remount or umount keywords, but all mount conditions are optional. Unspecified optional conditionals are assumed to match all entries (eg, not specifying fstype means all fstypes are matched). Due to the complexity of the mount command and how options may be specified, AppArmor allows specifying conditionals three different ways:

  1. If a conditional is specified using '=', then the rule only grants permission for mounts matching the exactly specified options. For example, an AppArmor policy with the following rule:
mount options=ro /dev/foo -> /mnt/,

Would match:

$ mount -o ro /dev/foo /mnt

but not either of these:

$ mount -o ro,atime /dev/foo /mnt

$ mount -o rw /dev/foo /mnt
  1. If a conditional is specified using 'in', then the rule grants permission for mounts matching any combination of the specified options. For example, if an AppArmor policy has the following rule:
mount options in (ro,atime) /dev/foo -> /mnt/,

all of these mount commands will match:

$ mount -o ro /dev/foo /mnt

$ mount -o ro,atime /dev/foo /mnt

$ mount -o atime /dev/foo /mnt

but none of these will:

$ mount -o ro,sync /dev/foo /mnt

$ mount -o ro,atime,sync /dev/foo /mnt

$ mount -o rw /dev/foo /mnt

$ mount -o rw,noatime /dev/foo /mnt

$ mount /dev/foo /mnt
  1. If multiple conditionals are specified in a single mount rule, then the rule grants permission for each set of options. This provides a shorthand when writing mount rules which might help to logically break up a conditional. For example, if an AppArmor policy has the following rule:
mount options=ro options=atime,

both of these mount commands will match:

$ mount -o ro /dev/foo /mnt

$ mount -o atime /dev/foo /mnt

but this one will not:

$ mount -o ro,atime /dev/foo /mnt

Note that separate mount rules are distinct and the options do not accumulate. For example, these AppArmor mount rules:

mount options=ro,

mount options=atime,

are not equivalent to either of these mount rules:

mount options=(ro,atime),

mount options in (ro,atime),

To help clarify the flexibility and complexity of mount rules, here are some example rules with accompanying matching commands:

  • mount, โ€” the 'mount' rule without any conditionals is the most generic and allows any mount. Equivalent to 'mount fstype=** options=** ** -> /**'. Main character energy, honestly.
  • mount /dev/foo, โ€” allow mounting of /dev/foo anywhere with any options. Some matching mount commands:
$ mount /dev/foo /mnt

$ mount -t ext3 /dev/foo /mnt

$ mount -t vfat /dev/foo /mnt

$ mount -o ro,atime,noexec,nodiratime /dev/foo /srv/some/mountpoint
  • mount options=ro /dev/foo, โ€” allow mounting of /dev/foo anywhere, as read only. Some matching mount commands:
$ mount -o ro /dev/foo /mnt

$ mount -o ro /dev/foo /some/where/else
  • mount options=(ro,atime) /dev/foo, โ€” allow mount of /dev/foo anywhere, as read only and using inode access times. Some matching mount commands:
$ mount -o ro,atime /dev/foo /mnt

$ mount -o ro,atime /dev/foo /some/where/else
  • mount options in (ro,atime) /dev/foo, โ€” allow mount of /dev/foo anywhere using some combination of 'ro' and 'atime' (see above). Some matching mount commands:
$ mount -o ro /dev/foo /mnt

$ mount -o atime /dev/foo /some/where/else

$ mount -o ro,atime /dev/foo /some/other/place
  • mount options=ro /dev/foo, mount options=atime /dev/foo, โ€” allow mount of /dev/foo anywhere as read only, and allow mount of /dev/foo anywhere using inode access times. Note this is expressed as two different rules. Matches:
$ mount -o ro /dev/foo /mnt/1

$ mount -o atime /dev/foo /mnt/2
  • mount -> /mnt/**, โ€” allow mounting anything under a directory in /mnt/**. Some matching mount commands:
$ mount /dev/foo1 /mnt/1

$ mount -o ro,atime,noexec,nodiratime /dev/foo2 /mnt/deep/path/foo2
  • mount options=ro -> /mnt/**, โ€” allow mounting anything under /mnt/**, as read only. Some matching mount commands:
$ mount -o ro /dev/foo1 /mnt/1

$ mount -o ro /dev/foo2 /mnt/deep/path/foo2
  • mount fstype=ext3 options=(rw,atime) /dev/sdb1 -> /mnt/stick/, โ€” allow mounting an ext3 filesystem in /dev/sdb1 on /mnt/stick as read/write and using inode access times. Matches only:
$ mount -o rw,atime /dev/sdb1 /mnt/stick
  • mount options=(ro, atime) options in (nodev, user) /dev/foo -> /mnt/, โ€” allow mounting /dev/foo on /mnt/ read only and using inode access times, in addition to allowing some combination of 'nodev' and 'user' to be added on top. Matches only:
$ mount -o ro,atime /dev/foo /mnt

$ mount -o ro,atime,nodev /dev/foo /mnt

$ mount -o ro,atime,user /dev/foo /mnt
    $ mount -o ro,atime,nodev,user /dev/foo /mnt

๐Ÿ’Œ Message Queue rules

okay so AppArmor mediates POSIX and SYSV message queues. both. she's versatile like that ๐Ÿ’…

AppArmor Message Queue permissions are implied whenever a rule doesn't explicitly state an access list โ€” and by default, all Message Queue permissions are implied. The more info you hand over, the more restricted the permissions get. You can pin down policy by nailing its access mode, type, label, and message queue name. four lil knobs, infinite power โœจ

Access modes, bestie:

  • r, read โ€” read messages from the queue ๐Ÿ“ฅ
  • w, write โ€” write to the message queue ๐Ÿ“ค
  • create โ€” create the message queue
  • open โ€” get the message queue identifier when the queue is already created
  • delete โ€” remove the message queue ๐Ÿ—‘๏ธ
  • setattr โ€” set attributes of the message queue
  • getattr โ€” get attributes of the message queue

The type of the policy can be either posix or sysv. This matters when the message queue name isn't specified โ€” and when it is specified, you can just infer the type from the queue name, because message queues' names for posix must start with /, and message queues' keys for SYSV must be a positive integer. it's giving self-explanatory ๐Ÿ˜Œ

The policy label is the label assigned to the message queue when it is created.

The message queue name can be either a string starting with / (if the type is POSIX) or a positive integer (if the type is SYSV). If the type isn't specified, it gets inferred from the queue name. king behavior ๐Ÿ‘‘

Example AppArmor Message Queue rules:

    # Allow all Message Queue access
    mqueue,

    # Explicitly allow all Message Queue access,
    mqueue (create, open, delete, read, write, getattr, setattr),

    # Explicitly deny use of Message Queue
    deny mqueue,

    # Allow all access for POSIX queue of name /bar
    mqueue type=posix /bar,

    # Allow create permission for a SYSV queue of label foo
    mqueue create label=foo 123,

๐Ÿงš User Namespace Rules

user namespaces are the moment in so many sandboxing and containerization solutions ๐Ÿ’– They give a non-system-root process a way to be root inside the container. Super iconic for containersโ€ฆ but unfortunately this opens up attack surface in the kernel and has been part of several exploit chains ๐Ÿ˜ญ As such, AppArmor can be used to restrict the creation of user namespaces to select processes. choose your fighters, fr fr.

User namespace permissions are implied when a rule doesn't explicitly state an access list. The rule becomes more restrictive as further information is specified.

Note: user namespace creation may be restricted so that it is not available to unprivileged unconfined processes. If this is the case any process trying to create user namespaces will require a profile that allows the necessary permissions. no profile? no namespace. sorry bestie ๐Ÿ’€

create

Allow creation of user namespaces. that's it. that's the permission ๐Ÿซถ

Example userns rules:

  # Allow all userns perms
  userns,

  # Allow creation of a userns
  userns create,

๐ŸŒ€ IO_URing Rules

AppArmor supports mediation of the new Linux high speed IO interface โ€” and ngl, there's limited mediation at this time to just a few permissions at the moment. baby steps, she's growing ๐ŸŒฑ

IO Uring permissions are implied when a rule doesn't explicitly state an access list. The rule becomes more restrictive as further information is specified.

Note: io_uring access may be restricted so that it is not available to unprivileged unconfined processes. If this is the case any process trying to use io_uring will require a profile that allows the necessary io_uring permissions.

sqpoll

All the task confined by the profile to spawn a io_uring polling thread.

override_creds

Grants the task confined by the profile to override (change) its credentials to the specified label, when executing an io_uring operation. identity theft but make it policy-approved โœจ

Example IO_URING rules:

  # Allow io_uring operations
  io_uring,

  # Allow creation of a polling thread
  io_uring sqpoll,

  # Allow task to override credentials during io_uring operation
  io_uring override_creds label=new_creds,

๐ŸŒณ Pivot Root Rules

AppArmor mediates changing of the root filesystem through the pivot_root(2) system call. The syntax of pivot_root rules in AppArmor is based on the pivot_root(2) system call parameters โ€” with the notable exception that the ordering is reversed ๐Ÿ™ƒ (yes girl, keep up). The path corresponding to the put_old parameter of pivot_root(2) is optionally specified in the pivot_root rule using the oldroot= prefix.

AppArmor pivot_root rules can specify a profile transition to occur during the pivot_root(2) system call. Note that currently, this feature is not supported by any kernel. When this feature will be supported, AppArmor will only transition the process calling pivot_root(2) to the new profile.

The paths specified in pivot_root rules must end with / since they are directories. don't forget the slash, or it's a vibe check fail ๐Ÿ˜ค

Here are some example pivot_root rules:

    # Allow any pivot
    pivot_root,

    # Allow pivoting to any new root directory and putting the old root
    # directory at /mnt/root/old/
    pivot_root oldroot=/mnt/root/old/,

    # Allow pivoting the root directory to /mnt/root/
    pivot_root /mnt/root/,

    # Allow pivoting to /mnt/root/ and putting the old root directory at
    # /mnt/root/old/
    pivot_root oldroot=/mnt/root/old/ /mnt/root/,

    # Allow pivoting to /mnt/root/, putting the old root directory at
    # /mnt/root/old/ and transition to the /mnt/root/sbin/init profile
    pivot_root oldroot=/mnt/root/old/ /mnt/root/ -> /mnt/root/sbin/init,

๐Ÿ‘€ PTrace rules

AppArmor supports mediation of ptrace(2). AppArmor PTrace rules are accumulated, so the granted PTrace permissions are the union of all the listed PTrace rule permissions. stack them, collect them, union them ๐Ÿ’…

AppArmor PTrace permissions are implied when a rule doesn't explicitly state an access list. By default, all PTrace permissions are implied. she comes with everything on by default, bold of her.

The trace and tracedby permissions govern ptrace(2), while read and readby govern certain proc(5) filesystem accesses, kcmp(2), futexes (get_robust_list(2)) and perf trace events.

For a ptrace operation to be allowed, the profile of the tracing process and the profile of the target task must both have the correct permissions. For example, the profile of the process attaching to another task must have the trace permission for the target task's profile, and the task being traced must have the tracedby permission for the tracing process' profile. it takes two to ptrace, periodt ๐Ÿซถ

Example AppArmor PTrace rules:

    # Allow all PTrace access
    ptrace,

    # Explicitly allow all PTrace access,
    ptrace (read, readby, trace, tracedby),

    # Explicitly deny use of ptrace(2)
    deny ptrace (trace),

    # Allow unconfined processes (eg, a debugger) to ptrace us
    ptrace (readby, tracedby) peer=unconfined,

    # Allow ptrace of a process running under the /usr/bin/foo profile
    ptrace (trace) peer=/usr/bin/foo,

๐Ÿ”” Signal rules

AppArmor supports mediation of signal(7). AppArmor signal rules are accumulated too, so the granted signal permissions are the union of all the listed signal rule permissions โœจ

AppArmor signal permissions are implied when a rule doesn't explicitly state an access list. By default, all signal permissions are implied.

For the sending of a signal to be allowed, the profile of the sending process and the profile of the target task must both have the correct permissions. For example, the profile of a process sending a signal to another task must have the send permission for the target task's profile, and the task receiving the signal must have a receive permission for the sending process' profile. mutual consent but for signals ๐Ÿ’Œ

Example AppArmor signal rules:

    # Allow all signal access
    signal,

    # Explicitly deny sending the HUP and INT signals
    deny signal (send) set=(hup, int),

    # Allow unconfined processes to send us signals
    signal (receive) peer=unconfined,

    # Allow sending of signals to a process running under the /usr/bin/foo
    # profile
    signal (send) peer=/usr/bin/foo,

    # Allow checking for PID existence
    signal (receive, send) set=("exists"),

    # Allow us to signal ourselves using the built-in @{profile_name} variable
    signal peer=@{profile_name},

    # Allow two real-time signals
    signal set=(rtmin+0 rtmin+32),

๐Ÿฆ‹ DBus rules

AppArmor supports DBus mediation โ€” and the mediation is performed in conjunction with the DBus daemon. The DBus daemon verifies that communications over the bus are permitted by AppArmor policy. teamwork, fr fr ๐Ÿ”ฅ

AppArmor DBus rules are accumulated so that the granted DBus permissions are the union of all the listed DBus rule permissions.

AppArmor DBus rules are broad and general and become more restrictive as further information is specified. Policy may be specified down to the interface member level (method or signal name), however the contents of messages are not examined. read the room, not the messages ๐Ÿ˜Œ

Some AppArmor DBus permissions are not compatible with all AppArmor DBus rules:

  • The bind permission cannot be used in message rules.
  • The send and receive permissions cannot be used in service rules.
  • The eavesdrop permission cannot be used in rules containing any conditionals outside of the bus conditional.

Synonym slay:

  • r and read are synonyms for receive.
  • w and write are synonyms for send.
  • rw is a synonym for both send and receive.

AppArmor DBus permissions are implied when a rule doesn't explicitly state an access list. By default, all DBus permissions are implied โ€” but heads up: only message permissions are implied for message rules and only service permissions are implied for service rules. context matters, bestie ๐Ÿ’…

Example AppArmor DBus rules:

    # Allow all DBus access
    dbus,

    # Explicitly allow all DBus access,
    dbus (send, receive, bind),

    # Deny send/receive/bind access to the session bus
    deny dbus bus=session,

    # Allow bind access for a particular name on any bus
    dbus bind name=com.example.ExampleName,

    # Allow receive access for a particular path and interface
    dbus receive path=/com/example/path interface=com.example.Interface,

    # Deny send/receive access to the system bus for a particular interface
    deny dbus bus=system interface=com.example.ExampleInterface,

    # Allow send access for a particular path, interface, member, and pair of
    # peer names:
    dbus send
         bus=session
         path=/com/example/path
         interface=com.example.Interface
         member=ExampleMethod
         peer=(name=(com.example.ExampleName1|com.example.ExampleName2)),

    # Allow receive access for all unconfined peers
    dbus receive peer=(label=unconfined),

    # Allow eavesdropping on the system bus
    dbus eavesdrop bus=system,

    # Allow and audit all eavesdropping
    audit dbus eavesdrop,

๐Ÿฆ‹ change_profile rules ๐Ÿฆ‹

AppArmor supports self directed profile transitions via the change_profile api. Change_profile rules control which permissions for which profiles a confined task can transition to. The profile name can contain AppArmor pattern matching to specify different profiles. slay, pattern matching in your profile names ๐Ÿ’…

change_profile -> **,

The change_profile api allows the transition to be delayed until when a task executes another application. If an exec rule transition is specified for the application and the change_profile api is used to make a transition at exec time, the transition specified by the change_profile api takes precedence. (yes bestie, the api wins the vibe check ๐Ÿซถ)

The Change_profile permission can restrict which profiles can be transitioned to based off of the executable name by specifying the exec condition.

change_profile /bin/bash -> new_profile,

The restricting of the transition profile to a given executable at exec time is only useful when the current task is allowed to make dynamic decisions about what confinement should be, but the decision set needs to be controlled. A list of profiles or multiple rules can be used to specify the profiles in the set. Eg.

change_profile /bin/bash -> {new_profile1,new_profile2,new_profile3},

An exec rule can be used to specify a transition for the executable, if the transition should be allowed even if the change_profile api has not been used to select a transition for those available in the change_profile rule set. Eg.

/bin/bash Px -> new_profile1,
change_profile /bin/bash -> {new_profile1,new_profile2,new_profile3},

The exec mode dictates whether or not the Linux Kernel's unsafe_exec routines should be used to set ld.so(8) secure-execution mode and clear environment variables such as LD_PRELOAD, similar to setuid programs. (See ld.so(8) for more information.) The safe mode sets up secure-execution mode for the new application, and unsafe mode disables AppArmor's requirement for it (the kernel and/or libc may still turn it on). An exec mode can only be specified when an exec condition is present.

change_profile safe /bin/bash -> new_profile,
Heads up bestie ๐Ÿ’€ Not all kernels support safe mode and the parser will downgrade rules to unsafe mode in that situation. If no exec mode is specified, the default is safe mode in kernels that support it.

๐ŸŒˆ all rule ๐ŸŒˆ

The all rule is used to add a generic rule for all supported rule types. This is useful when policy wants to define a black list instead of white list, but can also be useful to add an access qualifier to all rules. It's giving "catch-all" energy โœจ

Eg. Black list

allow all,
# begin blacklist
deny file,
deny unix,

Eg. Adding audit qualifier

audit access all,

๐Ÿ“ rlimit rules ๐Ÿ“

AppArmor can set and control the resource limits associated with a profile as described in the setrlimit(2) man page.

The AppArmor rlimit controls allow setting of limits and restricting changes of them and these actions can be audited. Enforcement of the set limits is handled by the standard kernel enforcement mechanism for rlimits and will not result in an audited AppArmor message if the limit is enforced. (so the kernel does the enforcing, it's not AppArmor popping up to say anything โ€” no cap)

If a profile does not have an rlimit rule associated with a given rlimit then the rlimit is left alone and regular access, including changing the limit, is allowed. However if the profile sets an rlimit then the current limit is checked and if greater than the limit specified in the rule it will be changed to the specified limit.

AppArmor rlimit rules control the hard limit of an application and ensure that if the hard limit is lowered that the soft limit does not exceed the hard limit value.

Eg.

set rlimit data <= 100M,
set rlimit nproc <= 10,
set rlimit nice <= 5,

๐Ÿงš Variables ๐Ÿงš

AppArmor's policy language allows embedding variables into file rules to enable easier configuration for some common (and pervasive) setups. Variables may have multiple values assigned, but any variable assignments must be made before the start of the profile. like, ground rules first, profile later ๐Ÿ’–

The parser will automatically expand variables to include all values that they have been assigned; it is an error to reference a variable without setting at least one value. You can use empty quotes ("") to explicitly add an empty value.

At the time of this writing, the following variables are defined in the provided AppArmor policy:

@{HOME}
@{HOMEDIRS}
@{multiarch}
@{pid}
@{pids}
@{PROC}
@{securityfs}
@{apparmorfs}
@{sys}
@{tid}
@{run}
@{XDG_DESKTOP_DIR}
@{XDG_DOWNLOAD_DIR}
@{XDG_TEMPLATES_DIR}
@{XDG_PUBLICSHARE_DIR}
@{XDG_DOCUMENTS_DIR}
@{XDG_MUSIC_DIR}
@{XDG_PICTURES_DIR}
@{XDG_VIDEOS_DIR}

These are defined in files in /etc/apparmor.d/tunables and are used in many of the abstractions described later.

You may also add files in /etc/apparmor.d/tunables/home.d for site-specific customization of @{HOMEDIRS}, /etc/apparmor.d/tunables/multiarch.d for @{multiarch} and /etc/apparmor.d/tunables/xdg-user-dirs.d for @{XDG_*}.

โœจ Special builtin variables โœจ

AppArmor has some builtin variables that are not declared in policy but are available to be used in policy. yes queen, free of charge ๐Ÿ’…

@{profile_name} - the profile name
@{attach_path}  - the profile exec attachment path - if one has been defined
@{exec_path}    - the executables path

The @{profile_name} variable is set to the profile name and may be used in all policy. It is only defined when used inside of a profile.

The @{attach_path} variable is only defined if the profile will attach to an executable. It will be the path attachment specification or if that is not defined it may be the profile's name if the profile name is a path.

The @{exec_path} variable like @{attach_path} is only defined if the profile attaches to an executable. If the kernel supports it as a kernel variable, it will be set to the specific path that matches the executable at run time. If the kernel does not support kernel variables it will have the same value as @{attach_path}.

๐ŸŒธ Assignment of variables ๐ŸŒธ

AppArmor provides 3 different assignment operators for variables.

  • = does a straight assignment of the right hand side to the variable. The variable must not be declared before or an error will occur. If there is a chance that the variable could be declared before the +=, :=, or ?= assignment operators can be used instead.
  • += will add new set values to a previously declared variable
  • ?= will assign the right hand side to the variable only if the variable was not previously declared.
  • := does a straight assignment of the right hand side to the variable. If the variable has already been declared before the assignment the rhs will override the preexisting variable value(s).

๐Ÿ‘‘ Notes on variable expansion and the / character ๐Ÿ‘‘

It is important to note that how AppArmor performs variable expansion depends on the context where a variable is used. When a variable is expanded it can result in a string with multiple path characters next to each other, in a way that is not evident when looking at policy. the way that / / / just stacks up ๐Ÿ˜ญ

Eg.

Given the following variable definition and rule

@{HOME}=/home/*/ file rw @{HOME}/*,

The variable expansion results in a rule of

file rw /home/*//*.

When this occurs in a context where a path is expected, AppArmor will canonicalize the path by collapsing consecutive / characters into a single character. For the above example, this would be

file rw /home/*/*,

There is one exception to this rule, when the consecutive / characters are at the beginning of a path, this indicates a posix namespace and the characters will not be collapsed.

Eg.

@{HOME}=/home/*/ file rw /@{HOME}/*,

will result in an expansion of

file rw //home/*//*,

which is collapsed to

file rw //home/*/*,
Note: that the leading // in the above example is not collapsed to a single /. However the second // (that was also seen in the first example) is collapsed. iykyk ๐Ÿคญ

๐Ÿซถ Boolean Variables ๐Ÿซถ

In addition to the set variables AppArmor supports boolean variables. These begin with a $ and can only be used in conditional expressions. Boolean variables provide a convenient way to enable/disable policy rules that have been wrapped in the proper if condition.


๐Ÿ’œ Alias rules ๐Ÿ’œ

AppArmor also provides alias rules for remapping paths for site-specific layouts. They are an alternative form of path rewriting to using variables, and are done after variable resolution. Alias rules must occur within the preamble of the profile. System-wide aliases are found in /etc/apparmor.d/tunables/alias, which is included by /etc/apparmor.d/tunables/global. /etc/apparmor.d/tunables/global is typically included at the beginning of an AppArmor profile.


๐ŸŒˆ Globbing (AARE) ๐ŸŒˆ

File resources and other parameters accepting an AARE may be specified with a globbing syntax similar to that used by popular shells, such as csh(1), bash(1), zsh(1). bestie this is the part where the wildcards come OUT ๐Ÿฆ‹

  • * โ€” can substitute for any number of characters, excepting /
  • ** โ€” can substitute for any number of characters, including /
  • ? โ€” can substitute for any single character excepting /
  • [abc] โ€” will substitute for the single character a, b, or c
  • [a-c] โ€” will substitute for the single character a, b, or c
  • [^a-c] โ€” will substitute for any single character not matching a, b or c
  • {ab,cd} โ€” will expand to one rule to match ab, one rule to match cd

Can also include variables.

  • @{variable} โ€” will expand to all values assigned to the given variable.

When AppArmor looks up a directory the pathname being looked up will end with a slash (e.g., /var/tmp/); otherwise it will not end with a slash. Only rules that match a trailing slash will match directories. Some examples, none matching the /tmp/ directory itself, are:

  • /tmp/* โ€” Files directly in /tmp.
  • /tmp/*/ โ€” Directories directly in /tmp.
  • /tmp/** โ€” Files and directories anywhere underneath /tmp.
  • /tmp/**/ โ€” Directories anywhere underneath /tmp.

โญ Rule Qualifiers โญ

There are several rule qualifiers that can be applied to permission rules. Rule qualifiers can modify the rule and/or permissions within the rule. literally the sprinkle-on-top of policy โœจ

  • priority โ€” Specifies the priority of the rule. Currently the allowed range is -1000 to 1000 with the default priority of rule is 0. Rules with higher priority are given preferences and will completely override permissions of lower priority rules where they overlap. When rules partially overlap the permissions of the higher priority rule will completely override lower priority rules within in overlap. Within a given priority level rules that overlap will accumulate permissions in the standard AppArmor fashion.
  • allow โ€” permission requests that match the rule are, well, allowed. This is the default for rules so you don't have to write it out at all. Conflicts with the deny qualifier. ๐Ÿ’…
  • audit โ€” permission requests that match the rule get recorded to the audit log. receipts โœจ
  • deny โ€” permission requests that match the rule get denied and not logged. You can combine it with audit to turn logging back on. Conflicts with the allow qualifier.
  • owner โ€” the task has to have the same euid/fsuid as the object the permission check is referencing. no borrowing other people's vibes ๐Ÿ”’

๐Ÿ’– Qualifier Blocks ๐Ÿ’–

Wanna apply Rule Qualifiers to a bunch of rules at once? Group the rules into a rule block, bestie:

audit {
   /foo r,
   network,
}

๐ŸŒธ #include mechanism ๐ŸŒธ

AppArmor gives you the easiest abstraction mechanism ever to group common access requirements โ€” and it's lowkey the most flexible way to grant site-specific rights. It makes writing new AppArmor profiles so simple because you're just assembling the building blocks each program needs. it's giving Lego but make it security ๐Ÿงฑโœจ

The use of #include is modelled directly after cpp(1); using it replaces the #include statement with the contents of the specified file. The leading # is optional, and the #include keyword can be followed by an optional conditional if exists that says profile compilation should keep going if the specified file or directory isn't found. no drama, we move on ๐Ÿ’

  • #include "/absolute/path" โ€” says /absolute/path should be used.
  • #include "relative/path" โ€” says relative/path should be used, where the path is relative to the current working directory.
  • #include <magic/path> โ€” the most common usage; it loads magic/path relative to a directory specified to apparmor_parser(8). The AppArmor default is /etc/apparmor.d/.

The supplied AppArmor profiles follow several conventions; the abstractions stored in /etc/apparmor.d/abstractions/ are some big clusters that get used in most profiles. Here's the lowdown on how some of them get used:

  • abstractions/audio โ€” includes accesses to device files used for audio applications. ๐ŸŽง
  • abstractions/authentication โ€” includes access to files and services typically necessary for services that perform user authentication.
  • abstractions/base โ€” includes files that should be readable and writable in all profiles.
  • abstractions/bash โ€” includes many files used by bash; useful for interactive shells and programs that call system(3).
  • abstractions/consoles โ€” includes read and write access to the device files controlling the virtual console, sshd(8), xterm(1), etc. This abstraction is needed for many programs that interact with users.
  • abstractions/fonts โ€” includes access to fonts and the font libraries.
  • abstractions/gnome โ€” includes read and write access to GNOME configuration files, plus read access to GNOME libraries.
  • abstractions/kde โ€” includes read and write access to KDE configuration files, plus read access to KDE libraries.
  • abstractions/kerberosclient โ€” includes file access rules needed for common kerberos clients.
  • abstractions/nameservice โ€” includes file rules to allow DNS, LDAP, NIS, SMB, user and group password databases, services, and protocols lookups.
  • abstractions/perl โ€” includes read access to perl modules.
  • abstractions/user-download
  • abstractions/user-mail
  • abstractions/user-manpages
  • abstractions/user-tmp
  • abstractions/user-write โ€” some profiles for typical "user" programs will use these include files to describe rights that users have in the system.
  • abstractions/wutmp โ€” includes write access to files used to maintain wtmp(5) and utmp(5) databases, used with the w(1) and associated commands.
  • abstractions/X โ€” includes read access to libraries, configuration files, X authentication files, and the X socket.

Some of the abstractions rely on variables that are set in files in the /etc/apparmor.d/tunables/ directory. Those variables are currently @{HOME} and @{HOMEDIRS}. Heads up: variables cannot be set in profile scope โ€” they can only be set before the profile. So any profiles that use abstractions should either #include <tunables/global> or otherwise make sure @{HOME} and @{HOMEDIRS} are set before the profile definition starts. The aa-autodep(8) and aa-genprof(8) utilities will automatically emit #include <tunables/global> in generated profiles, so you're covered. ๐Ÿซถ

๐ŸŒˆ Feature ABI ๐ŸŒˆ

The feature abi tells AppArmor which feature set the policy was developed under. This matters because it makes sure kernels with a different feature set don't enforce features that the policy doesn't support โ€” which would otherwise cause unexpected application failures. ๐Ÿ’€

When policy is compiled, both the kernel feature abi and the policy feature abi get consulted to build a policy that'll work for the system's kernel.

If the kernel supports a feature that the policy doesn't support, then the policy gets built so that the kernel does NOT enforce that feature.

If the policy supports a feature that the kernel doesn't support, the compile may downgrade the rule with the feature to something the kernel supports, drop the rule completely, or fail the compile. spicy ๐ŸŒถ๏ธ

If the policy abi is specified as kernel then the running kernel's abi will be used. > This should never be used in shipped policy as it can cause system breakage when a new kernel is installed. fr fr, don't do it.

The special abi default is equivalent to not specifying an ABI.

โœจ ABI compatibility with AppArmor 2.x โœจ

AppArmor 3 remains compatible with AppArmor 2.x by detecting when a profile doesn't have a feature ABI specified. In that case the policy compile will either apply the pinned feature ABI as specified by the config file or the command line, or โ€” if neither of those are applied โ€” by using a default feature ABI.

It's important to note that the default feature ABI does not support new features added in AppArmor 3 or later. periodt. ๐Ÿ™ˆ

โญ EXAMPLE โญ

An example AppArmor profile:

# which feature abi the policy was developed with
abi <abi/3.0>,

# a variable definition in the preamble
@{HOME} = /home/*/ /root/

# a comment about foo.
/usr/bin/foo {
  /bin/mount          ux,
  /dev/{,u}random     r,
  /etc/ld.so.cache    r,
  /etc/foo.conf       r,
  /etc/foo/*          r,
  /lib/ld-*.so*       rmix,
  /lib/lib*.so*       r,
  /proc/[0-9]**       r,
  /usr/lib/**         r,
  /tmp/foo.*          lrw,
  @{HOME}/.foo_file  rw,
  /usr/bin/baz        Cx -> baz,

  # a comment about foo's hat (subprofile), bar.
  ^bar {
    /lib/ld-*.so*       rmix,
    /usr/bin/bar        rmix,
    /var/spool/*        rwl,
  }

  # a comment about foo's subprofile, baz.
  profile baz {
    #include <abstractions/bash>
    owner /proc/[0-9]*/stat r,
    /bin/bash ixr,
    /var/lib/baz/ r,
    owner /var/lib/baz/* rw,
  }
}

๐Ÿฆ‹ Conditional rules ๐Ÿฆ‹

AppArmor provides a mechanism to conditionally enable and disable rules in a profile. Rules you want to be conditional get wrapped in an if condition block, and the condition expression is controlled by setting variable values. customize your policy, bestie ๐Ÿ’…

The condition expression can be composed of variables, boolean variables, a defined check, the comparison operators in, ==, !=, >, =>, <, and <=, open '(' and close ')' parentheses, and the boolean operators and, or, and not. Boolean operators are evaluated left to right with priority in the order of this list:

  • in โ€” tests whether the left text or variable is a subset of the text or variable on the right. The subset check is done by a full match, therefore partial string matches would not evaluate to true.
  • == โ€” tests whether both text or variable evaluate to the same value.
  • != โ€” tests whether both text or variable evaluate to different values.
  • > โ€” tests whether the left text or variable is greater than the right text or variable. Comparisons between integers and set variables will fail to compile unless the variable contents are exactly one value, an integer. Other comparison will be strictly lexicographical.
  • => โ€” tests whether the left text or variable is greater than or equal to the right text or variable. Comparisons between integers and set variables will fail to compile unless the variable contents are exactly one value, an integer. Other comparison will be strictly lexicographical.
  • < โ€” tests whether the left text or variable is lesser than the right text or variable. Comparisons between integers and set variables will fail to compile unless the variable contents are exactly one value, an integer. Other comparison will be strictly lexicographical.
  • <= โ€” tests whether the left text or variable is lesser than or equal to the right text or variable. Comparisons between integers and set variables will fail to compile unless the variable contents are exactly one value, an integer. Other comparison will be strictly lexicographical.
  • defined โ€” tests whether the following variable or boolean variable has been defined/created.
  • parentheses โ€” open '(' and close ')' parentheses are used to group operations by priority.
  • not โ€” boolean not operator, negates the value of the following expression.
  • and โ€” boolean and operator, both expressions being combined with and must be true for the result to be true.
  • or โ€” boolean or operator, either one or both expressions being combined with or can be true for the result to be true.

An example of a profile conditional:

if ${distro_mods} and defined @{HOME} {
  /@{HOME}/.foo_file  rw,
} else {
  /home/*/.foo_file  rw,
}

Since lexicographical comparisons using the >, =>, <, <= operators could lead to mistakes when comparing integers, comparisons between variables and integers will fail to compile unless the variable contains an integer.

Eg.

@{BAR} = /home/user/ /home/user2/
@{BAR} += /home/user3/
@{TEST_VERSION} = 2
@{BAZ} = 10

/usr/bin/foo {
  if /home/user/ in @{BAR} {
    /** r,
  }
  if @{TEST_VERSION} >= @{BAZ} {
    /** w,
  } else if 10 > @{TEST_VERSION} {
    /** rw,
  }
  if @{BAZ} <= 10 {
    /** rw,
  }
}

๐Ÿ“ FILES ๐Ÿ“

  • /etc/apparmor.d/

๐Ÿ’€ KNOWN BUGS ๐Ÿ’€

okay bestie, real talk time โ€” nobody's perfect, not even AppArmor, and the docs are gonna be honest with you about the stuff that's lowkey busted. read this before you file a bug, fr fr ๐Ÿ™ˆ

  • Mount options support the use of pattern matching, but mount flags are not correctly intersected against specified patterns. Like, mount options=**, should be equivalent to mount, โ€” but it is not. (LP: #965690) ๐Ÿ˜ญ
  • The fstype may not be matched against when certain mount command flags are used. Specifically, fstype matching currently only works when creating a new mount and not remount, bind, etc. so like... yeah, those ones just vibe past the check ๐Ÿซ 
  • Mount rules with multiple options conditionals are not applied as documented โ€” instead they get merged, such that options in (ro,nodev) options in (atime) is equivalent to options in (ro,nodev,atime). not the glow-up you were expecting, ik ๐Ÿ’…
  • When specifying mount options with the in conditional, both the positive and negative values match when specifying one or the other. Eg, rw matches when ro is specified, and dev matches when nodev is specified, such that options in (ro,nodev) is equivalent to options in (rw,dev). yes bestie it's giving chaotic, no you're not misreading it ๐Ÿ˜ตโ€๐Ÿ’ซ
bestie PSA: these are documented bugs, not secret lore. if you hit one, you didn't do anything wrong โ€” the parser did. ๐Ÿ’€

๐ŸŒˆ SEE ALSO ๐ŸŒˆ

go forth and read the rest of the family, they're all iconic in their own way โœจ


and that's a wrap on the whole page, bestie!! ๐ŸŽ€ you just read the entire APPARMOR.D(5) man page and honestly? slay. this gorgeous specimen of documentation came to you from AppArmor 6.0.0~alpha1, dated 2026-10-05, and it lives its best life as APPARMOR.D(5). go forth and confine things, no cap ๐Ÿ‘‘๐Ÿ’–

๐Ÿ“ฆ where this page comes from