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:
parent
14a526cb28
commit
47e84e131b
4 changed files with 20 additions and 7 deletions
|
|
@ -1,5 +1,7 @@
|
||||||
# Used by docker-compose.yml to provision the local Postgres container.
|
# Used by docker-compose.yml to provision the local Postgres container.
|
||||||
POSTGRES_USER=batchcooking
|
# Pick your own values — do not reuse these across environments, and never
|
||||||
POSTGRES_PASSWORD=batchcooking
|
# commit the real .env (it's git-ignored).
|
||||||
|
POSTGRES_USER=changeme
|
||||||
|
POSTGRES_PASSWORD=changeme
|
||||||
POSTGRES_DB=batchcooking
|
POSTGRES_DB=batchcooking
|
||||||
POSTGRES_PORT=5432
|
POSTGRES_PORT=5432
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,12 @@ cp .env.example .env
|
||||||
cp apps/api/.env.example apps/api/.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
|
### Cypress : téléchargement du binaire
|
||||||
|
|
||||||
`pnpm install` installe le package `cypress` mais **pas forcément son binaire** (le
|
`pnpm install` installe le package `cypress` mais **pas forcément son binaire** (le
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
NODE_ENV=development
|
NODE_ENV=development
|
||||||
PORT=3000
|
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"
|
||||||
|
|
|
||||||
|
|
@ -3,15 +3,18 @@ services:
|
||||||
image: postgres:16-alpine
|
image: postgres:16-alpine
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
environment:
|
environment:
|
||||||
POSTGRES_USER: ${POSTGRES_USER:-batchcooking}
|
# No defaults on purpose: POSTGRES_USER/PASSWORD/DB must be set in your
|
||||||
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-batchcooking}
|
# local, git-ignored .env (see .env.example). Compose fails loudly if
|
||||||
POSTGRES_DB: ${POSTGRES_DB:-batchcooking}
|
# 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:
|
ports:
|
||||||
- "${POSTGRES_PORT:-5432}:5432"
|
- "${POSTGRES_PORT:-5432}:5432"
|
||||||
volumes:
|
volumes:
|
||||||
- postgres_data:/var/lib/postgresql/data
|
- postgres_data:/var/lib/postgresql/data
|
||||||
healthcheck:
|
healthcheck:
|
||||||
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-batchcooking}"]
|
test: ["CMD-SHELL", "pg_isready -U $$POSTGRES_USER"]
|
||||||
interval: 5s
|
interval: 5s
|
||||||
timeout: 5s
|
timeout: 5s
|
||||||
retries: 5
|
retries: 5
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue