Skip to content

Commit 615f491

Browse files
committed
fix(db): remove hardcoded local DB password from docker-compose (#600)
GitGuardian flagged the static dev password in docker-compose.yml. Move all credentials to .env interpolation (DB_PASSWORD is now required, no default) and add .env.example with a placeholder. .env is already gitignored.
1 parent 2447cb5 commit 615f491

2 files changed

Lines changed: 32 additions & 10 deletions

File tree

.env.example

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Issue #600: local serverless DB multiplexing (docker-compose).
2+
# Copy to .env and set a real value for DB_PASSWORD. Never commit .env.
3+
#
4+
# cp .env.example .env
5+
6+
# Database / PgBouncer credentials (used by docker-compose.yml)
7+
DB_NAME=subtrackr
8+
DB_USER=subtrackr_app
9+
DB_PASSWORD=change-me
10+
11+
# Serverless pool target (point the app at PgBouncer, not Postgres directly)
12+
DB_PROXY_HOST=localhost
13+
DB_PROXY_PORT=6432
14+
DB_PROXY_AUTH_MODE=scram-256
15+
DB_PROXY_TXN_POOLING=true
16+
DB_PROXY_PREPARED_STATEMENTS=true
17+
DB_PROXY_MAX_CONN=50
18+
DB_LEAK_THRESHOLD_MS=30000

docker-compose.yml

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,29 @@
55
#
66
# App / serverless handlers -> PgBouncer :6432 -> PostgreSQL :5432
77
#
8+
# Credentials are read from a local .env file (see .env.example) — never
9+
# hardcoded here. Copy .env.example to .env and set DB_PASSWORD before running:
10+
# cp .env.example .env && docker compose up
11+
#
812
# Point the app at the proxy:
9-
# DB_PROXY_HOST=localhost DB_PROXY_PORT=6432
10-
# DB_PROXY_AUTH_MODE=scram-256 DB_USER=subtrackr_app DB_PASSWORD=subtrackr
13+
# DB_PROXY_HOST=localhost DB_PROXY_PORT=6432 DB_PROXY_AUTH_MODE=scram-256
1114
version: "3.9"
1215

1316
services:
1417
postgres:
1518
image: postgres:16-alpine
1619
environment:
17-
POSTGRES_DB: subtrackr
18-
POSTGRES_USER: subtrackr_app
19-
POSTGRES_PASSWORD: subtrackr
20+
POSTGRES_DB: ${DB_NAME:-subtrackr}
21+
POSTGRES_USER: ${DB_USER:-subtrackr_app}
22+
POSTGRES_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD in .env}
2023
# SCRAM-SHA-256 so PgBouncer auth matches production.
2124
POSTGRES_INITDB_ARGS: "--auth-host=scram-sha-256"
2225
ports:
2326
- "5432:5432"
2427
volumes:
2528
- pgdata:/var/lib/postgresql/data
2629
healthcheck:
27-
test: ["CMD-SHELL", "pg_isready -U subtrackr_app -d subtrackr"]
30+
test: ["CMD-SHELL", "pg_isready -U ${DB_USER:-subtrackr_app} -d ${DB_NAME:-subtrackr}"]
2831
interval: 5s
2932
timeout: 3s
3033
retries: 10
@@ -34,12 +37,13 @@ services:
3437
depends_on:
3538
postgres:
3639
condition: service_healthy
40+
# DB_USER / DB_PASSWORD / DB_NAME interpolated from .env (see below).
3741
environment:
3842
DB_HOST: postgres
3943
DB_PORT: "5432"
40-
DB_USER: subtrackr_app
41-
DB_PASSWORD: subtrackr
42-
DB_NAME: subtrackr
44+
DB_USER: ${DB_USER:-subtrackr_app}
45+
DB_PASSWORD: ${DB_PASSWORD:?set DB_PASSWORD in .env}
46+
DB_NAME: ${DB_NAME:-subtrackr}
4347
# Transaction pooling: small server pool fans out to many clients.
4448
POOL_MODE: transaction
4549
AUTH_TYPE: scram-sha-256
@@ -55,7 +59,7 @@ services:
5559
ports:
5660
- "6432:6432"
5761
healthcheck:
58-
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 6432 -U subtrackr_app"]
62+
test: ["CMD-SHELL", "pg_isready -h 127.0.0.1 -p 6432 -U ${DB_USER:-subtrackr_app}"]
5963
interval: 5s
6064
timeout: 3s
6165
retries: 10

0 commit comments

Comments
 (0)