mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
80c3ed1c0c
In certain cases (unattended upgrades), system services can disable loaded AppArmor profiles. However, since /etc being read-only is a supported setup we cannot just write a copy of the profile to /etc/apparmor.d. Instead, dynamically load the docker-default AppArmor profile if a container is started with that profile set. This code will short-cut if the profile is already loaded. Fixes:2f7596aaef
("apparmor: do not save profile to /etc/apparmor.d") Signed-off-by: Aleksa Sarai <asarai@suse.de> (cherry picked from commit567ef8e785
) Signed-off-by: Victor Vieux <vieux@docker.com>
36 lines
806 B
Go
36 lines
806 B
Go
// +build linux
|
|
|
|
package daemon
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
aaprofile "github.com/docker/docker/profiles/apparmor"
|
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
|
)
|
|
|
|
// Define constants for native driver
|
|
const (
|
|
defaultApparmorProfile = "docker-default"
|
|
)
|
|
|
|
func ensureDefaultAppArmorProfile() error {
|
|
if apparmor.IsEnabled() {
|
|
loaded, err := aaprofile.IsLoaded(defaultApparmorProfile)
|
|
if err != nil {
|
|
return fmt.Errorf("Could not check if %s AppArmor profile was loaded: %s", defaultApparmorProfile, err)
|
|
}
|
|
|
|
// Nothing to do.
|
|
if loaded {
|
|
return nil
|
|
}
|
|
|
|
// Load the profile.
|
|
if err := aaprofile.InstallDefault(defaultApparmorProfile); err != nil {
|
|
return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", defaultApparmorProfile)
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|