daemon: add ability for custom AppArmor profiles#41442
daemon: add ability for custom AppArmor profiles#41442cyphar wants to merge 1 commit intomoby:masterfrom
Conversation
|
(Probably needs some tests.) |
1a2e95a to
03024a8
Compare
d303240 to
a45a30d
Compare
a45a30d to
5ca027a
Compare
|
I was under the impression that the current way to customize AppArmor profiles was to ship a
Maybe better to send fixes as a separate PR? We've hit this before and it's a little annoyed that dockerd manages its own profile instead of writing a /etc/apparmor.d profile as part of its deb configuration. We use a local addition for abstractions/base and because Docker manually shells out to apparmor_parser, restarting the apparmor unit doesn't reload docker-default. We've had to manually nuke the docker-default profile by interacting with the securityfs instead to force dockerd to pick up our changes. Is there some history on why dockerd manages its own profile instead of including it as part of its packaging? |
That is not /quite/ right and actually this patch would make this no longer true at all (because of the forcefully load patch). Right now, Docker will try to insert it's own profile if it isn't already loaded -- though it is true that adding a profile file to And as mentioned this behaviour is actually a bug because we need to forcefully push the profile on Docker daemon start because otherwise updates will silently result in old AppArmor profiles being used (meaning security or correctness fixes won't be applied until after reboot). Another thing this patch allows is for you to more directly control and know what the default profile is, which currently isn't possible because we don't write to
This is intentional (though I agree it is annoying -- and I say that as the person who originally implemented this behaviour in #26518). This is working around a design limitation of AppArmor which was found in EDIT: I actually can't find the original issue describing the AppArmor reload behaviour, but I am fairly sure that this was a problem we hit at some point in the past...?
See above, though the reason for not including it in packaging and needing to dynamically generate it is that certain AppArmor profile features are dependent on which version of |
|
Breaking the ability to override docker-default by shipping it yourself sounds like a bad idea. We've used this in the past when there have been bugs in docker's apparmor parsing. I remember the issue of containers dropping to unconfined, but I can't reproduce with my currently install apparmor unit. Even if you update a profile, it appears that existing processes running as the profile don't become unconfined: |
|
Also you can run code during configuration of debs and rpms to do templating :) |
This may have been fixed since then and to be honest probably was some weird interaction with the systemd apparmor "service" on Ubuntu/Debian (which internally might have done some wacky stuff to
I don't want to break things, but right now Docker is broken with regards to upgrades and we need to fix it somehow. Future updates to Docker will involve changes to the built-in In addition the fact that Fixing the issue of upgrades requires clobbering the existing profile if the existing profile is an old Docker built-in profile -- the catch is it's not possible to tell whether a profile is a built-in or custom one without any other information from the system administrator (regardless of whether we start writing to
Can you clarify what you mean by that? Docker doesn't parse AppArmor profiles. (But I do agree that being able to modify the
Most distributions don't use the packaging scripts in If we supported |
ericchiang
left a comment
There was a problem hiding this comment.
Okay so a short description of this PR is:
- Previously, if a docker-default profile was installed (by the daemon or an administrator), the daemon would just use it. If not it would load it's compiled in profile.
- Now, starting the daemon will always force-reload the default profile.
- If users want to supply a custom default profile, they can use the --apparmor-profile flag to supply a template.
For the comment about parsing, sorry, I meant to say: when we've had issues with docker's apparmor profile such a signals, we've supplied our own docker-default profile through /etc/apparmor.d.
I'm fine with this change for the reasons you state, but frankly there's no way we can use Docker's apparmor integration after this. Though our setup is a little unique :) We won't give dockerd the permissions to modify apparmor state. Being able to provide a docker-default profile ourselves was a nice out, so you might want to ensure other distributions weren't using that feature.
profiles/apparmor/default-profile
Outdated
There was a problem hiding this comment.
What this file moved from somewhere? Is there anything new in it?
There was a problem hiding this comment.
No, this file didn't exist before -- it's like profiles/seccomp/default.json and is a plaintext version of the profile contents.
daemon/info.go
Outdated
There was a problem hiding this comment.
Should this be profile-path or something similar instead of profile?
There was a problem hiding this comment.
I copied this from the seccomp profile for consistency (you're quite right that arguably they should both refer to "profile path" rather than "profile" but I don't know if changing both will break anything).
I could implement some kind of "don't you dare touch |
|
Sorry, didn't mean to be so dramatic with that. I think that I'll handle the docker-default issues with a feature or workaround like #41553, that shouldn't impact this PR. This PR lgtm. Is there a place to document this change? |
|
Are you sure you don't want something like |
|
I think it'd be easier for us to break the daemon's access to the AppArmor securityfs to disable AppArmor integration. I believe we can make runc transition to a container profile using AppArmor if we really wanted to :) Either way we'd need to control the dockerd profile, since we'd both want to restrict change_profile to only docker-default and we need to block access to our enterprise specific paths. I think it's easier to skip the --apparmor-profile=NONE feature for now. |
5ca027a to
c0efa52
Compare
This is a long-requested feature, and it solves several usability
problems with the default AppArmor profile:
1. The profile is completely opaque because we don't write to
/etc/apparmor.d anymore -- this leads to lots of headaches when
trying to run certain semi-privileged programs inside containers.
It's much nicer to be able to have a starting point for a custom
AppArmor profile.
2. Changes to AppArmor have broken backwards compatibility in the past
(leading to containers not working properly) -- the poster-child for
this problem was signal mediation. In order to fix this problem,
distributions had to patch Docker when it would've been much nicer
to provide a hotfix in the form of a custom configuration they could
apply to their hosts.
It also bridges the feature gap between the default seccomp profile
(which has been configurable for a very long time). This patch also
fixes a few minor bugs in the AppArmor profile implementation (notably,
Docker would not forcefully load its built-in profile at start time --
meaning a Docker update wouldn't actually update the profile).
This feature should probably be ported to other container runtimes
(containerd, podman/cri-o, etc) so that we can continue with the effort
to merge all of the disparate AppArmor profile implementations. Ideally
they would all use the same template variables too.
Signed-off-by: Aleksa Sarai <[email protected]>
c0efa52 to
2d75617
Compare
This is a long-requested feature, and it solves several usability
problems with the default AppArmor profile:
The profile is completely opaque because we don't write to
/etc/apparmor.d anymore -- this leads to lots of headaches when
trying to run certain semi-privileged programs inside containers.
It's much nicer to be able to have a starting point for a custom
AppArmor profile.
Changes to AppArmor have broken backwards compatibility in the past
(leading to containers not working properly) -- the poster-child for
this problem was signal mediation. In order to fix this problem,
distributions had to patch Docker when it would've been much nicer
to provide a hotfix in the form of a custom configuration they could
apply to their hosts.
It also bridges the feature gap between the default seccomp profile
(which has been configurable for a very long time). This patch also
fixes a few minor bugs in the AppArmor profile implementation (notably,
Docker would not forcefully load its built-in profile at start time --
meaning a Docker update wouldn't actually update the profile).
This feature should probably be ported to other container runtimes
(containerd, podman/cri-o, etc) so that we can continue with the effort
to merge all of the disparate AppArmor profile implementations. Ideally
they would all use the same template variables too.
Mostly fixes #33060
Signed-off-by: Aleksa Sarai [email protected]