From 27046d18414028cffbd697cae88c85cf26208a30 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 19 Dec 2021 00:45:49 +0200 Subject: [PATCH] feat(recipes): move `SECRET_KEY` to autogenerated remembered secret (#1559) * feat(recipes): move `SECRET_KEY` to autogenerated remembered secret * bump major --- charts/stable/recipes/Chart.yaml | 2 +- charts/stable/recipes/questions.yaml | 12 ----------- charts/stable/recipes/templates/_sercrets.tpl | 20 +++++++++++++++++++ charts/stable/recipes/templates/common.yaml | 3 +++ charts/stable/recipes/values.yaml | 7 +++++-- 5 files changed, 29 insertions(+), 15 deletions(-) create mode 100644 charts/stable/recipes/templates/_sercrets.tpl diff --git a/charts/stable/recipes/Chart.yaml b/charts/stable/recipes/Chart.yaml index 1f164f2c790..ba818cc3547 100644 --- a/charts/stable/recipes/Chart.yaml +++ b/charts/stable/recipes/Chart.yaml @@ -2,7 +2,7 @@ apiVersion: v2 appVersion: "1.0.2" description: Recipes is a Django application to manage, tag and search recipes using either built in models or external storage providers hosting PDF's, Images or other files. name: recipes -version: 4.0.18 +version: 5.0.0 kubeVersion: ">=1.16.0-0" keywords: - recipes diff --git a/charts/stable/recipes/questions.yaml b/charts/stable/recipes/questions.yaml index c824d3bfeeb..e798dafbf31 100644 --- a/charts/stable/recipes/questions.yaml +++ b/charts/stable/recipes/questions.yaml @@ -73,18 +73,6 @@ questions: - value: "OnDelete" description: "(Legacy) OnDelete: ignore .spec.template changes" # Include{controllerExpert} - - variable: secret - group: "Container Configuration" - label: "Image Secrets" - schema: - type: dict - attrs: - - variable: SECRET_KEY - label: "SECRET_KEY" - description: "Sets the SECRET_KEY env var" - schema: - type: string - default: "changeme" - variable: env group: "Container Configuration" label: "Image Environment" diff --git a/charts/stable/recipes/templates/_sercrets.tpl b/charts/stable/recipes/templates/_sercrets.tpl new file mode 100644 index 00000000000..c5b8056fd28 --- /dev/null +++ b/charts/stable/recipes/templates/_sercrets.tpl @@ -0,0 +1,20 @@ +{{/* Define the secrets */}} +{{- define "recipes.secrets" -}} +--- + +apiVersion: v1 +kind: Secret +type: Opaque +metadata: + name: recipes-secrets +{{- $recipesprevious := lookup "v1" "Secret" .Release.Namespace "recipes-secrets" }} +{{- $secret_key := "" }} +data: + {{- if $recipesprevious}} + SECRET_KEY: {{ index $recipesprevious.data "SECRET_KEY" }} + {{- else }} + {{- $secret_key := randAlphaNum 50 }} + SECRET_KEY: {{ $secret_key | b64enc | quote }} + {{- end }} + +{{- end -}} diff --git a/charts/stable/recipes/templates/common.yaml b/charts/stable/recipes/templates/common.yaml index 710aed0f01e..21e879a998b 100644 --- a/charts/stable/recipes/templates/common.yaml +++ b/charts/stable/recipes/templates/common.yaml @@ -14,5 +14,8 @@ persistence: {{- end -}} {{- $_ := mergeOverwrite .Values (include "recipes.harcodedValues" . | fromYaml) -}} +{{/* Render secrets for recipes */}} +{{- include "recipes.secrets" . }} + {{/* Render the templates */}} {{ include "common.postSetup" . }} diff --git a/charts/stable/recipes/values.yaml b/charts/stable/recipes/values.yaml index f0312dbfd40..20e644f42c7 100644 --- a/charts/stable/recipes/values.yaml +++ b/charts/stable/recipes/values.yaml @@ -23,16 +23,15 @@ podSecurityContext: # -- environment variables. See [project docs](https://raw.githubusercontent.com/vabene1111/recipes/master/.env.template) for more details. # @default -- See below env: - TIMEZONE: UTC DEBUG: 0 ALLOWED_HOSTS: "*" - SECRET_KEY: "changeme" GUNICORN_MEDIA: 0 FRACTION_PREF_DEFAULT: 0 COMMENT_PREF_DEFAULT: 1 SHOPPING_MIN_AUTOSYNC_INTERVAL: 5 envTpl: + TIMEZONE: "{{ .Values.env.TZ }}" DB_ENGINE: "django.db.backends.postgresql" POSTGRES_DB: "{{ .Values.postgresql.postgresqlDatabase }}" POSTGRES_USER: "{{ .Values.postgresql.postgresqlUsername }}" @@ -47,6 +46,10 @@ envValueFrom: secretKeyRef: name: dbcreds key: plainhost + SECRET_KEY: + secretKeyRef: + name: recipes-secrets + key: SECRET_KEY additionalContainers: nginx: