From 479245f4f17c71d4170e2593caa726835179537b Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 01:26:22 +0100 Subject: [PATCH 1/5] fix(monitoring): give Alerta a real signing key and its own admin password Alerta signs its session JWTs with SECRET_KEY, but the upstream image never wires a real value into it: the entrypoint renders the generated key into alertad.conf under the name SECRET (which the application never reads) and unsets SECRET_KEY before exec, so at runtime the built-in default from alerta.settings ("changeme") signs and verifies every token. Anyone can mint a valid admin token without credentials. Alerta's admin account also reused Grafana's credentials (grafana-admin-password), and Alerta exposes the whole process environment via /api/management/properties to any admin-scoped caller, so admin on Alerta yielded Grafana's admin password. Generate a strong SECRET_KEY and a dedicated admin password, persist both in the alerta Secret so they survive upgrades and restarts, feed the key to the application through a mounted alertad.conf under the name it actually reads, and stop referencing grafana-admin-password. Add a unittest covering the key, the mount and the credential decoupling. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- .../monitoring/templates/alerta/alerta.yaml | 48 +++++++++-- .../tests/alerta_secret_key_test.yaml | 83 +++++++++++++++++++ 2 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 packages/system/monitoring/tests/alerta_secret_key_test.yaml diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index 25e68d7ed..3ef4ede6d 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -104,9 +104,33 @@ {{- end }} {{- $apiKey := randAlphaNum 32 }} +{{- /* + Alerta signs its session JWTs with SECRET_KEY. The upstream image never + wires a real value into it: the entrypoint renders the generated key into + alertad.conf under the name SECRET (which the application never reads) and + unsets SECRET_KEY before exec, so at runtime the built-in default from + alerta.settings ("changeme") is used to sign and verify every token. We + generate a strong key here, persist it in this Secret so it survives + upgrades and pod restarts, and feed it to the application as a mounted + alertad.conf under the name the application actually reads. +*/}} +{{- $secretKey := randAlphaNum 64 }} +{{- /* + 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. +*/}} +{{- $adminPassword := randAlphaNum 32 }} {{- $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 @@ -118,6 +142,12 @@ metadata: 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 }} --- apiVersion: v1 kind: ConfigMap @@ -178,15 +208,12 @@ spec: resources: {{- toYaml .Values.alerta.resources | nindent 12 }} env: - name: ADMIN_USERS - valueFrom: - secretKeyRef: - key: user - name: grafana-admin-password + value: "admin" - name: ADMIN_PASSWORD valueFrom: secretKeyRef: - key: password - name: grafana-admin-password + name: alerta + key: admin-password - name: ADMIN_KEY valueFrom: secretKeyRef: @@ -268,10 +295,19 @@ spec: - name: alerta-config mountPath: /app/config.js subPath: config.js + - name: alerta-server-config + mountPath: /app/alertad.conf + subPath: alertad.conf volumes: - name: alerta-config configMap: name: alerta + - name: alerta-server-config + secret: + secretName: alerta + items: + - key: alertad.conf + path: alertad.conf {{- if ne $gatewayEnabled "true" }} --- apiVersion: networking.k8s.io/v1 diff --git a/packages/system/monitoring/tests/alerta_secret_key_test.yaml b/packages/system/monitoring/tests/alerta_secret_key_test.yaml new file mode 100644 index 000000000..5a26f1943 --- /dev/null +++ b/packages/system/monitoring/tests/alerta_secret_key_test.yaml @@ -0,0 +1,83 @@ +suite: alerta is given its own signing key and admin password, decoupled from Grafana +templates: + - templates/alerta/alerta.yaml + +release: + name: monitoring + namespace: tenant-root + +set: + _cluster: + issuer-name: letsencrypt-prod + solver: http01 + gateway-enabled: "false" + _namespace: + host: example.org + ingress: tenant-root + +tests: + - it: renders a 64-char SECRET_KEY for Alerta into a mounted alertad.conf + documentIndex: 0 + 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: + path: data.admin-password + + - it: mounts the server config so Alerta reads the generated key at runtime + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: alerta-server-config + mountPath: /app/alertad.conf + subPath: alertad.conf + - contains: + path: spec.template.spec.volumes + content: + name: alerta-server-config + secret: + secretName: alerta + items: + - key: alertad.conf + path: alertad.conf + + - it: gives Alerta its own admin password instead of reusing Grafana's + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].env + content: + name: ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: alerta + key: admin-password + - notContains: + path: spec.template.spec.containers[0].env + content: + name: ADMIN_PASSWORD + valueFrom: + secretKeyRef: + name: grafana-admin-password + key: password From bd1bdc7a38004efe7f36fe369fffc0be78407b89 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 05:13:48 +0100 Subject: [PATCH 2/5] security(monitoring): keep Alerta credentials out of its container log The Alerta entrypoint prints the whole environment, including the admin password and API key, and echoes the admin API keys it creates, while nginx logs the request line where Alertmanager passes the key as a query parameter. Pod logs are readable at lower tenant tiers than the credentials themselves. This line runs the upstream image, so the entrypoint and nginx template are mounted over the image's copies from a ConfigMap, changed only to drop that output and mask the parameter. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- .../files/alerta/docker-entrypoint.sh | 107 ++++++++++++++++++ .../monitoring/files/alerta/nginx.conf.j2 | 77 +++++++++++++ .../monitoring/templates/alerta/alerta.yaml | 29 +++++ .../tests/alerta_log_redaction_test.yaml | 74 ++++++++++++ 4 files changed, 287 insertions(+) create mode 100755 packages/system/monitoring/files/alerta/docker-entrypoint.sh create mode 100644 packages/system/monitoring/files/alerta/nginx.conf.j2 create mode 100644 packages/system/monitoring/tests/alerta_log_redaction_test.yaml diff --git a/packages/system/monitoring/files/alerta/docker-entrypoint.sh b/packages/system/monitoring/files/alerta/docker-entrypoint.sh new file mode 100755 index 000000000..3401907b9 --- /dev/null +++ b/packages/system/monitoring/files/alerta/docker-entrypoint.sh @@ -0,0 +1,107 @@ +#!/bin/bash +# docker-entrypoint.sh of docker.io/alerta/alerta-web:9.1.0 +# (sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39), +# Apache-2.0, mounted over the image's copy by templates/alerta/alerta.yaml. +# Changed from upstream only so that Alerta's credentials stay out of the +# container log: the environment dump is removed and the output of the two +# `alertad key` calls is discarded. +set -e + +JINJA2="import os, sys, jinja2; sys.stdout.write(jinja2.Template(sys.stdin.read()).render(env=os.environ)+'\n')" + +ALERTA_CONF_FILE=${ALERTA_CONF_FILE:-/app/alerta.conf} +ALERTA_SVR_CONF_FILE=${ALERTA_SVR_CONF_FILE:-/app/alertad.conf} +ALERTA_WEB_CONF_FILE=${ALERTA_WEB_CONF_FILE:-/web/config.json} +NGINX_CONF_FILE=/app/nginx.conf +UWSGI_CONF_FILE=/app/uwsgi.ini +SUPERVISORD_CONF_FILE=/app/supervisord.conf + +ADMIN_USER=${ADMIN_USERS%%,*} +ADMIN_PASSWORD=${ADMIN_PASSWORD:-alerta} +MAXAGE=${ADMIN_KEY_MAXAGE:-315360000} # default=10 years + + +# Generate minimal server config, if not supplied +if [ ! -f "${ALERTA_SVR_CONF_FILE}" ]; then + echo "# Create server configuration file." + export SECRET_KEY=${SECRET_KEY:-$(< /dev/urandom tr -dc A-Za-z0-9_\!\@\#\$\%\^\&\*\(\)-+= | head -c 32)} + python3 -c "${JINJA2}" < ${ALERTA_SVR_CONF_FILE}.j2 >${ALERTA_SVR_CONF_FILE} + unset SECRET_KEY +fi + +# Init admin users and API keys +if [ -n "${ADMIN_USERS}" ]; then + echo "# Create admin users." + alertad user --all --password "${ADMIN_PASSWORD}" || true + echo "# Create admin API keys." + alertad key --all >/dev/null + + # Create user-defined API key, if required + if [ -n "${ADMIN_KEY}" ]; then + echo "# Create user-defined admin API key." + alertad key --username "${ADMIN_USER}" --key "${ADMIN_KEY}" --duration "${MAXAGE}" >/dev/null || true + fi +fi + +# Generate minimal client config, if not supplied +if [ ! -f "${ALERTA_CONF_FILE}" ]; then + # Add API key to client config, if required + if [ "${AUTH_REQUIRED,,}" == "true" ]; then + echo "# Auth enabled; add admin API key to client configuration." + HOUSEKEEPING_SCOPES="--scope read --scope write:alerts --scope admin:management" + if grep -qE 'CUSTOMER_VIEWS.*=.*True' ${ALERTA_SVR_CONF_FILE};then + HOUSEKEEPING_SCOPES="--scope admin:alerts ${HOUSEKEEPING_SCOPES}" + fi + export API_KEY=$(alertad key \ + --username "${ADMIN_USER}" \ + ${HOUSEKEEPING_SCOPES} \ + --duration "${MAXAGE}" \ + --text "Housekeeping") + fi + echo "# Create client configuration file." + python3 -c "${JINJA2}" < ${ALERTA_CONF_FILE}.j2 >${ALERTA_CONF_FILE} +fi + +# Generate supervisord config, if not supplied +if [ ! -f "${SUPERVISORD_CONF_FILE}" ]; then + echo "# Create supervisord configuration file." + python3 -c "${JINJA2}" < ${SUPERVISORD_CONF_FILE}.j2 >${SUPERVISORD_CONF_FILE} +fi + +# Generate nginx config, if not supplied. +if [ ! -f "${NGINX_CONF_FILE}" ]; then + echo "# Create nginx configuration file." + python3 -c "${JINJA2}" < ${NGINX_CONF_FILE}.j2 >${NGINX_CONF_FILE} +fi +nginx -t -c ${NGINX_CONF_FILE} + +# Generate uWSGI config, if not supplied. +if [ ! -f "${UWSGI_CONF_FILE}" ]; then + echo "# Create uWSGI configuration file." + python3 -c "${JINJA2}" < ${UWSGI_CONF_FILE}.j2 >${UWSGI_CONF_FILE} +fi + +# Generate web config, if not supplied. +if [ ! -f "${ALERTA_WEB_CONF_FILE}" ]; then + echo "# Create web configuration file." + python3 -c "${JINJA2}" < ${ALERTA_WEB_CONF_FILE}.j2 >${ALERTA_WEB_CONF_FILE} +fi + +echo +echo '# Checking versions.' +echo Alerta Server ${SERVER_VERSION} +echo Alerta Client ${CLIENT_VERSION} +echo Alerta WebUI ${WEBUI_VERSION} + +nginx -v +echo uwsgi $(uwsgi --version) +mongosh --version +psql --version +python3 --version +/venv/bin/pip list + +echo +echo 'Alerta init process complete; ready for start up.' +echo + +exec "$@" diff --git a/packages/system/monitoring/files/alerta/nginx.conf.j2 b/packages/system/monitoring/files/alerta/nginx.conf.j2 new file mode 100644 index 000000000..5661484ed --- /dev/null +++ b/packages/system/monitoring/files/alerta/nginx.conf.j2 @@ -0,0 +1,77 @@ +{#- nginx.conf.j2 of docker.io/alerta/alerta-web:9.1.0 + (sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39), + Apache-2.0, mounted over the image's copy by templates/alerta/alerta.yaml. + Changed from upstream only so that the access log masks the api-key query + parameter Alertmanager and the Telegram webhook authenticate with. #} + +worker_processes {{ env.NGINX_WORKER_PROCESSES }}; +pid /tmp/nginx.pid; + +daemon off; +{%- if env.DEBUG %} +error_log /dev/stderr debug; +{%- else %} +error_log /dev/stderr {{ env.LOG_LEVEL|lower or 'warn' }}; +{%- endif %} + +events { + worker_connections {{ env.NGINX_WORKER_CONNECTIONS }}; +} + +http { + client_body_temp_path /tmp/client_body; + fastcgi_temp_path /tmp/fastcgi_temp; + proxy_temp_path /tmp/proxy_temp; + scgi_temp_path /tmp/scgi_temp; + uwsgi_temp_path /tmp/uwsgi_temp; + + include /etc/nginx/mime.types; + + server_tokens off; + + gzip on; + gzip_disable "msie6"; + client_max_body_size {{ env.NGINX_MAX_BODY_SIZE or '2M' }}; + + map $request $request_redacted { + "~*^(?.*[?&]api-key=)[^&\s]*(?.*)$" "${redact_pre}REDACTED${redact_post}"; + default $request; + } + + log_format main '$remote_addr - $remote_user [$time_local] ' + '"$request_redacted" $status $body_bytes_sent ' + '"$http_referer" "$http_user_agent" - $request_time ' + 'x_forwarded_for=$http_x_forwarded_for host=$host ' + '$request_id $sent_http_x_request_id'; + + default_type application/octet-stream; + + upstream backend { + server 127.0.0.1:29000; + } + + server { + listen 8080 default_server; + {%- if env.ENABLE_IPV6 is defined and env.ENABLE_IPV6|lower == 'true' %} + listen [::]:8080 default_server; + {%- endif %} + + access_log /dev/stdout main; + + location /api { + include /etc/nginx/uwsgi_params; + uwsgi_pass backend; + + uwsgi_param Host $host; + uwsgi_param X-Real-IP $remote_addr; + uwsgi_param X-Forwarded-For $proxy_add_x_forwarded_for; + uwsgi_param X-Forwarded-Proto $http_x_forwarded_proto; + } + + root /web; + index index.html; + location / { + try_files $uri $uri/ /index.html; + } + } +} diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index 3ef4ede6d..21f46ce58 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -166,6 +166,25 @@ data: }) .constant('colors', {}); --- +{{- /* + The image's entrypoint prints the whole environment and the admin API keys + it creates, and its nginx logs the api-key query parameter, so Alerta's + credentials end up in the container log, which is readable at lower tenant + tiers than the credentials themselves. Both files are mounted over the + image's copies with that output removed; see the headers in files/alerta/. +*/}} +apiVersion: v1 +kind: ConfigMap +metadata: + name: alerta-entrypoint + labels: + app: alerta +data: + docker-entrypoint.sh: |- +{{ .Files.Get "files/alerta/docker-entrypoint.sh" | trimSuffix "\n" | indent 4 }} + nginx.conf.j2: |- +{{ .Files.Get "files/alerta/nginx.conf.j2" | trimSuffix "\n" | indent 4 }} +--- apiVersion: v1 kind: Service metadata: @@ -298,6 +317,12 @@ spec: - name: alerta-server-config mountPath: /app/alertad.conf subPath: alertad.conf + - name: alerta-entrypoint + mountPath: /usr/local/bin/docker-entrypoint.sh + subPath: docker-entrypoint.sh + - name: alerta-entrypoint + mountPath: /app/nginx.conf.j2 + subPath: nginx.conf.j2 volumes: - name: alerta-config configMap: @@ -308,6 +333,10 @@ spec: items: - key: alertad.conf path: alertad.conf + - name: alerta-entrypoint + configMap: + name: alerta-entrypoint + defaultMode: 0755 {{- if ne $gatewayEnabled "true" }} --- apiVersion: networking.k8s.io/v1 diff --git a/packages/system/monitoring/tests/alerta_log_redaction_test.yaml b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml new file mode 100644 index 000000000..744f85d50 --- /dev/null +++ b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml @@ -0,0 +1,74 @@ +suite: alerta keeps its credentials out of the container log +templates: + - templates/alerta/alerta.yaml + +release: + name: monitoring + namespace: tenant-root + +set: + _cluster: + issuer-name: letsencrypt-prod + solver: http01 + gateway-enabled: "false" + _namespace: + host: example.org + ingress: tenant-root + +tests: + - it: ships an entrypoint without the environment dump and with key creation silenced + documentSelector: + path: metadata.name + value: alerta-entrypoint + asserts: + - isKind: + of: ConfigMap + - notMatchRegex: + path: data["docker-entrypoint.sh"] + pattern: '(?m)^env' + - matchRegex: + path: data["docker-entrypoint.sh"] + pattern: '(?m)^ alertad key --all >/dev/null$' + - matchRegex: + path: data["docker-entrypoint.sh"] + pattern: '(?m)^ alertad key --username "\$\{ADMIN_USER\}" --key "\$\{ADMIN_KEY\}" --duration "\$\{MAXAGE\}" >/dev/null \|\| true$' + + - it: ships an nginx config that masks the api-key parameter in the access log + documentSelector: + path: metadata.name + value: alerta-entrypoint + asserts: + - matchRegex: + path: data["nginx.conf.j2"] + pattern: 'map \$request \$request_redacted' + - matchRegex: + path: data["nginx.conf.j2"] + pattern: '"\$request_redacted" \$status' + - notMatchRegex: + path: data["nginx.conf.j2"] + pattern: '"\$request" ' + + - it: mounts both files over the image's copies + documentSelector: + path: kind + value: Deployment + asserts: + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: alerta-entrypoint + mountPath: /usr/local/bin/docker-entrypoint.sh + subPath: docker-entrypoint.sh + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: alerta-entrypoint + mountPath: /app/nginx.conf.j2 + subPath: nginx.conf.j2 + - contains: + path: spec.template.spec.volumes + content: + name: alerta-entrypoint + configMap: + name: alerta-entrypoint + defaultMode: 0755 From cbdb4f64a594883eda1e737d6c1b6f6e5161ebf3 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 05:24:15 +0100 Subject: [PATCH 3/5] 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 --- .../templates/dashboard-resourcemap.yaml | 1 + .../monitoring-rd/cozyrds/monitoring.yaml | 1 + .../monitoring/templates/alerta/alerta.yaml | 39 ++++++++++----- .../tests/alerta_secret_key_test.yaml | 47 +++++++++++++------ 4 files changed, 61 insertions(+), 27 deletions(-) diff --git a/packages/extra/monitoring/templates/dashboard-resourcemap.yaml b/packages/extra/monitoring/templates/dashboard-resourcemap.yaml index 5a5a3def9..98faa3612 100644 --- a/packages/extra/monitoring/templates/dashboard-resourcemap.yaml +++ b/packages/extra/monitoring/templates/dashboard-resourcemap.yaml @@ -17,6 +17,7 @@ rules: - secrets resourceNames: - grafana-admin-password + - alerta-admin-password verbs: ["get", "list", "watch"] - apiGroups: - "" diff --git a/packages/system/monitoring-rd/cozyrds/monitoring.yaml b/packages/system/monitoring-rd/cozyrds/monitoring.yaml index 014605e76..7fc3969ad 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 21f46ce58..5b4b248c3 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -119,18 +119,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 @@ -143,11 +148,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 @@ -227,12 +239,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: From 51acf0fcbb5796ca399d170b11d51f9ad6437444 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 05:40:32 +0100 Subject: [PATCH 4/5] security(monitoring): reset the Alerta admin password on every start The entrypoint creates admin users only when they are missing, so an admin user created before Alerta had a password of its own keeps the Grafana password, which stays valid after an operator rotates Grafana's. The mounted entrypoint runs a step right after user creation that sets every admin user's password to ADMIN_PASSWORD, and stops the container if it fails. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- .../files/alerta/docker-entrypoint.sh | 6 ++-- .../files/alerta/sync-admin-password.py | 29 +++++++++++++++++++ .../monitoring/templates/alerta/alerta.yaml | 11 ++++++- .../tests/alerta_log_redaction_test.yaml | 18 ++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 packages/system/monitoring/files/alerta/sync-admin-password.py diff --git a/packages/system/monitoring/files/alerta/docker-entrypoint.sh b/packages/system/monitoring/files/alerta/docker-entrypoint.sh index 3401907b9..d5656d2ee 100755 --- a/packages/system/monitoring/files/alerta/docker-entrypoint.sh +++ b/packages/system/monitoring/files/alerta/docker-entrypoint.sh @@ -3,8 +3,9 @@ # (sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39), # Apache-2.0, mounted over the image's copy by templates/alerta/alerta.yaml. # Changed from upstream only so that Alerta's credentials stay out of the -# container log: the environment dump is removed and the output of the two -# `alertad key` calls is discarded. +# container log (the environment dump is removed and the output of the two +# `alertad key` calls is discarded), and so that existing admin users take +# ADMIN_PASSWORD on every start through sync-admin-password.py. set -e JINJA2="import os, sys, jinja2; sys.stdout.write(jinja2.Template(sys.stdin.read()).render(env=os.environ)+'\n')" @@ -33,6 +34,7 @@ fi if [ -n "${ADMIN_USERS}" ]; then echo "# Create admin users." alertad user --all --password "${ADMIN_PASSWORD}" || true + /venv/bin/python /app/sync-admin-password.py echo "# Create admin API keys." alertad key --all >/dev/null diff --git a/packages/system/monitoring/files/alerta/sync-admin-password.py b/packages/system/monitoring/files/alerta/sync-admin-password.py new file mode 100644 index 000000000..21ce71258 --- /dev/null +++ b/packages/system/monitoring/files/alerta/sync-admin-password.py @@ -0,0 +1,29 @@ +"""Set the password of every Alerta admin user to ADMIN_PASSWORD. + +`alertad user --all` only creates admin users that are missing, so an admin +user that already exists keeps the password it was created with, which on +installations that predate the dedicated Alerta password is Grafana's. The +entrypoint runs this right after it, on every start. It never prints the +password, and a failure stops the container rather than leaving the old +password in place. +""" +import os +import sys + +from alerta.app import create_app + +password = os.environ.get('ADMIN_PASSWORD') +if not password: + sys.exit('ADMIN_PASSWORD is not set') + +app = create_app() +# Imported after the app exists: importing the model first runs into a +# circular import through alerta.auth. +from alerta.models.user import User # noqa: E402 + +with app.app_context(): + for login in app.config['ADMIN_USERS']: + user = User.find_by_username(login) + if user is not None and not user.verify_password(password): + user.update(password=password) + print(f'# Reset the password of admin user {login}.') diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index 5b4b248c3..dfd2b42ec 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -183,7 +183,11 @@ data: it creates, and its nginx logs the api-key query parameter, so Alerta's credentials end up in the container log, which is readable at lower tenant tiers than the credentials themselves. Both files are mounted over the - image's copies with that output removed; see the headers in files/alerta/. + image's copies with that output removed. The entrypoint also runs + sync-admin-password.py after creating admin users, because it only creates + missing ones and an existing admin user would keep the password it was + created with, Grafana's on installations that predate Alerta's own. See the + headers in files/alerta/. */}} apiVersion: v1 kind: ConfigMap @@ -196,6 +200,8 @@ data: {{ .Files.Get "files/alerta/docker-entrypoint.sh" | trimSuffix "\n" | indent 4 }} nginx.conf.j2: |- {{ .Files.Get "files/alerta/nginx.conf.j2" | trimSuffix "\n" | indent 4 }} + sync-admin-password.py: |- +{{ .Files.Get "files/alerta/sync-admin-password.py" | trimSuffix "\n" | indent 4 }} --- apiVersion: v1 kind: Service @@ -338,6 +344,9 @@ spec: - name: alerta-entrypoint mountPath: /app/nginx.conf.j2 subPath: nginx.conf.j2 + - name: alerta-entrypoint + mountPath: /app/sync-admin-password.py + subPath: sync-admin-password.py volumes: - name: alerta-config configMap: diff --git a/packages/system/monitoring/tests/alerta_log_redaction_test.yaml b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml index 744f85d50..fa2a3740b 100644 --- a/packages/system/monitoring/tests/alerta_log_redaction_test.yaml +++ b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml @@ -33,6 +33,18 @@ tests: path: data["docker-entrypoint.sh"] pattern: '(?m)^ alertad key --username "\$\{ADMIN_USER\}" --key "\$\{ADMIN_KEY\}" --duration "\$\{MAXAGE\}" >/dev/null \|\| true$' + - it: resets the admin users' password to ADMIN_PASSWORD right after creating them + documentSelector: + path: metadata.name + value: alerta-entrypoint + asserts: + - matchRegex: + path: data["docker-entrypoint.sh"] + pattern: '(?m)^ alertad user --all --password "\$\{ADMIN_PASSWORD\}" \|\| true\n /venv/bin/python /app/sync-admin-password\.py$' + - matchRegex: + path: data["sync-admin-password.py"] + pattern: 'user\.update\(password=password\)' + - it: ships an nginx config that masks the api-key parameter in the access log documentSelector: path: metadata.name @@ -65,6 +77,12 @@ tests: name: alerta-entrypoint mountPath: /app/nginx.conf.j2 subPath: nginx.conf.j2 + - contains: + path: spec.template.spec.containers[0].volumeMounts + content: + name: alerta-entrypoint + mountPath: /app/sync-admin-password.py + subPath: sync-admin-password.py - contains: path: spec.template.spec.volumes content: From d85c8d7c7b704aac6d1589a5bc25f5d96eb89e79 Mon Sep 17 00:00:00 2001 From: Andrei Kvapil Date: Fri, 27 Nov 2026 05:46:06 +0100 Subject: [PATCH 5/5] security(monitoring): pin the Alerta image by digest The entrypoint and nginx template mounted over the image are copies of alerta-web 9.1.0 at this digest. A retagged image could carry different files, and the mounted copies would then no longer match it. Assisted-by: LLM Signed-off-by: Andrei Kvapil --- packages/system/monitoring/templates/alerta/alerta.yaml | 4 +++- .../monitoring/tests/alerta_log_redaction_test.yaml | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/packages/system/monitoring/templates/alerta/alerta.yaml b/packages/system/monitoring/templates/alerta/alerta.yaml index dfd2b42ec..f14885994 100644 --- a/packages/system/monitoring/templates/alerta/alerta.yaml +++ b/packages/system/monitoring/templates/alerta/alerta.yaml @@ -240,7 +240,9 @@ spec: spec: containers: - name: alerta - image: "alerta/alerta-web:9.1.0" + {{- /* Pinned by digest: the entrypoint and nginx template mounted + from alerta-entrypoint are copies of this exact image's. */}} + image: "docker.io/alerta/alerta-web:9.1.0@sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39" imagePullPolicy: IfNotPresent resources: {{- toYaml .Values.alerta.resources | nindent 12 }} env: diff --git a/packages/system/monitoring/tests/alerta_log_redaction_test.yaml b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml index fa2a3740b..7c92212ca 100644 --- a/packages/system/monitoring/tests/alerta_log_redaction_test.yaml +++ b/packages/system/monitoring/tests/alerta_log_redaction_test.yaml @@ -90,3 +90,12 @@ tests: configMap: name: alerta-entrypoint defaultMode: 0755 + + - it: runs the exact image the mounted files were copied from + documentSelector: + path: kind + value: Deployment + asserts: + - equal: + path: spec.template.spec.containers[0].image + value: docker.io/alerta/alerta-web:9.1.0@sha256:693845fb8a95a483c8c9d560786f661f5b6198e5ea0baa6ddf368a7e53c94f39