Protect the CA keys¶
File permissions (0600, owned by the CA's user) protect the keys from
other users of the running machine. They do not protect copies:
backups, VM snapshots, disk images, a lost USB stick. Encryption does, as
long as the passphrase is not copied along with the key.
The root key: offline¶
The root key is always encrypted, with a passphrase of at least 12 characters. The server never reads it, so it should not stay on the CA machine at all:
writes it straight to removable storage; it never touches data_dir. Keep
a second copy somewhere else, and the passphrase in a password manager.
You need the root key only to
replace the intermediate. For scripts,
--root-passphrase-file reads the passphrase from a file (/dev/stdin
works) instead of asking.
If the root key is still in data_dir, the server and bxp doctor
warn.
The server's keys: encrypted, with the passphrase elsewhere¶
The keys the server uses (intermediate.key, the SSH CA keys,
token.key) can be encrypted too. Then the server needs their passphrase
every time it starts. Where it keeps that passphrase decides whether
the encryption helps:
| Where the passphrase is | Protects copies of data_dir? |
|---|---|
| systemd credential sealed to the machine's TPM | Yes, also a copy of the whole disk: it decrypts only on that machine. Recommended. |
| Kubernetes or Docker secret, or the environment | Yes: it is kept apart from the CA's storage. |
A file on the same disk, outside data_dir |
Backups of data_dir alone, not a disk image. The server warns. |
A file inside data_dir |
No. BastionXP CA refuses it. |
No passphrase protects the keys from someone who takes over the running CA as root: the keys are in memory then. Only a hardware security module (HSM) covers that.
With systemd and a TPM (recommended)¶
# Make a random passphrase and seal it to this machine's TPM.
openssl rand -base64 32 | systemd-creds encrypt --with-key=tpm2 \
--name=bastionxp-ca-key-passphrase - /etc/credstore.encrypted/bastionxp-ca-key-passphrase
# Create the CA with it (bash: the passphrase goes through a pipe, never
# onto the disk).
BXP_KEY_PASSPHRASE_FILE=<(systemd-creds decrypt /etc/credstore.encrypted/bastionxp-ca-key-passphrase -) \
bxp init --config /etc/bastionxp-ca/bastionxp-ca.yaml --root-key-out /media/usb/root.key
Then, in the service unit (systemd finds the file in
/etc/credstore.encrypted by its name):
BastionXP CA finds the credential by itself.
Without systemd¶
asks for the server's passphrase. It must differ from the root's. Give it to the server with one of the sources below.
Where the server looks for its passphrase¶
In this order:
ca.key_passphrase_filein the configuration;- the systemd credential
bastionxp-ca-key-passphrase; - the file named by
BXP_KEY_PASSPHRASE_FILE; BXP_KEY_PASSPHRASE, the passphrase itself. BastionXP CA removes it from its environment as soon as it has read it, so nothing it starts inherits it. But mind who else can see it: a systemdEnvironment=line is shown to every local user bysystemctl show, anddocker inspectprints a container's environment;- otherwise it asks on the terminal, if there is one.
bxp token on the CA machine opens the token key, so with encrypted
keys it needs the passphrase the same way. bxp doctor reports where
the passphrase comes from and whether the keys open, without ever asking.
The file format¶
The key files are standard encrypted PKCS#8 (PBES2 with scrypt and AES-256), so OpenSSL can read them:
Checklist¶
-
root.keyis offline, with a second copy elsewhere. - The root passphrase is in a password manager, not next to the key.
- The server's keys are encrypted, with the passphrase sealed to the TPM or in a secret store.
-
data_diris mode700, owned by the CA's user. - Backups of
data_dirare kept as private asdata_dir.