Docker inspect "AppArmorProfile" field now shows "docker-default" when AppArmor is enabled and no other profile was defined #27083
Docker inspect "AppArmorProfile" field now shows "docker-default" when AppArmor is enabled and no other profile was defined #27083tonistiigi merged 1 commit intomoby:masterfrom RobSkye:25935-show-apparmor-default-profile-in-docker-inspect
Conversation
|
@RobSkye did you close this on purpose, or by accident? |
|
By Accident...laptops and beds are bad combination....I'm editing the description too. |
|
GitHub buttons are also a disaster at times, haha, no worries, thanks! |
|
Guess this fixes #25935 |
|
Yes. |
tonistiigi
left a comment
There was a problem hiding this comment.
Please squash the commits as well.
daemon/container_linux.go
Outdated
There was a problem hiding this comment.
there is const defaultApparmorProfile
There was a problem hiding this comment.
Also need to handle --privileged. See https://github.com/docker/docker/blob/master/daemon/oci_linux.go#L709-L714
Even with privileged fixed this is a slight behavioral change. If apparmor is enabled after container was created this var will not change. I think if this is only called on inspecting single container we can lazy load the value like we do in container startup.
There was a problem hiding this comment.
Even with privileged fixed this is a slight behavioral change. If apparmor is enabled after container was created this var will not change. I think if this is only called on inspecting single container we can lazy load the value like we do in container startup.
Yes, I agree on that. Maybe docker inspect is not the best place to show security information because one thing is the definition of the security you want and the other the security you really have in place at execution time.
Having said that, we can check in daemon.containerStart if the container apparmor options are compatible with the actual execution environment and if not, change the value to unconfined.
I'm going to commit and push this ASAP and..I will squash the commits, sorry about that :p
|
@RobSkye can you address @tonistiigi's comments, and squash your commits? |
|
With the latest push, if you change apparmor configuration and apparmor completely disappear from the dockerhost (I have some comments about this below) the AppArmorProfile is updated with the expected configuration but still there is some issues we have to address:
I don't know if addressing this issues are in the scope of the main issue. I' have the feeling that implementing a real-time check of the security configuration of containers will require more than a "slight behavioral change". I have some ideas of adding security information in the "docker ps" command and a more detailed "docker security" showing all the security settings of a container. I look forward to your feedback. |
daemon/container_linux.go
Outdated
There was a problem hiding this comment.
Don't understand this. Why is unconfined profile switched back to default.
There was a problem hiding this comment.
That is actually an error. I was trying to restore "docker-default" to the unconfined containers if the containers were created after apparmor was enabled but i didn't notice the effect of enabling apparmor to the containers with --security-opt app-armor:unconfined.
I'm gonna think on how manage this correctly.
|
I did a little refactor of the patch in the last commit. Now inspect always shows an empty AppArmorProfile when the container is stopped ( maybe empty is not the best value but this can be changed easily to undefined, unconfined or something more clarifying). The correct value of AppArmorProfile is set at container startup using the actual status of apparmor, the privileged flag and the configured apparmor settings using --security-opt. |
|
@RobSkye I'm not sure that I like an idea of clearing profile on stopped containers - it's breaking change, and indeed it might be useful for debugging. Otherwise, the patch is ok for me. |
|
ping @RobSkye , needs a rebase. I personally don't think showing the previous apparmor profile when inspecting old containers is an issue to be fixed otherwise. It properly reflect how this container was run. |
|
Ok, i'll delete that part and rebase/commit. |
|
ping @tonistiigi @LK4D4 PTAL what's the status on this one? |
daemon/container_linux.go
Outdated
There was a problem hiding this comment.
I'd call this saveApparmorConfig
daemon/container_linux.go
Outdated
There was a problem hiding this comment.
This shows unconfined when apparmor is disabled.
There was a problem hiding this comment.
Yes, do you want to show "Disabled" instead?
There was a problem hiding this comment.
I think empty would do. unconfined implies that special privileged profile was applied(at least to me).
|
ping @RobSkye |
…AppArmor is enabled or not. It is set in NewDaemon using sysInfo information. Signed-off-by: Roberto Muñoz Fernández <robertomf@gmail.com> Added an apparmorEnabled boolean in the Daemon struct to indicate if AppArmor is enabled or not. It is set in NewDaemon using sysInfo information. Signed-off-by: Roberto Muñoz Fernández <robertomf@gmail.com> gofmt'd Signed-off-by: Roberto Muñoz Fernández <robertomf@gmail.com> change the function name to something more adequate and changed the behaviour to show empty value on an apparmor disabled system. Signed-off-by: Roberto Muñoz Fernández <robertomf@gmail.com> go fmt Signed-off-by: Roberto Muñoz Fernández <robertomf@gmail.com>
|
LGTM |
In saveAppArmorConfig, the privileged check unconditionally overwrites the AppArmor profile to "unconfined", even when the user explicitly set a custom profile via --security-opt apparmor=<profile>. This causes the persisted container.AppArmorProfile to be "unconfined" regardless of user intent. On first container start this is masked because createSpec/WithApparmor runs before saveAppArmorConfig and builds the OCI spec from the in-memory value (which still has the correct profile from creation). But saveAppArmorConfig then overwrites it to "unconfined" and CheckpointTo persists that to disk. On subsequent starts (restart, stop+start, host reboot), the container loads with AppArmorProfile "unconfined", and WithApparmor picks up that stale value — resulting in the container running without its intended AppArmor policy. Fix the condition nesting so that "unconfined" and "docker-default" are only applied as defaults when no explicit profile was set via SecurityOpt. This makes saveAppArmorConfig consistent with the existing behavior in both WithApparmor (oci_linux.go) and execSetPlatformOpt (exec_linux.go), which already give explicit profiles precedence over the privileged default. The bug was introduced in d97a00d (Docker 17.04, moby#27083) and survived a refactor in 483aa62 (moby#43130). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> Signed-off-by: Stefan Agner <stefan@agner.ch>
This pull request fixes #25935 showing "AppArmorProfile" in docker inspect filled with "docker-default" when AppArmor is enabled and no other profile was defined using --security-opt.