Chapter 14: Incident response¶
14.1 First 15 minutes: do NOT¶
Caution
- ❌ restart,
down/up, or reconfigure the suspicious database/container (H8, H16) - ❌ delete files or volumes
- ❌ "clean up" before copying evidence
14.2 Collect evidence (self-hosted container example)¶
mkdir -p ~/incident && cd ~/incident
docker logs <db> > db.log 2>&1
docker top <db> > top.txt
docker diff <db> > diff.txt
docker exec <db> cat /var/lib/postgresql/data/pg_hba.conf > pg_hba.conf
docker exec <db> cat /var/lib/postgresql/data/postgresql.auto.conf > postgresql.auto.conf
docker exec <db> psql -U postgres -c '\du' > roles.txt
docker stop <db> # stops attacker processes
docker export <db> | gzip > container_fs.tar.gz
sudo tar czf volume.tar.gz -C /var/lib/docker/volumes/<volume> _data && sudo chown "$USER" volume.tar.gz
sha256sum * > SHA256SUMS
Copy off the server (scp -r), verify with sha256sum -c SHA256SUMS. The archives contain malware and personal data: never extract/run them casually; store encrypted. If something gets deleted by mistake, re-collect from the (stopped) container; note it honestly in your records.
For RDS: download all error/postgresql.log.* files immediately (3-day retention; use CloudShell + AWS CLI to get them all), and export CloudTrail events.
14.3 Contain¶
- Close the network path first (security group change: add-verify-remove, Chapter 5.3).
- Block attacker IPs (
iptables -I DOCKER-USER -d <ip> -j DROP, VPC network ACL deny). - Rotate every credential the attacker could have seen.
14.4 Investigate¶
- Timeline from logs: first failed logins, first
PROGRAMuse, role creation, config reloads (received SIGHUP). - Indicators: unknown roles,
COPY … PROGRAM,ALTER SYSTEM,archive_command, hidden files (.gs_*,.temp*), processes named like system processes (init,kworker) with high CPU, cron jobs, connections to unknown IPs. - Check other environments: clones, shared passwords, shared networks.
- Decide on breach notification early (GDPR: 72 hours from discovery).
14.5 Recover¶
- Rebuild, don't clean: fresh volume or instance, hardened configuration.
- Restore from a backup taken before the compromise, or salvage data only (dump
publicschema, strip functions/triggers/unknown tables, review admin accounts and scheduled tasks) in an isolated container with no network and archiving forced off. - Invalidate sessions/tokens; consider forcing password resets.
- Run Chapter 11 in full.
14.6 Learn¶
Write down: what happened, how it happened, what you changed, what you'll check from now on. Add new hazards to Chapter 3.