Pcornel
Databases

Database Security

Cheat sheet · https://pcornel.dk/topic.php?topic=6096

Back to the Topic

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 topic
  • psql -c "SELECT now(), version();" — PostgreSQL reachable and version
  • mysql -e "SELECT NOW(), VERSION();" — MariaDB/MySQL reachable and version
  • sqlcmd -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

BoundaryInspectHealthy interpretationDo not infer
IntentAuthenticationIntended object/scope is explicit and versioned where relevantIntent is already effective
Owning runtime/control planeLeast privilege / Roles/grantsOwner accepts and reports the expected object stateDownstream dependencies are healthy
Effective stateTLS transportIndependent read-back matches the intended stateEvery client sees the same result
Consumer outcomeCredential/secret handling boundariesThe original bounded check succeeds in the same time windowProduction 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

Confirmation

Confirm action

Continue?