fix(helm): hardening from review

- _helpers.tpl: required guard on image.tag — silent empty deploys can
  no longer happen; helm fails fast with a clear message.
- configmap-nginx: HTTPS fastcgi param uses if_not_empty, so PHP only
  sees HTTPS when X-Forwarded-Proto is actually present.
- deployment-app: add startupProbe with 100s budget so first-boot cache
  warmup doesn't trip liveness.
- deployment-horizon: failureThreshold=5 on the horizon:status probe;
  transient Valkey blips no longer cause restart loops.
- job-migrate: mount oauth-keys so seeders that touch Passport clients
  don't silently fail.
- statefulset-valkey: replace separate password Secret with a
  requirePassword toggle that reads REDIS_PASSWORD from the main chart
  Secret (same Secret app/horizon/scheduler already mount). Liveness
  probe authenticates with the password when set.
- values-us-prod: enable valkey.requirePassword.
- README: add REDIS_PASSWORD to bootstrap procedure.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-26 23:08:10 -04:00
parent 548fc5f1ee
commit 4ff3048dd3
9 changed files with 54 additions and 24 deletions

View File

@@ -37,6 +37,7 @@ openssl rsa -in "$TMP_KEYS/oauth-private.key" -pubout -out "$TMP_KEYS/oauth-publ
# 3. Gather production secrets. Read each one and store in shell vars. # 3. Gather production secrets. Read each one and store in shell vars.
DB_PASS=$(openssl rand -base64 32 | tr -d '/=+' | cut -c1-32) DB_PASS=$(openssl rand -base64 32 | tr -d '/=+' | cut -c1-32)
REDIS_PASS=$(openssl rand -base64 32 | tr -d '/=+' | cut -c1-32)
read -sp "STRIPE_KEY (pk_live_...): " STRIPE_KEY; echo read -sp "STRIPE_KEY (pk_live_...): " STRIPE_KEY; echo
read -sp "STRIPE_SECRET (sk_live_...): " STRIPE_SECRET; echo read -sp "STRIPE_SECRET (sk_live_...): " STRIPE_SECRET; echo
read -sp "STRIPE_WEBHOOK_SECRET (whsec_...): " STRIPE_WEBHOOK; echo read -sp "STRIPE_WEBHOOK_SECRET (whsec_...): " STRIPE_WEBHOOK; echo
@@ -54,6 +55,7 @@ kubectl create secret generic ezscale-website-secrets \
--namespace ezscale \ --namespace ezscale \
--from-literal=APP_KEY="$APP_KEY" \ --from-literal=APP_KEY="$APP_KEY" \
--from-literal=DB_PASSWORD="$DB_PASS" \ --from-literal=DB_PASSWORD="$DB_PASS" \
--from-literal=REDIS_PASSWORD="$REDIS_PASS" \
--from-literal=STRIPE_KEY="$STRIPE_KEY" \ --from-literal=STRIPE_KEY="$STRIPE_KEY" \
--from-literal=STRIPE_SECRET="$STRIPE_SECRET" \ --from-literal=STRIPE_SECRET="$STRIPE_SECRET" \
--from-literal=STRIPE_WEBHOOK_SECRET="$STRIPE_WEBHOOK" \ --from-literal=STRIPE_WEBHOOK_SECRET="$STRIPE_WEBHOOK" \

View File

@@ -35,7 +35,8 @@ Usage: {{ include "ezscale-website.image" (dict "ctx" . "role" "app") }}
*/}} */}}
{{- define "ezscale-website.image" -}} {{- define "ezscale-website.image" -}}
{{- $ctx := .ctx -}} {{- $ctx := .ctx -}}
{{- printf "%s/%s:%s-%s" $ctx.Values.image.registry $ctx.Values.image.repository .role $ctx.Values.image.tag -}} {{- $tag := required "image.tag is required (set via --set image.tag=vX.Y.Z)" $ctx.Values.image.tag -}}
{{- printf "%s/%s:%s-%s" $ctx.Values.image.registry $ctx.Values.image.repository .role $tag -}}
{{- end -}} {{- end -}}
{{/* Secret name (existing or generated) */}} {{/* Secret name (existing or generated) */}}

View File

@@ -34,7 +34,10 @@ data:
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_param DOCUMENT_ROOT $realpath_root; fastcgi_param DOCUMENT_ROOT $realpath_root;
fastcgi_param HTTP_PROXY ""; fastcgi_param HTTP_PROXY "";
fastcgi_param HTTPS $http_x_forwarded_proto; # Pass HTTPS to PHP only when X-Forwarded-Proto is non-empty.
# if_not_empty avoids the param being set to "" when the header
# is missing (which would falsely satisfy isset($_SERVER['HTTPS'])).
fastcgi_param HTTPS $http_x_forwarded_proto if_not_empty;
fastcgi_buffers 16 16k; fastcgi_buffers 16 16k;
fastcgi_buffer_size 32k; fastcgi_buffer_size 32k;
fastcgi_read_timeout 300; fastcgi_read_timeout 300;

View File

@@ -51,11 +51,19 @@ spec:
- name: nginx-config - name: nginx-config
mountPath: /etc/nginx/conf.d mountPath: /etc/nginx/conf.d
readOnly: true readOnly: true
# Startup probe gives the app up to 100s for first-boot work
# (config:cache + route:cache + view:cache + opcache warmup) before
# liveness takes over.
startupProbe:
httpGet:
path: {{ .Values.healthCheck.livenessPath }}
port: http
failureThreshold: 20
periodSeconds: 5
livenessProbe: livenessProbe:
httpGet: httpGet:
path: {{ .Values.healthCheck.livenessPath }} path: {{ .Values.healthCheck.livenessPath }}
port: http port: http
initialDelaySeconds: {{ .Values.healthCheck.initialDelaySeconds }}
periodSeconds: {{ .Values.healthCheck.periodSeconds }} periodSeconds: {{ .Values.healthCheck.periodSeconds }}
timeoutSeconds: {{ .Values.healthCheck.timeoutSeconds }} timeoutSeconds: {{ .Values.healthCheck.timeoutSeconds }}
failureThreshold: {{ .Values.healthCheck.failureThreshold }} failureThreshold: {{ .Values.healthCheck.failureThreshold }}
@@ -63,7 +71,6 @@ spec:
httpGet: httpGet:
path: {{ .Values.healthCheck.readinessPath }} path: {{ .Values.healthCheck.readinessPath }}
port: http port: http
initialDelaySeconds: 5
periodSeconds: 5 periodSeconds: 5
- name: app - name: app
image: {{ include "ezscale-website.image" (dict "ctx" . "role" "app") }} image: {{ include "ezscale-website.image" (dict "ctx" . "role" "app") }}

View File

@@ -41,6 +41,8 @@ spec:
readOnly: true readOnly: true
resources: resources:
{{- toYaml .Values.horizon.resources | nindent 12 }} {{- toYaml .Values.horizon.resources | nindent 12 }}
# horizon:status hits Redis. failureThreshold: 5 + periodSeconds: 30
# gives 150s of tolerance for transient Valkey blips before restart.
livenessProbe: livenessProbe:
exec: exec:
command: command:
@@ -50,6 +52,7 @@ spec:
initialDelaySeconds: 30 initialDelaySeconds: 30
periodSeconds: 30 periodSeconds: 30
timeoutSeconds: 10 timeoutSeconds: 10
failureThreshold: 5
volumes: volumes:
- name: oauth-keys - name: oauth-keys
secret: secret:

View File

@@ -41,4 +41,18 @@ spec:
name: {{ include "ezscale-website.fullname" . }}-env name: {{ include "ezscale-website.fullname" . }}-env
- secretRef: - secretRef:
name: {{ include "ezscale-website.secretName" . }} name: {{ include "ezscale-website.secretName" . }}
volumeMounts:
- name: oauth-keys
mountPath: /var/www/html/secrets
readOnly: true
volumes:
- name: oauth-keys
secret:
secretName: {{ include "ezscale-website.secretName" . }}
items:
- key: oauth-private.key
path: oauth-private.key
- key: oauth-public.key
path: oauth-public.key
optional: true
{{- end }} {{- end }}

View File

@@ -1,18 +1,4 @@
{{- if .Values.valkey.enabled }} {{- if .Values.valkey.enabled }}
{{- $secretName := printf "%s-valkey" (include "ezscale-website.fullname" .) }}
{{- if .Values.valkey.password }}
apiVersion: v1
kind: Secret
metadata:
name: {{ $secretName }}
labels: {{- include "ezscale-website.labels" . | nindent 4 }}
annotations:
helm.sh/resource-policy: keep
type: Opaque
stringData:
password: {{ .Values.valkey.password | quote }}
---
{{- end }}
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
@@ -53,6 +39,10 @@ spec:
containers: containers:
- name: valkey - name: valkey
image: {{ .Values.valkey.image }} image: {{ .Values.valkey.image }}
# When requirePassword is true, REDIS_PASSWORD is sourced from the
# main chart Secret (same Secret the app/horizon/scheduler pods read
# via envFrom). Local dev can put it in secret.values; prod
# bootstraps it manually per the chart README.
command: command:
- valkey-server - valkey-server
- --appendonly - --appendonly
@@ -61,17 +51,17 @@ spec:
- {{ .Values.valkey.maxmemory | quote }} - {{ .Values.valkey.maxmemory | quote }}
- --maxmemory-policy - --maxmemory-policy
- allkeys-lru - allkeys-lru
{{- if .Values.valkey.password }} {{- if .Values.valkey.requirePassword }}
- --requirepass - --requirepass
- $(REDIS_PASSWORD) - $(REDIS_PASSWORD)
{{- end }} {{- end }}
{{- if .Values.valkey.password }} {{- if .Values.valkey.requirePassword }}
env: env:
- name: REDIS_PASSWORD - name: REDIS_PASSWORD
valueFrom: valueFrom:
secretKeyRef: secretKeyRef:
name: {{ $secretName }} name: {{ include "ezscale-website.secretName" . }}
key: password key: REDIS_PASSWORD
{{- end }} {{- end }}
ports: ports:
- name: redis - name: redis
@@ -81,7 +71,11 @@ spec:
mountPath: /data mountPath: /data
livenessProbe: livenessProbe:
exec: exec:
{{- if .Values.valkey.requirePassword }}
command: ["sh", "-c", "valkey-cli -a \"$REDIS_PASSWORD\" --no-auth-warning ping"]
{{- else }}
command: ["valkey-cli", "ping"] command: ["valkey-cli", "ping"]
{{- end }}
initialDelaySeconds: 10 initialDelaySeconds: 10
periodSeconds: 10 periodSeconds: 10
volumeClaimTemplates: volumeClaimTemplates:

View File

@@ -43,9 +43,11 @@ mariadb:
database: ezscale_billing database: ezscale_billing
username: ezscale_billing_app username: ezscale_billing_app
# Per-app Valkey for sessions/cache/queue. # Per-app Valkey for sessions/cache/queue. requirePassword=true means
# REDIS_PASSWORD must be present in ezscale-website-secrets.
valkey: valkey:
enabled: true enabled: true
requirePassword: true
storage: storage:
size: 10Gi size: 10Gi
storageClassName: longhorn storageClassName: longhorn

View File

@@ -77,7 +77,11 @@ mariadb:
valkey: valkey:
enabled: true enabled: true
image: valkey/valkey:9-alpine image: valkey/valkey:9-alpine
password: "" # if empty, chart generates a random secret # When true, valkey runs with --requirepass and reads REDIS_PASSWORD from
# the main chart Secret (same key the app/horizon/scheduler pods read via
# envFrom). The Secret MUST contain a REDIS_PASSWORD key — bootstrap it
# alongside APP_KEY in production, or include it in secret.values for dev.
requirePassword: false
maxmemory: "1gb" maxmemory: "1gb"
storage: storage:
size: 5Gi size: 5Gi