Skip to content

Commit b9ff32c

Browse files
committed
Update CatalogSource Pod security context
Signed-off-by: perdasilva <[email protected]>
1 parent 9ced412 commit b9ff32c

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

pkg/controller/registry/reconciler/reconciler.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,10 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
113113
pullPolicy = corev1.PullAlways
114114
}
115115

116+
// Security context
116117
readOnlyRootFilesystem := false
118+
allowPrivilegeEscalation := false
119+
runAsNonRoot := true
117120

118121
pod := &corev1.Pod{
119122
ObjectMeta: metav1.ObjectMeta{
@@ -158,12 +161,22 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name string, image string, saN
158161
},
159162
},
160163
SecurityContext: &corev1.SecurityContext{
161-
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
164+
ReadOnlyRootFilesystem: &readOnlyRootFilesystem,
165+
AllowPrivilegeEscalation: &allowPrivilegeEscalation,
166+
Capabilities: &corev1.Capabilities{
167+
Drop: []corev1.Capability{"ALL"},
168+
},
162169
},
163170
ImagePullPolicy: pullPolicy,
164171
TerminationMessagePolicy: corev1.TerminationMessageFallbackToLogsOnError,
165172
},
166173
},
174+
SecurityContext: &corev1.PodSecurityContext{
175+
RunAsNonRoot: &runAsNonRoot,
176+
SeccompProfile: &corev1.SeccompProfile{
177+
Type: corev1.SeccompProfileTypeRuntimeDefault,
178+
},
179+
},
167180
NodeSelector: map[string]string{
168181
"kubernetes.io/os": "linux",
169182
},

pkg/controller/registry/reconciler/reconciler_test.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,20 @@ func TestPullPolicy(t *testing.T) {
7979

8080
func TestPodContainerSecurityContext(t *testing.T) {
8181
expectedReadOnlyRootFilesystem := false
82+
expectedAllowPrivilegeEscalation := false
83+
expectedRunAsNonRoot := true
8284
expectedContainerSecCtx := &corev1.SecurityContext{
83-
ReadOnlyRootFilesystem: &expectedReadOnlyRootFilesystem,
85+
ReadOnlyRootFilesystem: &expectedReadOnlyRootFilesystem,
86+
AllowPrivilegeEscalation: &expectedAllowPrivilegeEscalation,
87+
Capabilities: &corev1.Capabilities{
88+
Drop: []corev1.Capability{"ALL"},
89+
},
90+
}
91+
expectedPodSecCtx := &corev1.PodSecurityContext{
92+
RunAsNonRoot: &expectedRunAsNonRoot,
93+
SeccompProfile: &corev1.SeccompProfile{
94+
Type: corev1.SeccompProfileTypeRuntimeDefault,
95+
},
8496
}
8597

8698
catsrc := &v1alpha1.CatalogSource{
@@ -92,7 +104,9 @@ func TestPodContainerSecurityContext(t *testing.T) {
92104

93105
gotPod := Pod(catsrc, "hello", "busybox", "", map[string]string{}, map[string]string{}, int32(0), int32(0))
94106
gotContainerSecCtx := gotPod.Spec.Containers[0].SecurityContext
95-
require.Equal(t, expectedContainerSecCtx, gotContainerSecCtx)
107+
gotPodSecCtx := gotPod.Spec.SecurityContext
108+
require.Equal(t, *expectedContainerSecCtx, *gotContainerSecCtx)
109+
require.Equal(t, *expectedPodSecCtx, *gotPodSecCtx)
96110
}
97111

98112
func TestPodSchedulingOverrides(t *testing.T) {

0 commit comments

Comments
 (0)