@@ -356,12 +356,22 @@ func Pod(source *operatorsv1alpha1.CatalogSource, name, opmImg, utilImage, img s
356
356
}
357
357
358
358
func addSecurityContext (pod * corev1.Pod , runAsUser int64 ) {
359
+ pod .Spec .SecurityContext = & corev1.PodSecurityContext {
360
+ SeccompProfile : & corev1.SeccompProfile {
361
+ Type : corev1 .SeccompProfileTypeRuntimeDefault ,
362
+ },
363
+ }
364
+ if runAsUser > 0 {
365
+ pod .Spec .SecurityContext .RunAsUser = & runAsUser
366
+ pod .Spec .SecurityContext .RunAsNonRoot = ptr .To (true )
367
+ }
368
+
359
369
for i := range pod .Spec .InitContainers {
360
370
if pod .Spec .InitContainers [i ].SecurityContext == nil {
361
371
pod .Spec .InitContainers [i ].SecurityContext = & corev1.SecurityContext {}
362
372
}
363
373
pod .Spec .InitContainers [i ].SecurityContext .AllowPrivilegeEscalation = ptr .To (false )
364
- pod .Spec .InitContainers [i ].SecurityContext .ReadOnlyRootFilesystem = ptr . To ( true )
374
+ pod .Spec .InitContainers [i ].SecurityContext .ReadOnlyRootFilesystem = pod . Spec . SecurityContext . RunAsNonRoot
365
375
pod .Spec .InitContainers [i ].SecurityContext .Capabilities = & corev1.Capabilities {
366
376
Drop : []corev1.Capability {"ALL" },
367
377
}
@@ -371,21 +381,11 @@ func addSecurityContext(pod *corev1.Pod, runAsUser int64) {
371
381
pod .Spec .Containers [i ].SecurityContext = & corev1.SecurityContext {}
372
382
}
373
383
pod .Spec .Containers [i ].SecurityContext .AllowPrivilegeEscalation = ptr .To (false )
374
- pod .Spec .Containers [i ].SecurityContext .ReadOnlyRootFilesystem = ptr . To ( true )
384
+ pod .Spec .Containers [i ].SecurityContext .ReadOnlyRootFilesystem = pod . Spec . SecurityContext . RunAsNonRoot
375
385
pod .Spec .Containers [i ].SecurityContext .Capabilities = & corev1.Capabilities {
376
386
Drop : []corev1.Capability {"ALL" },
377
387
}
378
388
}
379
-
380
- pod .Spec .SecurityContext = & corev1.PodSecurityContext {
381
- SeccompProfile : & corev1.SeccompProfile {
382
- Type : corev1 .SeccompProfileTypeRuntimeDefault ,
383
- },
384
- }
385
- if runAsUser > 0 {
386
- pod .Spec .SecurityContext .RunAsUser = & runAsUser
387
- pod .Spec .SecurityContext .RunAsNonRoot = ptr .To (true )
388
- }
389
389
}
390
390
391
391
// getDefaultPodContextConfig returns Restricted if the defaultNamespace has the 'pod-security.kubernetes.io/enforce' label set to 'restricted',
0 commit comments