Fix seccomp PSP docker/default annotation handling

With the graduation of seccomp to GA we automatically convert the
deprecated seccomp profile annotation `docker/default` to
`runtime/default`. This means that we now have to automatically allow
`runtime/default` if a user specifies `docker/default` and vice versa in
an allowed PSP seccomp profile.

Signed-off-by: Sascha Grunert <sgrunert@suse.com>
This commit is contained in:
Sascha Grunert 2020-10-29 11:33:41 +01:00
parent 518b826b1d
commit 5588f025e2
No known key found for this signature in database
GPG Key ID: 8CE029DD1A866E52
3 changed files with 32 additions and 1 deletions

View File

@ -13,6 +13,7 @@ go_library(
deps = [
"//pkg/api/pod:go_default_library",
"//pkg/apis/core:go_default_library",
"//staging/src/k8s.io/api/core/v1:go_default_library",
"//staging/src/k8s.io/apimachinery/pkg/util/validation/field:go_default_library",
],
)

View File

@ -20,6 +20,7 @@ import (
"fmt"
"strings"
v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation/field"
podutil "k8s.io/kubernetes/pkg/api/pod"
api "k8s.io/kubernetes/pkg/apis/core"
@ -67,6 +68,15 @@ func NewStrategy(pspAnnotations map[string]string) Strategy {
allowAnyProfile = true
continue
}
// With the graduation of seccomp to GA we automatically convert
// the deprecated seccomp profile annotation `docker/default` to
// `runtime/default`. This means that we now have to automatically
// allow `runtime/default` if a user specifies `docker/default` and
// vice versa in a PSP.
if p == v1.DeprecatedSeccompProfileDockerDefault || p == v1.SeccompProfileRuntimeDefault {
allowedProfiles[v1.SeccompProfileRuntimeDefault] = true
allowedProfiles[v1.DeprecatedSeccompProfileDockerDefault] = true
}
allowedProfiles[p] = true
}
}

View File

@ -21,7 +21,7 @@ import (
"strings"
"testing"
"k8s.io/api/core/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
api "k8s.io/kubernetes/pkg/apis/core"
)
@ -45,6 +45,12 @@ var (
allowSpecificLocalhost = map[string]string{
AllowedProfilesAnnotationKey: v1.SeccompLocalhostProfileNamePrefix + "foo",
}
allowSpecificDockerDefault = map[string]string{
AllowedProfilesAnnotationKey: v1.DeprecatedSeccompProfileDockerDefault,
}
allowSpecificRuntimeDefault = map[string]string{
AllowedProfilesAnnotationKey: v1.SeccompProfileRuntimeDefault,
}
)
func TestNewStrategy(t *testing.T) {
@ -256,6 +262,20 @@ func TestValidatePod(t *testing.T) {
},
expectedError: "",
},
"docker/default PSP annotation automatically allows runtime/default pods": {
pspAnnotations: allowSpecificDockerDefault,
podAnnotations: map[string]string{
api.SeccompPodAnnotationKey: v1.SeccompProfileRuntimeDefault,
},
expectedError: "",
},
"runtime/default PSP annotation automatically allows docker/default pods": {
pspAnnotations: allowSpecificRuntimeDefault,
podAnnotations: map[string]string{
api.SeccompPodAnnotationKey: v1.DeprecatedSeccompProfileDockerDefault,
},
expectedError: "",
},
}
for k, v := range tests {
pod := &api.Pod{