dataiotech Labs
dbaguidedbaguideDBAdataxtoolsdataopsphere
Scripts Library/postgresql/#18
Script #18
postgresql
Securityread-only (pg_hba için superuser)Min Version: 10

PostgreSQL Privileged Roles and Insecure pg_hba Rules

Lists superusers and high-privilege roles plus 'trust' or weak authentication rules. A quick start for security audits and hardening.

#roles#superuser#pg_hba#hardening
postgresql · sql
SELECT rolname, rolsuper, rolcreaterole, rolcreatedb, rolreplication, rolbypassrls, rolcanlogin, rolvaliduntil
FROM pg_roles
WHERE rolsuper OR rolcreaterole OR rolreplication OR rolbypassrls
ORDER BY rolsuper DESC, rolname;

SELECT line_number, type, database, user_name, address, auth_method
FROM pg_hba_file_rules
WHERE auth_method IN ('trust','password','md5')
ORDER BY line_number;
Operational Notes & Remediation Guidance

Review `trust` or overly broad CIDR rules (`0.0.0.0/0`) in `pg_hba.conf` and restrict superuser privileges.

Production Safety & Execution Standards
  • This script is designed for read-only diagnostics; it does not alter schema or modify data directly.
  • Prior to executing on production systems under high load, verify the target database version (Min. Version: 10).
  • Exercise caution with mutating actions (e.g., terminating sessions or dropping indexes) referenced in the notes section.