2016-03-18 18:50:19 +00:00
|
|
|
// +build linux,seccomp
|
|
|
|
|
|
|
|
package daemon
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Sirupsen/logrus"
|
|
|
|
"github.com/docker/docker/container"
|
2016-03-19 21:07:17 +00:00
|
|
|
"github.com/docker/docker/profiles/seccomp"
|
2016-03-18 18:50:19 +00:00
|
|
|
"github.com/opencontainers/specs/specs-go"
|
|
|
|
)
|
|
|
|
|
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 {
|
2016-03-19 21:07:17 +00:00
|
|
|
var profile *specs.Seccomp
|
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-03-19 21:07:17 +00:00
|
|
|
profile, err = seccomp.LoadProfile(c.SeccompProfile)
|
2016-03-18 18:50:19 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
} else {
|
2016-05-06 14:17:41 +00:00
|
|
|
profile, err = seccomp.GetDefaultProfile(rs)
|
2016-03-19 21:07:17 +00:00
|
|
|
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
|
|
|
}
|