Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8I3l-00049r-8K for pgsql-admin@arkaria.postgresql.org; Thu, 22 Dec 2022 09:40:17 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1p8I3k-0006re-4e for pgsql-admin@arkaria.postgresql.org; Thu, 22 Dec 2022 09:40:16 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8I3j-0006rU-M4 for pgsql-admin@lists.postgresql.org; Thu, 22 Dec 2022 09:40:15 +0000 Received: from jakobs.com ([85.214.83.89] helo=rs.plausibolo.de) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1p8I3c-0002fX-Ck for pgsql-admin@lists.postgresql.org; Thu, 22 Dec 2022 09:40:14 +0000 Received: from localhost (localhost [127.0.0.1]) by rs.plausibolo.de (Postfix) with ESMTP id 553A23801F4; Thu, 22 Dec 2022 10:40:05 +0100 (CET) Received: from rs.plausibolo.de ([127.0.0.1]) by localhost (h2367442.stratoserver.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2zDq8RvUmola; Thu, 22 Dec 2022 10:40:05 +0100 (CET) Received: from [192.168.171.86] (dynamic-046-114-004-028.46.114.pool.telefonica.de [46.114.4.28]) by rs.plausibolo.de (Postfix) with ESMTPSA id DC6AA380116; Thu, 22 Dec 2022 10:40:04 +0100 (CET) Message-ID: <05afcadd-0e31-751c-c915-cb27e6bf5a5b@jakobs.com> Date: Thu, 22 Dec 2022 10:40:04 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.0 To: pgsql-admin@lists.postgresql.org References: From: Holger Jakobs Subject: Re: Facing issue with cert authentication In-Reply-To: Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------cKPxezC5wTkw0L6sdmyf8Drq" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk This is an OpenPGP/MIME signed message (RFC 4880 and 3156) --------------cKPxezC5wTkw0L6sdmyf8Drq Content-Type: multipart/mixed; boundary="------------cO5du4LAouU009n08DJbfyN2"; protected-headers="v1" From: Holger Jakobs To: pgsql-admin@lists.postgresql.org Message-ID: <05afcadd-0e31-751c-c915-cb27e6bf5a5b@jakobs.com> Subject: Re: Facing issue with cert authentication References: In-Reply-To: --------------cO5du4LAouU009n08DJbfyN2 Content-Type: multipart/alternative; boundary="------------XxOsZviYtCXspDmVujW1fq17" --------------XxOsZviYtCXspDmVujW1fq17 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: base64 QW0gMjIuMTIuMjIgdW0gMDU6MjUgc2NocmllYiBEaGlyZW5kcmEgU2luZ2g6DQo+IEhpIEFs bCwNCj4gSSBhbSB1c2luZyBjZXJ0IGF1dGhlbnRpY2F0aW9uIHRvIGF1dGhlbnRpY2F0ZS4N Cj4gSSBoYXZlIGNyZWF0ZWQgYSB1c2VyIHdpdGggbmFtZSBTMTE0NTQ2ICh3aXRoIHVwcGVy Y2FzZSAnUycpLiB1c2VyIA0KPiBjcmVhdGVkIGlzIHMxMTQ1NDYgKHdpdGggbG93ZXJjYXNl ICdzJykuDQo+IENOIGluIHRoZSBjbGllbnQgY2VydGlmaWNhdGUgaXMgInBnLXJlYWQgKFMx MTQ1NDYpIi4gJ1MnIGluIFMxMTQ1NDYgaXMgDQo+IHVwcGVyY2FzZS4gSSBoYXZlIG5vIGNv bnRyb2wgdG8gaGF2ZSB0aGUgJ1MnIGluIHRoZSBDTiBpbiBsb3dlcmNhc2UuIA0KPiBNeSBv cmdhb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2x2ZSB0aGlzIGlzc3VlID8NCj4gSSBjYW4gY3JlYXRlIHRoZSB1c2VyIHdpdGggdXBw ZXJjYXNlICdTJyBieSBkb3VibGUgcXVvdGluZyB0aGUgDQo+IHVzZXJuYW1lLiBidXQgdGhl IHNjcmlwdCB3aGljaCBjcmVhdGVzIHRoZSB1c2VyIHdpbGwgZG8gdGhlIHNhbWUgZm9yIA0K PiBhbGwgdXNlcnMgd2hpY2ggaSBkbyBub3Qgd2FudC4NCj4NCj4gVGhhbmtzLA0KPiBEaGly ZW5kcmEuDQoNCg0KQ2FuIHlvdSB0cnk6DQoNCnBzcWwgImhvc3Q9cG9zdGdyZXMuYXBwLm5l dCA8aHR0cDovL3Bvc3RncmVzLmFwcC5uZXQ+IHVzZXI9XCJTMTE0NTQ2XCIgDQpkYm5hbWU9 YXBwZGIgc3NsbW9kZT12ZXJpZnktZnVsbCBzc2xjZXJ0PWNlcnQucGVtIHNzbGtleT1jZXJ0 LWtleS5wZW0gDQpzc2xyb290Y2VydD10bHMtY2EtYnVuZGxlLnBlbSINCg0KVGhpcyBzaG91 bGQga2VlcCB0aGUgdXNlciBuYW1lIGluIHVwcGVyIGNhc2UuIFdpdGhvdXQgcXVvdGVzICh3 aGljaCBoYXZlIA0KdG8gYmUgcHJvdGVjdGVkIGJ5IGEgcHJlY2VkaW5nIGJhY2tzbGFzaCwg YmVjYXVzZSB0aGUgd2hvbGUgY29ubmluZm8gaXMgDQphbHJlYWR5IGluIHF1b3RlcykgdGhl IG5hbWUgd2lsbCBiZSBmb2xkZWQgdG8gbG93ZXIgY2FzZS4NCg0KQmVzdCBSZWdhcmRzLA0K DQpIb2xnZXINCg0KLS0gDQpIb2xnZXIgSmFrb2JzLCBCZXJnaXNjaCBHbGFkYmFjaCwgVGVs LiArNDktMTc4LTk3NTkwMTINCg0K --------------XxOsZviYtCXspDmVujW1fq17 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Am 22.12.22 um 05:25 schrieb Dhirendra= Singh:
Hi All,
I am using cert authentication to authenticate.
I have created a user with name S114546 (with uppercase 'S'). user created is s114546 (with lowercase 's').
CN in the client certificate is "pg-read (S114546)". 'S' in S114546 is uppercase. I have no control to have the 'S' in the CN in lowercase. My organization PKI always create the certificate with uppercase 'S'.
I extracted the string S114546 from the CN using regex in the pg_ident.conf file.
cert-cn-map =C2=A0 =C2=A0 /^.*[(]([Ss][0-9.]*)[)]$ =C2=A0 =C2=A0= =C2=A0 \1

Now when i try to connect using psql, authentication fails. I try to connect with both as user S114546(uppercase S) as well as s114546(lowercase s). In both case it fails.

When i try to connect with S114546, it fail with message that no role "S114546" exist.
psql "host=3Dpostgres.app.net user=3DS114546 dbname=3Dappdb sslmode=3Dverify-full sslcert=3Dcert.pem sslkey=3Dcert-key.pem sslrootcert=3Dtls-ca-bundle.pem"
psql: error: connection to server at "pos= tgres.app.net" (10.129.187.27), port 5432 failed: FATAL: =C2=A0role "S114546" = does not exist

When i try to connect with s114546, certificate authentication fail. extracted username from CN is S114546(uppercase S) and supplied username in connection is s114546(lowercase s).
psql "host=3Dpostgres.app.net user=3Ds114546 dbname=3Dappdb sslmode=3Dverify-full sslcert=3Dcert.pem sslkey=3Dcert-key.pem sslrootcert=3Dtls-ca-bundle.pem"
psql: error: connection to server at "pos= tgres.app.net" (10.129.187.27), port 5432 failed: FATAL: =C2=A0certificate authentication failed for user "s114546"

isn't it strange behavior? while creating the user it ignores the case but checks the case during authentication.
Anyone can please suggest how to resolve this issue ?
I can create the user with uppercase 'S' by double quoting the username. but the script which creates the user will do the same for all users which i do not want.

Thanks,
Dhirendra.


Can you try:

psql "host=3Dpostgres.app.net<= /a> user=3D\"S114546\" dbname=3Dappdb sslmode=3Dverify-full sslcert=3Dc= ert.pem sslkey=3Dcert-key.pem sslrootcert=3Dtls-ca-bundle.pem"

This should keep the user name in upper case. Without quotes (which have to be protected by a preceding backslash, because the whole conninfo is already in quotes) the name will be folded to lower case.

Best Regards,

Holger

--=20
Holger Jakobs, Bergisch Gladbach, Tel. +49-178-9759012
--------------XxOsZviYtCXspDmVujW1fq17-- --------------cO5du4LAouU009n08DJbfyN2-- --------------cKPxezC5wTkw0L6sdmyf8Drq Content-Type: application/pgp-signature; name="OpenPGP_signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="OpenPGP_signature" -----BEGIN PGP SIGNATURE----- wmMEABEIACMWIQScuJCxWJK1p5BOebGKV5yTsxlhugUCY6Ql9AUDAAAAAAAKCRCKV5yTsxlhupR+ AJwOWg2R+FahRKqbcch9bvxDFmLyngCeJrvqrvRnSCad8jptaBJk9ScpKQQ= =W5BW -----END PGP SIGNATURE----- --------------cKPxezC5wTkw0L6sdmyf8Drq--