|
@@ -3,7 +3,8 @@
|
|
|
package daemon
|
|
|
|
|
|
import (
|
|
|
- "github.com/Sirupsen/logrus"
|
|
|
+ "fmt"
|
|
|
+
|
|
|
aaprofile "github.com/docker/docker/profiles/apparmor"
|
|
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
|
|
)
|
|
@@ -13,18 +14,23 @@ const (
|
|
|
defaultApparmorProfile = "docker-default"
|
|
|
)
|
|
|
|
|
|
-func installDefaultAppArmorProfile() {
|
|
|
+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 {
|
|
|
- apparmorProfiles := []string{defaultApparmorProfile}
|
|
|
-
|
|
|
- // Allow daemon to run if loading failed, but are active
|
|
|
- // (possibly through another run, manually, or via system startup)
|
|
|
- for _, policy := range apparmorProfiles {
|
|
|
- if err := aaprofile.IsLoaded(policy); err != nil {
|
|
|
- logrus.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", policy)
|
|
|
- }
|
|
|
- }
|
|
|
+ return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", defaultApparmorProfile)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ return nil
|
|
|
}
|