-
Notifications
You must be signed in to change notification settings - Fork 18.8k
Fix AppArmor not being applied to Exec processes #36466
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Exec processes do not automatically inherit AppArmor profiles from the container. This patch sets the AppArmor profile for the exec process. Before this change: apparmor_parser -q -r <<EOF #include <tunables/global> profile deny-write flags=(attach_disconnected) { #include <abstractions/base> file, network, deny /tmp/** w, capability, } EOF docker run -dit --security-opt "apparmor=deny-write" --name aa busybox docker exec aa sh -c 'mkdir /tmp/test' (no error) With this change applied: docker exec aa sh -c 'mkdir /tmp/test' mkdir: can't create directory '/tmp/test': Permission denied Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
ping @justincormack @mlaventure PTAL |
) | ||
|
||
func TestExecSetPlatformOpt(t *testing.T) { | ||
if !apparmor.IsEnabled() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For reference; looks like this check also checks for an CONTAINER
env-var;
moby/vendor/github.com/opencontainers/runc/libcontainer/apparmor/apparmor.go
Lines 11 to 20 in f58aa31
// IsEnabled returns true if apparmor is enabled for the host. | |
func IsEnabled() bool { | |
if _, err := os.Stat("/sys/kernel/security/apparmor"); err == nil && os.Getenv("container") == "" { | |
if _, err = os.Stat("/sbin/apparmor_parser"); err == nil { | |
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") | |
return err == nil && len(buf) > 1 && buf[0] == 'Y' | |
} | |
} | |
return false | |
} |
But our integration-cli checks in a different way;
moby/integration-cli/requirements_test.go
Lines 110 to 113 in f58aa31
func Apparmor() bool { | |
buf, err := ioutil.ReadFile("/sys/module/apparmor/parameters/enabled") | |
return err == nil && len(buf) > 1 && buf[0] == 'Y' | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Failure seems to be related to libnetwork, restarting the ci
Codecov Report
@@ Coverage Diff @@
## master #36466 +/- ##
==========================================
- Coverage 34.65% 34.65% -0.01%
==========================================
Files 613 613
Lines 45375 45376 +1
==========================================
Hits 15725 15725
- Misses 27588 27590 +2
+ Partials 2062 2061 -1 |
fixes #36456
Exec processes do not automatically inherit AppArmor profiles from the container.
This patch sets the AppArmor profile for the exec process.
Before this change:
Running
docker exec
doesn't get the profile applied:With this change:
Running
docker exec
gets the AppArmor profile applied- How to verify it
Build a
.deb
from this PR, using the Docker CE packaging scripts; https://github.com/docker/docker-ce-packaging/tree/master/debWhich puts the package in
debbuild/ubuntu-xenial
On an Ubuntu 16.04 machine, install the package:
Run the reproduction steps above
- Description for the changelog