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 1lEm0O-0004Dl-IJ for pgsql-admin@arkaria.postgresql.org; Wed, 24 Feb 2021 04:42:32 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEm0M-0005MT-Q3 for pgsql-admin@arkaria.postgresql.org; Wed, 24 Feb 2021 04:42:30 +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 1lEm0M-0005ML-Il for pgsql-admin@lists.postgresql.org; Wed, 24 Feb 2021 04:42:30 +0000 Received: from ook.raf.org ([139.99.156.21]) by magus.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lEm0K-0003d5-3U for pgsql-admin@lists.postgresql.org; Wed, 24 Feb 2021 04:42:30 +0000 Received: from localhost (localhost [127.0.0.1]) by ook.raf.org (Postfix) with ESMTP id C190E5DE4B; Wed, 24 Feb 2021 15:42:23 +1100 (AEDT) X-Virus-Scanned: Debian amavisd-new at ook.raf.org Received: from ook.raf.org ([127.0.0.1]) by localhost (ook.raf.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0SthIfivEKKB; Wed, 24 Feb 2021 15:42:23 +1100 (AEDT) Received: by ook.raf.org (Postfix, from userid 1001) id 852E05E264; Wed, 24 Feb 2021 15:42:23 +1100 (AEDT) Date: Wed, 24 Feb 2021 15:42:23 +1100 From: raf To: Tim Cross Cc: pgsql-admin@lists.postgresql.org Subject: Re: How to encrypt password in pgpass file Message-ID: <20210224044223.7cwkbced3ticu6bk@raf.org> References: <87eeh6xnyy.fsf@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <87eeh6xnyy.fsf@gmail.com> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Wed, Feb 24, 2021 at 11:27:45AM +1100, Tim Cross wrote: > Vipin Madhusoodanan writes: > > > Hi Team, > > > > We have a security requirement to encrypt passwords in .pgpass file. Could you please advise on the options and steps to be followed to achieve this. > > > > Basically, don't use .pgpass. I think .pgpass should be viewed as old > legacy solution which is not terribly compatible with today's security > requirements. I don't think there is support for encrypting the .pgpass > file. Even if you could encrypt the .pgpass file, you would then need to > decrypt it with a passpharase anyway (you could have a key which has no > passpharase, but if that is on the same system, what have you achieved > apart from a false sense of security). > > How to best solve your requirement depends on the specifics of your > requirement. However, often you can implement something more secure by > using environment variables which are set for the process the psql (or > whatever) command executes in. The value for the variable can be > obtained from a secure source, such as a keyring, ldap server, gpg > encrypted file etc. Sometimes, the security requirements are for encryption-at-rest, and it doesn't particularly matter if encryption-at-rest is actually secure against likely threats (sadly). For example, you could use file system encryption (e.g. ecryptfs/LUKS/Linux, FileVault/macOS, BitLocker/Windows). Then all of your files are encrypted at rest, including .pgpass. But it's only secure when the computer is powered down (i.e. if it is physically stolen, or the disk is physically removed). It provides no security for a computer that is up and running, and compromised. But that might satisfy the parties that make up the requirements. It all depends on the threat model that they need to address. So it can be easy to do, but does it satisfy your requirements? If so, encrypt the file system (and know that it isn't secure). If not, maybe Hashicorp's Vault product, or clevis and tang, could be used to store passwords instead of putting them in a .pgpass file. cheers, raf