Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1eg0R0-0006iL-2d for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2018 03:48:42 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1eg0Qx-0006DH-TP for pgsql-general@arkaria.postgresql.org; Mon, 29 Jan 2018 03:48:39 +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 1eg0Qx-0006D7-I6 for pgsql-general@lists.postgresql.org; Mon, 29 Jan 2018 03:48:39 +0000 Received: from momjian.us ([72.94.173.45]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1eg0Qq-00034g-Dm for pgsql-general@postgresql.org; Mon, 29 Jan 2018 03:48:38 +0000 Received: from bruce by momjian.us with local (Exim 4.84_2) (envelope-from ) id 1eg0Qn-0003En-V4; Sun, 28 Jan 2018 22:48:29 -0500 Date: Sun, 28 Jan 2018 22:48:29 -0500 From: Bruce Momjian To: Andrew Dunstan Cc: Tom Lane , Desidero , pgsql-general@postgresql.org Subject: Re: [GENERAL] pgpass file type restrictions Message-ID: <20180129034829.GC11620@momjian.us> References: <11556.1508393575@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.5.23 (2014-03-12) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Oct 19, 2017 at 08:22:18AM -0400, Andrew Dunstan wrote: > > > On 10/19/2017 02:12 AM, Tom Lane wrote: > > Desidero writes: > >> I’m running into problems with the restriction on pgpass file types. When > >> attempting to use something like an anonymous pipe for a passfile, psql > >> throws an error stating that it only accepts plain files. > >> ... > >> Does anyone know why it’s set up to avoid using things like anonymous pipes > >> (or anything but "plain files")? > > A bit of digging in the git history says that the check was added here: > > > > commit 453d74b99c9ba6e5e75d214b0d7bec13553ded89 > > Author: Bruce Momjian > > Date: Fri Jun 10 03:02:30 2005 +0000 > > > > Add the "PGPASSFILE" environment variable to specify to the password > > file. > > > > Andrew Dunstan > > > > and poking around in the mailing list archives from that time finds > > what seems to be the originating thread: > > > > https://www.postgresql.org/message-id/flat/4123BF8C.5000909%40pse-consulting.de > > > > There's no real discussion there of the check for plain-file-ness. > > My first guess would have been that the idea was to guard against > > symlink attacks; but then surely the stat call needed to have been > > changed to lstat? So I'm not quite sure of the reasoning. Perhaps > > Andrew remembers. > > > > That was written 13 years ago. I'm afraid my memory isn't that good. I am coming in late here, but the thread does say: https://www.postgresql.org/message-id/200506100302.j5A32aj12016%40candle.pha.pa.us Another new addition is that we now will check to see that the password file is a regular file and not a symlink or something. This was part of your patch for PGPASSFILE but I extended it to ~/.pgpass too. Seems the stat, and not lstat, usage is a bug. -- Bruce Momjian http://momjian.us EnterpriseDB http://enterprisedb.com + As you are, so once was I. As I am, so you will be. + + Ancient Roman grave inscription +