2016-03-18 14:50:19 -04:00
|
|
|
// +build linux,seccomp
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/container"
|
2016-03-19 17:07:17 -04:00
|
|
|
"github.com/docker/docker/profiles/seccomp"
|
2016-08-17 12:38:34 -04:00
|
|
|
"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
|
|
|
)
|
|
|
|
|
2016-07-08 18:54:48 -04:00
|
|
|
var supportsSeccomp = true
|
|
|
|
|
2016-03-18 14:50:19 -04:00
|
|
|
func setSeccomp(daemon *Daemon, rs *specs.Spec, c *container.Container) error {
|
2017-04-27 17:52:47 -04:00
|
|
|
var profile *specs.LinuxSeccomp
|
2016-03-18 14:50:19 -04: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 09:41:30 -04:00
|
|
|
profile, err = seccomp.LoadProfile(c.SeccompProfile, rs)
|
2016-03-18 14:50:19 -04:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2016-09-02 09:20:54 -04: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 14:50:19 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-19 17:07:17 -04:00
|
|
|
rs.Linux.Seccomp = profile
|
|
|
|
return nil
|
2016-03-18 14:50:19 -04:00
|
|
|
}
|