2016-03-18 18:50:19 +00:00
|
|
|
// +build linux,seccomp
|
|
|
|
|
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 (
|
2019-04-10 18:45:14 +00:00
|
|
|
"context"
|
2016-03-18 18:50:19 +00:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-10 18:45:14 +00:00
|
|
|
"github.com/containerd/containerd/containers"
|
|
|
|
coci "github.com/containerd/containerd/oci"
|
2016-03-18 18:50:19 +00:00
|
|
|
"github.com/docker/docker/container"
|
2016-03-19 21:07:17 +00:00
|
|
|
"github.com/docker/docker/profiles/seccomp"
|
2016-08-17 16:38:34 +00:00
|
|
|
"github.com/opencontainers/runtime-spec/specs-go"
|
2017-07-26 21:42:13 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-03-18 18:50:19 +00:00
|
|
|
)
|
|
|
|
|
2016-07-08 22:54:48 +00:00
|
|
|
var supportsSeccomp = true
|
|
|
|
|
2019-04-10 18:45:14 +00:00
|
|
|
// WithSeccomp sets the seccomp profile
|
|
|
|
func WithSeccomp(daemon *Daemon, c *container.Container) coci.SpecOpts {
|
|
|
|
return func(ctx context.Context, _ coci.Client, _ *containers.Container, s *coci.Spec) error {
|
|
|
|
var profile *specs.LinuxSeccomp
|
|
|
|
var err error
|
2016-03-18 18:50:19 +00:00
|
|
|
|
2019-04-10 18:45:14 +00:00
|
|
|
if c.HostConfig.Privileged {
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 18:50:19 +00:00
|
|
|
|
2019-04-10 18:45:14 +00:00
|
|
|
if !daemon.seccompEnabled {
|
|
|
|
if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" {
|
|
|
|
return fmt.Errorf("Seccomp is not enabled in your kernel, cannot run a custom seccomp profile.")
|
|
|
|
}
|
|
|
|
logrus.Warn("Seccomp is not enabled in your kernel, running container without default profile.")
|
|
|
|
c.SeccompProfile = "unconfined"
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
2019-04-10 18:45:14 +00:00
|
|
|
if c.SeccompProfile == "unconfined" {
|
|
|
|
return nil
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
2019-04-10 18:45:14 +00:00
|
|
|
if c.SeccompProfile != "" {
|
|
|
|
profile, err = seccomp.LoadProfile(c.SeccompProfile, s)
|
2016-09-02 13:20:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-10 18:45:14 +00:00
|
|
|
if daemon.seccompProfile != nil {
|
|
|
|
profile, err = seccomp.LoadProfile(string(daemon.seccompProfile), s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
profile, err = seccomp.GetDefaultProfile(s)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-09-02 13:20:54 +00:00
|
|
|
}
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
|
|
|
|
2019-04-10 18:45:14 +00:00
|
|
|
s.Linux.Seccomp = profile
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|