Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion config/core/configmaps/features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ metadata:
app.kubernetes.io/component: controller
app.kubernetes.io/version: devel
annotations:
knative.dev/example-checksum: "433d7e74"
knative.dev/example-checksum: "23732fd7"
data:
_example: |-
################################
Expand Down Expand Up @@ -109,6 +109,7 @@ data:
# - RunAsNonRoot
# - SupplementalGroups
# - RunAsUser
# - SeccompProfile
#
# This feature flag should be used with caution as the PodSecurityContext
# properties may have a side-effect on non-user sidecar containers that come
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/serving/fieldmask.go
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ func PodSecurityContextMask(ctx context.Context, in *corev1.PodSecurityContext)
out.RunAsNonRoot = in.RunAsNonRoot
out.FSGroup = in.FSGroup
out.SupplementalGroups = in.SupplementalGroups
out.SeccompProfile = in.SeccompProfile

// Disallowed
// This list is unnecessary, but added here for clarity
Expand Down Expand Up @@ -629,6 +630,10 @@ func SecurityContextMask(ctx context.Context, in *corev1.SecurityContext) *corev
// We do want the ability for folks to set this value to true
out.RunAsNonRoot = in.RunAsNonRoot

// SeccompProfile defaults to "unconstrained", but the safe values are
// "RuntimeDefault" or "Localhost" (with localhost path set)
out.SeccompProfile = in.SeccompProfile

// Disallowed
// This list is unnecessary, but added here for clarity
out.Privileged = nil
Expand Down
21 changes: 21 additions & 0 deletions pkg/apis/serving/fieldmask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,9 @@ func TestPodSecurityContextMask(t *testing.T) {
RunAsGroup: ptr.Int64(1),
RunAsNonRoot: ptr.Bool(true),
FSGroup: ptr.Int64(1),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

want := &corev1.PodSecurityContext{}
Expand Down Expand Up @@ -688,6 +691,9 @@ func TestPodSecurityContextMask_FeatureEnabled(t *testing.T) {
RunAsGroup: ptr.Int64(1),
RunAsNonRoot: ptr.Bool(true),
FSGroup: ptr.Int64(1),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

want := &corev1.PodSecurityContext{
Expand All @@ -696,6 +702,9 @@ func TestPodSecurityContextMask_FeatureEnabled(t *testing.T) {
RunAsNonRoot: ptr.Bool(true),
FSGroup: ptr.Int64(1),
SupplementalGroups: []int64{1},
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

ctx := config.ToContext(context.Background(),
Expand Down Expand Up @@ -727,6 +736,9 @@ func TestSecurityContextMask(t *testing.T) {
RunAsGroup: ptr.Int64(2),
RunAsNonRoot: ptr.Bool(true),
ReadOnlyRootFilesystem: ptr.Bool(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}
in := &corev1.SecurityContext{
RunAsUser: ptr.Int64(1),
Expand All @@ -738,6 +750,9 @@ func TestSecurityContextMask(t *testing.T) {
ReadOnlyRootFilesystem: ptr.Bool(true),
AllowPrivilegeEscalation: ptr.Bool(true),
ProcMount: &mtype,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

got := SecurityContextMask(context.Background(), in)
Expand Down Expand Up @@ -765,6 +780,9 @@ func TestSecurityContextMask_FeatureEnabled(t *testing.T) {
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(1),
ReadOnlyRootFilesystem: ptr.Bool(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}
in := &corev1.SecurityContext{
AllowPrivilegeEscalation: ptr.Bool(true),
Expand All @@ -776,6 +794,9 @@ func TestSecurityContextMask_FeatureEnabled(t *testing.T) {
RunAsNonRoot: ptr.Bool(true),
RunAsUser: ptr.Int64(1),
SELinuxOptions: &corev1.SELinuxOptions{},
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}

ctx := config.ToContext(context.Background(),
Expand Down