fix(helm): preserve SYSTEM_AES_KEY/TENANT_AES_KEY across upgrades
The Secret template defaulted both keys to randAlphaNum 32, which Helm re-rolls on every template render. As a result, any `helm upgrade` without explicit secrets.systemAesKey / secrets.tenantAesKey rotated the keys, breaking decryption of every previously encrypted field (tenants.api_key, model API keys, vector store credentials, web search provider keys, WeKnoraCloud.AppSecret) and surfacing "enc:v1:..." ciphertext in the UI. Use Helm's `lookup` to reuse the values stored in the existing Secret when one is already present, falling back to randAlphaNum only on first install. Also document the recovery caveat in values.yaml so operators understand the risk of relying on the auto-generated value.
This commit is contained in:
@@ -11,10 +11,30 @@ IMPORTANT: For production deployments, use one of these approaches:
|
||||
4. Provide an existing secret via secrets.existingSecret
|
||||
*/}}
|
||||
{{- if not .Values.secrets.existingSecret }}
|
||||
{{/*
|
||||
Reuse the previously generated random keys on upgrade. Without this lookup,
|
||||
randAlphaNum would re-roll on every `helm upgrade` and rotate SYSTEM_AES_KEY /
|
||||
TENANT_AES_KEY, making any data encrypted with the old key unreadable
|
||||
(e.g. tenants.api_key would surface as enc:v1:... in the UI).
|
||||
*/}}
|
||||
{{- $secretName := include "weknora.secretName" . }}
|
||||
{{- $existing := lookup "v1" "Secret" .Release.Namespace $secretName }}
|
||||
{{- $existingTenantKey := "" }}
|
||||
{{- $existingSystemKey := "" }}
|
||||
{{- if and $existing $existing.data }}
|
||||
{{- if index $existing.data "TENANT_AES_KEY" }}
|
||||
{{- $existingTenantKey = index $existing.data "TENANT_AES_KEY" | b64dec }}
|
||||
{{- end }}
|
||||
{{- if index $existing.data "SYSTEM_AES_KEY" }}
|
||||
{{- $existingSystemKey = index $existing.data "SYSTEM_AES_KEY" | b64dec }}
|
||||
{{- end }}
|
||||
{{- end }}
|
||||
{{- $tenantAesKey := .Values.secrets.tenantAesKey | default $existingTenantKey | default (randAlphaNum 32) }}
|
||||
{{- $systemAesKey := .Values.secrets.systemAesKey | default $existingSystemKey | default (randAlphaNum 32) }}
|
||||
apiVersion: v1
|
||||
kind: Secret
|
||||
metadata:
|
||||
name: {{ include "weknora.secretName" . }}
|
||||
name: {{ $secretName }}
|
||||
namespace: {{ .Release.Namespace }}
|
||||
labels:
|
||||
{{- include "weknora.labels" . | nindent 4 }}
|
||||
@@ -29,8 +49,8 @@ stringData:
|
||||
REDIS_PASSWORD: {{ required "secrets.redisPassword is required" .Values.secrets.redisPassword | quote }}
|
||||
# Application secrets
|
||||
JWT_SECRET: {{ required "secrets.jwtSecret is required" .Values.secrets.jwtSecret | quote }}
|
||||
TENANT_AES_KEY: {{ .Values.secrets.tenantAesKey | default (randAlphaNum 32) | quote }}
|
||||
SYSTEM_AES_KEY: {{ .Values.secrets.systemAesKey | default (randAlphaNum 32) | quote }}
|
||||
TENANT_AES_KEY: {{ $tenantAesKey | quote }}
|
||||
SYSTEM_AES_KEY: {{ $systemAesKey | quote }}
|
||||
{{- if .Values.neo4j.enabled }}
|
||||
# Neo4j credentials (for GraphRAG)
|
||||
NEO4J_USERNAME: {{ .Values.neo4j.username | quote }}
|
||||
|
||||
Reference in New Issue
Block a user