Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions controllers/gitopsservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (r *ReconcileGitopsService) Reconcile(ctx context.Context, request reconcil
}

// Create namespace if it doesn't already exist
namespaceRef := newNamespace(namespace)
namespaceRef := newRestrictedNamespace(namespace)
err = r.Client.Get(ctx, types.NamespacedName{Name: namespace}, &corev1.Namespace{})
if err != nil {
if errors.IsNotFound(err) {
Expand Down Expand Up @@ -300,7 +300,7 @@ func (r *ReconcileGitopsService) ensureDefaultArgoCDInstanceDoesntExist(instance
return err
}

argocdNS := newNamespace(defaultArgoCDInstance.Namespace)
argocdNS := newRestrictedNamespace(defaultArgoCDInstance.Namespace)
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: argocdNS.Name}, &corev1.Namespace{})
if err != nil {

Expand Down Expand Up @@ -339,7 +339,7 @@ func (r *ReconcileGitopsService) reconcileDefaultArgoCDInstance(instance *pipeli
// The operator decides the namespace based on the version of the cluster it is installed in
// 4.6 Cluster: Backend in openshift-pipelines-app-delivery namespace and argocd in openshift-gitops namespace
// 4.7 Cluster: Both backend and argocd instance in openshift-gitops namespace
argocdNS := newNamespace(defaultArgoCDInstance.Namespace)
argocdNS := newRestrictedNamespace(defaultArgoCDInstance.Namespace)
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: argocdNS.Name}, &corev1.Namespace{})
if err != nil {
if errors.IsNotFound(err) {
Expand Down Expand Up @@ -762,6 +762,10 @@ func newBackendDeployment(ns types.NamespacedName) *appsv1.Deployment {
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{
"app.kubernetes.io/name": ns.Name,

// restricted-v2 pinning is recommended for openshift workloads
// This SCC mutates the Pod Spec to pass PSA's restricted policy.
"openshift.io/required-scc": "restricted-v2",
},
},
Spec: podSpec,
Expand Down Expand Up @@ -811,14 +815,26 @@ func newBackendService(ns types.NamespacedName) *corev1.Service {
return svc
}

func newNamespace(ns string) *corev1.Namespace {
func newRestrictedNamespace(ns string) *corev1.Namespace {
objectMeta := metav1.ObjectMeta{
Name: ns,
Labels: map[string]string{
// Enable full-fledged support for integration with cluster monitoring.
"openshift.io/cluster-monitoring": "true",
},
}

if strings.HasPrefix(ns, "openshift-") {
// Set pod security policy, which is required for namespaces pre-fixed with openshift
// as the pod security label syncer doesn't set them on OCP namespaces.
objectMeta.Labels["pod-security.kubernetes.io/enforce"] = "restricted"
objectMeta.Labels["pod-security.kubernetes.io/enforce-version"] = "v1.29"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ibihim, just trying to understand this change. Was there any special reason to set it to v1.29 and not latest?

objectMeta.Labels["pod-security.kubernetes.io/audit"] = "restricted"
objectMeta.Labels["pod-security.kubernetes.io/audit-version"] = "latest"
objectMeta.Labels["pod-security.kubernetes.io/warn"] = "restricted"
objectMeta.Labels["pod-security.kubernetes.io/warn-version"] = "latest"
}

return &corev1.Namespace{
ObjectMeta: objectMeta,
}
Expand Down