Lion Cipher Lab

Harden a PostgreSQL database on your own machine

Why it matters

Almost every application you use is really a thin layer in front of a DATABASE -- a program whose whole job is to store and hand back data (accounts, messages, orders, health records) in an organized way. PostgreSQL is one of the most widely used open-source databases in the world, running behind countless companies' apps. Here is the uncomfortable truth about database security: a huge share of real-world data breaches are not clever code exploits at all -- they are databases that were left wide open. A database reachable from the whole internet, protected by a default or blank password, or…

What you'll learn

Steps in this lab

  1. First: what a database is, why it is a target, and the one safety rule
  2. Get PostgreSQL running (from nothing) -- pick one path
  3. Open a terminal, connect with psql, and meet the 'postgres' superuser
  4. Strong authentication: scram-sha-256 in pg_hba.conf (and never 'trust')
  5. Least privilege: revoke PUBLIC's default access and build a limited app role
  6. Shrink the network surface: listen_addresses
  7. Encrypt connections in transit: turn on TLS
  8. Turn on logging and auditing: log_connections, failed logins, and pgAudit
  9. PROVE it: try an over-privileged action as the limited role and watch it get denied
  10. Clean up, make it a habit, and where to take this next

Open the full interactive lab →