I doubt it's ideal to have apparmor_parser called from a service file to begin with. AppArmor protects specific processes, and often times said processes are already started by systemd. There is an AppArmorProfile directive in systemd already, but unfortunately it just switches profiles instead of loading them. Having something akin to that, which both loads a profile and makes sure not to load the daemon if the profile it's associated with isn't loaded, would be nice. That would allow systemd to handle the boot parallelisation as well as security, both things that only PID1 can really be trusted to do right.
In the mean while, I'm using templates for handling that, with an apparmor.target for managing them all at the same time:
This does mean that you initially need to either manually specify each profile to load (using `systemctl enable <email address hidden>` for instance, which is fairly inefficient since it passes files to the parser one by one), and/or use a drop-in, like nginx.service.d/01-apparmor.conf:
Which is quite nice, since it ensures that the service, when enabled and run, will make sure to load its own profile, or refuse to run if it fails to load. In this case the loading can happen at any time during boot, it doesn't have to be early boot. But it does mean that you need a drop-in file for every protected service.
I doubt it's ideal to have apparmor_parser called from a service file to begin with. AppArmor protects specific processes, and often times said processes are already started by systemd. There is an AppArmorProfile directive in systemd already, but unfortunately it just switches profiles instead of loading them. Having something akin to that, which both loads a profile and makes sure not to load the daemon if the profile it's associated with isn't loaded, would be nice. That would allow systemd to handle the boot parallelisation as well as security, both things that only PID1 can really be trusted to do right.
In the mean while, I'm using templates for handling that, with an apparmor.target for managing them all at the same time:
[Unit] AppArmor target encies= no sysinit. target
Description=
DefaultDepend
Before=
[Install] sysinit. target
WantedBy=
And the template unit apparmor@.service:
[Unit] AppArmor profile: %i encies= no apparmor. target
Description=
DefaultDepend
Before=
[Service] /sbin/apparmor_ parser -r /etc/apparmor.d/%i /sbin/apparmor_ parser -R /etc/apparmor.d/%i /sbin/apparmor_ parser --reload /etc/apparmor.d/%i it=yes
Type=oneshot
ExecStart=
ExecStop=
ExecReload=
RemainAfterEx
[Install] apparmor. target
WantedBy=
This does mean that you initially need to either manually specify each profile to load (using `systemctl enable <email address hidden>` for instance, which is fairly inefficient since it passes files to the parser one by one), and/or use a drop-in, like nginx.service. d/01-apparmor. conf:
[Unit]
<email address hidden>
<email address hidden>
Which is quite nice, since it ensures that the service, when enabled and run, will make sure to load its own profile, or refuse to run if it fails to load. In this case the loading can happen at any time during boot, it doesn't have to be early boot. But it does mean that you need a drop-in file for every protected service.