|
| 1 | +From 72613d23483353ed27d8c40d0ae6ebf0ff986694 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Clay Kauzlaric < [email protected]> |
| 3 | +Date: Wed, 13 Sep 2023 12:57:30 -0400 |
| 4 | +Subject: [PATCH 2/3] run as non root by default |
| 5 | + |
| 6 | +--- |
| 7 | + pkg/apis/serving/v1/revision_defaults.go | 4 ++++ |
| 8 | + 1 file changed, 4 insertions(+) |
| 9 | + |
| 10 | +diff --git a/pkg/apis/serving/v1/revision_defaults.go b/pkg/apis/serving/v1/revision_defaults.go |
| 11 | +index 8acbf3446fd1..4805f5b1fe35 100644 |
| 12 | +--- a/pkg/apis/serving/v1/revision_defaults.go |
| 13 | ++++ b/pkg/apis/serving/v1/revision_defaults.go |
| 14 | +@@ -208,6 +208,10 @@ func (rs *RevisionSpec) defaultSecurityContext(psc *corev1.PodSecurityContext, c |
| 15 | + } |
| 16 | + } |
| 17 | + |
| 18 | ++ if psc.RunAsNonRoot == nil { |
| 19 | ++ updatedSC.RunAsNonRoot = ptr.Bool(true) |
| 20 | ++ } |
| 21 | ++ |
| 22 | + if *updatedSC != (corev1.SecurityContext{}) { |
| 23 | + container.SecurityContext = updatedSC |
| 24 | + } |
| 25 | + |
| 26 | +From 2cf6abf1cc3c884e13d4fab9dc03bbe8b7d3850e Mon Sep 17 00:00:00 2001 |
| 27 | +From: Clay Kauzlaric < [email protected]> |
| 28 | +Date: Wed, 13 Sep 2023 16:26:53 -0400 |
| 29 | +Subject: [PATCH 3/3] update tests to expect new default run as nonroot |
| 30 | + |
| 31 | +--- |
| 32 | + pkg/apis/serving/v1/revision_defaults_test.go | 6 ++++++ |
| 33 | + 1 file changed, 6 insertions(+) |
| 34 | + |
| 35 | +diff --git a/pkg/apis/serving/v1/revision_defaults_test.go b/pkg/apis/serving/v1/revision_defaults_test.go |
| 36 | +index 332fecfb4d9d..0fe5e65079b7 100644 |
| 37 | +--- a/pkg/apis/serving/v1/revision_defaults_test.go |
| 38 | ++++ b/pkg/apis/serving/v1/revision_defaults_test.go |
| 39 | +@@ -900,6 +900,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 40 | + ReadinessProbe: defaultProbe, |
| 41 | + Resources: defaultResources, |
| 42 | + SecurityContext: &corev1.SecurityContext{ |
| 43 | ++ RunAsNonRoot: ptr.Bool(true), |
| 44 | + AllowPrivilegeEscalation: ptr.Bool(false), |
| 45 | + SeccompProfile: &corev1.SeccompProfile{ |
| 46 | + Type: corev1.SeccompProfileTypeRuntimeDefault, |
| 47 | +@@ -913,6 +914,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 48 | + Name: "sidecar", |
| 49 | + Resources: defaultResources, |
| 50 | + SecurityContext: &corev1.SecurityContext{ |
| 51 | ++ RunAsNonRoot: ptr.Bool(true), |
| 52 | + AllowPrivilegeEscalation: ptr.Bool(false), |
| 53 | + SeccompProfile: &corev1.SeccompProfile{ |
| 54 | + Type: corev1.SeccompProfileTypeRuntimeDefault, |
| 55 | +@@ -925,6 +927,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 56 | + Name: "special-sidecar", |
| 57 | + Resources: defaultResources, |
| 58 | + SecurityContext: &corev1.SecurityContext{ |
| 59 | ++ RunAsNonRoot: ptr.Bool(true), |
| 60 | + AllowPrivilegeEscalation: ptr.Bool(true), |
| 61 | + SeccompProfile: &corev1.SeccompProfile{ |
| 62 | + Type: corev1.SeccompProfileTypeRuntimeDefault, |
| 63 | +@@ -938,6 +941,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 64 | + InitContainers: []corev1.Container{{ |
| 65 | + Name: "special-init", |
| 66 | + SecurityContext: &corev1.SecurityContext{ |
| 67 | ++ RunAsNonRoot: ptr.Bool(true), |
| 68 | + AllowPrivilegeEscalation: ptr.Bool(true), |
| 69 | + SeccompProfile: &corev1.SeccompProfile{ |
| 70 | + Type: corev1.SeccompProfileTypeLocalhost, |
| 71 | +@@ -1000,6 +1004,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 72 | + ReadinessProbe: defaultProbe, |
| 73 | + Resources: defaultResources, |
| 74 | + SecurityContext: &corev1.SecurityContext{ |
| 75 | ++ RunAsNonRoot: ptr.Bool(true), |
| 76 | + AllowPrivilegeEscalation: ptr.Bool(false), |
| 77 | + Capabilities: &corev1.Capabilities{ |
| 78 | + Drop: []corev1.Capability{"ALL"}, |
| 79 | +@@ -1009,6 +1014,7 @@ func TestRevisionDefaulting(t *testing.T) { |
| 80 | + InitContainers: []corev1.Container{{ |
| 81 | + Name: "init", |
| 82 | + SecurityContext: &corev1.SecurityContext{ |
| 83 | ++ RunAsNonRoot: ptr.Bool(true), |
| 84 | + AllowPrivilegeEscalation: ptr.Bool(false), |
| 85 | + Capabilities: &corev1.Capabilities{ |
| 86 | + Drop: []corev1.Capability{"ALL"}, |
0 commit comments