This is not about (Docker) container AppArmor profiles but this is about enforcing the Docker Daemon AppArmor profile.
Docker's AppArmor-related documentation only briefly mentions that the profile for the engine daemon doesn't get installed with Debian packages and then links to .go files in the code repository.
How do I get this working, that is, how do I apply the profile to my Docker engine for some testing?
Any attempt at go install github.com/moby/moby/blob/master/contrib/apparmor/main.go@latest or go install github.com/moby/moby/blob/master/contrib/apparmor/main.go@master fails with module github.com/moby/moby@latest found (v20.10.6+incompatible), but does not contain package github.com/moby/moby/blob/master/contrib/apparmor or similar.
Not sure why there's such a lack of documentation on their part, but I think you could just cut and paste most of that
.gofile into a valid AppArmor profile. The only thing you would need to edit is the sections such as{{if ge .Version 209000}}, where you would remove the{{if ... }}{{end}}markers if your docker daemon is new enough (>= 20.09), or remove those sections entirely if for some reason you're running an older daemon.So I was able to save this as
/etc/apparmor.d/usr.bin.docker:Then I loaded the profile into complain mode for testing:
aa-complain /usr/bin/docker.You can see that it's loaded with
aa-status:Then, you can restart your docker daemon/containers, watch for profile violations in your syslog, and adjust the profile in
/etc/apparmor.d/usr.bin.dockerif something breaks.When you're statisfied with the profile, then you just put it into enforce mode:
One other thing to consider is that this only covers
/usr/bin/docker, but not/usr/bin/dockerdor/usr/bin/containerd, so I think to get full AppArmor coverage for docker itself one would also need to write profiles for those.https://ubuntu.com/server/docs/security-apparmor