Skip to content

Commit 2a4164a

Browse files
committed
Remove noinline in seccomp SpecOpts
Signed-off-by: Jin Dong <[email protected]>
1 parent 98af40b commit 2a4164a

File tree

2 files changed

+39
-13
lines changed

2 files changed

+39
-13
lines changed

contrib/seccomp/seccomp.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,6 @@ import (
3030
// WithProfile receives the name of a file stored on disk comprising a json
3131
// formatted seccomp profile, as specified by the opencontainers/runtime-spec.
3232
// The profile is read from the file, unmarshaled, and set to the spec.
33-
//
34-
// FIXME: pkg/cri/[sb]server/container_create_linux_test.go depends on go:noinline
35-
// since Go 1.21.
36-
//
37-
//go:noinline
3833
func WithProfile(profile string) oci.SpecOpts {
3934
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
4035
s.Linux.Seccomp = &specs.LinuxSeccomp{}
@@ -51,11 +46,6 @@ func WithProfile(profile string) oci.SpecOpts {
5146

5247
// WithDefaultProfile sets the default seccomp profile to the spec.
5348
// Note: must follow the setting of process capabilities
54-
//
55-
// FIXME: pkg/cri/[sb]server/container_create_linux_test.go depends on go:noinline
56-
// since Go 1.21.
57-
//
58-
//go:noinline
5949
func WithDefaultProfile() oci.SpecOpts {
6050
return func(_ context.Context, _ oci.Client, _ *containers.Container, s *specs.Spec) error {
6151
s.Linux.Seccomp = DefaultProfile(s)

internal/cri/server/container_create_linux_test.go

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,49 @@ func TestGenerateSeccompSecurityProfileSpecOpts(t *testing.T) {
10031003
ssp = csp
10041004
}
10051005
specOpts, err := cri.generateSeccompSpecOpts(ssp, test.privileged, !test.disable)
1006-
assert.Equal(t,
1007-
reflect.ValueOf(test.specOpts).Pointer(),
1008-
reflect.ValueOf(specOpts).Pointer())
10091006
if test.expectErr {
10101007
assert.Error(t, err)
10111008
} else {
10121009
assert.NoError(t, err)
1010+
if test.specOpts == nil && specOpts == nil {
1011+
return
1012+
}
1013+
if test.specOpts == nil || specOpts == nil {
1014+
t.Fatalf("unexpected nil specOpts, expected nil: %t, actual nil: %t", test.specOpts == nil, specOpts == nil)
1015+
}
1016+
// `specOpts` for seccomp only uses/modifies `*specs.Spec`, not
1017+
// `oci.Client` or `*containers.Container`, so let's construct a
1018+
// `*specs.Spec` and compare if the results are the same.
1019+
expected := runtimespec.Spec{
1020+
Linux: &runtimespec.Linux{},
1021+
Process: &runtimespec.Process{
1022+
Capabilities: &runtimespec.LinuxCapabilities{
1023+
Bounding: []string{
1024+
"CAP_DAC_READ_SEARCH",
1025+
"CAP_SYS_ADMIN",
1026+
"CAP_SYS_BOOT",
1027+
"CAP_SYS_CHROOT",
1028+
"CAP_SYS_MODULE",
1029+
"CAP_SYS_PACCT",
1030+
"CAP_SYS_PTRACE",
1031+
"CAP_SYS_RAWIO",
1032+
"CAP_SYS_TIME",
1033+
"CAP_SYS_TTY_CONFIG",
1034+
"CAP_SYS_NICE",
1035+
"CAP_SYSLOG",
1036+
"CAP_BPF",
1037+
"CAP_PERFMON",
1038+
},
1039+
},
1040+
},
1041+
}
1042+
var actual runtimespec.Spec
1043+
err := util.DeepCopy(&actual, &expected)
1044+
assert.NoError(t, err)
1045+
1046+
test.specOpts(context.TODO(), nil, nil, &expected)
1047+
specOpts(context.TODO(), nil, nil, &actual)
1048+
assert.Equal(t, expected, actual)
10131049
}
10141050
}
10151051
})

0 commit comments

Comments
 (0)