From 68b0e80d1771c18065f97c88da992696b95c5a25 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 05:24:15 +0100 Subject: [PATCH] security(monitoring): show tenants Alerta's login apart from its keys Tenants logged in to the Alerta UI with the Grafana credentials, the only Secret of the release they are shown. With Alerta on a password of its own, that password moves to a Secret that holds nothing but the login, listed for tenants next to Grafana's, so the signing key and the API key in the alerta Secret stay hidden. The alerta Secret is now rendered under data alone. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- .../monitoring-rd/cozyrds/monitoring.yaml | 1 + .../monitoring/templates/alerta/alerta.yaml | 39 ++++++++++----- .../tests/alerta_secret_key_test.yaml | 47 +++++++++++++------ 3 files changed, 60 insertions(+), 27 deletions(-) diff --git a/packages/system/monitoring-rd/cozyrds/monitoring.yaml b/packages/system/monitoring-rd/cozyrds/monitoring.yaml index 2ef708196..134761f11 100644 --- a/packages/system/monitoring-rd/cozyrds/monitoring.yaml +++ b/packages/system/monitoring-rd/cozyrds/monitoring.yaml @@ -44,6 +44,7 @@ spec: include: - resourceNames: - grafana-admin-password + - alerta-admin-password services: exclude: [] include: diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index 01e4cddc6..c7cab4270 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -130,18 +130,23 @@ Alerta's admin account must not share Grafana's credentials: Alerta exposes the whole process environment through /api/management/properties to any admin-scoped caller, so a shared password would hand Grafana's admin over - with it. Give Alerta its own password, persisted the same way. + with it. Its own login lives in a Secret apart from this one, so tenants can + be shown it (monitoring-rd lists it) without the signing key and API key. + The entrypoint resets the admin user's password to it on every start, which + also replaces the Grafana password on installations that predate this. */}} {{- $adminPassword := randAlphaNum 32 }} +{{- with lookup "v1" "Secret" .Release.Namespace "alerta-admin-password" }} +{{- with index .data "password" }} +{{- $adminPassword = b64dec . }} +{{- end }} +{{- end }} {{- $existingSecret := lookup "v1" "Secret" .Release.Namespace "alerta" }} {{- if $existingSecret }} {{- $apiKey = index $existingSecret.data "alerta-api-key" | b64dec }} {{- if index $existingSecret.data "secret-key" }} {{- $secretKey = index $existingSecret.data "secret-key" | b64dec }} {{- end }} -{{- if index $existingSecret.data "admin-password" }} -{{- $adminPassword = index $existingSecret.data "admin-password" | b64dec }} -{{- end }} {{- end }} --- apiVersion: v1 @@ -154,11 +159,18 @@ type: Opaque data: alerta-api-key: {{ $apiKey | b64enc }} secret-key: {{ $secretKey | b64enc }} - admin-password: {{ $adminPassword | b64enc }} -stringData: - alertad.conf: | - DEBUG = False - SECRET_KEY = {{ $secretKey | quote }} + alertad.conf: {{ printf "DEBUG = False\nSECRET_KEY = %s\n" ($secretKey | quote) | b64enc }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: alerta-admin-password + labels: + app: alerta +type: Opaque +data: + user: {{ b64enc "admin" }} + password: {{ $adminPassword | b64enc }} --- apiVersion: v1 kind: ConfigMap @@ -219,12 +231,15 @@ spec: resources: {{- toYaml .Values.alerta.resources | nindent 12 }} env: - name: ADMIN_USERS - value: "admin" + valueFrom: + secretKeyRef: + name: alerta-admin-password + key: user - name: ADMIN_PASSWORD valueFrom: secretKeyRef: - name: alerta - key: admin-password + name: alerta-admin-password + key: password - name: ADMIN_KEY valueFrom: secretKeyRef: diff --git a/packages/system/monitoring/tests/alerta_secret_key_test.yaml b/packages/system/monitoring/tests/alerta_secret_key_test.yaml index 5a26f1943..bcb36ab27 100644 --- a/packages/system/monitoring/tests/alerta_secret_key_test.yaml +++ b/packages/system/monitoring/tests/alerta_secret_key_test.yaml @@ -1,4 +1,4 @@ -suite: alerta is given its own signing key and admin password, decoupled from Grafana +suite: alerta is given its own signing key and admin login, decoupled from Grafana templates: - templates/alerta/alerta.yaml @@ -21,24 +21,33 @@ tests: asserts: - isKind: of: Secret - - equal: - path: metadata.name - value: alerta - - matchRegex: - path: stringData["alertad.conf"] - pattern: 'SECRET_KEY = "[A-Za-z0-9]{64}"' - - - it: persists the signing key and admin password in the alerta Secret - documentIndex: 0 - asserts: - equal: path: metadata.name value: alerta - isNotNullOrEmpty: path: data.secret-key - - isNotNullOrEmpty: + - notExists: + path: stringData + - notExists: path: data.admin-password + - it: keeps Alerta's login in its own Secret, apart from the signing key + documentSelector: + path: metadata.name + value: alerta-admin-password + asserts: + - isKind: + of: Secret + - equal: + path: data.user + value: YWRtaW4= + - isNotNullOrEmpty: + path: data.password + - notExists: + path: data.secret-key + - notExists: + path: data.alerta-api-key + - it: mounts the server config so Alerta reads the generated key at runtime documentSelector: path: kind @@ -60,7 +69,7 @@ tests: - key: alertad.conf path: alertad.conf - - it: gives Alerta its own admin password instead of reusing Grafana's + - it: gives Alerta its own admin login instead of reusing Grafana's documentSelector: path: kind value: Deployment @@ -71,8 +80,16 @@ tests: name: ADMIN_PASSWORD valueFrom: secretKeyRef: - name: alerta - key: admin-password + name: alerta-admin-password + key: password + - contains: + path: spec.template.spec.containers[0].env + content: + name: ADMIN_USERS + valueFrom: + secretKeyRef: + name: alerta-admin-password + key: user - notContains: path: spec.template.spec.containers[0].env content: