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 1ksChx-0003h9-1z for pgsql-general@arkaria.postgresql.org; Wed, 23 Dec 2020 22:34:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ksChv-0004PK-NJ for pgsql-general@arkaria.postgresql.org; Wed, 23 Dec 2020 22:34:11 +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 1ksChv-0004PD-FN for pgsql-general@lists.postgresql.org; Wed, 23 Dec 2020 22:34:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ksCht-0007bd-8G for pgsql-general@postgresql.org; Wed, 23 Dec 2020 22:34:10 +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 0BNMY57M742642; Wed, 23 Dec 2020 17:34:06 -0500 From: Tom Lane To: Stephen Frost cc: Gustavsson Mikael , Magnus Hagander , Kyotaro Horiguchi , "pgsql-general@postgresql.org" , Svensson Peter Subject: Re: Problem with ssl and psql in Postgresql 13 In-reply-to: <740093.1608760567@sss.pgh.pa.us> References: <89909.1608222331@sss.pgh.pa.us> <61e2a65bbc2f47d297a6f3cdac2cc6cc@smhi.se> <169637.1608321770@sss.pgh.pa.us> <723586.1608740901@sss.pgh.pa.us> <737386.1608757126@sss.pgh.pa.us> <20201223211448.GR27507@tamriel.snowman.net> <738715.1608758847@sss.pgh.pa.us> <20201223214534.GS27507@tamriel.snowman.net> <740093.1608760567@sss.pgh.pa.us> Comments: In-reply-to Tom Lane message dated "Wed, 23 Dec 2020 16:56:07 -0500" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <742640.1608762845.1@sss.pgh.pa.us> Date: Wed, 23 Dec 2020 17:34:05 -0500 Message-ID: <742641.1608762845@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Oh ... wait a second. I've just managed to partially reproduce this report. Assume that we have a working Kerberos environment on both ends. Then libpq will establish a connection with GSS encryption and continue on with the usual PG authentication exchange. If that part fails, then this logic (fe_connect.c around line 3350): /* * If gssencmode is "prefer" and we're using GSSAPI, retry * without it. */ if (conn->gssenc && conn->gssencmode[0] == 'p') { /* postmaster expects us to drop the connection */ conn->try_gss = false; pqDropConnection(conn, true); conn->status = CONNECTION_NEEDED; goto keep_going; } drops the connection and tries again without GSS. But *we already cleared allow_ssl_try*, in pqsecure_open_gss, so the next try will not bother with SSL either. So this directly explains the original report: if the only applicable pg_hba.conf entry is "hostssl", right here is where libpq will see that error, and it will go around and fail again because the next try uses neither GSS nor SSL. However, in the tests Mikael ran after backing that pg_hba.conf entry off to just "host", pg_hba wouldn't have caused an authentication-stage failure, so it's not so clear why we'd have looped back at this step. We'd need to explain the later cases to have a full theory. It's plenty plausible that something else caused an auth-stage failure, but if so, why would the second GSS-free try work? In any case, that allow_ssl_try reset in pqsecure_open_gss is definitely even more broken than I thought before. I think we need to rejigger the state machine so that it doesn't do that at all, but instead skips SSL establishment when GSS is already active via an explicit test, rather than munging the state variables. regards, tom lane