@@ -217,7 +217,7 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
217
217
}
218
218
219
219
// Create namespace if it doesn't already exist
220
- namespaceRef := newNamespace (namespace )
220
+ namespaceRef := newRestrictedNamespace (namespace )
221
221
err = r .Client .Get (ctx , types.NamespacedName {Name : namespace }, & corev1.Namespace {})
222
222
if err != nil {
223
223
if errors .IsNotFound (err ) {
@@ -300,7 +300,7 @@ func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance
300
300
return err
301
301
}
302
302
303
- argocdNS := newNamespace (defaultArgoCDInstance .Namespace )
303
+ argocdNS := newRestrictedNamespace (defaultArgoCDInstance .Namespace )
304
304
err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, & corev1.Namespace {})
305
305
if err != nil {
306
306
@@ -339,7 +339,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
339
339
// The operator decides the namespace based on the version of the cluster it is installed in
340
340
// 4.6 Cluster: Backend in openshift-pipelines-app-delivery namespace and argocd in openshift-gitops namespace
341
341
// 4.7 Cluster: Both backend and argocd instance in openshift-gitops namespace
342
- argocdNS := newNamespace (defaultArgoCDInstance .Namespace )
342
+ argocdNS := newRestrictedNamespace (defaultArgoCDInstance .Namespace )
343
343
err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, & corev1.Namespace {})
344
344
if err != nil {
345
345
if errors .IsNotFound (err ) {
@@ -762,6 +762,10 @@ func newBackendDeployment(ns types.NamespacedName) *appsv1.Deployment {
762
762
ObjectMeta : metav1.ObjectMeta {
763
763
Labels : map [string ]string {
764
764
"app.kubernetes.io/name" : ns .Name ,
765
+
766
+ // restricted-v2 pinning is recommended for openshift workloads
767
+ // This SCC mutates the Pod Spec to pass PSA's restricted policy.
768
+ "openshift.io/required-scc" : "restricted-v2" ,
765
769
},
766
770
},
767
771
Spec : podSpec ,
@@ -811,14 +815,26 @@ func newBackendService(ns types.NamespacedName) *corev1.Service {
811
815
return svc
812
816
}
813
817
814
- func newNamespace (ns string ) * corev1.Namespace {
818
+ func newRestrictedNamespace (ns string ) * corev1.Namespace {
815
819
objectMeta := metav1.ObjectMeta {
816
820
Name : ns ,
817
821
Labels : map [string ]string {
818
822
// Enable full-fledged support for integration with cluster monitoring.
819
823
"openshift.io/cluster-monitoring" : "true" ,
820
824
},
821
825
}
826
+
827
+ if strings .HasPrefix (ns , "openshift-" ) {
828
+ // Set pod security policy, which is required for namespaces pre-fixed with openshift
829
+ // as the pod security label syncer doesn't set them on OCP namespaces.
830
+ objectMeta .Labels ["pod-security.kubernetes.io/enforce" ] = "restricted"
831
+ objectMeta .Labels ["pod-security.kubernetes.io/enforce-version" ] = "v1.29"
832
+ objectMeta .Labels ["pod-security.kubernetes.io/audit" ] = "restricted"
833
+ objectMeta .Labels ["pod-security.kubernetes.io/audit-version" ] = "latest"
834
+ objectMeta .Labels ["pod-security.kubernetes.io/warn" ] = "restricted"
835
+ objectMeta .Labels ["pod-security.kubernetes.io/warn-version" ] = "latest"
836
+ }
837
+
822
838
return & corev1.Namespace {
823
839
ObjectMeta : objectMeta ,
824
840
}
0 commit comments