mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-30 12:16:03 +09:00
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 <kvapss@gmail.com>
This commit is contained in:
2 files changed
+125
-6
No files matched your search
@@ -115,9 +115,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
|
||||
@@ -129,6 +153,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
|
||||
@@ -189,15 +219,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:
|
||||
@@ -279,10 +306,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
|
||||
|
||||
@@ -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
|
||||
Reference in new issue
Block a user