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 1palHn-0004JC-4e for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 22:32:27 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1palHl-0003FS-JZ for pgsql-hackers@arkaria.postgresql.org; Fri, 10 Mar 2023 22:32:25 +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 1palHl-0003DP-8F for pgsql-hackers@lists.postgresql.org; Fri, 10 Mar 2023 22:32:25 +0000 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1palHg-0004hK-Tb for pgsql-hackers@postgresql.org; Fri, 10 Mar 2023 22:32:24 +0000 Received: by mail-pj1-x102d.google.com with SMTP id qa18-20020a17090b4fd200b0023750b675f5so11324129pjb.3 for ; Fri, 10 Mar 2023 14:32:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=timescale.com; s=google; t=1678487539; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=BoTERMibDOYxwU3HN3t2oJALDH8rPb8QKCe8+o6yXmA=; b=NWi1nltdHtU8sMxlKZizbNrFC1EOyYq7jfYWscLm2rFx2HxKYzgXGnaXdJ+H8W9pmA 1BjD8MtsVLfLKfAVx+LaXC5wUcic2n6aqKCe4s/gLQldHJkOagNu36/vWXYcSPm/42PV c8YfEgq/ASd+JVhkHKZA4SQMQvS3WLowQh1KApyE83l/jPwuR5AFaVGa9eQVxFNFS7xz vbaF5KLF4k1SGNU1uXaI3eN4iMAg+ZkxPylBgt/4UKMT5Cqh/moMEeJYRZpN4Zc3EmTD xovs5/3s/vg3wD+BD7+ZijcAfJKfrctWl6h9cQToSvIMahZvl8xWvAAS93N3AypogXZ9 4AFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678487539; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=BoTERMibDOYxwU3HN3t2oJALDH8rPb8QKCe8+o6yXmA=; b=MQb0Xn171yOVyxJCD0FNb7mDrUUH3Ho5lzaZ/j+p0lUOX1zxjwnZaxMKKXBxIHKp2s a0LrIXkN+YJuwaZrGUQ1Qh2OwfYD4+fAWo8CMih4Io1t9xKEIuDDP9qVtdI/UR7FkpYh sSZCS4bVagCEr866m7q5j+klHqZaDaLAH2a+fMDoRrBbH+nMaNb2+Wqqmg5OMyfRzMZl r1LPmSw45QcJlLQMbHpxxj78cA3QsuZe0zCo0W5S6UzpTBHAT4FT3fS4wpzvnO13rw/n F1x/FZvLbWsVvFQDTHEVHbV8Fwag5kU/OPBhLbUO3MOUyjyf3870ncGGUn6waJVwQC44 8zbg== X-Gm-Message-State: AO0yUKUip3Nd1+EkvMAdL4W4MWcqX6FQuxmG8yopOA3YFmc/JHo/XAVf lqBV/hfhty3zCggiHpyDR0jdPw== X-Google-Smtp-Source: AK7set8Zd/0y2D2UjNDOaT50WbztxMLHleMTP8JDiIs/gB1Z3u/kMNuM4/qgXa7vbGb6WZ6QMWyTQw== X-Received: by 2002:a05:6a20:6a0c:b0:cc:a93:2b82 with SMTP id p12-20020a056a206a0c00b000cc0a932b82mr33891907pzk.58.1678487538685; Fri, 10 Mar 2023 14:32:18 -0800 (PST) Received: from [192.168.1.21] ([50.53.8.205]) by smtp.gmail.com with ESMTPSA id p24-20020a62ab18000000b005a8ce67874asm284629pff.86.2023.03.10.14.32.17 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Mar 2023 14:32:18 -0800 (PST) Message-ID: Date: Fri, 10 Mar 2023 14:32:17 -0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.1 Subject: Re: [PoC] Let libpq reject unexpected authentication requests Content-Language: en-US To: Michael Paquier Cc: "pgsql-hackers@postgresql.org" , Aleksander Alekseev , Peter Eisentraut , "David G. Johnston" References: <9de74f8d-fbf4-63d9-7bcb-b9c27edf8b73@enterprisedb.com> From: Jacob Champion In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 3/8/23 22:35, Michael Paquier wrote: > I have been reviewing 0001, finishing with the attached, and that's > nice work. My notes are below. Thanks! > pqDropServerData() is in charge of cleaning up the transient data of a > connection between different attempts. Shouldn't client_finished_auth > be reset to false there? No parameters related to the connection > parameters should be reset in this code path, but this state is > different. It does not seem possible that we could reach > pqDropServerData() after client_finished_auth has been set to true, > but that feels safer. Yeah, that seems reasonable. > + case AUTH_REQ_SCM_CREDS: > + return libpq_gettext("server requested UNIX socket credentials"); > I am not really cool with the fact that this would fail and that we > offer no options to control that. Now, this involves servers up to > 9.1, which is also a very good to rip of this code entirely. For now, > I think that we'd better allow this option, and discuss the removal of > that in a separate thread. Fair enough. > pgindent has been complaining on the StaticAssertDecl() in fe-auth.c: > src/interfaces/libpq/fe-auth.c: Error@847: Unbalanced parens > Warning@847: Extra ) > Warning@847: Extra ) > Warning@848: Extra ) > > From what I can see, this comes from the use of {0} within the > expression itself. I don't really want to dig into why pg_bsd_indent > thinks this is a bad idea, so let's just move the StaticAssertDecl() a > bit, like in the attached. The result is the same. Works for me. I wonder if sizeof(((PGconn*) 0)->allowed_auth_methods) would make pgindent any happier? That'd let you keep the assertion local to auth_method_allowed, but it looks scarier. :) > As of the "sensitive" cases of the patch: > - I don't really think that we have to care much of the cases like > "none,scram" meaning that a SASL exchange hastily downgraded to > AUTH_REQ_OK by the server would be a success, as "none" means that the > client is basically OK with trust-level. This said, "none" could be a > dangerous option in some cases, while useful in others. Yeah. I think a server shouldn't be allowed to abandon a SCRAM exchange partway through, but that's completely independent of this patchset. > - SSPI is the default connection setup for the TAP tests on Windows. Oh, I don't think I ever noticed that. > We could stick a small test somewhere, perhaps, certainly not in > src/test/authentication/. Where were you thinking? (Would it be so bad to have a tiny t/005_sspi.pl that's just skipped on *nix?) > - SASL/SCRAM is indeed a problem on its own. My guess is that we > should let channel_binding do the job for SASL, or introduce a new > option to decide which sasl mechanisms are authorized. At the end, > using "scram-sha-256" as the keyword is fine by me as we use that even > for HBA files, so that's quite known now, I hope. Did you have any thoughts about the 0003 generalization attempt? > -+ if (conn->require_auth) > ++ if (conn->require_auth && conn->require_auth[0]) Thank you for that catch. I guess we should test somewhere that `require_auth=` behaves normally? > + reason = libpq_gettext("server did not complete authentication"), > -+ result = false; > ++ result = false; > + } This reindentation looks odd. nit: some of the new TAP test names have been rewritten with commas, others with colons. Thanks, --Jacob