Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hziN4-0003iJ-DL for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Aug 2019 14:10:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hziN3-0002lF-9x for pgsql-bugs@arkaria.postgresql.org; Mon, 19 Aug 2019 14:10:53 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hziJq-0001Ao-Ih for pgsql-bugs@lists.postgresql.org; Mon, 19 Aug 2019 14:07:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hziJn-0007aD-Co for pgsql-bugs@lists.postgresql.org; Mon, 19 Aug 2019 14:07:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x7JE7Q83020827; Mon, 19 Aug 2019 10:07:26 -0400 From: Tom Lane To: Arthur Zakirov cc: rhpatrick@gmail.com, pgsql-bugs@lists.postgresql.org Subject: Re: BUG #15961: psql should be able to read password from stdin In-reply-to: <174993ee-33da-4b5a-8568-7575b7f9e9dc@postgrespro.ru> References: <15961-a17e673003b92f17@postgresql.org> <174993ee-33da-4b5a-8568-7575b7f9e9dc@postgrespro.ru> Comments: In-reply-to Arthur Zakirov message dated "Mon, 19 Aug 2019 12:40:05 +0300" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <20825.1566223645.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Mon, 19 Aug 2019 10:07:25 -0400 Message-ID: <20826.1566223645@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Arthur Zakirov writes: > On 16.08.2019 17:20, PG Bug reporting form wrote: >> My use case is that I am writing terraform scripts to standup Sonarqube= in >> AWS. After creating the AWS RDS PostgreSQL database, I need to be able= to >> create the sonarqube user and grant access to the sonarqube database th= at >> was created with the RDS instance. I can work around this using the >> PGPASSWORD environment variable but that seems to be deprecated. I don= 't >> want to use the .pgpass solution since I don't want/need the postgres u= ser's >> credentials in my EC2 instance where the Sonarqube server will be runni= ng... > Is PGPASSWORD really deprecated? It's insecure on some platforms (where other users can see a process's environment variables). AWS may not be like that, not sure. > I guess passing a password by command-line might have similar security = > problems. If it suits you then PGPASSWORD should work for you too. Yeah, this. It's not very clear to me how such a feature wouldn't just move the security problem somewhere else. Where is the program on the front end of the pipe going to get the password from? I don't think that Peter's objection has much force. We could just say that a password-from-stdin feature is only allowed in combination with -f and/or -c, so that there's no conflict as to what stdin should provide. So given a bulletproof use-case, I wouldn't be averse to adding such a feature. But if it's just moving the problem elsewhere, I'm not in favor of it. We try to steer people away from insecure password usage --- that's why there's no put-the-password-on-the- command-line option. (I'm afraid that password-from-stdin would encourage people to do "echo $PASSWORD | psql" and thereby be completely vulnerable to command-line exposure hazards.) In any case, that would be a new feature not a bug fix, so the very earliest you could hope to see it would be v13 next year. For shorter-term fixes, you could consider: * Run psql in an environment where /dev/tty is a pseudo-tty that you can feed input to. This fails to avoid any of the security questions mentioned above, but at least it's a solution available today. * Don't use passwords. PG offers a bunch of other authentication technologies that are way friendlier to use in scripts. regards, tom lane