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