diff --git a/.changeset/dashboards-include-release-namespace.md b/.changeset/dashboards-include-release-namespace.md new file mode 100644 index 0000000..27879da --- /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. 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/README.md b/charts/clickstack/README.md index f8300a6..9ba9757 100644 --- a/charts/clickstack/README.md +++ b/charts/clickstack/README.md @@ -57,7 +57,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","ENABLE_PROMQL":"{{ if .Values.hyperdx.promql.enabled }}true{{ else }}false{{ end }}","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","NEXT_PUBLIC_ENABLE_PROMQL":"{{ if .Values.hyperdx.promql.enabled }}true{{ else }}false{{ end }}","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":"128Mi"},"requests":{"cpu":"10m","memory":"64Mi"}},"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":"128Mi"},"requests":{"cpu":"10m","memory":"64Mi"}},"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 \"from\": {\n \"databaseName\": \"default\",\n \"tableName\": \"metrics_ts\"\n },\n \"kind\": \"promql\",\n \"timestampValueExpression\": \"timestamp\",\n \"name\": \"PromQL\",\n \"connection\": \"Local ClickHouse\"\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 2cee14f..8204f82 100644 --- a/charts/clickstack/templates/_helpers.tpl +++ b/charts/clickstack/templates/_helpers.tpl @@ -145,7 +145,8 @@ user's setting (passwords, replicas, opt-outs) would fall back to the default. {{/* 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" -}} @@ -163,6 +164,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 -}} @@ -200,15 +207,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 "," -}} @@ -225,12 +233,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..127131c 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, 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) (printf "%s-scoped" $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 a8a1596..0e03130 100644 --- a/charts/clickstack/tests/dashboard-provisioner_test.yaml +++ b/charts/clickstack/tests/dashboard-provisioner_test.yaml @@ -1077,3 +1077,393 @@ 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-scoped + 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, 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-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: + 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 55f1855..07a4cb3 100644 --- a/charts/clickstack/values.yaml +++ b/charts/clickstack/values.yaml @@ -59,7 +59,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) @@ -73,6 +74,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).