Skip to content

Commit

Permalink
Update tests to use SecurityContextto account for enabling secure-pod…
Browse files Browse the repository at this point in the history
…-defaults
  • Loading branch information
Kauana dos Santos committed Jul 12, 2023
1 parent 7f51c74 commit 18474ca
Show file tree
Hide file tree
Showing 7 changed files with 951 additions and 7 deletions.
8 changes: 4 additions & 4 deletions 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: "b08d16b1"
knative.dev/example-checksum: "43e1a61b"
data:
_example: |-
################################
Expand All @@ -40,10 +40,10 @@ data:
# this example block and unindented to be in the data block
# to actually change the configuration.
# Default SecurityContext settings to secure-by-default values
# if unset.
#
# Indicates whether secure-pod-defaults support is enabled
# WARNING: Cannot safely be disabled once enabled.
# See: TBD
secure-pod-defaults: "enabled"
# Indicates whether multi container support is enabled
Expand Down
2 changes: 1 addition & 1 deletion pkg/apis/config/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func defaultFeaturesConfig() *Features {
PodSpecInitContainers: Disabled,
PodSpecDNSPolicy: Disabled,
PodSpecDNSConfig: Disabled,
SecurePodDefaults: Disabled,
SecurePodDefaults: Enabled,
TagHeaderBasedRouting: Disabled,
AutoDetectHTTP2: Disabled,
}
Expand Down
6 changes: 5 additions & 1 deletion pkg/apis/serving/fieldmask_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,11 @@ func TestPodSecurityContextMask(t *testing.T) {
},
}

want := &corev1.PodSecurityContext{}
want := &corev1.PodSecurityContext{
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
}
ctx := context.Background()

got := PodSecurityContextMask(ctx, in)
Expand Down
54 changes: 54 additions & 0 deletions pkg/apis/serving/v1/configuration_defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ func TestConfigurationDefaulting(t *testing.T) {
Image: "busybox",
Resources: defaultResources,
ReadinessProbe: defaultProbe,
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Privileged: nil,
SELinuxOptions: nil,
RunAsUser: nil,
RunAsNonRoot: nil,
ReadOnlyRootFilesystem: nil,
AllowPrivilegeEscalation: ptr.Bool(false),
RunAsGroup: nil,
ProcMount: nil,
WindowsOptions: nil,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
LocalhostProfile: nil,
},
},
}},
},
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
Expand Down Expand Up @@ -111,6 +129,24 @@ func TestConfigurationDefaulting(t *testing.T) {
Image: "busybox",
Resources: defaultResources,
ReadinessProbe: defaultProbe,
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Privileged: nil,
SELinuxOptions: nil,
RunAsUser: nil,
RunAsNonRoot: nil,
ReadOnlyRootFilesystem: nil,
AllowPrivilegeEscalation: ptr.Bool(false),
RunAsGroup: nil,
ProcMount: nil,
WindowsOptions: nil,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
LocalhostProfile: nil,
},
},
}},
},
TimeoutSeconds: ptr.Int64(config.DefaultRevisionTimeoutSeconds),
Expand Down Expand Up @@ -148,6 +184,24 @@ func TestConfigurationDefaulting(t *testing.T) {
Image: "busybox",
Resources: defaultResources,
ReadinessProbe: defaultProbe,
SecurityContext: &corev1.SecurityContext{
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
Privileged: nil,
SELinuxOptions: nil,
RunAsUser: nil,
RunAsNonRoot: nil,
ReadOnlyRootFilesystem: nil,
AllowPrivilegeEscalation: ptr.Bool(false),
RunAsGroup: nil,
ProcMount: nil,
WindowsOptions: nil,
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
LocalhostProfile: nil,
},
},
}},
},
TimeoutSeconds: ptr.Int64(60),
Expand Down
Loading

0 comments on commit 18474ca

Please sign in to comment.