Configuring the pg_hba Client Authentication Whitelist
Overview
PostgreSQL client authentication is controlled by pg_hba.conf. In a cluster
managed by the PostgreSQL Operator, this file is rendered and managed by
Patroni — editing pg_hba.conf inside the container has no effect because
Patroni overwrites it. Instead, declare the rules in the postgresql custom
resource under spec.patroni.pg_hba, and the Operator/Patroni will apply and
reload them.
Prerequisites
- A running PostgreSQL cluster managed by the PostgreSQL Operator.
- Permission to edit the
postgresqlcustom resource.
Procedure
1. Locate the custom resource
2. Set the pg_hba rules
Edit the postgresql resource and add the whitelist under spec.patroni.pg_hba.
Keep the internal Patroni/replication entries, and append your own rules. Order
matters — the first matching rule wins.
Apply with kubectl apply / kubectl edit. Patroni reloads the configuration
without a database restart.
host all all 0.0.0.0/0 md5 (and its IPv6 form ::0/0) allow unencrypted
password authentication from any address, exposing credentials to network
sniffing. Prefer the hostssl ... md5 rules and require clients to use SSL.
Only add the plain host catch-all rules when a client genuinely cannot use
SSL — see
Connection fails with "SSL off".
3. Verify
The output should reflect the rules you declared. pg_hba_file_rules also
reports parse errors in the error column if a rule is malformed.
Notes
- Prefer
hostssl ... md5over plainhost ... md5when exposing the database beyond the cluster, so that credentials are not sent over an unencrypted connection. See also Connection fails with "SSL off". +zalandosis an internal role group used by the Operator; do not remove the+zalandoslines or internal components may lose access.