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