Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLV8M-003IK5-AC for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jul 2023 20:47:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qLV8K-00Eqx6-Rd for pgsql-hackers@arkaria.postgresql.org; Mon, 17 Jul 2023 20:47:52 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qLV8K-00Eqwy-FI for pgsql-hackers@lists.postgresql.org; Mon, 17 Jul 2023 20:47:52 +0000 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qLV8H-0019Iq-HT for pgsql-hackers@postgresql.org; Mon, 17 Jul 2023 20:47:51 +0000 Received: by mail-pf1-x42b.google.com with SMTP id d2e1a72fcca58-668711086f4so3008736b3a.1 for ; Mon, 17 Jul 2023 13:47:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689626867; x=1692218867; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=53bRpR8wL0jZy3C4TEcd1OjZVkpZOdpEu2XL0hYY1VE=; b=GurVVDhWZ/8RIXo0NFrE7a/YFjWueV3+4fVN608udh/A4MZsriH0l8yPbJhALqa0ww OndEQ6Tjj9taL1dDbsGWWwmnbMaAizz71Rzcz+P8uEFD6rmlu8wdZWTCeqGmvNTbSyTq 7krc/B+VS/VlI68gg1iWYMST9AvufC91AVF8eTKPCI0wwXzdOrUrm54VWtEzu7E252/5 Fp71qUoJmXxQjOROMEgZk+YTSMdgX/czUrCvIVP1W9z4Xz/8PlT7tZe0+WaRZD3SkH2F K3y8guRNbyqk4VY2WhOlPcC9uo5F7CySrcIwrRl6f579IxZw0L+i6IBh5l+Xn5qQjFlY UzEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689626867; x=1692218867; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=53bRpR8wL0jZy3C4TEcd1OjZVkpZOdpEu2XL0hYY1VE=; b=GPXNfRJA770v/8Hk+lzVY0cunioClF+b7BlS/QO+I8/AEoWWd4ofZ4y2oBNiS6BbVG r3k6/N/+m5i8xY8XNqePGSzjSHKbbZhuDEQXeC/LHyd7uQymGYoNVOJG2PO6IsH8LwyC BoKO5cdsGtXutbYgjG/ylYcQERbgqBrkvFqacg2uSjUnGsBfrRwR6nylg5NCDdJ0ffrW yaQWgEYDzuJRuTYuYmxKMYzD1QuH7U0uf0GuvLTRO7o64qdpuh+wTw37s+nR8sxfStRw qJNhsKQkUH9/QsfIdSdB3EpJjPP84etcvX2czNMyiA6DbN73YBBA48mA+DMAqjUEVcDZ ohfw== X-Gm-Message-State: ABy/qLYors2OzcMPrHSRMnOV212AQrgl8D6hN0Cp5yPHqAfYbVnucEhp NDXKULan9StpfIuFQ7O16mE= X-Google-Smtp-Source: APBJJlGPLo6xfIQyDVtXdTZ/Rb/8ubQ8YxXW1DF3Vpi3DS3vW7JhlQMMYaDWvZDoXUFip0ZQ2awR8g== X-Received: by 2002:a05:6a00:802:b0:67c:db:c2f4 with SMTP id m2-20020a056a00080200b0067c00dbc2f4mr15131009pfk.4.1689626867076; Mon, 17 Jul 2023 13:47:47 -0700 (PDT) Received: from nathanxps13 ([50.47.162.83]) by smtp.gmail.com with ESMTPSA id e9-20020aa78c49000000b00666e2dac482sm201105pfd.124.2023.07.17.13.47.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 17 Jul 2023 13:47:46 -0700 (PDT) Date: Mon, 17 Jul 2023 13:47:44 -0700 From: Nathan Bossart To: Gurjeet Singh Cc: pgsql-hackers@postgresql.org Subject: Re: harmonize password reuse in vacuumdb, clusterdb, and reindexdb Message-ID: <20230717204744.GA890035@nathanxps13> References: <20230628045741.GA1813397@nathanxps13> <20230629052409.GB2049807@nathanxps13> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="Dxnq1zWXvFF0Q93v" Content-Disposition: inline In-Reply-To: <20230629052409.GB2049807@nathanxps13> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --Dxnq1zWXvFF0Q93v Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Jun 28, 2023 at 10:24:09PM -0700, Nathan Bossart wrote: > On Wed, Jun 28, 2023 at 09:20:03PM -0700, Gurjeet Singh wrote: >> The comment on top of connect_utils.c:connectDatabase() seems pertinent: >> >>> (Callers should not pass >>> * allow_password_reuse=true unless reconnecting to the same database+user >>> * as before, else we might create password exposure hazards.) >> >> The callers of {cluster|reindex}_one_database() (which in turn call >> connectDatabase()) clearly pass different database names in successive >> calls to these functions. So the patch seems to be in conflict with >> the recommendation in the comment. >> >> I'm not sure if the concern raised in that comment is a legitimate >> one, though. I mean, if the password is reused to connect to a >> different database in the same cluster/instance, which I think is >> always the case with these utilities, the password will exposed in the >> server logs (if at all). And since the admins of the instance already >> have full control over the passwords of the user, I don't think this >> patch will give them any more information than what they can get >> anyways. >> >> It is a valid concern, though, if the utility connects to a different >> instance in the same run/invocation, and hence exposes the password >> from the first instance to the admins of the second cluster. > > The same commit that added this comment (ff402ae) also set the > allow_password_reuse parameter to true in vacuumdb's connectDatabase() > calls. I found a message from the corresponding thread that provides some > additional detail [0]. I wonder if this comment should instead recommend > against using the allow_password_reuse flag unless reconnecting to the same > host/port/user target. Connecting to different databases with the same > host/port/user information seems okay. Maybe I am missing something... Here is a new version of the patch in which I've updated this comment as proposed. Gurjeet, do you have any other concerns about this patch? -- Nathan Bossart Amazon Web Services: https://aws.amazon.com --Dxnq1zWXvFF0Q93v Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="v2-0001-harmonize-password-reuse-in-vacuumdb-clusterdb-an.patch" From 85d0a1bbe62c4cc01b3fdba7c653f95b8472cc7a Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Tue, 27 Jun 2023 21:38:24 -0700 Subject: [PATCH v2 1/1] harmonize password reuse in vacuumdb, clusterdb, and reindexdb --- doc/src/sgml/ref/reindexdb.sgml | 14 -------------- doc/src/sgml/ref/vacuumdb.sgml | 13 ------------- src/bin/scripts/clusterdb.c | 2 +- src/bin/scripts/reindexdb.c | 2 +- src/fe_utils/connect_utils.c | 2 +- 5 files changed, 3 insertions(+), 30 deletions(-) diff --git a/doc/src/sgml/ref/reindexdb.sgml b/doc/src/sgml/ref/reindexdb.sgml index 8cb8bf4fa3..8d9ced212f 100644 --- a/doc/src/sgml/ref/reindexdb.sgml +++ b/doc/src/sgml/ref/reindexdb.sgml @@ -432,20 +432,6 @@ PostgreSQL documentation - - - Notes - - - reindexdb might need to connect several - times to the PostgreSQL server, asking - for a password each time. It is convenient to have a - ~/.pgpass file in such cases. See for more information. - - - - Examples diff --git a/doc/src/sgml/ref/vacuumdb.sgml b/doc/src/sgml/ref/vacuumdb.sgml index da2393783b..09356ea4fa 100644 --- a/doc/src/sgml/ref/vacuumdb.sgml +++ b/doc/src/sgml/ref/vacuumdb.sgml @@ -605,19 +605,6 @@ PostgreSQL documentation - - - Notes - - - vacuumdb might need to connect several - times to the PostgreSQL server, asking - for a password each time. It is convenient to have a - ~/.pgpass file in such cases. See for more information. - - - Examples diff --git a/src/bin/scripts/clusterdb.c b/src/bin/scripts/clusterdb.c index 58a774013b..65428031c7 100644 --- a/src/bin/scripts/clusterdb.c +++ b/src/bin/scripts/clusterdb.c @@ -195,7 +195,7 @@ cluster_one_database(const ConnParams *cparams, const char *table, PGconn *conn; - conn = connectDatabase(cparams, progname, echo, false, false); + conn = connectDatabase(cparams, progname, echo, false, true); initPQExpBuffer(&sql); diff --git a/src/bin/scripts/reindexdb.c b/src/bin/scripts/reindexdb.c index 5b297d1dc1..002c41f221 100644 --- a/src/bin/scripts/reindexdb.c +++ b/src/bin/scripts/reindexdb.c @@ -315,7 +315,7 @@ reindex_one_database(ConnParams *cparams, ReindexType type, bool failed = false; int items_count = 0; - conn = connectDatabase(cparams, progname, echo, false, false); + conn = connectDatabase(cparams, progname, echo, false, true); if (concurrently && PQserverVersion(conn) < 120000) { diff --git a/src/fe_utils/connect_utils.c b/src/fe_utils/connect_utils.c index 7a1edea7c8..7d45f5c609 100644 --- a/src/fe_utils/connect_utils.c +++ b/src/fe_utils/connect_utils.c @@ -25,7 +25,7 @@ * * If allow_password_reuse is true, we will try to re-use any password * given during previous calls to this routine. (Callers should not pass - * allow_password_reuse=true unless reconnecting to the same database+user + * allow_password_reuse=true unless reconnecting to the same host+port+user * as before, else we might create password exposure hazards.) */ PGconn * -- 2.25.1 --Dxnq1zWXvFF0Q93v--