From 073e3c43aefce200ca11c9ab2fd77e1ce8b1588d Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Thu, 21 Dec 2023 16:18:36 -0700 Subject: [PATCH 1/2] feat: fail when users store secrets in plaintext Signed-off-by: Derek Brown --- charts/grafana/templates/_config.tpl | 1 + charts/grafana/templates/_helpers.tpl | 49 +++++++++++++++++++++++++++ charts/grafana/values.yaml | 10 ++++++ 3 files changed, 60 insertions(+) diff --git a/charts/grafana/templates/_config.tpl b/charts/grafana/templates/_config.tpl index face210934..19df19cd2a 100644 --- a/charts/grafana/templates/_config.tpl +++ b/charts/grafana/templates/_config.tpl @@ -2,6 +2,7 @@ Generate config map data */}} {{- define "grafana.configData" -}} +{{ include "grafana.assertNoLeakedSecrets" . }} {{- $files := .Files }} {{- $root := . -}} {{- with .Values.plugins }} diff --git a/charts/grafana/templates/_helpers.tpl b/charts/grafana/templates/_helpers.tpl index ead2449e37..44c00f3570 100644 --- a/charts/grafana/templates/_helpers.tpl +++ b/charts/grafana/templates/_helpers.tpl @@ -225,3 +225,52 @@ Formats imagePullSecrets. Input is (dict "root" . "imagePullSecrets" .{specific {{- end }} {{- $secretFound}} {{- end -}} + +{{/* + Checks whether the user is attempting to store secrets in plaintext + in the grafana.ini configmap +*/}} +{{/* grafana.assertNoLeakedSecrets checks for sensitive keys in values */}} +{{- define "grafana.assertNoLeakedSecrets" -}} + {{- $sensitiveKeysYaml := ` +sensitiveKeys: +- path: ["database", "password"] +- path: ["smtp", "password"] +- path: ["security", "secret_key"] +- path: ["security", "admin_password"] +- path: ["auth.basic", "password"] +- path: ["auth.ldap", "bind_password"] +- path: ["auth.google", "client_secret"] +- path: ["auth.github", "client_secret"] +- path: ["auth.gitlab", "client_secret"] +- path: ["auth.generic_oauth", "client_secret"] +- path: ["auth.okta", "client_secret"] +- path: ["auth.azuread", "client_secret"] +- path: ["auth.grafana_com", "client_secret"] +- path: ["auth.grafananet", "client_secret"] +- path: ["azure", "user_identity_client_secret"] +- path: ["unified_alerting", "ha_redis_password"] +- path: ["metrics", "basic_auth_password"] +- path: ["external_image_storage.s3", "secret_key"] +- path: ["external_image_storage.webdav", "password"] +- path: ["external_image_storage.azure_blob", "account_key"] +` | fromYaml -}} + {{- if $.Values.assertNoLeakedSecrets -}} + {{- $grafanaIni := index .Values "grafana.ini" -}} + {{- range $_, $secret := $sensitiveKeysYaml.sensitiveKeys -}} + {{- $currentMap := $grafanaIni -}} + {{- $shouldContinue := true -}} + {{- range $index, $elem := $secret.path -}} + {{- if and $shouldContinue (hasKey $currentMap $elem) -}} + {{- if eq (len $secret.path) (add1 $index) -}} + {{- fail (printf "Sensitive key '%s' should not be defined explicitly in values. Use variable expansion instead." (join "." $secret.path)) -}} + {{- else -}} + {{- $currentMap = index $currentMap $elem -}} + {{- end -}} + {{- else -}} + {{- $shouldContinue = false -}} + {{- end -}} + {{- end -}} + {{- end -}} + {{- end -}} +{{- end -}} diff --git a/charts/grafana/values.yaml b/charts/grafana/values.yaml index afa1472dd7..803585d1a8 100644 --- a/charts/grafana/values.yaml +++ b/charts/grafana/values.yaml @@ -1297,3 +1297,13 @@ extraObjects: [] # data: # - key: grafana-admin-password # name: adminPassword + +# assertNoLeakedSecrets is a helper function defined in _helpers.tpl that checks if secret +# values are not exposed in the rendered grafana.ini configmap. It is enabled by default. +# +# To pass values into grafana.ini without exposing them in a configmap, use variable expansion: +# https://grafana.com/docs/grafana/latest/setup-grafana/configure-grafana/#variable-expansion +# +# Alternatively, if you wish to allow secret values to be exposed in the rendered grafana.ini configmap, +# you can disable this check by setting assertNoLeakedSecrets to false. +assertNoLeakedSecrets: true From 6725f741c63f2ef1960588905d33e4586987c59d Mon Sep 17 00:00:00 2001 From: Derek Brown Date: Thu, 4 Jan 2024 14:33:01 -0800 Subject: [PATCH 2/2] version bump Signed-off-by: Derek Brown --- charts/grafana/Chart.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/charts/grafana/Chart.yaml b/charts/grafana/Chart.yaml index 8c2c9e1126..194b224051 100644 --- a/charts/grafana/Chart.yaml +++ b/charts/grafana/Chart.yaml @@ -1,6 +1,6 @@ apiVersion: v2 name: grafana -version: 7.0.19 +version: 7.1.0 appVersion: 10.2.2 kubeVersion: "^1.8.0-0" description: The leading tool for querying and visualizing time series and metrics.