2016-03-18 18:50:19 +00:00
|
|
|
// +build linux,seccomp
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"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
|
|
|
|
|
2016-03-18 18:50:19 +00:00
|
|
|
func setSeccomp(daemon *Daemon, rs *specs.Spec, c *container.Container) error {
|
2017-04-27 21:52:47 +00:00
|
|
|
var profile *specs.LinuxSeccomp
|
2016-03-18 18:50:19 +00:00
|
|
|
var err error
|
|
|
|
|
|
|
|
if c.HostConfig.Privileged {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
}
|
|
|
|
if c.SeccompProfile == "unconfined" {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if c.SeccompProfile != "" {
|
2016-07-13 13:41:30 +00:00
|
|
|
profile, err = seccomp.LoadProfile(c.SeccompProfile, rs)
|
2016-03-18 18:50:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-02 13:20:54 +00:00
|
|
|
if daemon.seccompProfile != nil {
|
|
|
|
profile, err = seccomp.LoadProfile(string(daemon.seccompProfile), rs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
profile, err = seccomp.GetDefaultProfile(rs)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 21:07:17 +00:00
|
|
|
rs.Linux.Seccomp = profile
|
|
|
|
return nil
|
2016-03-18 18:50:19 +00:00
|
|
|
}
|