pg.ddx.io  pgsql-hackers@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruce Momjian <bruce@momjian.us>
To: Neil Chen <carpenter.nail.cz@gmail.com>
Cc: PostgreSQL-development <pgsql-hackers@postgresql.org>
Cc: Masahiko Sawada <masahiko.sawada@2ndquadrant.com>
Subject: Re: Proposed patch for key managment
Date: Thu, 10 Dec 2020 20:32:39 -0500
Message-ID: <20201211013239.GD13515@momjian.us> (raw)
In-Reply-To: <CAA3qoJkvH7Dae529cmJ8Ws4bPon+FF7=V5M-Txht_4u3=ALkOQ@mail.gmail.com>
References: <20201202213814.GG20285@momjian.us>
	<CAA3qoJkvH7Dae529cmJ8Ws4bPon+FF7=V5M-Txht_4u3=ALkOQ@mail.gmail.com>

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  <bruce@momjian.us>        https://momjian.us
  EnterpriseDB                             https://enterprisedb.com

  The usefulness of a cup is in its emptiness, Bruce Lee






view thread (93+ messages)  latest in thread

Message-ID: <20201211013239.GD13515@momjian.us>
Permalink:  ../20201211013239.GD13515@momjian.us/
Also on:    postgresql.org/message-id/20201211013239.GD13515@momjian.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-hackers@postgresql.org
  Cc: bruce@momjian.us, carpenter.nail.cz@gmail.com, masahiko.sawada@2ndquadrant.com
  Subject: Re: Proposed patch for key managment
  In-Reply-To: <20201211013239.GD13515@momjian.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox