feat(ops): script to rotate PostgreSQL password safely
Add rotate-postgres-password.sh with optional app role, document the procedure, and stop defaulting production POSTGRES_PASSWORD to postgres. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -57,4 +57,4 @@ Optional später: `analytics.kapteins-daagbok.eu` als Alias auf dieselbe Plausib
|
||||
|
||||
## Docker Compose
|
||||
|
||||
Keine Default-Passwörter in Produktion: `POSTGRES_PASSWORD` und `SESSION_SECRET` in `.env` setzen (siehe [`.env.example`](../../.env.example)).
|
||||
Keine Default-Passwörter in Produktion: starkes `POSTGRES_PASSWORD` (siehe [postgres-password.md](postgres-password.md)) und `SESSION_SECRET` in `.env` setzen (siehe [`.env.example`](../../.env.example)).
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
# PostgreSQL absichern (Produktion)
|
||||
|
||||
## Ist-Zustand
|
||||
|
||||
- Die Datenbank läuft im Container `daagbox-prod-db` **ohne** Host-Port (nur Docker-Netz `db:5432`) — gut.
|
||||
- Das Passwort wird beim **ersten** Start des Volumes gesetzt; ein späteres Ändern nur von `POSTGRES_PASSWORD` in `.env` **ändert nicht** das laufende Passwort.
|
||||
- Nach Sprint 1 war auf dem Server noch das Legacy-Passwort `postgres` möglich → per Skript rotieren.
|
||||
|
||||
## Empfohlene Schritte
|
||||
|
||||
1. **Backup/Snapshot** (hast du laut Vorgabe).
|
||||
2. Auf dem Server im Repo:
|
||||
```bash
|
||||
cd /opt/kapteins-daagbok
|
||||
git pull
|
||||
chmod +x scripts/rotate-postgres-password.sh
|
||||
./scripts/rotate-postgres-password.sh
|
||||
```
|
||||
3. Inhalt von `.postgres-credentials.<timestamp>` in den Passwort-Manager übernehmen, Datei auf dem Server löschen:
|
||||
```bash
|
||||
shred -u .postgres-credentials.* # oder rm nach manuellem Notieren
|
||||
```
|
||||
|
||||
### Optional: eigener App-Benutzer (statt `postgres` für Prisma)
|
||||
|
||||
```bash
|
||||
./scripts/rotate-postgres-password.sh --app-user daagbok
|
||||
```
|
||||
|
||||
- **`daagbok`**: Login für Backend/Prisma (kein Superuser)
|
||||
- **`postgres`**: nur noch Admin (Passwort in `POSTGRES_ADMIN_PASSWORD` in `.env`)
|
||||
|
||||
## Lokale Entwicklung
|
||||
|
||||
`scripts/start-dev.sh` nutzt weiterhin `postgres/postgres` auf localhost — nur für Dev. Produktion nie dieses Passwort wiederverwenden.
|
||||
|
||||
## Verifikation
|
||||
|
||||
```bash
|
||||
docker exec daagbox-prod-backend wget -qO- http://127.0.0.1:5000/api/health
|
||||
curl -sf https://kapteins-daagbok.eu/api/health
|
||||
```
|
||||
Reference in New Issue
Block a user