|
@@ -11,6 +11,7 @@ import (
|
|
"github.com/docker/docker/container"
|
|
"github.com/docker/docker/container"
|
|
dconfig "github.com/docker/docker/daemon/config"
|
|
dconfig "github.com/docker/docker/daemon/config"
|
|
doci "github.com/docker/docker/oci"
|
|
doci "github.com/docker/docker/oci"
|
|
|
|
+ "github.com/docker/docker/pkg/sysinfo"
|
|
"github.com/docker/docker/profiles/seccomp"
|
|
"github.com/docker/docker/profiles/seccomp"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
specs "github.com/opencontainers/runtime-spec/specs-go"
|
|
"gotest.tools/v3/assert"
|
|
"gotest.tools/v3/assert"
|
|
@@ -31,7 +32,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "unconfined seccompProfile runs unconfined",
|
|
comment: "unconfined seccompProfile runs unconfined",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: dconfig.SeccompProfileUnconfined,
|
|
SeccompProfile: dconfig.SeccompProfileUnconfined,
|
|
@@ -45,7 +46,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "privileged container w/ custom profile runs unconfined",
|
|
comment: "privileged container w/ custom profile runs unconfined",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_LOG\" }",
|
|
@@ -59,7 +60,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "privileged container w/ default runs unconfined",
|
|
comment: "privileged container w/ default runs unconfined",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: "",
|
|
SeccompProfile: "",
|
|
@@ -73,7 +74,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "privileged container w/ daemon profile runs unconfined",
|
|
comment: "privileged container w/ daemon profile runs unconfined",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
@@ -88,7 +89,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "custom profile when seccomp is disabled returns error",
|
|
comment: "custom profile when seccomp is disabled returns error",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: false,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: false},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
|
@@ -103,7 +104,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "empty profile name loads default profile",
|
|
comment: "empty profile name loads default profile",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: "",
|
|
SeccompProfile: "",
|
|
@@ -122,7 +123,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "load container's profile",
|
|
comment: "load container's profile",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
|
SeccompProfile: "{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }",
|
|
@@ -143,7 +144,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "load daemon's profile",
|
|
comment: "load daemon's profile",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
@@ -165,7 +166,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
{
|
|
{
|
|
comment: "load prioritise container profile over daemon's",
|
|
comment: "load prioritise container profile over daemon's",
|
|
daemon: &Daemon{
|
|
daemon: &Daemon{
|
|
- seccompEnabled: true,
|
|
|
|
|
|
+ sysInfo: &sysinfo.SysInfo{Seccomp: true},
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
seccompProfile: []byte("{ \"defaultAction\": \"SCMP_ACT_ERRNO\" }"),
|
|
},
|
|
},
|
|
c: &container.Container{
|
|
c: &container.Container{
|
|
@@ -185,6 +186,7 @@ func TestWithSeccomp(t *testing.T) {
|
|
}(),
|
|
}(),
|
|
},
|
|
},
|
|
} {
|
|
} {
|
|
|
|
+ x := x
|
|
t.Run(x.comment, func(t *testing.T) {
|
|
t.Run(x.comment, func(t *testing.T) {
|
|
opts := WithSeccomp(x.daemon, x.c)
|
|
opts := WithSeccomp(x.daemon, x.c)
|
|
err := opts(nil, nil, nil, &x.inSpec)
|
|
err := opts(nil, nil, nil, &x.inSpec)
|