seccomp_linux.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // +build linux,seccomp
  2. package daemon
  3. import (
  4. "fmt"
  5. "github.com/Sirupsen/logrus"
  6. "github.com/docker/docker/container"
  7. "github.com/docker/docker/profiles/seccomp"
  8. "github.com/opencontainers/specs/specs-go"
  9. )
  10. var supportsSeccomp = true
  11. func setSeccomp(daemon *Daemon, rs *specs.Spec, c *container.Container) error {
  12. var profile *specs.Seccomp
  13. var err error
  14. if c.HostConfig.Privileged {
  15. return nil
  16. }
  17. if !daemon.seccompEnabled {
  18. if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" {
  19. return fmt.Errorf("Seccomp is not enabled in your kernel, cannot run a custom seccomp profile.")
  20. }
  21. logrus.Warn("Seccomp is not enabled in your kernel, running container without default profile.")
  22. c.SeccompProfile = "unconfined"
  23. }
  24. if c.SeccompProfile == "unconfined" {
  25. return nil
  26. }
  27. if c.SeccompProfile != "" {
  28. profile, err = seccomp.LoadProfile(c.SeccompProfile)
  29. if err != nil {
  30. return err
  31. }
  32. } else {
  33. profile, err = seccomp.GetDefaultProfile(rs)
  34. if err != nil {
  35. return err
  36. }
  37. }
  38. rs.Linux.Seccomp = profile
  39. return nil
  40. }