Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1anvl7-0002Jk-Ec for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Apr 2016 22:17:09 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1anvl6-0007fw-Rq for pgsql-hackers@arkaria.postgresql.org; Wed, 06 Apr 2016 22:17:08 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1anvjm-0006Ak-5T for pgsql-hackers@postgresql.org; Wed, 06 Apr 2016 22:15:46 +0000 Received: from mx1.redhat.com ([209.132.183.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1anvjj-0000Cw-7b for pgsql-hackers@postgresql.org; Wed, 06 Apr 2016 22:15:45 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id BAA0E3683C; Wed, 6 Apr 2016 22:15:40 +0000 (UTC) Received: from localhost (vpn-232-254.phx2.redhat.com [10.3.232.254]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id u36MFeY7008078; Wed, 6 Apr 2016 18:15:40 -0400 From: Robbie Harwood To: Tom Lane Cc: Stephen Frost , pgsql-hackers@postgresql.org Subject: Re: [PATCH v12] GSSAPI encryption support In-Reply-To: <1530.1459977031@sss.pgh.pa.us> References: <20160406112105.GG10850@tamriel.snowman.net> <1530.1459977031@sss.pgh.pa.us> User-Agent: Notmuch/0.21 (http://notmuchmail.org) Emacs/24.5.1 (x86_64-pc-linux-gnu) Date: Wed, 06 Apr 2016 18:15:37 -0400 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.22 X-Pg-Spam-Score: -7.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 Tom Lane writes: > Robbie Harwood writes: >> I need to flush this any time we might be doing encryption because it >> needs to be in a separate request to _secure_write() from what follows >> it. We don't know whether we should be doing encryption until >> connection parameters are parsed; to put it another way, >> port->gss->encrypt will never be true here because it hasn't been parsed >> out of port->gss->gss_encrypt yet. > > Wait a second. So the initial connection-request packet is necessarily > unencrypted under this scheme? That seems like a pretty substantial > step backwards from what happens with SSL. Even granting that stuff > like passwords won't be sent till later, the combination of user name > and database name might already be useful info to an eavesdropper. > > I would think a design similar to the SSL one (special protocol version > to cause encryption negotiation before the actual connection request > is sent) would be better. (Apologies for the wall of text that follows. My GSSAPI encryption support has gone through three major redesigns, so I've got a fair bit to say about it at this point, and it's probably better that I say too much than too little. The short version is that GSSAPI works differently than SSL and username is sent in the clear no matter what, but this isn't a problem.) Yes, by necessity. The username must be sent in the clear, even if only as part of the GSSAPI handshake (i.e., the GSSAPI username will appear in plantext in the GSSAPI blobs which are otherwise encrypted). GSSAPI performs authentication before it can start encryption. In this design, the contents of the Startup Message are the only non-authentication related information sent in the clear. This contains: username (which we need anyway), database, application_name, and I add gss_encrypt. Why does it look this way? Fallback support. We already have GSSAPI authentication code in the project, and unfortunately we can't fix the multitude of older clients that won't have encryption support, whatever form it takes. What if we didn't need fallback support, though? Doing it with a special protocol version, as in the SSL/TLS case, would cause a separate path for authentication to occur, during which everything would look pretty much the same, except we wouldn't send database. We would then complete the auth handshake, and in a separate exchange, pass in the database information. Only then could we perform authorization checking. Authorization checking is currently coupled with the authentication as well; we would need a way to bypass the normal auth sequence and enter encryption. Bottom line is that designing similarly to SSL/TLS doesn't really make sense because the two schemes work differently. Typically, usernames are not considered sensitive information unless one is worried about the security of the authentication information that goes with them. For instance, MIT Kerberos will reveal the difference between "username not found" and the equivalent of "bad password". I don't know how much admins care about the database names being in the clear; I suspect it doesn't matter much because just knowing their names isn't enough to connect. Even if it's something people care about, this is still far better than no encryption at all (which is the current GSSAPI behavior), and would be better addressed by supporting connecting without specifying a database immediately anyway. >>> I'm aware that enlargeStringInfo() does check and handle the case where >>> the length ends up >1G, but that feels a bit grotty to me- are you sure >>> you want the generic enlargeStringInfo() to handle that case? > >> This is a good point. We definitely have to draw the line somewhere; 1G >> is a high upper bound. Digging around the server code I don't see a >> precedent for what's a good size to stop at. There's >> PG_MAX_AUTH_TOKEN_LENGTH, which is 65k, and the password length in >> auth.c is 1k. Beyond that, SocketBackend() calls pq_getmessage() with >> no maximum length, which causes the enlargeStringInfo() size >> restrictions to be the only control (wrapped in a PG_TRY()). > > Note that SocketBackend() only runs *after* we've accepted the user as > authorized. We should be a lot charier of what we're willing to accept > before authorization, IMO. Note MAX_STARTUP_PACKET_LENGTH, which is > only 10K. Correct, we're only talking about packets that are sent after authentication+authorization are complete. Before authentication is complete, the GSSAPI encryption codepaths are not taken. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQIcBAEBAgAGBQJXBYqKAAoJECUy+RdqlaRCqhAQAJX7aDqhcD4aO+DFyTTnAHOn r2Ug7xrxOKakAJcwfxv+kEHbaIfMQIQ6mPxOsZA7ChvmmK03eT7WDvCyQ7tfKf/j xUUgQfIYlHDYuRPD/DOdn3QaPrqWkhktPGyMN6UJyZjuc1ZygoEirxda/Vj9+U0U 36nq1DzOyWu/kuzLxxVahVurAeKEp41tUoZNvXwCjjvicSJPp0ZOO5MT7sWl8J2x aN7olThx/12b/4FDCNYZELmk7t4FQ63+BazvHqMTX84dVpGDGSdnbwrAC/+PZUim 26Ld/ubV9ZPDgmRO+Zdc7rReEgBXDTDpOEdCIhhiQg/pPV/9hz7zRH44ucsZLteD elOlYiZooBL+TCnWOifk4E5JQkiaoYwA/I3rWppNj0yjU1RoojePJ9SG+Kf7CF1A Z6ZGKTJ7pbXZ+svWIEwUZbSmk8dqOSfIhNyywTpe6m1VeH7f7R+vbghYN4rFI8Hg lcdRXSM0Sa6jmWv8k3qvRHqU7U66xYoqIqE2HhhKOn3MCK9Ky+OVG4y85l9OLwH9 4kRUr3ntcc+G8syEa0/W+RcU4tI6tZ5jF0R6EbjzCQjJ2Ne/1q0yd6psHnMNKFgP IocKQth+LpaX/qf1eDNUepKRFrIAxOqPNOwiAy8VAo12FAYwPZCWPA103Abi3APX Pz2osrSOGU9n8CrYxGGC =BzcI -----END PGP SIGNATURE----- --=-=-=--