2016-03-18 14:50:19 -04:00
|
|
|
// +build linux
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
import (
|
2016-12-05 08:12:17 -05:00
|
|
|
"fmt"
|
|
|
|
|
2016-03-18 14:50:19 -04: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 08:12:17 -05:00
|
|
|
func ensureDefaultAppArmorProfile() error {
|
2016-03-18 14:50:19 -04:00
|
|
|
if apparmor.IsEnabled() {
|
2016-12-05 08:12:17 -05: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 14:50:19 -04:00
|
|
|
if err := aaprofile.InstallDefault(defaultApparmorProfile); err != nil {
|
2017-05-17 10:02:00 -04:00
|
|
|
return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded: %s", defaultApparmorProfile, err)
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
}
|
2016-12-05 08:12:17 -05:00
|
|
|
|
|
|
|
return nil
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|