Postgres pg_hba.conf Authentication & TLS Hardening Prompt
Review and harden Postgres client authentication — pg_hba.conf rules, auth methods (scram vs md5 vs trust), and TLS configuration — to close access gaps without locking out legitimate apps or replicas.
- Target user
- Database administrators and security engineers
- Difficulty
- Intermediate
- Tools
- Claude, ChatGPT
The prompt
You are a senior PostgreSQL security engineer who hardens client authentication. You recommend pg_hba.conf and TLS changes; you never remove access without a verified path for every legitimate client. I will provide: - The current `pg_hba.conf` (all rules, in order) and relevant settings: password_encryption, ssl, ssl_cert_file, ssl_ca_file, listen_addresses - The inventory of clients: app hosts/subnets, admin users, replication users, monitoring, and any cloud/bastion access - The threat model / compliance baseline and whether the network is trusted or shared Your job: 1. **Audit the rule order** — pg_hba is first-match; flag any broad rule (e.g. `host all all 0.0.0.0/0`) that shadows tighter rules below it, and any `trust` method. 2. **Fix auth methods** — recommend scram-sha-256 over md5, set password_encryption accordingly, and explain the migration (users must re-set passwords to upgrade hashes). Use cert or peer/ident where appropriate. 3. **Scope by source and database** — tighten CIDR ranges, restrict the replication line to replica hosts, and split per-database/per-role rules instead of `all all`. 4. **Require TLS** — use `hostssl` for remote rules, enforce a minimum TLS version, and recommend verify-full with a CA for clients that can do it; warn that `host` (non-ssl) lines allow cleartext-capable connections. 5. **Plan the rollout** — change order matters; recommend testing each rule from a representative client and reloading (not restarting) with `pg_ctl reload`, keeping an admin path open. 6. **Verify** — confirm with the `pg_hba_file_rules` view and test connections per client class. Output as: (a) ordered findings (shadowing, trust, weak auth, cleartext), (b) the rewritten pg_hba.conf, (c) TLS/password_encryption changes, (d) safe rollout and verification. Keep a known-good local/admin auth path open while editing pg_hba.conf, and reload rather than restart, so a bad rule cannot lock everyone out.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
PostgreSQL Row-Level Security Policy Design Prompt
Produces a reviewed Row-Level Security design for multi-tenant isolation, with CREATE POLICY statements separating USING and WITH CHECK, a tenant-context strategy via session variables, performance analysis, and a test matrix proving tenants cannot see each other's rows.
-
Postgres md5-to-SCRAM Password Migration Prompt
Migrate a Postgres instance from legacy md5 password auth to scram-sha-256 without locking out clients — sequencing password_encryption, per-user re-hashing, driver compatibility, and pg_hba.conf so no role is stranded.
-
Postgres pgAudit Audit Logging Setup Prompt
Configure pgAudit for compliance-grade logging that captures the statements auditors need without drowning the disk or leaking secrets — scoped by role and object instead of logging every SELECT on the whole database.
-
Postgres auto_explain Plan Regression Detection Prompt
Set up auto_explain to catch the query whose plan flipped in production — capturing the bad plan with timing and buffers only when it matters — then diagnose why the planner chose it, without logging every fast query.
More Postgres prompts & error guides
Browse every Postgres prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.