Skip to content

feat(helm): read the built-in Postgres and Redis passwords from an existing Secret - #906

Open
MrHencke wants to merge 2 commits into
jonwiggins:mainfrom
MrHencke:feat/helm-existing-secret-postgres-redis
Open

MrHencke wants to merge 2 commits into
jonwiggins:mainfrom
MrHencke:feat/helm-existing-secret-postgres-redis

Conversation

@MrHencke

@MrHencke MrHencke commented Dec 4, 2026

Copy link
Copy Markdown

Summary

The built-in Postgres and Redis can't currently be used from a GitOps tool that renders the chart with helm template (Argo CD, Kargo, Flux with post-rendering):

  • postgresql.auth.password has to be set in values, so the password ends up in Git or in the rendered manifests.
  • The Redis password is generated with randAlphaNum and kept stable with lookup. lookup returns nothing without a cluster, so every render produces a new password and the API and Redis drift apart.

This adds postgresql.auth.existingSecret and redis.auth.existingSecret (each with an existingSecretKey). When set, the chart renders no password Secret of its own and points every consumer at the given Secret. Values and rendered output then hold no password. Default rendering is unchanged.

Changes

values.yaml

  • postgresql.auth.existingSecret / existingSecretKey (default key POSTGRES_PASSWORD)
  • redis.auth.existingSecret / existingSecretKey (default key REDIS_PASSWORD)

Templates

  • _helpers.tpl: optio.postgresPasswordSecret and optio.redisPasswordSecret give the Secret name/key (existing or chart-rendered). optio.pgPasswordEnv adds a PGPASSWORD env from the existing Secret. With existingSecret, optio.databaseUrl builds the URL without a password.
  • postgres.yaml, redis-tls.yaml: skip the chart's own credentials/auth Secret when existingSecret is set. The servers read the password through the helpers.
  • api-deployment.yaml: REDIS_PASSWORD through the helper. PGPASSWORD added when Postgres uses existingSecret.
  • backup-cronjob.yaml: PGPASSWORD on the container that runs pg_dump.
  • secrets.yaml: the "password required" check accepts existingSecret in place of password.

No API changes are needed. The API already injects REDIS_PASSWORD into the Redis URL (services/redis-config.ts). postgres.js falls back to PGPASSWORD when the URL has no password, and so does pg_dump (libpq).

PGPASSWORD isn't added when existingSecrets.DATABASE_URL is set, since a user-supplied URL carries its own credentials.

Docs: AGENTS.md Helm Chart section.

Testing

  • New scripts/chart-existing-secrets.test.mjs (picked up by CI's node --test scripts/*.test.mjs; skipped when helm is missing) renders the chart and checks:

    • defaults: both password Secrets rendered, password in DATABASE_URL, no PGPASSWORD
    • existingSecret: no password Secrets, DATABASE_URL without a password
    • the API, Postgres, Redis and backup CronJob all reference the existing Secrets
    • no PGPASSWORD when DATABASE_URL comes from existingSecrets
  • Default render (TLS off) is byte-identical to main.

  • The individual check:push steps pass: lint, knip, prettier, typecheck, check-infra.sh, affected unit tests.

  • pnpm check:push passes. I couldn't run it as a whole on Windows: scripts/check-push.mjs spawns pnpm without a shell, which fails with spawn pnpm ENOENT, so I ran its steps by hand. shellcheck, hadolint and kubeconform weren't installed locally, and I didn't run the e2e suites. I'm leaving those to CI.

Related

…isting Secret

postgresql.auth.existingSecret and redis.auth.existingSecret (with
existingSecretKey) point the built-in databases, the API and the backup job
at a Secret the chart does not render. Installs rendered with helm template
(GitOps tools such as Argo CD or Kargo) then keep no password in values or in
the rendered output, and the Redis password no longer depends on lookup.
DATABASE_URL carries no password in that case; postgres.js and pg_dump read
PGPASSWORD. Default rendering is unchanged.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant