games_app/deploy/vps-hardening/allow-docker-pg.sh
Your Name 5ce6a6811a
Some checks failed
CI / test-and-build (push) Failing after 25s
Add Gitea CI/CD stack, tloto-deploy, and tagged Compose images
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-11-17 19:56:39 +02:00

27 lines
966 B
Bash

#!/usr/bin/env bash
# UFW: allow Docker bridges → host Postgres only (not public internet).
set -euo pipefail
cd ~/games_app
sudo ufw allow from 172.16.0.0/12 to any port 5432 proto tcp comment 'Docker to Postgres'
sudo ufw allow from 192.168.0.0/16 to any port 5432 proto tcp comment 'Docker bridge alt'
# Also accept on docker bridges by interface (covers hairpin edge cases)
sudo ufw allow in on docker0 to any port 5432 proto tcp comment 'docker0 to PG' || true
sudo ufw status numbered | head -40
PGPASS=$(python3 - <<'PY'
import re
from pathlib import Path
m=re.search(r'^POSTGRES_PASSWORD=(.*)$', Path('.env').read_text(), re.M)
print(m.group(1).strip() if m else '')
PY
)
export PGPASSWORD="$PGPASS"
echo "Docker→PG test:"
sudo docker run --rm --add-host=host.docker.internal:host-gateway \
-e PGPASSWORD="$PGPASS" postgres:16-alpine \
psql -h host.docker.internal -U postgres -d games_platform_db -c 'SELECT 1 AS docker_ok;'
echo "DOCKER_PG_OK"