@@ -217,7 +217,7 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
217217 }
218218
219219 // Create namespace if it doesn't already exist
220- namespaceRef := newNamespace (namespace )
220+ namespaceRef := newRestrictedNamespace (namespace )
221221 err = r .Client .Get (ctx , types.NamespacedName {Name : namespace }, & corev1.Namespace {})
222222 if err != nil {
223223 if errors .IsNotFound (err ) {
@@ -300,7 +300,7 @@ func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance
300300 return err
301301 }
302302
303- argocdNS := newNamespace (defaultArgoCDInstance .Namespace )
303+ argocdNS := newRestrictedNamespace (defaultArgoCDInstance .Namespace )
304304 err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, & corev1.Namespace {})
305305 if err != nil {
306306
@@ -339,7 +339,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
339339 // The operator decides the namespace based on the version of the cluster it is installed in
340340 // 4.6 Cluster: Backend in openshift-pipelines-app-delivery namespace and argocd in openshift-gitops namespace
341341 // 4.7 Cluster: Both backend and argocd instance in openshift-gitops namespace
342- argocdNS := newNamespace (defaultArgoCDInstance .Namespace )
342+ argocdNS := newRestrictedNamespace (defaultArgoCDInstance .Namespace )
343343 err = r .Client .Get (context .TODO (), types.NamespacedName {Name : argocdNS .Name }, & corev1.Namespace {})
344344 if err != nil {
345345 if errors .IsNotFound (err ) {
@@ -762,6 +762,10 @@ func newBackendDeployment(ns types.NamespacedName) *appsv1.Deployment {
762762 ObjectMeta : metav1.ObjectMeta {
763763 Labels : map [string ]string {
764764 "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" ,
765769 },
766770 },
767771 Spec : podSpec ,
@@ -811,14 +815,26 @@ func newBackendService(ns types.NamespacedName) *corev1.Service {
811815 return svc
812816}
813817
814- func newNamespace (ns string ) * corev1.Namespace {
818+ func newRestrictedNamespace (ns string ) * corev1.Namespace {
815819 objectMeta := metav1.ObjectMeta {
816820 Name : ns ,
817821 Labels : map [string ]string {
818822 // Enable full-fledged support for integration with cluster monitoring.
819823 "openshift.io/cluster-monitoring" : "true" ,
820824 },
821825 }
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+
822838 return & corev1.Namespace {
823839 ObjectMeta : objectMeta ,
824840 }
0 commit comments