2021-08-23 13:14:53 +00:00
|
|
|
//go:build linux
|
2016-03-18 18:50:19 +00:00
|
|
|
// +build linux
|
|
|
|
|
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"
|
2023-02-06 18:52:40 +00:00
|
|
|
"os"
|
|
|
|
"sync"
|
2016-12-05 13:12:17 +00:00
|
|
|
|
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"
|
2023-02-06 18:52:40 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
|
|
)
|
|
|
|
|
2023-02-06 18:52:40 +00:00
|
|
|
var (
|
|
|
|
checkAppArmorOnce sync.Once
|
|
|
|
isAppArmorAvailable bool
|
|
|
|
)
|
|
|
|
|
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-06 18:52:40 +00:00
|
|
|
checkAppArmorOnce.Do(func() {
|
|
|
|
if apparmor.HostSupports() {
|
|
|
|
// Restore the apparmor_parser check removed in containerd:
|
|
|
|
// https://github.com/containerd/containerd/commit/1acca8bba36e99684ee3489ea4a42609194ca6b9
|
|
|
|
// Fixes: https://github.com/moby/moby/issues/44900
|
|
|
|
if _, err := os.Stat("/sbin/apparmor_parser"); err == nil {
|
|
|
|
isAppArmorAvailable = true
|
|
|
|
} else {
|
|
|
|
logrus.Warn("AppArmor enabled on system but \"apparmor_parser\" binary is missing, so profile can't be loaded")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
if isAppArmorAvailable {
|
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
|
|
|
}
|