From 65a89cd6f20a9cacfa3e83d5216b005ab9a5849f Mon Sep 17 00:00:00 2001 From: "Wachter, Julian" Date: Thu, 5 Nov 2026 10:27:45 +0100 Subject: [PATCH 1/2] fix(chart): authenticate ServiceMonitor via token Secret instead of bearerTokenFile Grafana Alloy (and Prometheus Operator setups without arbitrary file access) reject ServiceMonitors using bearerTokenFile, so drop metrics were never scraped. Create a dedicated metrics-scraper ServiceAccount with a token Secret bound to the metrics-reader ClusterRole and reference it via authorization.credentials. Verify TLS against the cert-manager CA when enabled, and scrape over plain HTTP when secureServing is off. --- .../drop/templates/metrics-scraper-rbac.yaml | 33 +++++++++++++++++++ charts/drop/templates/servicemonitor.yaml | 24 ++++++++++++-- docs/content/docs/monitoring.md | 7 ++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 charts/drop/templates/metrics-scraper-rbac.yaml diff --git a/charts/drop/templates/metrics-scraper-rbac.yaml b/charts/drop/templates/metrics-scraper-rbac.yaml new file mode 100644 index 0000000..2c28260 --- /dev/null +++ b/charts/drop/templates/metrics-scraper-rbac.yaml @@ -0,0 +1,33 @@ +{{- if and .Values.serviceMonitor.enabled .Values.metrics.enabled .Values.metrics.secureServing }} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "drop.fullname" . }}-metrics-scraper + labels: + {{- include "drop.labels" . | nindent 4 }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: {{ include "drop.fullname" . }}-metrics-scraper-token + labels: + {{- include "drop.labels" . | nindent 4 }} + annotations: + kubernetes.io/service-account.name: {{ include "drop.fullname" . }}-metrics-scraper +type: kubernetes.io/service-account-token +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: {{ include "drop.fullname" . }}-metrics-scraper + labels: + {{- include "drop.labels" . | nindent 4 }} +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: {{ include "drop.fullname" . }}-metrics-reader +subjects: + - kind: ServiceAccount + name: {{ include "drop.fullname" . }}-metrics-scraper + namespace: {{ .Release.Namespace }} +{{- end }} diff --git a/charts/drop/templates/servicemonitor.yaml b/charts/drop/templates/servicemonitor.yaml index 1ec5a09..dae9028 100644 --- a/charts/drop/templates/servicemonitor.yaml +++ b/charts/drop/templates/servicemonitor.yaml @@ -1,4 +1,4 @@ -{{- if .Values.serviceMonitor.enabled }} +{{- if and .Values.serviceMonitor.enabled .Values.metrics.enabled }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: @@ -11,14 +11,32 @@ metadata: spec: endpoints: - port: https-metrics - scheme: https interval: {{ .Values.serviceMonitor.interval }} {{- if .Values.serviceMonitor.scrapeTimeout }} scrapeTimeout: {{ .Values.serviceMonitor.scrapeTimeout }} {{- end }} + {{- if .Values.metrics.secureServing }} + scheme: https + # Token is read from a Secret instead of bearerTokenFile, which is + # rejected by Grafana Alloy and newer Prometheus Operator setups. + authorization: + type: Bearer + credentials: + name: {{ include "drop.fullname" . }}-metrics-scraper-token + key: token tlsConfig: + {{- if .Values.certManager.enabled }} + serverName: {{ include "drop.fullname" . }}-metrics.{{ .Release.Namespace }}.svc + ca: + secret: + name: {{ include "drop.fullname" . }}-metrics-tls + key: ca.crt + {{- else }} insecureSkipVerify: true - bearerTokenFile: /var/run/secrets/kubernetes.io/serviceaccount/token + {{- end }} + {{- else }} + scheme: http + {{- end }} selector: matchLabels: {{- include "drop.selectorLabels" . | nindent 6 }} diff --git a/docs/content/docs/monitoring.md b/docs/content/docs/monitoring.md index 9f57c66..427db83 100644 --- a/docs/content/docs/monitoring.md +++ b/docs/content/docs/monitoring.md @@ -29,6 +29,13 @@ helm install drop oci://ghcr.io/corewire/charts/drop \ --set serviceMonitor.enabled=true ``` +With `metrics.secureServing=true` (default) the chart creates a dedicated +`-metrics-scraper` ServiceAccount, a token Secret, and a binding to +`-metrics-reader`. The ServiceMonitor references that token via +`authorization.credentials`, so it works with scrapers that forbid +`bearerTokenFile` (e.g. Grafana Alloy). With `certManager.enabled=true` the +scraper verifies the metrics certificate against the cert-manager CA. + ### Example Queries ```promql From f4f1ce325f305af73a5f4a81e949ebb5514388e2 Mon Sep 17 00:00:00 2001 From: "Wachter, Julian" Date: Thu, 5 Nov 2026 10:29:51 +0100 Subject: [PATCH 2/2] fix(chart): require cert-manager for secure ServiceMonitor scraping Drop the insecureSkipVerify fallback. Without cert-manager the operator serves an in-memory self-signed certificate that no scraper can verify, so fail rendering with a clear message instead. --- charts/drop/templates/servicemonitor.yaml | 7 +++---- docs/content/docs/monitoring.md | 9 ++++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/charts/drop/templates/servicemonitor.yaml b/charts/drop/templates/servicemonitor.yaml index dae9028..0ee7b40 100644 --- a/charts/drop/templates/servicemonitor.yaml +++ b/charts/drop/templates/servicemonitor.yaml @@ -1,4 +1,7 @@ {{- if and .Values.serviceMonitor.enabled .Values.metrics.enabled }} +{{- if and .Values.metrics.secureServing (not .Values.certManager.enabled) }} +{{- fail "serviceMonitor.enabled with metrics.secureServing requires certManager.enabled=true so the scraper can verify the metrics TLS certificate" }} +{{- end }} apiVersion: monitoring.coreos.com/v1 kind: ServiceMonitor metadata: @@ -25,15 +28,11 @@ spec: name: {{ include "drop.fullname" . }}-metrics-scraper-token key: token tlsConfig: - {{- if .Values.certManager.enabled }} serverName: {{ include "drop.fullname" . }}-metrics.{{ .Release.Namespace }}.svc ca: secret: name: {{ include "drop.fullname" . }}-metrics-tls key: ca.crt - {{- else }} - insecureSkipVerify: true - {{- end }} {{- else }} scheme: http {{- end }} diff --git a/docs/content/docs/monitoring.md b/docs/content/docs/monitoring.md index 427db83..c1877f8 100644 --- a/docs/content/docs/monitoring.md +++ b/docs/content/docs/monitoring.md @@ -26,15 +26,18 @@ llmsDescription: | ```bash helm install drop oci://ghcr.io/corewire/charts/drop \ - --set serviceMonitor.enabled=true + --set serviceMonitor.enabled=true \ + --set certManager.enabled=true ``` With `metrics.secureServing=true` (default) the chart creates a dedicated `-metrics-scraper` ServiceAccount, a token Secret, and a binding to `-metrics-reader`. The ServiceMonitor references that token via `authorization.credentials`, so it works with scrapers that forbid -`bearerTokenFile` (e.g. Grafana Alloy). With `certManager.enabled=true` the -scraper verifies the metrics certificate against the cert-manager CA. +`bearerTokenFile` (e.g. Grafana Alloy). The scraper verifies the metrics +certificate against the cert-manager CA, so `certManager.enabled=true` is +required; rendering fails otherwise. With `metrics.secureServing=false` the +endpoint is scraped over plain HTTP without authentication. ### Example Queries