Skip to content

feat(pgsql): add pg_cert_extra_san for extra server cert SANs - #802

Closed
tpmckenzie wants to merge 1 commit into
pgsty:mainfrom
tpmckenzie:feat/pg-cert-extra-san
Closed

tpmckenzie wants to merge 1 commit into
pgsty:mainfrom
tpmckenzie:feat/pg-cert-extra-san

Conversation

@tpmckenzie

Copy link
Copy Markdown

What

Adds an optional pg_cert_extra_san list (default []) whose entries are appended to the subjectAltName of every PostgreSQL server certificate that pg_cert_issue generates.

pg-meta:
  vars:
    pg_cert_extra_san: [ 'DNS:db.example.com' ]     # cluster-wide
  hosts:
    10.10.10.10: { pg_seq: 1, pg_role: primary, pg_cert_extra_san: [ 'DNS:db.example.com', 'IP:100.64.0.10' ] }  # per host

Why

We point clients (Cloudflare Hyperdrive with sslmode=verify-full) at a DNS name that a Patroni callback moves to the current primary. That name is neither <cluster> nor <cluster><pg_dns_suffix>, so it needs to be in each member's certificate. Two things block doing that by hand today:

  • pg_cert_copy replaces /pg/cert/server.crt whenever its content differs from the generated one, not only when it is missing, so a hand-issued cert is lost on the next pg_cert/pgsql.yml run.
  • Putting a hand-made cert into files/pki/pgsql/ does not help either: pg_cert_issue regenerates it from the CSR and drops the extra names.

The same list is handy for an extra address (for example a Tailscale IP that Patroni's REST connect_address uses once patroni_ssl_enabled is on).

Testing

On v4.6.0 (Debian 12, 3-node cluster): with the list set, ./pgsql.yml -t pg_cert reissued all members' certs signed by the existing CA with the extra names, patronictl reload plus systemctl reload pgbouncer picked them up, and openssl s_client -starttls postgres -verify_hostname <name> returned 0 (ok) on 5432 and 6432. With the default [], the generated SAN list is unchanged.

Not included

files/cmdb.sql registers parameters with hand-assigned ids, so I left that entry (and the pigsty.io parameter docs) for you. Happy to add them if you tell me the id to use.

Clients that connect with sslmode=verify-full through a name other
than <cluster><pg_dns_suffix> (for example a DNS record that follows
the primary on failover) need that name in every member's certificate.
pg_cert reissues certificates whenever their content differs, so a
hand-issued certificate does not survive the next run. The new list is
appended to the generated subjectAltName and defaults to empty.
@tpmckenzie tpmckenzie closed this Nov 29, 2026
@tpmckenzie
tpmckenzie deleted the feat/pg-cert-extra-san branch November 29, 2026 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant