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 1oTy1E-0003bm-FX for pgsql-general@arkaria.postgresql.org; Fri, 02 Sep 2022 04:11:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oTy1C-00064m-D8 for pgsql-general@arkaria.postgresql.org; Fri, 02 Sep 2022 04:10:58 +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 1oTy1A-00064W-K9 for pgsql-general@lists.postgresql.org; Fri, 02 Sep 2022 04:10:58 +0000 Received: from wout3-smtp.messagingengine.com ([64.147.123.19]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1oTy15-00077a-Et for pgsql-general@lists.postgresql.org; Fri, 02 Sep 2022 04:10:55 +0000 Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.west.internal (Postfix) with ESMTP id 34D763200B45; Fri, 2 Sep 2022 00:10:47 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Fri, 02 Sep 2022 00:10:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; t=1662091846; x= 1662178246; bh=Z3vmC6LvdsZSpM2rGzGqWxxzCsp7vnDxJN+2RThXk7M=; b=Z bK+Jv57KRWtIc6SNwe+OWsgAone8adNQW8mU38KMzV0lJSEUwUvskjsvpqfkXhMT SCoDjYJyxasMvkuA8TRrhT9brwK1B3czxiJEEZBb7576LlR0i660XvlgrdKMykBm my6WQAk/676tLOUkUpaBN64QwA0rXH/YlMFyAQGv/u7lM9KK5JwjcWx391VS84He wG6IgIHsDfWA9g6FvdGyA1fEavh6jdnvKn1mk8dyTi0ntPFMRGV2I1dj4is0zxoS HGx2Sjd0H5syC2pbfm4HGFu/FAsNLNczH1H9twdKNHob+1uTiC3kDKYwpL0qV2Bo +ZQkpQyqKn4rRaPqyrR1A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm1; t=1662091846; x= 1662178246; bh=Z3vmC6LvdsZSpM2rGzGqWxxzCsp7vnDxJN+2RThXk7M=; b=N 7rfJiCQWQzbqaqY4zlr5xB1rFex08kGM9Rja9/hAD554be1HnCoGo6Lfo2CDAKie ReWWikFVteXz0sRg62XmYH2VY0g8roUca90GbCiNWQNz3iYZbMMUxE/h9BD88ssm R9mJ6Gg/mIjUtqfe1vZLqBZa+GRokwQ0LdkbQz8ymasBlHwNmsoJdLorSFyMRBCm /F9cvzlG9JHFm08AvaQh9S4fQdqdY+cQ/wR+AxDXY5OeP/C46xh+dWf7FF1rqJwQ Mloy3+IahHfE3pih2GYyH/GevZqk7bzZRXnol25V/ob7Bjz3ZbnTHRqWirWP6m5/ RQ7t2KfIqR12qXRlzsUAA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvfedrvdekledgkeduucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefuvfevfhfhkffffgggjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeduhedttd eigfefjefghfeugefgudetffdugedvteehheegffeuffevhedtteeftdenucffohhmrghi nheptghonhhfrdhimhdpphhoshhtghhrvghsqhhlrdhorhhgpdhgihhthhhusgdrtghomh enucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughr ihgrnhdrkhhlrghvvghrsegrkhhlrghvvghrrdgtohhm X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 2 Sep 2022 00:10:45 -0400 (EDT) Subject: Re: How to make PostreSQL utilities honor home directories? To: noloader@gmail.com, Tom Lane Cc: "Peter J. Holzer" , pgsql-general@lists.postgresql.org References: <780195.1662070574@sss.pgh.pa.us> <20220902002307.qrxhyeexronkdgsr@hjp.at> <810388.1662079862@sss.pgh.pa.us> From: Adrian Klaver Message-ID: Date: Thu, 1 Sep 2022 21:10:44 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 9/1/22 6:31 PM, Jeffrey Walton wrote: > On Thu, Sep 1, 2022 at 8:51 PM Tom Lane wrote: >> >> "Peter J. Holzer" writes: >>> However, the symlink doesn't seem to be the culprit. If I run >>> % sudo -u postgres -H /usr/lib/postgresql/13/bin/psql >>> (which is not a symlink) >>> I get the same behaviour. So it seems that psql changes to its basedir >>> and then can't change back again. >> >> Ah --- looking closer at that code, it will chdir *before* checking >> whether the target file is a symlink, which is probably unnecessarily >> stupid. I'm wondering whether we could drop that logic altogether [1], >> but that won't help you today. >> >> I concur with the other person asking why you want to sudo to postgres >> at all, though. It's generally safest if the client side isn't running >> as the same user as the server. > > The use case is an install of DefectDojo [2]. I _think_ they are > taking advantage of the fact that as root, you don't need to > authenticate because of postgresql's use of domain sockets. (Hat tip > for that, by the way). The installer code will install packages, setup > the database, install the DefectDojo programs, etc. You are not running as root(Postgres won't allow you do this anyway) you are running as postgres system user and the authentication is handled by pg_hba.conf. I'm also betting that if you look at pg_hba.conf it is set up to do peer authentication and hence the need to be postgres system user. You can obtain a similar result in pg_hba.conf with: TYPE DATABASE USER ADDRESS METHOD local all postgres trust Then you could eliminate the whole sudo dance. Or set up: TYPE DATABASE USER ADDRESS METHOD host postgres all scram- sha-256 if you want password protection. > > Jeff > >> [1] https://www.postgresql.org/message-id/797232.1662075573%40sss.pgh.pa.us > [2] https://github.com/DefectDojo/godojo > > -- Adrian Klaver adrian.klaver@aklaver.com