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 1oyXHq-0004I1-FE for pgsql-admin@arkaria.postgresql.org; Fri, 25 Nov 2022 11:54:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oyXHo-0005ei-L5 for pgsql-admin@arkaria.postgresql.org; Fri, 25 Nov 2022 11:54:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oyXHo-0005eZ-63 for pgsql-admin@lists.postgresql.org; Fri, 25 Nov 2022 11:54:28 +0000 Received: from mail-ed1-x52b.google.com ([2a00:1450:4864:20::52b]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oyXHj-0008QW-21 for pgsql-admin@lists.postgresql.org; Fri, 25 Nov 2022 11:54:27 +0000 Received: by mail-ed1-x52b.google.com with SMTP id e13so6071436edj.7 for ; Fri, 25 Nov 2022 03:54:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=OeROLR1+cM6QVpaukTER5jHXhkwlNYROIyHh9pRYAi8=; b=cVA+Yd6O7JROwsgwtEkhr9weqQs7j5/Sw/+RFUZMuoVe2X5sxplyo7OHN6pzcD9BiJ q4WULZmFTpB3OuuXdvri6XBpYDeJiUEIu4/ABj3WWQYR2XvFzNb3UpgJ4qApG2CTNYiV LEP3QIzxSFzfbRJaTi/pQsafycyh6AIxjz8IB4hae+WRRh6UnUe42w7pG5lRvgTOOoTK b1AJO3RfzyGICroDD8ZpCaSRjXFtzhSv6QfyVCOgdbO8YmMzzwqvvgaanWmN23vqRFRl C7g3h+45Y9WkvaNsDYY87aMk5QZlpQ4EVdeanHYGQ3BwTduP70EGkvqFoKVFtR9Um3PA gizA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:user-agent:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=OeROLR1+cM6QVpaukTER5jHXhkwlNYROIyHh9pRYAi8=; b=6/U2Zfa3RvvmoGYj5NdTGlyt78SrTJroOcEPNkf0jloG0moAJOv6FgQbOCuGA2Zn5g Ux43eWT8EcYJPoiaoEMEvFAsTUQN6Afp81O65Pa5CwO6AGllw1tSUP2qNjope6lXCGgT lwPjYAsDCvcAGekmMHbSg1KO+sFUnSZfJ78p2ZYOqGPt4xVEHo+W+h59lSRF5fl4dwJW wxIlunFZ6ur6iytmiP/ad0uFCzf6zFuaMQRvtyv3Sw+bAQgrKWDoHgpaYgchWQRDDdl1 SuBajew5+QLj2K3/ZGpd82RxoI+8zQ9QDPN+P1SyEwgUi7QSLxT/mErxz7cq1CeoVQxY Tx5g== X-Gm-Message-State: ANoB5pn2N0g4T2LP3OkBfL1PO0bAroxblNpVYviWVUxnt61RapEW6df/ AJ0imkarjNlrswHwf5iKyPPtZg== X-Google-Smtp-Source: AA0mqf6A/Gd0u5uweA9sZ5LNfXbVlUg/hG7x1xNjjXyz8dnbVh6/jbgRCp+fVAAtaM+SEVpJ2MwbPg== X-Received: by 2002:a05:6402:2946:b0:468:febe:ebab with SMTP id ed6-20020a056402294600b00468febeebabmr32931417edb.337.1669377261791; Fri, 25 Nov 2022 03:54:21 -0800 (PST) Received: from localhost.localdomain ([88.116.133.170]) by smtp.gmail.com with ESMTPSA id qw25-20020a1709066a1900b0073dd8e5a39fsm1464963ejc.156.2022.11.25.03.54.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 25 Nov 2022 03:54:21 -0800 (PST) Message-ID: Subject: Re: Question about cert authentication method. From: Laurenz Albe To: Dhirendra Singh , pgsql-admin@lists.postgresql.org Date: Fri, 25 Nov 2022 12:54:20 +0100 In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.42.4 (3.42.4-2.fc35) MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 2022-11-25 at 15:36 +0530, Dhirendra Singh wrote: > I have a question about cert authentication method. I am using postgres version 14. > > Following is the entry i have in the pg_hba file. > hostssl  all  all  0.0.0.0/0   cert map=mymap > > Following is the entry in the pg_ident file. > mymap  test  readonly > > trying to connect to the server using psql. CN in the certificate is "test (S114546)". > psql "host=localhost user='test (S114546)' dbname=appdb sslmode=verify-full sslcert=certificate.crt sslkey=certificate.key sslrootcert=cacerts" > > No mapping exist for "test (S114547)" in the pg_ident file. > > The connection failed with following error. > psql: error: connection to server at "localhost", port 5432 failed: FATAL:  certificate authentication failed for user "test (S114546)" > > Error in the server log is... > 2022-11-25 09:26:52.169 UTC [62] LOG: no match in usermap "mymap" for user "test (S114546)" authenticated as "test (S114546)" > 2022-11-25 09:26:52.169 UTC [62] FATAL: certificate authentication failed for user "test (S114546)" > 2022-11-25 09:26:52.169 UTC [62] DETAIL: Connection matched pg_hba.conf line 4: "hostssl all all 0.0.0.0/0 cert map=mymap" > > I am expecting the connection to fail because user "test (S114546) does not exist. but i am confused about the error message in the server log. > It says certificate authentication failed  for user "test (S114546)". but CN in the certificate matches with the user name in psql connection request. > So certificate authentication should pass. It should fail afterwards. Well, "test" is different from "test (S114546)", so what do you expect? You should use a regular expression in "pg_ident.conf", if you want that to match: mymap /^test readonly Yours, Laurenz Albe,