VALID UNTIL password expiry versus client-certificate expiry for PostgreSQL role credentials
0 reputation · 09 Jan 2021, 11:21 UTC
0 reputation · 09 Jan 2021, 11:21 UTC
I want to choose a single credential‑expiry mechanism for application roles that follows least‑privilege principles, so that expiry behaves predictably and cannot be sidestepped by other authentication methods.
PostgreSQL’s VALID UNTIL timestamp only blocks password‑based logins; it is ignored for cert, peer, trust and similar methods, allowing a role with an expired password to connect if pg_hba.conf permits those methods. Conversely, client‑certificate authentication enforces expiry during the TLS handshake but does not affect the stored SCRAM or MD5 verifier, so a valid certificate can be used with an expired password. The two paths therefore do not compose, and an expired password does not lock the role or trigger a self‑service reset because \password requires an already‑authenticated session.
VALID UNTIL, what pg_hba.conf ordering or restrictions are needed to prevent non‑password methods from bypassing the expiry check?34775 reputation · 09 Jan 2021, 13:45 UTC
PostgreSQL does not provide a single configuration or SQL feature that makes VALID UNTIL and client-certificate expiry compose for one role. The two authentication paths are orthogonal: VALID UNTIL only blocks password-based logins (SCRAM‑SHA‑256, MD5), while certificate expiry is enforced by the TLS handshake and is unknown to PostgreSQL’s password verifier.
No documented way exists to make them act together for a single role. If you need password expiry, you must rely on VALID UNTIL; if you need certificate-based expiry, you manage that through your PKI/TLS infrastructure. Choosing one mechanism per role—and documenting the choice—is the supported approach.
VALID UNTILTo prevent non‑password methods from bypassing the expiry check, pg_hba.conf must admit only password-auth methods (scram-sha-256, md5, or password). Example ordering:
# Password methods first; later rules must not allow cert/peer/trust host all all all scram-sha-256 host all all all cert
Placing password rules before cert rules reduces the chance that a cert-authenticated session bypasses VALID UNTIL, but this restriction applies globally per database/user, not per‑role. Restricting to password‑only methods may lock out users who legitimately authenticate via client certificates for the same role.
A role with an expired password cannot self‑reset because \password requires an already‑authenticated session. PostgreSQL does not expose certificate validity state in pg_authid or ALTER ROLE, so certificate renewal is an external PKI operation. If you grant CREATEROLE, a role can reset another role’s password, but only if it already has an authenticated session—and even then, the reset succeeds only if the target role’s VALID UNTIL has not already blocked the connection.
Delegated password reset without any authenticated session is not natively supported.
VALID UNTIL: CREATE ROLE test_role VALID UNTIL '2000-01-01';cert, because VALID UNTIL is ignored.sudo -u postgres psql -c 'SHOW hba_file;' && pg_ctl reloadopenssl x509 -in client.crt -noout -datesMissing diagnostic detail: Which PostgreSQL version are you running, and does your deployment actually use client‑certificate authentication for the roles in question? The answer about pg_hba.conf restrictions and recovery options depends on the auth methods in active use.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.