Skip to content

Commit 8c5e292

Browse files
authored
fix CVE namespace-isolation break (#868)
argocd adds cluster monitoring label if the ns contains openshift- prefix Signed-off-by: Anand Kumar Singh <[email protected]>
1 parent 74a836a commit 8c5e292

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

controllers/argocd_metrics_controller.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -109,14 +109,23 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
109109
}
110110

111111
const clusterMonitoringLabel = "openshift.io/cluster-monitoring"
112-
labelVal, exists := namespace.Labels[clusterMonitoringLabel]
112+
const userDefinedMonitoringLabel = "openshift.io/user-monitoring"
113+
var labelVal, monitoringLabel string
114+
var exists bool
115+
if strings.HasPrefix(namespace.Name, "openshift-") {
116+
labelVal, exists = namespace.Labels[clusterMonitoringLabel]
117+
monitoringLabel = clusterMonitoringLabel
118+
} else {
119+
labelVal, exists = namespace.Labels[userDefinedMonitoringLabel]
120+
monitoringLabel = userDefinedMonitoringLabel
121+
}
113122

114123
if argocd.Spec.Monitoring.DisableMetrics == nil || !*argocd.Spec.Monitoring.DisableMetrics {
115124
if !exists || labelVal != "true" {
116125
if namespace.Labels == nil {
117126
namespace.Labels = make(map[string]string)
118127
}
119-
namespace.Labels[clusterMonitoringLabel] = "true"
128+
namespace.Labels[monitoringLabel] = "true"
120129
err = r.Client.Update(ctx, &namespace)
121130
if err != nil {
122131
reqLogger.Error(err, "Error updating namespace",
@@ -178,7 +187,7 @@ func (r *ArgoCDMetricsReconciler) Reconcile(ctx context.Context, request reconci
178187
}
179188
} else {
180189
if exists {
181-
namespace.Labels[clusterMonitoringLabel] = "false"
190+
namespace.Labels[monitoringLabel] = "false"
182191
err = r.Client.Update(ctx, &namespace)
183192
if err != nil {
184193
reqLogger.Error(err, "Error updating namespace",

controllers/argocd_metrics_controller_test.go

+10-7
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,19 @@ func newMetricsReconciler(t *testing.T, namespace, name string, disableMetrics *
8181

8282
func TestReconcile_add_namespace_label(t *testing.T) {
8383
testCases := []struct {
84-
instanceName string
85-
namespace string
84+
instanceName string
85+
namespace string
86+
expectedLabel string
8687
}{
8788
{
88-
instanceName: argoCDInstanceName,
89-
namespace: "openshift-gitops",
89+
instanceName: argoCDInstanceName,
90+
namespace: "openshift-gitops",
91+
expectedLabel: "openshift.io/cluster-monitoring",
9092
},
9193
{
92-
instanceName: "instance-two",
93-
namespace: "namespace-two",
94+
instanceName: "instance-two",
95+
namespace: "namespace-two",
96+
expectedLabel: "openshift.io/user-monitoring",
9497
},
9598
}
9699
for _, tc := range testCases {
@@ -101,7 +104,7 @@ func TestReconcile_add_namespace_label(t *testing.T) {
101104
ns := corev1.Namespace{}
102105
err = r.Client.Get(context.TODO(), types.NamespacedName{Name: tc.namespace}, &ns)
103106
assert.NilError(t, err)
104-
value := ns.Labels["openshift.io/cluster-monitoring"]
107+
value := ns.Labels[tc.expectedLabel]
105108
assert.Equal(t, value, "true")
106109
}
107110
}

0 commit comments

Comments
 (0)