2016-03-18 18:50:19 +00:00
|
|
|
// +build linux
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
2016-12-05 13:12:17 +00:00
|
|
|
"fmt"
|
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
aaprofile "github.com/docker/docker/profiles/apparmor"
|
|
|
|
"github.com/opencontainers/runc/libcontainer/apparmor"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Define constants for native driver
|
|
|
|
const (
|
|
|
|
defaultApparmorProfile = "docker-default"
|
|
|
|
)
|
|
|
|
|
2016-12-05 13:12:17 +00:00
|
|
|
func ensureDefaultAppArmorProfile() error {
|
2016-03-18 18:50:19 +00:00
|
|
|
if apparmor.IsEnabled() {
|
2016-12-05 13:12:17 +00:00
|
|
|
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.
|
2016-03-18 18:50:19 +00:00
|
|
|
if err := aaprofile.InstallDefault(defaultApparmorProfile); err != nil {
|
2016-12-05 13:12:17 +00:00
|
|
|
return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded.", defaultApparmorProfile)
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 13:12:17 +00:00
|
|
|
|
|
|
|
return nil
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|