From 8193c81572673de21fc73e031d95c073e6268817 Mon Sep 17 00:00:00 2001 From: Diego Braga Date: Mon, 16 Nov 2026 16:55:42 +0100 Subject: [PATCH 1/2] feat: let the dashboard watcher skip the release namespace Add hyperdx.dashboards.includeReleaseNamespace (default true, unchanged output). With false, the watcher's NAMESPACE and the RBAC cover only hyperdx.dashboards.namespaces: a namespaced Role and RoleBinding in each listed namespace (namespace-qualified names), no ClusterRole, and nothing in the release namespace. Without it, the release namespace is always watched and readable, and granting narrower RBAC out-of-band makes the watcher 403 on the release namespace and crash-loop. The render fails when includeReleaseNamespace is false with no namespaces, or with inline configMaps while the release namespace is not watched (they would never be discovered). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01TLFnUd6g7xhDXDvaho4rDW --- .../dashboards-include-release-namespace.md | 5 + charts/clickstack/README.md | 2 +- charts/clickstack/templates/_helpers.tpl | 40 +- .../hyperdx/dashboard-provisioner-rbac.yaml | 26 +- .../tests/dashboard-provisioner_test.yaml | 344 ++++++++++++++++++ charts/clickstack/values.yaml | 12 +- 6 files changed, 408 insertions(+), 21 deletions(-) create mode 100644 .changeset/dashboards-include-release-namespace.md diff --git a/.changeset/dashboards-include-release-namespace.md b/.changeset/dashboards-include-release-namespace.md new file mode 100644 index 0000000..53b3bdc --- /dev/null +++ b/.changeset/dashboards-include-release-namespace.md @@ -0,0 +1,5 @@ +--- +"helm-charts": minor +--- + +feat: add `hyperdx.dashboards.includeReleaseNamespace` (default `true`, unchanged behaviour). Set it to `false` with `hyperdx.dashboards.namespaces: []` to confine the dashboard watcher, and its ConfigMap read access, to the listed namespaces: the chart then renders a namespaced Role and RoleBinding in each listed namespace, no ClusterRole, and nothing in the release namespace. The render fails if it is `false` with no namespaces listed, or with inline `configMaps` while the release namespace is not watched. diff --git a/charts/clickstack/README.md b/charts/clickstack/README.md index 8e5f2ce..8f0c30a 100644 --- a/charts/clickstack/README.md +++ b/charts/clickstack/README.md @@ -50,7 +50,7 @@ Documented values below. Undocumented keys (operator CRD passthrough fields, sub | global.imageRegistry | string | `""` | Optional prefix for container images (e.g. registry.example.com/). | | hyperdx.autoscaling | object | `{"enabled":false,"spec":{}}` | HorizontalPodAutoscaler for HyperDX. spec is passed through verbatim (autoscaling/v2). Do not include scaleTargetRef — the chart auto-wires it. When enabled, omit deployment.replicas; disabling autoscaling reverts to deployment.replicas (default 1). | | hyperdx.config | object | `{"API_PORT":"8000","APP_PORT":"3000","CLICKHOUSE_ENDPOINT":"tcp://{{ include \"clickstack.clickhouse.svc\" . }}:{{ .Values.clickhouse.nativePort }}?dial_timeout=10s","CLICKHOUSE_PROMETHEUS_METRICS_ENDPOINT":"{{ include \"clickstack.clickhouse.svc\" . }}:{{ .Values.clickhouse.prometheus.port }}","CLICKHOUSE_SERVER_ENDPOINT":"{{ include \"clickstack.clickhouse.svc\" . }}:{{ .Values.clickhouse.nativePort }}","CLICKHOUSE_USER":"otelcollector","FRONTEND_URL":"http://localhost:3000","HDX_EXPORTER_ENABLED":"{{ if .Values.hyperdx.config.NEXT_PUBLIC_OTEL_EXPORTER_OTLP_ENDPOINT }}true{{ else }}false{{ end }}","HYPERDX_API_PORT":"8000","HYPERDX_APP_PORT":"3000","HYPERDX_LOG_LEVEL":"info","HYPERDX_OTEL_EXPORTER_CLICKHOUSE_DATABASE":"default","HYPERDX_OTEL_EXPORTER_TABLES_TTL":"720h","MONGO_URI":"mongodb://hyperdx:{{ .Values.hyperdx.secrets.MONGODB_PASSWORD }}@{{ include \"clickstack.mongodb.svc\" . }}:27017/hyperdx?authSource=hyperdx","OPAMP_PORT":"4320","OPAMP_SERVER_URL":"http://{{ include \"clickstack.hyperdx.fullname\" . }}:{{ .Values.hyperdx.ports.opamp }}","OTEL_EXPORTER_OTLP_ENDPOINT":"http://{{ include \"clickstack.otel.fullname\" . }}:4318","OTEL_SERVICE_NAME":"hdx-oss-api","RUN_SCHEDULED_TASKS_EXTERNALLY":"false","USAGE_STATS_ENABLED":"true"}` | Shared non-sensitive environment variables (clickstack-config ConfigMap). Used by HyperDX and OTEL collector via envFrom. Values support tpl expressions. Override entries with plain strings to point at external services. Changes to the rendered ConfigMap roll the HyperDX Deployment; the otel-collector rolls on every helm upgrade. | -| hyperdx.dashboards | object | `{"configMaps":{},"enabled":false,"namespaces":[],"rbac":{"create":true},"resources":{"limits":{"cpu":"50m","memory":"64Mi"},"requests":{"cpu":"10m","memory":"32Mi"}},"sidecarImage":"kiwigrid/k8s-sidecar:2.10.1","sidecarPullPolicy":"IfNotPresent"}` | Dashboard provisioning: upserts dashboard JSON into MongoDB (matched by name, never deletes). Provide dashboards inline via configMaps, or label ConfigMaps hyperdx.io/dashboard: "true" for a k8s-sidecar watcher to discover. | +| hyperdx.dashboards | object | `{"configMaps":{},"enabled":false,"includeReleaseNamespace":true,"namespaces":[],"rbac":{"create":true},"resources":{"limits":{"cpu":"50m","memory":"64Mi"},"requests":{"cpu":"10m","memory":"32Mi"}},"sidecarImage":"kiwigrid/k8s-sidecar:2.10.1","sidecarPullPolicy":"IfNotPresent"}` | Dashboard provisioning: upserts dashboard JSON into MongoDB (matched by name, never deletes). Provide dashboards inline via configMaps, or label ConfigMaps hyperdx.io/dashboard: "true" for a k8s-sidecar watcher to discover. | | hyperdx.deployment | object | `{"annotations":{},"containerSecurityContext":{},"defaultConnections":"[\n {\n \"name\": \"Local ClickHouse\",\n \"host\": \"http://{{ include \"clickstack.clickhouse.svc\" . }}:8123\",\n \"port\": 8123,\n \"username\": \"app\",\n \"password\": \"{{ .Values.hyperdx.secrets.CLICKHOUSE_APP_PASSWORD }}\"\n }\n]\n","defaultSources":"[\n {\n \"from\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_logs\"\n },\n \"kind\": \"log\",\n \"timestampValueExpression\": \"Timestamp\",\n \"name\": \"Logs\",\n \"displayedTimestampValueExpression\": \"Timestamp\",\n \"implicitColumnExpression\": \"Body\",\n \"serviceNameExpression\": \"ServiceName\",\n \"bodyExpression\": \"Body\",\n \"eventAttributesExpression\": \"LogAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"defaultTableSelectExpression\": \"Timestamp,ServiceName,SeverityText,Body\",\n \"severityTextExpression\": \"SeverityText\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"connection\": \"Local ClickHouse\",\n \"traceSourceId\": \"Traces\",\n \"metricSourceId\": \"Metrics\"\n },\n {\n \"from\": {\n \"databaseName\": \"default\",\n \"tableName\": \"otel_traces\"\n },\n \"kind\": \"trace\",\n \"timestampValueExpression\": \"Timestamp\",\n \"name\": \"Traces\",\n \"displayedTimestampValueExpression\": \"Timestamp\",\n \"implicitColumnExpression\": \"SpanName\",\n \"serviceNameExpression\": \"ServiceName\",\n \"eventAttributesExpression\": \"SpanAttributes\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"defaultTableSelectExpression\": \"Timestamp,ServiceName,StatusCode,round(Duration/1e6),SpanName\",\n \"traceIdExpression\": \"TraceId\",\n \"spanIdExpression\": \"SpanId\",\n \"durationExpression\": \"Duration\",\n \"durationPrecision\": 9,\n \"parentSpanIdExpression\": \"ParentSpanId\",\n \"spanNameExpression\": \"SpanName\",\n \"spanKindExpression\": \"SpanKind\",\n \"statusCodeExpression\": \"StatusCode\",\n \"statusMessageExpression\": \"StatusMessage\",\n \"spanEventsValueExpression\": \"Events\",\n \"spanLinksValueExpression\": \"Links\",\n \"connection\": \"Local ClickHouse\",\n \"logSourceId\": \"Logs\",\n \"sessionSourceId\": \"Sessions\",\n \"metricSourceId\": \"Metrics\"\n },\n {\n \"from\": {\n \"databaseName\": \"default\",\n \"tableName\": \"\"\n },\n \"kind\": \"metric\",\n \"timestampValueExpression\": \"TimeUnix\",\n \"name\": \"Metrics\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"metricTables\": {\n \"gauge\": \"otel_metrics_gauge\",\n \"histogram\": \"otel_metrics_histogram\",\n \"sum\": \"otel_metrics_sum\",\n \"summary\": \"otel_metrics_summary\",\n \"exponential histogram\": \"otel_metrics_exponential_histogram\"\n },\n \"connection\": \"Local ClickHouse\",\n \"logSourceId\": \"Logs\"\n },\n {\n \"from\": {\n \"databaseName\": \"default\",\n \"tableName\": \"hyperdx_sessions\"\n },\n \"kind\": \"session\",\n \"timestampValueExpression\": \"TimestampTime\",\n \"name\": \"Sessions\",\n \"resourceAttributesExpression\": \"ResourceAttributes\",\n \"connection\": \"Local ClickHouse\",\n \"traceSourceId\": \"Traces\"\n }\n]\n","deploymentAnnotations":{},"env":[],"existingConfigConnectionsKey":"connections.json","existingConfigSecret":"","existingConfigSourcesKey":"sources.json","image":{"pullPolicy":"IfNotPresent","repository":"docker.hyperdx.io/hyperdx/hyperdx","tag":null},"initContainers":[],"labels":{},"livenessProbe":{"enabled":true,"failureThreshold":3,"initialDelaySeconds":10,"path":"/health","periodSeconds":30,"timeoutSeconds":5},"nodeSelector":{},"podAnnotations":{},"podLabels":{},"podSecurityContext":{},"priorityClassName":"","readinessProbe":{"enabled":true,"failureThreshold":3,"initialDelaySeconds":1,"path":"/ready","periodSeconds":10,"timeoutSeconds":5},"replicas":1,"resources":{},"tolerations":[],"topologySpreadConstraints":[],"useExistingConfigSecret":false,"volumeMounts":[],"volumes":[],"waitForMongodb":{"image":"busybox@sha256:1fcf5df59121b92d61e066df1788e8df0cc35623f5d62d9679a41e163b6a0cdb","pullPolicy":"IfNotPresent"}}` | HyperDX Deployment spec (image, probes, scheduling, init containers, volumes). defaultConnections/defaultSources JSON: set to "" to disable; use useExistingConfigSecret for external secrets. | | hyperdx.deployment.env | list | `[]` | Extra environment variables for the HyperDX container, rendered verbatim (supports `valueFrom`, e.g. `secretKeyRef`). | | hyperdx.deployment.existingConfigSecret | string | `""` | Secret containing connections and sources JSON when useExistingConfigSecret is true. | diff --git a/charts/clickstack/templates/_helpers.tpl b/charts/clickstack/templates/_helpers.tpl index 098e135..8ee9771 100644 --- a/charts/clickstack/templates/_helpers.tpl +++ b/charts/clickstack/templates/_helpers.tpl @@ -62,7 +62,8 @@ the namespaced Role and the cluster-scoped ClusterRole branches. {{/* Fail fast on invalid dashboards input instead of surfacing Go template panics or API-server rejections: unusable ServiceAccount config, a non-list or ill-typed -namespaces value, the contradictory ALL-plus-named-namespaces scope, malformed +namespaces value, the contradictory ALL-plus-named-namespaces scope, an empty scope +or unwatched inline dashboards when the release namespace is excluded, malformed configMaps entries, and volume/mount names that collide with the provisioner's. */}} {{- define "clickstack.hyperdx.validateDashboards" -}} @@ -80,6 +81,12 @@ configMaps entries, and volume/mount names that collide with the provisioner's. {{- fail "hyperdx.dashboards.namespaces: entries must be quoted strings" -}} {{- end -}} {{- end -}} +{{- if and (ne (include "clickstack.hyperdx.dashboardsIncludeReleaseNamespace" .) "true") (not $namespaces) -}} +{{- fail "hyperdx.dashboards.includeReleaseNamespace: false requires at least one entry in hyperdx.dashboards.namespaces (otherwise the watcher has nothing to watch)" -}} +{{- end -}} +{{- if and $dashboards.configMaps (ne (include "clickstack.hyperdx.dashboardsClusterWide" .) "true") (not (has .Release.Namespace (include "clickstack.hyperdx.effectiveNamespaces" . | splitList ","))) -}} +{{- fail "hyperdx.dashboards.configMaps: inline dashboards are created in the release namespace, which includeReleaseNamespace: false excludes from discovery; list the release namespace in hyperdx.dashboards.namespaces or ship the dashboards as labeled ConfigMaps in a watched namespace" -}} +{{- end -}} {{- if and (eq (include "clickstack.hyperdx.dashboardsClusterWide" .) "true") (gt (len $namespaces) 1) -}} {{- fail "hyperdx.dashboards.namespaces: \"ALL\" cannot be combined with specific namespaces (it already grants cluster-wide discovery)" -}} {{- end -}} @@ -117,15 +124,16 @@ configMaps entries, and volume/mount names that collide with the provisioner's. {{/* Namespaces the watcher discovers in for the non-ALL scope: the release namespace -plus any configured extras, deduped and comma-joined. Single source for both the -watcher NAMESPACE env and the per-namespace RoleBindings so watch scope and granted -scope can't drift. +(unless includeReleaseNamespace is false) plus any configured extras, deduped and +comma-joined. Single source for both the watcher NAMESPACE env and the per-namespace +RBAC objects so watch scope and granted scope can't drift. */}} {{- define "clickstack.hyperdx.effectiveNamespaces" -}} {{- $raw := default (list) (default (dict) .Values.hyperdx.dashboards).namespaces -}} {{- $namespaces := ternary $raw (list) (kindIs "slice" $raw) -}} +{{- $base := ternary (list .Release.Namespace) (list) (eq (include "clickstack.hyperdx.dashboardsIncludeReleaseNamespace" .) "true") -}} {{- $trimmed := list -}} -{{- range (concat (list .Release.Namespace) $namespaces) -}} +{{- range (concat $base $namespaces) -}} {{- $trimmed = append $trimmed (trim (toString .)) -}} {{- end -}} {{- $trimmed | uniq | join "," -}} @@ -142,12 +150,26 @@ Deployment, so the granted scope and the watched scope can't diverge. Renders "t {{- end -}} {{/* -Whether discovery spans more than one namespace (the effective, deduped set is larger -than just the release namespace). Selects the scoped ClusterRole + per-namespace -RoleBinding path over a plain namespaced Role. Renders "true" or "". +Whether discovery spans the release namespace plus at least one other namespace. +Selects the scoped ClusterRole + per-namespace RoleBinding path over namespaced +Roles. An effective set without the release namespace (includeReleaseNamespace: +false) gets a namespaced Role + RoleBinding in each target namespace instead, so +nothing is granted in the release namespace and no cluster-scoped object is +created. Renders "true" or "". */}} {{- define "clickstack.hyperdx.dashboardsCrossNamespace" -}} -{{- if gt (len (include "clickstack.hyperdx.effectiveNamespaces" . | splitList ",")) 1 }}true{{- end -}} +{{- $effective := include "clickstack.hyperdx.effectiveNamespaces" . | splitList "," -}} +{{- if and (gt (len $effective) 1) (has .Release.Namespace $effective) }}true{{- end -}} +{{- end -}} + +{{/* +Whether the release namespace is part of the watcher's discovery scope. A missing +key (e.g. an upgrade with --reuse-values from a chart version without it) keeps the +chart default of true. Renders "true" or "". +*/}} +{{- define "clickstack.hyperdx.dashboardsIncludeReleaseNamespace" -}} +{{- $dashboards := default (dict) .Values.hyperdx.dashboards -}} +{{- if or (not (hasKey $dashboards "includeReleaseNamespace")) $dashboards.includeReleaseNamespace }}true{{- end -}} {{- end -}} {{/* diff --git a/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml b/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml index ff3025a..5d6d3bf 100644 --- a/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml +++ b/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml @@ -56,31 +56,37 @@ subjects: namespace: {{ $.Release.Namespace }} {{- end }} {{- else }} -{{- /* Default: discovery scoped to the release namespace only — a namespaced Role, no cluster-scoped objects. */}} +{{- /* Default: discovery scoped to the release namespace only — a namespaced Role, no cluster-scoped objects. With includeReleaseNamespace: false, the same namespaced Role + RoleBinding pair is rendered in each target namespace instead, and nothing in the release namespace. Outside the release namespace the names are namespace-qualified like the cluster-scoped objects above, so two same-named releases can't collide in a shared target namespace. */}} +{{- range $i, $ns := (include "clickstack.hyperdx.effectiveNamespaces" . | splitList ",") }} +{{- $name := ternary (printf "%s-dashboard-provisioner" $fullname) $clusterName (eq $ns $.Release.Namespace) }} +{{- if $i }} +--- +{{- end }} apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: - name: {{ $fullname }}-dashboard-provisioner - namespace: {{ .Release.Namespace }} + name: {{ $name }} + namespace: {{ $ns }} labels: - {{- include "clickstack.labels" . | nindent 4 }} + {{- include "clickstack.labels" $ | nindent 4 }} rules: - {{- include "clickstack.hyperdx.dashboardRbacRules" . | nindent 2 }} + {{- include "clickstack.hyperdx.dashboardRbacRules" $ | nindent 2 }} --- apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: - name: {{ $fullname }}-dashboard-provisioner - namespace: {{ .Release.Namespace }} + name: {{ $name }} + namespace: {{ $ns }} labels: - {{- include "clickstack.labels" . | nindent 4 }} + {{- include "clickstack.labels" $ | nindent 4 }} roleRef: apiGroup: rbac.authorization.k8s.io kind: Role - name: {{ $fullname }}-dashboard-provisioner + name: {{ $name }} subjects: - kind: ServiceAccount name: {{ $saName }} - namespace: {{ .Release.Namespace }} + namespace: {{ $.Release.Namespace }} +{{- end }} {{- end }} {{- end }} diff --git a/charts/clickstack/tests/dashboard-provisioner_test.yaml b/charts/clickstack/tests/dashboard-provisioner_test.yaml index a3da0a3..64b2513 100644 --- a/charts/clickstack/tests/dashboard-provisioner_test.yaml +++ b/charts/clickstack/tests/dashboard-provisioner_test.yaml @@ -1077,3 +1077,347 @@ tests: - failedTemplate: errorMessage: 'hyperdx.deployment.volumeMounts: the name "dashboards" and mountPath "/dashboards" are reserved by the dashboard provisioner' template: hyperdx/deployment.yaml + + - it: should keep the release namespace in scope when includeReleaseNamespace is explicitly true + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: true + namespaces: + - team-a + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: observability,team-a + template: hyperdx/deployment.yaml + - hasDocuments: + count: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: ClusterRole + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: observability + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should default to including the release namespace when the includeReleaseNamespace key is missing + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: null + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: observability + template: hyperdx/deployment.yaml + - isKind: + of: Role + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: observability + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should watch and grant only the listed namespace when includeReleaseNamespace is false + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - dashboards + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: dashboards + template: hyperdx/deployment.yaml + # A namespaced Role + RoleBinding in the target namespace only: no ClusterRole, + # and nothing in the release namespace. + - hasDocuments: + count: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: Role + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: dashboards + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: rules + value: + - apiGroups: [""] + resources: ["configmaps"] + verbs: ["list", "get", "watch"] + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: RoleBinding + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: dashboards + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: roleRef + value: + apiGroup: rbac.authorization.k8s.io + kind: Role + name: RELEASE-NAME-clickstack-observability-dashboard-provisioner + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: subjects + value: + - kind: ServiceAccount + name: RELEASE-NAME-clickstack-app + namespace: observability + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + # Outside the release namespace the names are namespace-qualified, so two + # same-named releases sharing a target namespace can't collide. + - equal: + path: metadata.name + value: RELEASE-NAME-clickstack-observability-dashboard-provisioner + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should render a namespaced Role and RoleBinding per listed namespace when includeReleaseNamespace is false + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - team-a + - team-b + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: team-a,team-b + template: hyperdx/deployment.yaml + - hasDocuments: + count: 4 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: Role + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: team-a + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: RoleBinding + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: team-a + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: Role + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: team-b + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: RoleBinding + documentIndex: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: team-b + documentIndex: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: roleRef.kind + value: Role + documentIndex: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: subjects[0].namespace + value: observability + documentIndex: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should keep the ClusterRole path when includeReleaseNamespace is false but the release namespace is listed + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - observability + - team-a + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: observability,team-a + template: hyperdx/deployment.yaml + - hasDocuments: + count: 3 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: ClusterRole + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should still watch all namespaces with ALL when includeReleaseNamespace is false + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - ALL + asserts: + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: "ALL" + template: hyperdx/deployment.yaml + - isKind: + of: ClusterRole + documentIndex: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - isKind: + of: ClusterRoleBinding + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + + - it: should render no RBAC but scope the watcher when includeReleaseNamespace is false and rbac.create is false + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - dashboards + rbac: + create: false + asserts: + - hasDocuments: + count: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: dashboards + template: hyperdx/deployment.yaml + + - it: should fail when includeReleaseNamespace is false and no namespaces are listed + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + asserts: + - failedTemplate: + errorMessage: "hyperdx.dashboards.includeReleaseNamespace: false requires at least one entry in hyperdx.dashboards.namespaces (otherwise the watcher has nothing to watch)" + template: hyperdx/deployment.yaml + + - it: should fail when includeReleaseNamespace is false and namespaces is null + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: null + asserts: + - failedTemplate: + errorMessage: "hyperdx.dashboards.includeReleaseNamespace: false requires at least one entry in hyperdx.dashboards.namespaces (otherwise the watcher has nothing to watch)" + template: hyperdx/deployment.yaml + + - it: should fail when inline configMaps are set but the release namespace is excluded from discovery + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - dashboards + configMaps: + test.json: | + { "name": "Test", "tiles": [] } + asserts: + - failedTemplate: + errorMessage: "hyperdx.dashboards.configMaps: inline dashboards are created in the release namespace, which includeReleaseNamespace: false excludes from discovery; list the release namespace in hyperdx.dashboards.namespaces or ship the dashboards as labeled ConfigMaps in a watched namespace" + template: hyperdx/deployment.yaml + + - it: should allow inline configMaps when includeReleaseNamespace is false but the release namespace is listed + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: false + namespaces: + - observability + configMaps: + test.json: | + { "name": "Test", "tiles": [] } + asserts: + - hasDocuments: + count: 1 + template: hyperdx/dashboard-configmap.yaml + - contains: + path: spec.template.spec.containers[1].env + content: + name: NAMESPACE + value: observability + template: hyperdx/deployment.yaml + + - it: should not enforce the includeReleaseNamespace guard when dashboards are disabled + set: + hyperdx: + dashboards: + enabled: false + includeReleaseNamespace: false + asserts: + - lengthEqual: + path: spec.template.spec.containers + count: 1 + template: hyperdx/deployment.yaml + - hasDocuments: + count: 0 + template: hyperdx/dashboard-provisioner-rbac.yaml diff --git a/charts/clickstack/values.yaml b/charts/clickstack/values.yaml index a393d36..e2f2fbf 100644 --- a/charts/clickstack/values.yaml +++ b/charts/clickstack/values.yaml @@ -51,7 +51,8 @@ hyperdx: # ── Discovery scope ────────────────────────────────────── # Namespaces the watcher discovers labeled ConfigMaps in: # [] only the release namespace (a namespaced Role; no cluster-wide access) - # [ns-a, ns-b] those namespaces plus the release namespace. A cluster-scoped ClusterRole + # [ns-a, ns-b] those namespaces plus the release namespace (see includeReleaseNamespace + # below to drop the release namespace). A cluster-scoped ClusterRole # rule-template is created, but access stays namespace-scoped — it is bound # only via a RoleBinding in each namespace, never a ClusterRoleBinding. # [ALL] every namespace cluster-wide (creates a ClusterRole + ClusterRoleBinding) @@ -65,6 +66,15 @@ hyperdx: # watched namespace can upsert dashboards into the shared HyperDX. Prefer [ALL] only on # single-tenant clusters; a wider scope is a wider blast radius. namespaces: [] + # Whether the release namespace is always part of the discovery scope above. Set to false + # to watch (and grant ConfigMap read in) only the listed namespaces, e.g. a dedicated + # dashboards namespace when the release namespace holds other components' ConfigMaps. + # The chart then creates a namespaced Role + RoleBinding in each listed namespace (no + # ClusterRole) and nothing in the release namespace. Requires a non-empty `namespaces`, + # and inline `configMaps` (created in the release namespace) would not be discovered, so + # the render fails if they are set while the release namespace is not listed. No effect + # with [ALL]. + includeReleaseNamespace: true rbac: # Create the Role/ClusterRole and binding(s) the watcher needs. Set to false to # grant access out-of-band (e.g. a RoleBinding applied by each namespace owner). From a38e8313fd4b26b82f86bfaf24d90e99ada0adea Mon Sep 17 00:00:00 2001 From: Diego Braga Date: Wed, 18 Nov 2026 12:52:51 +0100 Subject: [PATCH 2/2] fix: Role-path RBAC outside the release namespace gets its own name With hyperdx.dashboards.namespaces: [ns], flipping includeReleaseNamespace on an existing install switched the RoleBinding in ns between the cross-namespace path (roleRef ClusterRole) and the Role path (roleRef Role) under the same name. roleRef is immutable, so helm upgrade failed with "roleRef: Invalid value", and the failed upgrade left a stray Role behind. Outside the release namespace the Role path's Role and RoleBinding are now named -scoped, so neither direction changes an existing roleRef. The suffix always survives: the cluster name is at most 149 characters. Checked with real helm upgrades against a kind API server, only this chart's RBAC installed: true -> false -> true with one target namespace failed before the change and passes after, each step leaving exactly that state's objects; the default (release namespace only) <-> cross-namespace flip passes both ways. The unit tests pin the new names and the cross-namespace RoleBinding's name in the same target namespace. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_016RAxvjuD1TdxneAHTCFpW8 --- .../dashboards-include-release-namespace.md | 2 +- .../hyperdx/dashboard-provisioner-rbac.yaml | 4 +- .../tests/dashboard-provisioner_test.yaml | 52 +++++++++++++++++-- 3 files changed, 52 insertions(+), 6 deletions(-) diff --git a/.changeset/dashboards-include-release-namespace.md b/.changeset/dashboards-include-release-namespace.md index 53b3bdc..27879da 100644 --- a/.changeset/dashboards-include-release-namespace.md +++ b/.changeset/dashboards-include-release-namespace.md @@ -2,4 +2,4 @@ "helm-charts": minor --- -feat: add `hyperdx.dashboards.includeReleaseNamespace` (default `true`, unchanged behaviour). Set it to `false` with `hyperdx.dashboards.namespaces: []` to confine the dashboard watcher, and its ConfigMap read access, to the listed namespaces: the chart then renders a namespaced Role and RoleBinding in each listed namespace, no ClusterRole, and nothing in the release namespace. The render fails if it is `false` with no namespaces listed, or with inline `configMaps` while the release namespace is not watched. +feat: add `hyperdx.dashboards.includeReleaseNamespace` (default `true`, unchanged behaviour). Set it to `false` with `hyperdx.dashboards.namespaces: []` to confine the dashboard watcher, and its ConfigMap read access, to the listed namespaces: the chart then renders a namespaced Role and RoleBinding in each listed namespace, no ClusterRole, and nothing in the release namespace. Those objects are named `--dashboard-provisioner-scoped`, distinct from the RoleBindings the cross-namespace mode renders, so the flag can be flipped either way on an existing install: no upgrade has to change an existing RoleBinding's `roleRef`. The render fails if it is `false` with no namespaces listed, or with inline `configMaps` while the release namespace is not watched. diff --git a/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml b/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml index 5d6d3bf..127131c 100644 --- a/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml +++ b/charts/clickstack/templates/hyperdx/dashboard-provisioner-rbac.yaml @@ -56,9 +56,9 @@ subjects: namespace: {{ $.Release.Namespace }} {{- end }} {{- else }} -{{- /* Default: discovery scoped to the release namespace only — a namespaced Role, no cluster-scoped objects. With includeReleaseNamespace: false, the same namespaced Role + RoleBinding pair is rendered in each target namespace instead, and nothing in the release namespace. Outside the release namespace the names are namespace-qualified like the cluster-scoped objects above, so two same-named releases can't collide in a shared target namespace. */}} +{{- /* Default: discovery scoped to the release namespace only — a namespaced Role, no cluster-scoped objects. With includeReleaseNamespace: false, the same namespaced Role + RoleBinding pair is rendered in each target namespace instead, and nothing in the release namespace. Outside the release namespace the names are namespace-qualified like the cluster-scoped objects above, so two same-named releases can't collide in a shared target namespace, and carry a -scoped suffix so they never reuse the name of the cross-namespace path's RoleBinding (roleRef ClusterRole) in that namespace: roleRef is immutable, so flipping includeReleaseNamespace on an existing install would otherwise fail the upgrade. The suffix always survives: $clusterName is at most 149 characters (fullname and namespace are at most 63 each), well under the 253 RBAC names allow. */}} {{- range $i, $ns := (include "clickstack.hyperdx.effectiveNamespaces" . | splitList ",") }} -{{- $name := ternary (printf "%s-dashboard-provisioner" $fullname) $clusterName (eq $ns $.Release.Namespace) }} +{{- $name := ternary (printf "%s-dashboard-provisioner" $fullname) (printf "%s-scoped" $clusterName) (eq $ns $.Release.Namespace) }} {{- if $i }} --- {{- end }} diff --git a/charts/clickstack/tests/dashboard-provisioner_test.yaml b/charts/clickstack/tests/dashboard-provisioner_test.yaml index 64b2513..7d1884a 100644 --- a/charts/clickstack/tests/dashboard-provisioner_test.yaml +++ b/charts/clickstack/tests/dashboard-provisioner_test.yaml @@ -1186,7 +1186,7 @@ tests: value: apiGroup: rbac.authorization.k8s.io kind: Role - name: RELEASE-NAME-clickstack-observability-dashboard-provisioner + name: RELEASE-NAME-clickstack-observability-dashboard-provisioner-scoped documentIndex: 1 template: hyperdx/dashboard-provisioner-rbac.yaml - equal: @@ -1198,12 +1198,58 @@ tests: documentIndex: 1 template: hyperdx/dashboard-provisioner-rbac.yaml # Outside the release namespace the names are namespace-qualified, so two - # same-named releases sharing a target namespace can't collide. + # same-named releases sharing a target namespace can't collide, and carry + # -scoped so they never reuse the cross-namespace RoleBinding's name (see the + # next-but-one test): roleRef is immutable. - equal: path: metadata.name - value: RELEASE-NAME-clickstack-observability-dashboard-provisioner + value: RELEASE-NAME-clickstack-observability-dashboard-provisioner-scoped documentIndex: 0 template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.name + value: RELEASE-NAME-clickstack-observability-dashboard-provisioner-scoped + documentIndex: 1 + template: hyperdx/dashboard-provisioner-rbac.yaml + + # Flipping includeReleaseNamespace on an existing install must not change the + # roleRef of an existing RoleBinding: the API server rejects that ("roleRef: + # Invalid value"), so the upgrade would fail. With the same target namespace, + # the cross-namespace path (true) binds it with a RoleBinding to the ClusterRole + # and the Role path (false) with a RoleBinding to a Role, so the two must have + # different names in that namespace. + - it: should not reuse the cross-namespace RoleBinding name in a target namespace when includeReleaseNamespace flips + release: + namespace: observability + set: + hyperdx: + dashboards: + enabled: true + includeReleaseNamespace: true + namespaces: + - dashboards + asserts: + # includeReleaseNamespace: true -> {observability, dashboards}: one ClusterRole, + # then a RoleBinding per namespace; the one in `dashboards` is document 2. + - isKind: + of: RoleBinding + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.namespace + value: dashboards + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: metadata.name + value: RELEASE-NAME-clickstack-observability-dashboard-provisioner + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml + - equal: + path: roleRef.kind + value: ClusterRole + documentIndex: 2 + template: hyperdx/dashboard-provisioner-rbac.yaml - it: should render a namespaced Role and RoleBinding per listed namespace when includeReleaseNamespace is false release: