apparmor_parser: loads AppArmor profiles into the kernel
apparmor_parser [options] <command> [profiles]...
apparmor_parser [-hv] [--help] [--version]
What it does
A general tool to compile and manage AppArmor policy, including loading new apparmor.d(5) profiles into the Linux kernel. The profiles may be specified by file name or a directory name containing a set of profiles; with neither, it reads standard input. Loading needs root (CAP_MAC_ADMIN).
Options you will use
-a, --add- Insert the AppArmor definitions given into the kernel. This is the default action. This gives an error message if a AppArmor definition by the same name already exists in the kernel.
-r, --replace- Required if an AppArmor definition by the same name already exists in the kernel; used to replace the definition already in the kernel with the definition given.
-R, --remove- Remove an AppArmor definition already in the kernel (it still needs the complete profile file).
-C, --Complain- Force the profile to load in complain mode.
-q, --quiet- Do not report on the profiles as they are loaded, and not show warnings.
-v, --verbose- Report on the profiles as they are loaded, and show warnings.
-N, --names- Produce a list of policies from a given set of profiles (implies -K).
-Q, --skip-kernel-load- Perform all actions except the actual loading of a profile into the kernel.
-K, --skip-cache- Perform no caching at all: disables -W, implies -T.
-T, --skip-read-cache- Do not load a profile from the cache even if the cache is newer than the profile.
-W, --write-cache- Write out cached profiles to the location specified in --cache-loc.
-d, --debug- Given once, only checks the profiles to ensure syntactic correctness. Given twice, dumps its interpretation of the profile for checking.
-V, --version- Print the version number and exit.
-h, --help- Give a quick reference guide.
Examples
$ sudo apparmor_parser -q /etc/apparmor.d/k8s-deny-writeload a profile, quietly
$ sudo apparmor_parser -r /etc/apparmor.d/k8s-deny-writereplace it after an edit
$ sudo apparmor_parser -R /etc/apparmor.d/k8s-deny-writeunload it
$ sudo aa-status | grep k8s-deny-writeis it loaded?
Gotchas
- A profile is loaded until reboot: for a node that must keep it, put the file in /etc/apparmor.d/ (the apparmor service loads that directory at boot).
- The name a pod refers to (securityContext.appArmorProfile.localhostProfile) is the profile NAME inside the file (
profile k8s-deny-write flags=(attach_disconnected) {), not the file name. The profile must be loaded on the node that runs the pod, or the container does not start. - Changed a profile that is already loaded? Load it with -r: -a refuses a name that exists.
Try apparmor_parser in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.