MOD_APPARMOR(8)
β¨ NAME β¨
mod_apparmor β fine-grained AppArmor confinement for Apache, bestie π
πΈ DESCRIPTION πΈ
okay so here's the vibe π
an AppArmor profile applies to an executable program. but likeβ¦ if one part of that program needs different access permissions than the other parts, the program can "change hats" β via aa_change_hat(2) β into a different role, also known as a subprofile. π©β¨
and THAT'S what the mod_apparmor Apache module does, fr fr. it uses the aa_change_hat(2) mechanism to offer more fine-grained confinement of dynamic elements within Apache β think individual php and perl scripts β while still letting you keep the performance benefits of using mod_php and mod_perl. no cap, it's giving best of both worlds. ππ₯
π¦ how do i even turn it on
To use mod_apparmor with Apache, make sure mod_apparmor is configured to be loaded into Apache β either via a2enmod, yast, or manual editing of the apache2(8)/httpd(8) configuration files β and restart Apache. also please make sure that apparmor is actually functioning. like. that part matters. π
π what happens once it's loaded
Once mod_apparmor is loaded within Apache, all requests to Apache will cause mod_apparmor to attempt to change into a hat that matches the ServerName for the server/vhost.
and if no such hat is found? bestie it does NOT just give up, it falls back like the icon it is:
- first it falls back by attempting to change into a hat composed of the
ServerName-URI (e.g."www.example.com-/app/some.cgi"). - if that hat is not found, it falls back to attempting to use the hat named by the URI (e.g.
"/app/some.cgi"). - if that hat is not found, it falls back to attempting to use the hat
DEFAULT_URI. - if that also does not exist, it falls back to using the global Apache profile.
Most static web pages can simply make use of the DEFAULT_URI hat. slay. π
π the untrusted input era
Additionally, before any requests come in to Apache, mod_apparmor will attempt to change hat into the HANDLING_UNTRUSTED_INPUT hat. mod_apparmor will attempt to use this hat while Apache is doing the initial parsing of a given http request β before it's given to a specific handler (like mod_php) for processing. it's literally the bouncer at the door checking IDs. ππ«Ά
π because doing this by hand is exhausting
Because defining hats for every URI/URL often becomes tedious, mod_apparmor provides the AAHatName and AADefaultHatName Apache configuration options. you're welcome. π
π AAHatName
AAHatName allows you to specify a hat to be used for a given Apache <Directory>, <DirectoryMatch>, <Location> or <LocationMatch> directive (see the Apache documentation for more details).
β οΈ note thatmod_apparmorbehavior can become confused if<Directory*>and<Location*>directives are intermingled, and it is recommended to use one type of directive. pick a lane bestie π
If the hat specified by AAHatName does not exist in the Apache profile, then it falls back to the behavior described above. π
π AADefaultHatName
AADefaultHatName allows you to specify a default hat to be used for virtual hosts and other Apache server directives, so that you can have different defaults for different virtual hosts. cute, right? π
This can be overridden by the AAHatName directive, and is checked for only if there isn't a matching AAHatName. The default value of AADefaultHatName is the ServerName for the server/vhost configuration.
If the AADefaultHatName hat does not exist, then it falls back to the behavior described above. π
β¨ URI REQUEST SUMMARY β¨
When profiling with mod_apparmor, it is helpful to keep the following order of operations in mind (iykyk π):
On each URI request, mod_apparmor will first aa_change_hat(2) into ^HANDLING_UNTRUSTED_INPUT, if it exists.
Then, after performing the initial parsing of the request, mod_apparmor will:
- try to
aa_change_hat(2)into a matchingAAHatNamehat if it exists and applies, otherwise it will - try to
aa_change_hat(2)into anAADefaultHatNamehat, either theServerName(the default) or the configuration value specified by theAADefaultHatNamedirective, for the server/vhost, otherwise it will - try to
aa_change_hat(2)into theServerName-URI, otherwise it will - try to
aa_change_hat(2)into the URI itself, otherwise it will - try to
aa_change_hat(2)into theDEFAULT_URIhat, if it exists, otherwise it will - fall back to the global Apache policy
π BUGS π
mod_apparmor() currently only supports apache2, and has only been tested with the prefork MPM configuration β threaded configurations of Apache may not work correctly. π For Apache 2.4 users, you should enable the mpm_prefork module. do it. don't skip this one. π
There are likely other bugs lurking about; if you find any, please report them at <https://gitlab.com/apparmor/apparmor/-/issues>. bestie we WANT the bug reports, they're a gift π«Ά
π¦ SEE ALSO π¦
okay that's the whole page!! β¨ go forth and confine your Apache, you absolute legend. this was AppArmor 6.0.0~alpha1, dated 2026-10-05 β periodt π ππ
π¦ where this page comes from
- ubuntu stonking: libapache2-mod-apparmor 6.0.0~alpha1-0ubuntu4 Β· GPL-2.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms