Remove hardcoded credentials from committed env/compose files

.env.example and apps/api/.env.example had a real usable default
credential pair (batchcooking/batchcooking) baked in, and
docker-compose.yml fell back to the same values via ${VAR:-default}
if .env was missing. Neither should ship a working credential:

- .env.example / apps/api/.env.example now use "changeme" placeholders
  that must be edited before use.
- docker-compose.yml uses ${VAR:?...} instead of ${VAR:-default} for
  POSTGRES_USER/PASSWORD/DB, so compose fails loudly if .env isn't set
  up rather than silently falling back to a guessable credential.
  Healthcheck reads the container's own env var ($$POSTGRES_USER)
  instead of duplicating the value in the compose file.
- README updated to say .env.example must be edited, not just copied.

Verified: `docker compose config` fails with a clear message when
.env is absent, and resolves correctly once .env is filled in.
This commit is contained in:
Nicolas 2026-08-16 10:40:07 +02:00
parent 14a526cb28
commit 47e84e131b
4 changed files with 20 additions and 7 deletions

View file

@ -1,5 +1,7 @@
# Used by docker-compose.yml to provision the local Postgres container.
POSTGRES_USER=batchcooking
POSTGRES_PASSWORD=batchcooking
# Pick your own values — do not reuse these across environments, and never
# commit the real .env (it's git-ignored).
POSTGRES_USER=changeme
POSTGRES_PASSWORD=changeme
POSTGRES_DB=batchcooking
POSTGRES_PORT=5432

View file

@ -24,6 +24,12 @@ cp .env.example .env
cp apps/api/.env.example apps/api/.env
```
Puis **édite ces deux `.env`** pour renseigner de vrais `POSTGRES_USER`/`POSTGRES_PASSWORD`
(et la `DATABASE_URL` correspondante dans `apps/api/.env`) : les fichiers `.env.example`
ne contiennent volontairement aucun identifiant réel (juste `changeme`), et
`docker-compose.yml` refuse de démarrer tant que `POSTGRES_USER`/`PASSWORD`/`DB` ne
sont pas définis dans `.env` — pas de valeur par défaut en dur dans les fichiers commités.
### Cypress : téléchargement du binaire
`pnpm install` installe le package `cypress` mais **pas forcément son binaire** (le

View file

@ -1,3 +1,5 @@
NODE_ENV=development
PORT=3000
DATABASE_URL="postgresql://batchcooking:batchcooking@localhost:5432/batchcooking?schema=public"
# Match whatever you set in the root .env (POSTGRES_USER/PASSWORD/DB) —
# do not commit the real value.
DATABASE_URL="postgresql://changeme:changeme@localhost:5432/batchcooking?schema=public"

View file

@ -3,15 +3,18 @@ services:
image: postgres:16-alpine
restart: unless-stopped
environment:
POSTGRES_USER: ${POSTGRES_USER:-batchcooking}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-batchcooking}
POSTGRES_DB: ${POSTGRES_DB:-batchcooking}
# No defaults on purpose: POSTGRES_USER/PASSWORD/DB must be set in your
# local, git-ignored .env (see .env.example). Compose fails loudly if
# they're missing instead of falling back to a guessable credential.
POSTGRES_USER: ${POSTGRES_USER:?set POSTGRES_USER in .env}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD in .env}
POSTGRES_DB: ${POSTGRES_DB:?set POSTGRES_DB in .env}
ports:
- "${POSTGRES_PORT:-5432}:5432"
volumes:
- postgres_data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-batchcooking}"]
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
interval: 5s
timeout: 5s
retries: 5