2016-03-18 14:50:19 -04:00
|
|
|
// +build linux,seccomp
|
|
|
|
|
2018-02-05 16:05:59 -05:00
|
|
|
package daemon // import "github.com/docker/docker/daemon"
|
2016-03-18 14:50:19 -04:00
|
|
|
|
|
|
|
import (
|
2019-04-10 14:45:14 -04:00
|
|
|
"context"
|
2016-03-18 14:50:19 -04:00
|
|
|
"fmt"
|
|
|
|
|
2019-04-10 14:45:14 -04:00
|
|
|
"github.com/containerd/containerd/containers"
|
|
|
|
coci "github.com/containerd/containerd/oci"
|
2016-03-18 14:50:19 -04:00
|
|
|
"github.com/docker/docker/container"
|
2016-03-19 17:07:17 -04:00
|
|
|
"github.com/docker/docker/profiles/seccomp"
|
2019-08-05 10:37:47 -04:00
|
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
2017-07-26 17:42:13 -04:00
|
|
|
"github.com/sirupsen/logrus"
|
2016-03-18 14:50:19 -04:00
|
|
|
)
|
|
|
|
|
2019-10-12 18:39:34 -04:00
|
|
|
const supportsSeccomp = true
|
2016-07-08 18:54:48 -04:00
|
|
|
|
2019-04-10 14:45:14 -04: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 14:50:19 -04:00
|
|
|
|
2019-04-10 14:45:14 -04:00
|
|
|
if c.HostConfig.Privileged {
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
|
2019-04-10 14:45:14 -04:00
|
|
|
if !daemon.seccompEnabled {
|
|
|
|
if c.SeccompProfile != "" && c.SeccompProfile != "unconfined" {
|
2019-08-05 09:13:46 -04:00
|
|
|
return fmt.Errorf("seccomp is not enabled in your kernel, cannot run a custom seccomp profile")
|
2019-04-10 14:45:14 -04:00
|
|
|
}
|
2019-08-05 09:13:46 -04:00
|
|
|
logrus.Warn("seccomp is not enabled in your kernel, running container without default profile")
|
2019-04-10 14:45:14 -04:00
|
|
|
c.SeccompProfile = "unconfined"
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2019-04-10 14:45:14 -04:00
|
|
|
if c.SeccompProfile == "unconfined" {
|
|
|
|
return nil
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
2019-04-10 14:45:14 -04:00
|
|
|
if c.SeccompProfile != "" {
|
|
|
|
profile, err = seccomp.LoadProfile(c.SeccompProfile, s)
|
2016-09-02 09:20:54 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2019-04-10 14:45:14 -04: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 09:20:54 -04:00
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|
|
|
|
|
2019-04-10 14:45:14 -04:00
|
|
|
s.Linux.Seccomp = profile
|
|
|
|
return nil
|
|
|
|
}
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|