Take the master key from KEEPORG_MASTER_KEY_FILE
Why: the usual way to hand a secret to a container is to mount it as a file and name the path in the environment. Compose, swarm and Kubernetes all do it that way, and it keeps the key out of the process environment and off any disk the container can write. What: the master key is now looked for in KEEPORG_MASTER_KEY, then KEEPORG_MASTER_KEY_FILE, then the configured master_key_file. A secret file may hold base64, with or without padding or a trailing newline, or exactly 32 raw bytes, because secret stores produce both. Only the configured path is ever created, which is what keeps a plain package install working with no setup. The two environment variables name a key something else owns, so a missing one is reported and vault creation refused. Minting a replacement there would be worse than failing: it opens none of the existing vaults, and the mistake would otherwise surface one failed merge at a time. The compose example now provisions the key as a real secret rather than an environment variable, and the Dockerfile and README show the same. Neither names a version any more, so they stop drifting as the server is bumped. Proved: unit tests for every source and precedence, all four accepted encodings, and that a missing secret writes nothing anywhere. In real containers: a podman secret carrying base64 survives a stop and start with "1 vault keys available for merging" and merges a stale push afterwards; a secret holding 32 raw bytes creates a vault; and a secret that failed to mount is named in the startup log, with vault creation answering with the three places a key may come from.
This commit is contained in:
@@ -132,9 +132,10 @@ func (s *Server) checkVaultKeys() {
|
||||
case broken > 0:
|
||||
s.log.Printf("WARNING: %d of %d stored vault keys do not open with this "+
|
||||
"master key. Those vaults cannot be merged until the original key is "+
|
||||
"restored (%s or %s). Nothing is lost: clients still open the vaults "+
|
||||
"with their own passwords.",
|
||||
broken, total, secret.MasterKeyEnv, s.cfg.MasterKeyFile)
|
||||
"restored ($%s, $%s, or %s). Nothing is lost: clients still open the "+
|
||||
"vaults with their own passwords.",
|
||||
broken, total, secret.MasterKeyEnv, secret.MasterKeyFileEnv,
|
||||
s.cfg.MasterKeyFile)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,8 +18,9 @@ import (
|
||||
const MinVaultPasswordLen = 12
|
||||
|
||||
var errNoKeyring = errors.New(
|
||||
"this server has no master key, so it cannot hold vault keys: set " +
|
||||
secret.MasterKeyEnv + " or master_key_file and restart")
|
||||
"this server has no master key, so it cannot hold vault keys: set $" +
|
||||
secret.MasterKeyEnv + ", $" + secret.MasterKeyFileEnv +
|
||||
", or master_key_file, and restart")
|
||||
|
||||
// createVault makes a new, empty KDBX database, encrypts it with the given
|
||||
// vault password and stores it as version 1. When the strategy needs the
|
||||
|
||||
Reference in New Issue
Block a user