seccomp_linux.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package daemon // import "github.com/docker/docker/daemon"
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/containerd/containerd/containers"
  6. coci "github.com/containerd/containerd/oci"
  7. "github.com/containerd/log"
  8. "github.com/docker/docker/container"
  9. dconfig "github.com/docker/docker/daemon/config"
  10. "github.com/docker/docker/profiles/seccomp"
  11. specs "github.com/opencontainers/runtime-spec/specs-go"
  12. )
  13. const supportsSeccomp = true
  14. // WithSeccomp sets the seccomp profile
  15. func WithSeccomp(daemon *Daemon, c *container.Container) coci.SpecOpts {
  16. return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
  17. if c.SeccompProfile == dconfig.SeccompProfileUnconfined {
  18. return nil
  19. }
  20. if c.HostConfig.Privileged {
  21. return nil
  22. }
  23. if !daemon.RawSysInfo().Seccomp {
  24. if c.SeccompProfile != "" && c.SeccompProfile != dconfig.SeccompProfileDefault {
  25. return fmt.Errorf("seccomp is not enabled in your kernel, cannot run a custom seccomp profile")
  26. }
  27. log.G(ctx).Warn("seccomp is not enabled in your kernel, running container without default profile")
  28. c.SeccompProfile = dconfig.SeccompProfileUnconfined
  29. return nil
  30. }
  31. if s.Linux == nil {
  32. s.Linux = &specs.Linux{}
  33. }
  34. var err error
  35. switch {
  36. case c.SeccompProfile == dconfig.SeccompProfileDefault:
  37. s.Linux.Seccomp, err = seccomp.GetDefaultProfile(s)
  38. case c.SeccompProfile != "":
  39. s.Linux.Seccomp, err = seccomp.LoadProfile(c.SeccompProfile, s)
  40. case daemon.seccompProfile != nil:
  41. s.Linux.Seccomp, err = seccomp.LoadProfile(string(daemon.seccompProfile), s)
  42. case daemon.seccompProfilePath == dconfig.SeccompProfileUnconfined:
  43. c.SeccompProfile = dconfig.SeccompProfileUnconfined
  44. default:
  45. s.Linux.Seccomp, err = seccomp.GetDefaultProfile(s)
  46. }
  47. return err
  48. }
  49. }