apparmor_default.go 1.1 KB

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