Proposal: Supporting URI SAN in Certificate Authentication - #399
pg-hub-mirror[bot] wants to merge 1 commit into
Conversation
Allow certificate authentication to use a URI subject alternative name as the client identity via clientname=URI in pg_hba.conf. URI SANs are extracted from the client certificate during TLS setup and stored on the Port, alongside the existing CN and DN. Following the SPIFFE X.509-SVID specification, authentication requires the certificate to carry exactly one URI SAN: the username is matched against it, and the matched URI, rather than the Subject DN, becomes the authenticated identity recorded in the connection log. Client certificates with an empty subject are now accepted as long as a URI SAN is present.clientname=CN and clientname=DN still reject such certificates, since there is no name to compare. The documentation describes clientname=URI, including the single URI SAN requirement and the caveat that, for SPIFFE deployments, ssl_ca_file should hold a single trust domain's CA bundle. TAP coverage is added for URI SAN matching: success with a single URI SAN (identity logged as the URI), rejection when the certificate has no URI SAN, rejection with multiple URI SANs, and success with an empty-subject certificate.
|
Jacob Champion <jacob(dot)champion(at)enterprisedb(dot)com> via pgsql-hackers · original email On Thu, Sep 17, 2026 at 3:10 AM Florin Irion <irionr(at)gmail(dot)com> wrote:
Looks like this was cut off?
|
pgsql-hackersa3335e80-c032-493b-83f6-de1d658e6489@gmail.comPatch files:
Hi
Here is the first version of the patch to support URI SAN in certificate
authentication (clientname=URI in pg_hba.conf). We can start a discussion
on the actual code now.The patch can also be reviewed on my “postgres”
project fork [1].
Together with Leonardo Cecchi, CloudNativePG (CNPG) maintainer, we also
tested the patch using the cnpg-i-spiffe plugin[2] that he wrote for the
occasion and the generated container image for CloudNativePG [3]. Everything
worked smoothly, and workloads can now authenticate natively with SPIFFE
IDs.
Given that both CloudNativePG and SPIFFE/SPIRE are CNCF projects, we
contacted
Agustín Martínez Fayó, a SPIRE maintainer, to verify the integration between
the two projects and to begin collaborating on the topic. We decided to
strictly allow only a single URI SAN per certificate. This follows the
X509-SVID spec, avoiding weird edge cases with user mapping, and making
connection logging very clear.
Cheers,
Florin
[1] - irionr#7
[2] - https://github.com/leonardoce/cnpg-i-spiffe
[3] -
https://github.com/leonardoce/postgres-trunk-containers/actions/runs/35070429177