Blank SECRET_KEY_BASE in .env.example and fix guide key setup

Merged
MA
4d ago
+71-28

Problem

Upstream now requires SECRET_KEY_BASE in the example compose files and documents the upgrade path (#3221, #3190). A few gaps remain around how installs get their key:

  • .env.example still ships SECRET_KEY_BASE=secret-value. An unedited copy passes the compose check and runs on a public key shared with every other unedited install.
  • The Hetzner guide tells users to put SECRET_KEY_BASE="$(openssl rand -hex 64)" into .env. Compose does not run commands in .env, so anyone who pasted it as-is runs on that literal text.
  • The Pipelock and MCP guides start the stack without a key step.
  • The Docker upgrade section says to copy the old default from the previous compose.yml, but the Docker and Hetzner guides download the new compose.yml first, so that value is gone by the time the user needs it.
  • The required-variable message in both compose files points to that same previous compose.yml.

Changes

  • .env.example: leave SECRET_KEY_BASE blank, so the compose check fails until it is set.
  • Compose files: the required-variable message now links to the upgrade section of the Docker guide. This is the only change to them.
  • Hetzner guide: generate the key and Postgres password (now hex) in the shell and write .env only if it does not exist, owner-only. A note covers installs that used the old instructions.
  • Pipelock and MCP guides: add a key step that links to Docker Step 3 for new installs and to the upgrade section for existing ones.
  • Docker guide:
    • create .env owner-only and never overwrite an existing one;
    • in the upgrade section, name the public values (old built-in default, secret-value, the literal Hetzner text, guide placeholders) and say to keep the current one until the data has moved to new keys;
    • warn upgraders not to download .env.example, whose postgres/postgres credentials differ from the compose defaults their database was created with.
  • Encryption guide: replace the pick-by-name steps for reading the old key from the container with a command scoped to the Compose project, which works after the new compose.yml is in place.

No application code changes: the public values are already in KNOWN_COMPROMISED_SECRET_KEY_BASES since #5225.

Validation

  • docker compose -f compose.example.yml config and -f compose.example.ai.yml config render with SECRET_KEY_BASE set and fail with the new required-variable message when it is unset, empty, or taken from an unedited .env.example.
  • The key-reading command was run on throwaway Compose projects with fake keys (Compose v5.6.1) under bash, sh, dash and zsh, with the container running, stopped and missing, and with a second project on the same host.
  • Ran the Hetzner heredoc and the guarded .env creation under bash and zsh with umask 022: a new .env is -rw------- with expanded values, and a rerun leaves an existing .env untouched.
  • The old key in the docs matches KNOWN_COMPROMISED_SECRET_KEY_BASES exactly.
  • All new links resolve to existing headings.