Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1aZ28c-0002Q3-5l for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Feb 2016 20:03:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1aZ28b-0005mh-B4 for pgsql-hackers@arkaria.postgresql.org; Thu, 25 Feb 2016 20:03:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aZ27F-0003gL-Ac for pgsql-hackers@postgresql.org; Thu, 25 Feb 2016 20:02:25 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1aZ279-0007lC-JR for pgsql-hackers@postgresql.org; Thu, 25 Feb 2016 20:02:24 +0000 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id EFB55627C2; Thu, 25 Feb 2016 20:02:15 +0000 (UTC) Received: from localhost (vpn-231-56.phx2.redhat.com [10.3.231.56]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u1PK2F6M025695; Thu, 25 Feb 2016 15:02:15 -0500 From: Robbie Harwood To: Michael Paquier , David Steele Cc: PostgreSQL mailing lists Subject: Re: [PATCH v5] GSSAPI encryption support In-Reply-To: References: <56BE0FF9.70302@pgmasters.net> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Thu, 25 Feb 2016 15:02:11 -0500 Message-ID: MIME-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha1; protocol="application/pgp-signature" X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 25 Feb 2016 20:02:16 +0000 (UTC) X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Michael Paquier writes: > On Tue, Feb 16, 2016 at 2:45 AM, Robbie Harwood wro= te: >> David Steele writes: >>> On 2/10/16 4:06 PM, Robbie Harwood wrote: >>>> Hello friends, >>>> >>>> For your consideration, here is a new version of GSSAPI encryption >>>> support. For those who prefer, it's also available on my github: >>>> https://github.com/frozencemetery/postgres/commit/c92275b6605d7929cda5= 551de47a4c60aab7179e >>> >>> It tried out this patch and ran into a few problems: >>> >>> 2) While I was able to apply the patch and get it compiled it seemed >>> pretty flaky - I was only able to logon about 1 in 10 times on average. >>> >>> When not successful the client always output this incomplete message >>> (without terminating LF): >>> >>> psql: expected authentication request from server, but received >>> >>> From the logs I can see the server is reporting EOF from the client, >>> though the client does not core dump and prints the above message before >>> exiting. >>> >>> I have attached files that contain server logs at DEBUG5 and tcpdump >>> output for both the success and failure cases. >>> >>> Please let me know if there's any more information you would like me to >>> provide. >> >> What I can't tell from looking at your methodology is whether both the >> client and server were running my patches or no. There's no fallback >> here (I'd like to talk about how that should work, with example from >> v1-v3, if people have ideas). This means that both the client and the >> server need to be running my patches for the moment. Is this your >> setup? > > We need to be careful here, backward-compatibility is critical for > both the client and the server, or to put it in other words, an > uptables client should still be able to connect a patched server, and > vice-versa. This is an area where it is important to not break any > third-part tool, either using libpq or reimplementing the frontend > protocol. Which is why in my introduction to the v4 patch I explicitly mentioned that this was missing. I wanted to talk about how this should be implemented, since I feel that I received no feedback on that design From=20last time. It's not hard to port that design over, if desired. > So I finally began to dive into your new patch... And after testing > this is breaking the authentication protocol for GSS. I have been able > to connect to a server once, but at the second attempt and after > connection is failing with the following error: > psql: expected authentication request from server, but received ioltas Interesting. I will see if I can find anything. The capture posted earlier (thanks David!) suggests that the client doesn't expect the encrypted data. I suspect what has happened is a race between the client buffering data From=20the socket and the client processing the completion of GSSAPI authentication. This kind of issue is why my v1 handled GSSAPI at the protocol level, not at the transport level. I think we end up with encrypted data in the buffer that's supposed to be decrypted, and since the GSSAPI blob starts with \x00, it doesn't know what to do. I'll cut a v6 with most of the changes we've talked about here. It should address this issue, but I suspect that no one will be happy about how, since the client essentially needs to "un-read" some data. As a side note, this would also explain why I can't reproduce the issue, since I'm running in very low-latency environments (three VMs on my laptop). > Also, something that is missing is the parametrization that has been > discussed the last time this patch was on the mailing list. Where is > the capacity to control if a client is connecting to a server that is > performing encryption and downgrade to non-ecrypted connection should > the server not be able to support it? Enforcing a client to require > encryption support using pg_hba.conf was as well a good thing. Some > more infrastructure is needed here, I thought that there was an > agreement previously regarding that. This does not match my impression of the discussion, but I would be happy to be wrong about that since it is less work for me. > Also, and to make the review a bit easier, it would be good to split > the patch into smaller pieces (thanks for waiting on my input here, > this became quite clear after looking at this code). Basically, > pg_GSS_error is moved to a new file, bringing with it pg_GSS_recvauth > because the error routine is being used by the new ones you are > introducing: be_gssapi_write, etc. The split that this patch is doing > is a bit confusing, all the GSS-related stuff is put within one single > file: > - read/write routines > - authentication routine > - constants > - routines for error handling > Mixing read/write routines with the authentication routine looks > wrong, because the read-write routines just need to create a > dependency with for example be-secure.c on the backend. In short, > where before authentication and secure read/writes after > authentication get linked to each other, and create a dependency that > did not exist before. > > For the sake of clarity I would suggest the following split: > - be-gss-common.c, where all the constants and the error handling > routine are located. > - Let authrecv in auth.c > - Move only the read/write routines to the new file be-[secure-]gssapi.c > Splitting the patches into one that moves around the routines, and a > second that introduces the new logic would bring more clarity. So... auth.c is now going to depend on be-gss-common.c, and be-secure-gssapi.c is also going to depend on be-gss-common.c. That doesn't seem better in terms of dependencies: now I'm creating two that didn't exist before. That said, I would believe that it makes everything clearer. I will do that shortly. > I am wondering how this patch is tested to be honest. We've already had this conversation; please let's stay constructive. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJWz13EAAoJECUy+RdqlaRCkRwP/0JzgBa4CLA0j7FTxe7rtgaj C0FZ70OeDiFPgEvVa49OAH6/BGqJ+zBG+79QSi1FNOFNNvfz2rITYe+0QyqUyQFw t/pasmjxNyaU4uE7wPHFqZTEoFTdCvI7TrP0zbb2lSCJFOZNgtuFAO7Pc/ugDlNW VHdueWUSiCDfMGMjo/OR1EXT6UvrZezs0HEvgROp4RgLw9I/nZps5hynyagVJSfQ xXWWZMakZ+SzWLuAQdL5rEruWiNAtNVhoSYya/YRJ7sHu+KSUncpW3fnnP4UWNZd pW9cRGkl0sI4qb50HMPmjK84xkwvXqvnAVRrr8D/bvID/azC6uq46cMchSOulzzl jzlTdq1/KKeWVT+1Pf/PDeCFCdUfKK7WKe2n5w15jpIXFfZCrPP0SRPWC84KEjFv 850Fvt3GgiZcrsBEczFI704uMUd+jmNLCJSvgLN9kjksBldx4WvGs2KeJIAALHqH prChJ3EwDV2o2loeSYRZhOmUejLNXDXFXQXAQDRscyASgZhmEt1B2cRK2HVOch53 7LEGX8dLQqpxxo4O/rYBqXA/CzGXO/1+1RGM8WFUtmkzNn9pFTrN2jgjzf5x6vF/ nHrBr6HHnJg0F33zZrv2at72UfiuUuKtUDjOMMK7BHwHGMT6zRg/L7ZM0NO2+akT M10xBleWR3F4vKLVPc1V =KuAe -----END PGP SIGNATURE----- --=-=-=--