From 47e84e131bc1e5bed47e1ca77f5dea022e7ba0f1 Mon Sep 17 00:00:00 2001 From: Nicolas Date: Sun, 16 Aug 2026 10:40:07 +0200 Subject: [PATCH] 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. --- .env.example | 6 ++++-- README.md | 6 ++++++ apps/api/.env.example | 4 +++- docker-compose.yml | 11 +++++++---- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 927641d..fdcc5a0 100644 --- a/.env.example +++ b/.env.example @@ -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 diff --git a/README.md b/README.md index 0d8c82f..a35ed9f 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/apps/api/.env.example b/apps/api/.env.example index 9f8347e..1cb9717 100644 --- a/apps/api/.env.example +++ b/apps/api/.env.example @@ -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" diff --git a/docker-compose.yml b/docker-compose.yml index 2d75301..e6ea603 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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