apparmor_default.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build linux
  2. package daemon // import "github.com/docker/docker/daemon"
  3. import (
  4. "fmt"
  5. "github.com/containerd/containerd/pkg/apparmor"
  6. aaprofile "github.com/docker/docker/profiles/apparmor"
  7. )
  8. // Define constants for native driver
  9. const (
  10. unconfinedAppArmorProfile = "unconfined"
  11. defaultAppArmorProfile = "docker-default"
  12. )
  13. // DefaultApparmorProfile returns the name of the default apparmor profile
  14. func DefaultApparmorProfile() string {
  15. if apparmor.HostSupports() {
  16. return defaultAppArmorProfile
  17. }
  18. return ""
  19. }
  20. func ensureDefaultAppArmorProfile() error {
  21. if apparmor.HostSupports() {
  22. loaded, err := aaprofile.IsLoaded(defaultAppArmorProfile)
  23. if err != nil {
  24. return fmt.Errorf("Could not check if %s AppArmor profile was loaded: %s", defaultAppArmorProfile, err)
  25. }
  26. // Nothing to do.
  27. if loaded {
  28. return nil
  29. }
  30. // Load the profile.
  31. if err := aaprofile.InstallDefault(defaultAppArmorProfile); err != nil {
  32. return fmt.Errorf("AppArmor enabled on system but the %s profile could not be loaded: %s", defaultAppArmorProfile, err)
  33. }
  34. }
  35. return nil
  36. }