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 1ksBEI-0000oD-NG for pgsql-general@arkaria.postgresql.org; Wed, 23 Dec 2020 20:59: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 1ksBDj-0000KS-NW for pgsql-general@arkaria.postgresql.org; Wed, 23 Dec 2020 20:58:55 +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 1ksBDj-0000KL-Fx for pgsql-general@lists.postgresql.org; Wed, 23 Dec 2020 20:58:55 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksBDf-0002a8-Vs for pgsql-general@postgresql.org; Wed, 23 Dec 2020 20:58:54 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 0BNKwk4o737387; Wed, 23 Dec 2020 15:58:46 -0500 From: Tom Lane To: Gustavsson Mikael cc: Stephen Frost , Magnus Hagander , Kyotaro Horiguchi , "pgsql-general@postgresql.org" , Svensson Peter Subject: Re: SV: SV: SV: SV: Problem with ssl and psql in Postgresql 13 In-reply-to: <723586.1608740901@sss.pgh.pa.us> References: <20201217.172938.170511532557914014.horikyota.ntt@gmail.com> <06191eae74d045e192a786a84a73ba53@smhi.se> <65644.1608214801@sss.pgh.pa.us> , <698125e1105644adaa27578bb37b18f6@smhi.se>,<89909.1608222331@sss.pgh.pa.us>,<61e2a65bbc2f47d297a6f3cdac2cc6cc@smhi.se> ,<169637.1608321770@sss.pgh.pa.us>, <723586.1608740901@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 23 Dec 2020 11:28:21 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <737385.1608757126.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 23 Dec 2020 15:58:46 -0500 Message-ID: <737386.1608757126@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I wrote: > Gustavsson Mikael writes: >> So if i set gssencmode=3Ddisable on my pgsql-13 to postgres 13 server c= onnection i get an SSL connection. > It looks like, if there is a credentials cache and gssencmode isn't > explicitly disabled, we try GSS first. If the server refuses that: > ... > that is, it decides the connection it has is good enough. This > is not OK if SSL should have been used. No, I misread the code; what will happen next is that an SSL connection will be tried. At least, it looks like that should happen, and it does happen for me. However: it is true (and undocumented, so we have at least a docs bug to fix) that v12-and-later libpq will try for GSS encryption first, and if it succeeds then it will not consider using SSL, regardless of sslmode. So about 95% of your report could be explained by assuming that you have a working Kerberos environment and the newer libpq is preferring GSS encryption over SSL. There is just one thing this theory is failing to explain: instead of "SSL connection", psql should have printed "GSSAPI-encrypted connection" in your test shown in . It didn't, so this can't be the true explanation. I think what must be happening is that libpq is trying for GSS (hence you have at least a credentials cache somewhere), failing to establish it, and then for some reason advancing to the startup-packet step without trying for SSL. But I can't see how to get the state machine to do that. Have you got any environment variables, service files, etc that would affect libpq's behavior? regards, tom lane