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 1knXIa-0002zL-VG for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Dec 2020 01:32:44 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1knXIZ-0000Da-Kw for pgsql-hackers@arkaria.postgresql.org; Fri, 11 Dec 2020 01:32:43 +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 1knXIZ-0000DT-EB for pgsql-hackers@lists.postgresql.org; Fri, 11 Dec 2020 01:32:43 +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 1knXIW-0001Kp-Pc for pgsql-hackers@postgresql.org; Fri, 11 Dec 2020 01:32:43 +0000 Received: from bruce by momjian.us with local (Exim 4.92) (envelope-from ) id 1knXIV-0002ie-1q; Thu, 10 Dec 2020 20:32:39 -0500 Date: Thu, 10 Dec 2020 20:32:39 -0500 From: Bruce Momjian To: Neil Chen Cc: PostgreSQL-development , Masahiko Sawada Subject: Re: Proposed patch for key managment Message-ID: <20201211013239.GD13515@momjian.us> References: <20201202213814.GG20285@momjian.us> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On Thu, Dec 10, 2020 at 07:26:48PM +0800, Neil Chen wrote: > > > Hi, everyone > > I have read the patch and did some simple tests. I'm not entirely sure > about some code segments; e.g.: > > In the BootStrapKmgr() we generate a data encryption key by: > key = generate_crypto_key(file_encryption_keylen); > > However, I found that the file_encryption_keylen is always 0 in bootstrap > mode because there exitst another variable bootstrap_file_encryption_keylen > in xlog.c and bootstrap.c. Oh, good point; that is very helpful. I was relying on SetConfigOption to set file_encryption_keylen, but that happens _after_ we create the keys, so they were zero length. I have fixed this by passing bootstrap_file_encryption_keylen to the boot routines. The diff URL has the fix: https://github.com/postgres/postgres/compare/master...bmomjian:key.diff > We get the REL/WAL key by KmgrGetKey() call and it works like: > return (const CryptoKey *) &(KmgrShmem->intlKeys[id]); > > But in bootstrap mode, the KmgrShmem are not assigned. So, if we want to > use it to encrypt something in bootstrap mode, I suggest we make the > following changes: > if ( in bootstrap mode) > return intlKeys[id]; // a static variable which contains key > else > reutrn (const CryptoKey *) &(KmgrShmem->intlKeys[id]); Yes, you are also correct here. I had not gotten to using KmgrGetKey yet, but it clearly needs your suggestion, so have done that. Thanks for your help. -- Bruce Momjian https://momjian.us EnterpriseDB https://enterprisedb.com The usefulness of a cup is in its emptiness, Bruce Lee