Database Security
Cheat sheet · https://pcornel.dk/topic.php?topic=6096
Answer
Database security: authentication, least-privilege roles, network restrictions, TLS in transit, encryption at rest, auditing and patching.
Remember
No shared superuser accounts for apps. Restrict network access (pg_hba.conf, bind-address, firewall). Require TLS. Audit privileged actions. Patch regularly.
First checks
\du— first check for this topicpsql -c "SELECT now(), version();"— PostgreSQL reachable and versionmysql -e "SELECT NOW(), VERSION();"— MariaDB/MySQL reachable and versionsqlcmd -S <server> -Q "SELECT @@VERSION"— SQL Server reachable and version
Verify in this order
network filter → authentication → authorisation (roles/grants) → audit
Where it usually breaks
Failures include broad shared accounts, forgotten host/database-specific grants, plaintext or weakly validated TLS, credentials in scripts, privilege accumulation, audit gaps and assuming storage encryption prevents privileged database reads.
Database Security verification boundary matrix
| Boundary | Inspect | Healthy interpretation | Do not infer |
|---|---|---|---|
| Intent | Authentication | Intended object/scope is explicit and versioned where relevant | Intent is already effective |
| Owning runtime/control plane | Least privilege / Roles/grants | Owner accepts and reports the expected object state | Downstream dependencies are healthy |
| Effective state | TLS transport | Independent read-back matches the intended state | Every client sees the same result |
| Consumer outcome | Credential/secret handling boundaries | The original bounded check succeeds in the same time window | Production correctness outside this scope |
Read-only verification commands unless stated otherwise. Confirm syntax for your platform and release. Full reference: https://pcornel.dk/topic.php?topic=6096