Track 09 · Lesson 5 of 9Shipping safely
Servers, ports and firewalls
Lesson 5 of 9· 7 min
A server listens on an address and a port. 127.0.0.1 means “only this machine”; 0.0.0.0 means “every network, including the internet”. One flag decides whether your database is private.
Scan your own server
Change how each container is published
# docker-compose.yml (nginx and sshd run on the host)
services:
app:
ports: ["3000:3000"] # 0.0.0.0
db:
ports: ["5432:5432"] # 0.0.0.0
redis:
ports: ["6379:6379"] # 0.0.0.0The Docker trap#
docker run -p 5432:5432 publishes on 0.0.0.0. Docker inserts its own firewall rules for published ports, and they run before ufw’s, so a port you denied in ufw can still be wide open. Publish only to 127.0.0.1 (or not at all, and let containers talk over a Docker network), and check with a scan from outside, not from the server itself.
Deploy scripts leak too#
A deploy script
Who can see each secret?
deploy.sh, run by CI
ssh -o StrictHostKeyChecking=no deploy@prod.example.com <<'SH'
docker login -u ci -p "$REGISTRY_TOKEN" ghcr.io
docker pull ghcr.io/acme/app:build-42
docker run -d -e DB_PASSWORD="$DB_PASSWORD" ghcr.io/acme/app:build-42
SH$ ps aux (any user on the server)
docker login -u ci -p ghp_R3g1stryT0ken ghcr.io
docker run -d -e DB_PASSWORD=Pr0dDbP4ss ghcr.io/acme/app:build-42$ docker inspect app (anyone with Docker access)
"Env": ["DB_PASSWORD=Pr0dDbP4ss", …]StrictHostKeyChecking=nolets anyone who can intercept the connection pose as your server. Pin the host key.docker login -panddocker run -e SECRET=…put secrets in the process list and shell history. Use--password-stdin, and an env file owned by root with mode 600, or Docker secrets.
In a code review
MediumDevOpsDeploy scripts that expose secrets
Fix: Pin host keys, use --password-stdin, pass secrets via a root-owned 600 env file or Docker secrets.
0 of 3 checked
Check yourself