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 1kpf7n-0004eU-R4 for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Dec 2020 22:18:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1kpf7m-0006Mi-P4 for pgsql-hackers@arkaria.postgresql.org; Wed, 16 Dec 2020 22:18:22 +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 1kpf7m-0006Mb-ID for pgsql-hackers@lists.postgresql.org; Wed, 16 Dec 2020 22:18:22 +0000 Received: from momjian.us ([72.94.173.45]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1kpf7g-0002xn-04 for pgsql-hackers@postgresql.org; Wed, 16 Dec 2020 22:18:22 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1kpf7c-0000Im-Cs; Wed, 16 Dec 2020 17:18:12 -0500 Date: Wed, 16 Dec 2020 17:18:12 -0500 From: Bruce Momjian To: Alastair Turner Cc: Stephen Frost , Michael Paquier , PostgreSQL-development , Masahiko Sawada Subject: Re: Proposed patch for key managment Message-ID: <20201216221812.GE4527@momjian.us> References: <20201215031902.GB14596@momjian.us> <20201215190909.GK16415@tamriel.snowman.net> <20201216001228.GC14807@momjian.us> <20201216184257.GA4527@momjian.us> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="tjCHc7DPkfUGtrlw" Content-Disposition: inline In-Reply-To: <20201216184257.GA4527@momjian.us> User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --tjCHc7DPkfUGtrlw Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Dec 16, 2020 at 01:42:57PM -0500, Bruce Momjian wrote: > On Wed, Dec 16, 2020 at 06:07:26PM +0000, Alastair Turner wrote: > > Hi Bruce > > > > On Wed, 16 Dec 2020 at 00:12, Bruce Momjian wrote: > > > > > ... > > > > > > The second approach is to make a new API for what you want.... > > > > I am trying to motivate for an alternate API. Specifically, an API > > which allows any potential adopter of Postgres and Cluster File > > Encryption to adopt them without having to accept any particular > > approach to key management, key derivation, wrapping, validation, etc. > > A passphrase key-wrapper with validation will probably be very useful > > to a lot of people, but making it mandatory and requiring twists and > > turns to integrate with already-established security infrastructure > > sounds like a barrier to adoption. > > Attached is a script that uses the AWS Secrets Manager, and it does key > rotation with the new pg_altercpass tool too, just like all the other > methods. Attached is an improved script that does not pass the secret on the command line. -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee --tjCHc7DPkfUGtrlw Content-Type: application/x-sh Content-Disposition: attachment; filename="pass_aws.sh" Content-Transfer-Encoding: quoted-printable :=0A=0A# This uses the AWS Secrets Manager using the AWS CLI=0A=0A[ "$#" -n= e 1 ] && echo "cluster_passphrase_command usage: $0 \"%d\"" 1>&2 && exit 1= =0A# No need for %R or -R since we are not prompting=0A=0ADIR=3D"$1"=0A=0A#= File containing the passphrased encrypted with the PIV_SLOT's public key= =0AAWS_ID_FILE=3D"$DIR/aws-secret.id"=0A=0A=0A# Create an AWS Secrets Manag= er secret?=0Aif [ ! -e "$AWS_ID_FILE" ]=0Athen # The 'postgres' operating s= ystem user must have permission to=0A # access the AWS CLI=0A=0A TIME=3D$(d= ate '+%s')=0A # The directory/time combination is unique=0A HASH=3D$(echo -= n "$DIR$TIME" | sha1sum | awk '{print $1}')=0A AWS_SECRET_ID=3D"Postgres-pa= ssphrase-$HASH"=0A=0A # Use stdin to avoid passing the secret on the comman= d line=0A openssl rand -hex 32 |=0A xxd -plain -cols 999 |=0A aws secretsma= nager create-secret \=0A --name "$AWS_SECRET_ID" \=0A --description 'Used= for Postgres cluster file encryption' \=0A --secret-string 'file:///dev/s= tdin' \=0A --output text > /dev/null=0A [ "$?" -ne 0 ] && exit 1=0A=0A ech= o "$AWS_SECRET_ID" > "$AWS_ID_FILE"=0Afi=0A=0Aif ! aws secretsmanager get-s= ecret-value \=0A --secret-id "$(cat "$AWS_ID_FILE")" \=0A --output text=0At= hen exit 1=0Afi | awk -F'\t' 'NR =3D=3D 1 {print $4}'=0A=0Aexit 0=0A --tjCHc7DPkfUGtrlw--