2021-08-23 09:14:53 -04:00
|
|
|
//go:build linux
|
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"
|
|
|
|
|
2021-04-08 09:37:13 -04:00
|
|
|
"github.com/containerd/containerd/pkg/apparmor"
|
2016-03-18 14:50:19 -04:00
|
|
|
aaprofile "github.com/docker/docker/profiles/apparmor"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Define constants for native driver
|
|
|
|
const (
|
2019-10-12 18:04:44 -04:00
|
|
|
unconfinedAppArmorProfile = "unconfined"
|
2019-08-09 06:33:15 -04:00
|
|
|
defaultAppArmorProfile = "docker-default"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2020-10-09 13:20:48 -04:00
|
|
|
// DefaultApparmorProfile returns the name of the default apparmor profile
|
|
|
|
func DefaultApparmorProfile() string {
|
2021-04-08 09:37:13 -04:00
|
|
|
if apparmor.HostSupports() {
|
2020-10-09 13:20:48 -04:00
|
|
|
return defaultAppArmorProfile
|
|
|
|
}
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
|
2016-12-05 08:12:17 -05:00
|
|
|
func ensureDefaultAppArmorProfile() error {
|
2021-04-08 09:37:13 -04:00
|
|
|
if apparmor.HostSupports() {
|
2019-08-09 06:33:15 -04:00
|
|
|
loaded, err := aaprofile.IsLoaded(defaultAppArmorProfile)
|
2016-12-05 08:12:17 -05:00
|
|
|
if err != nil {
|
2019-08-09 06:33:15 -04:00
|
|
|
return fmt.Errorf("Could not check if %s AppArmor profile was loaded: %s", defaultAppArmorProfile, err)
|
2016-12-05 08:12:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing to do.
|
|
|
|
if loaded {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the profile.
|
2019-08-09 06:33:15 -04:00
|
|
|
if err := aaprofile.InstallDefault(defaultAppArmorProfile); err != nil {
|
|
|
|
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
|
|
|
}
|