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