|
@@ -24,32 +24,32 @@ func TestLoadProfile(t *testing.T) {
|
|
}
|
|
}
|
|
var expectedErrno uint = 12345
|
|
var expectedErrno uint = 12345
|
|
expected := specs.LinuxSeccomp{
|
|
expected := specs.LinuxSeccomp{
|
|
- DefaultAction: "SCMP_ACT_ERRNO",
|
|
|
|
|
|
+ DefaultAction: specs.ActErrno,
|
|
Syscalls: []specs.LinuxSyscall{
|
|
Syscalls: []specs.LinuxSyscall{
|
|
{
|
|
{
|
|
Names: []string{"clone"},
|
|
Names: []string{"clone"},
|
|
- Action: "SCMP_ACT_ALLOW",
|
|
|
|
|
|
+ Action: specs.ActAllow,
|
|
Args: []specs.LinuxSeccompArg{{
|
|
Args: []specs.LinuxSeccompArg{{
|
|
Index: 0,
|
|
Index: 0,
|
|
Value: 2114060288,
|
|
Value: 2114060288,
|
|
ValueTwo: 0,
|
|
ValueTwo: 0,
|
|
- Op: "SCMP_CMP_MASKED_EQ",
|
|
|
|
|
|
+ Op: specs.OpMaskedEqual,
|
|
}},
|
|
}},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
|
|
|
|
Names: []string{"open"},
|
|
Names: []string{"open"},
|
|
- Action: "SCMP_ACT_ALLOW",
|
|
|
|
|
|
+ Action: specs.ActAllow,
|
|
Args: []specs.LinuxSeccompArg{},
|
|
Args: []specs.LinuxSeccompArg{},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
Names: []string{"close"},
|
|
Names: []string{"close"},
|
|
- Action: "SCMP_ACT_ALLOW",
|
|
|
|
|
|
+ Action: specs.ActAllow,
|
|
Args: []specs.LinuxSeccompArg{},
|
|
Args: []specs.LinuxSeccompArg{},
|
|
},
|
|
},
|
|
{
|
|
{
|
|
Names: []string{"syslog"},
|
|
Names: []string{"syslog"},
|
|
- Action: "SCMP_ACT_ERRNO",
|
|
|
|
|
|
+ Action: specs.ActErrno,
|
|
ErrnoRet: &expectedErrno,
|
|
ErrnoRet: &expectedErrno,
|
|
Args: []specs.LinuxSeccompArg{},
|
|
Args: []specs.LinuxSeccompArg{},
|
|
},
|
|
},
|
|
@@ -72,7 +72,7 @@ func TestLoadProfileWithDefaultErrnoRet(t *testing.T) {
|
|
|
|
|
|
expectedErrnoRet := uint(6)
|
|
expectedErrnoRet := uint(6)
|
|
expected := specs.LinuxSeccomp{
|
|
expected := specs.LinuxSeccomp{
|
|
- DefaultAction: "SCMP_ACT_ERRNO",
|
|
|
|
|
|
+ DefaultAction: specs.ActErrno,
|
|
DefaultErrnoRet: &expectedErrnoRet,
|
|
DefaultErrnoRet: &expectedErrnoRet,
|
|
}
|
|
}
|
|
|
|
|
|
@@ -92,7 +92,7 @@ func TestLoadProfileWithListenerPath(t *testing.T) {
|
|
}
|
|
}
|
|
|
|
|
|
expected := specs.LinuxSeccomp{
|
|
expected := specs.LinuxSeccomp{
|
|
- DefaultAction: "SCMP_ACT_ERRNO",
|
|
|
|
|
|
+ DefaultAction: specs.ActErrno,
|
|
ListenerPath: "/var/run/seccompaget.sock",
|
|
ListenerPath: "/var/run/seccompaget.sock",
|
|
ListenerMetadata: "opaque-metadata",
|
|
ListenerMetadata: "opaque-metadata",
|
|
}
|
|
}
|
|
@@ -100,6 +100,46 @@ func TestLoadProfileWithListenerPath(t *testing.T) {
|
|
assert.DeepEqual(t, expected, *p)
|
|
assert.DeepEqual(t, expected, *p)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func TestLoadProfileWithFlag(t *testing.T) {
|
|
|
|
+ profile := `{"defaultAction": "SCMP_ACT_ERRNO", "flags": ["SECCOMP_FILTER_FLAG_SPEC_ALLOW", "SECCOMP_FILTER_FLAG_LOG"]}`
|
|
|
|
+ expected := specs.LinuxSeccomp{
|
|
|
|
+ DefaultAction: specs.ActErrno,
|
|
|
|
+ Flags: []specs.LinuxSeccompFlag{"SECCOMP_FILTER_FLAG_SPEC_ALLOW", "SECCOMP_FILTER_FLAG_LOG"},
|
|
|
|
+ }
|
|
|
|
+ rs := createSpec()
|
|
|
|
+ p, err := LoadProfile(profile, &rs)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+ assert.DeepEqual(t, expected, *p)
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// TestLoadProfileValidation tests that invalid profiles produce the correct error.
|
|
|
|
+func TestLoadProfileValidation(t *testing.T) {
|
|
|
|
+ tests := []struct {
|
|
|
|
+ doc string
|
|
|
|
+ profile string
|
|
|
|
+ expected string
|
|
|
|
+ }{
|
|
|
|
+ {
|
|
|
|
+ doc: "conflicting architectures and archMap",
|
|
|
|
+ profile: `{"defaultAction": "SCMP_ACT_ERRNO", "architectures": ["A", "B", "C"], "archMap": [{"architecture": "A", "subArchitectures": ["B", "C"]}]}`,
|
|
|
|
+ expected: `use either 'architectures' or 'archMap'`,
|
|
|
|
+ },
|
|
|
|
+ {
|
|
|
|
+ doc: "conflicting syscall.name and syscall.names",
|
|
|
|
+ profile: `{"defaultAction": "SCMP_ACT_ERRNO", "syscalls": [{"name": "accept", "names": ["accept"], "action": "SCMP_ACT_ALLOW"}]}`,
|
|
|
|
+ expected: `use either 'name' or 'names'`,
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ for _, tc := range tests {
|
|
|
|
+ tc := tc
|
|
|
|
+ rs := createSpec()
|
|
|
|
+ t.Run(tc.doc, func(t *testing.T) {
|
|
|
|
+ _, err := LoadProfile(tc.profile, &rs)
|
|
|
|
+ assert.ErrorContains(t, err, tc.expected)
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
// TestLoadLegacyProfile tests loading a seccomp profile in the old format
|
|
// TestLoadLegacyProfile tests loading a seccomp profile in the old format
|
|
// (before https://github.com/docker/docker/pull/24510)
|
|
// (before https://github.com/docker/docker/pull/24510)
|
|
func TestLoadLegacyProfile(t *testing.T) {
|
|
func TestLoadLegacyProfile(t *testing.T) {
|
|
@@ -108,9 +148,17 @@ func TestLoadLegacyProfile(t *testing.T) {
|
|
t.Fatal(err)
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
rs := createSpec()
|
|
rs := createSpec()
|
|
- if _, err := LoadProfile(string(f), &rs); err != nil {
|
|
|
|
- t.Fatal(err)
|
|
|
|
|
|
+ p, err := LoadProfile(string(f), &rs)
|
|
|
|
+ assert.NilError(t, err)
|
|
|
|
+ assert.Equal(t, p.DefaultAction, specs.ActErrno)
|
|
|
|
+ assert.DeepEqual(t, p.Architectures, []specs.Arch{"SCMP_ARCH_X86_64", "SCMP_ARCH_X86", "SCMP_ARCH_X32"})
|
|
|
|
+ assert.Equal(t, len(p.Syscalls), 311)
|
|
|
|
+ expected := specs.LinuxSyscall{
|
|
|
|
+ Names: []string{"accept"},
|
|
|
|
+ Action: specs.ActAllow,
|
|
|
|
+ Args: []specs.LinuxSeccompArg{},
|
|
}
|
|
}
|
|
|
|
+ assert.DeepEqual(t, p.Syscalls[0], expected)
|
|
}
|
|
}
|
|
|
|
|
|
func TestLoadDefaultProfile(t *testing.T) {
|
|
func TestLoadDefaultProfile(t *testing.T) {
|