Allow matching the DN of a client certificate for authentication
authorAndrew Dunstan <[email protected]>
Mon, 29 Mar 2021 19:31:22 +0000 (15:31 -0400)
committerAndrew Dunstan <[email protected]>
Mon, 29 Mar 2021 19:49:39 +0000 (15:49 -0400)
commit6d7a6feac48b1970c4cd127ee65d4c487acbb5e9
tree8728162431269b3ae654eddb1d3a8e1c99972ec3
parentefcc7572f532ea564fedc6359c2df43045ee7908
Allow matching the DN of a client certificate for authentication

Currently we only recognize the Common Name (CN) of a certificate's
subject to be matched against the user name. Thus certificates with
subjects '/OU=eng/CN=fred' and '/OU=sales/CN=fred' will have the same
connection rights. This patch provides an option to match the whole
Distinguished Name (DN) instead of just the CN. On any hba line using
client certificate identity, there is an option 'clientname' which can
have values of 'DN' or 'CN'. The default is 'CN', the current procedure.

The DN is matched against the RFC2253 formatted DN, which looks like
'CN=fred,OU=eng'.

This facility of probably best used in conjunction with an ident map.

Discussion: https://postgr.es/m/92e70110-9273-d93c-5913-0bccb6562740@dunslane.net

Reviewed-By: Michael Paquier, Daniel Gustafsson, Jacob Champion
13 files changed:
doc/src/sgml/client-auth.sgml
src/backend/libpq/auth.c
src/backend/libpq/be-secure-openssl.c
src/backend/libpq/be-secure.c
src/backend/libpq/hba.c
src/include/libpq/hba.h
src/include/libpq/libpq-be.h
src/test/ssl/Makefile
src/test/ssl/client-dn.config [new file with mode: 0644]
src/test/ssl/ssl/client-dn.crt [new file with mode: 0644]
src/test/ssl/ssl/client-dn.key [new file with mode: 0644]
src/test/ssl/t/001_ssltests.pl
src/test/ssl/t/SSLServer.pm