Watch
0
0
Fork
You've already forked hyperhive
0

keep the container's secret key through the pod's first start

Grafana wraps the data keys of its database with secret_key, and a different
key makes them undecryptable, which grafana cli's re-encrypt cannot repair
(it decrypts with the current key first). So the init container takes the
store's key, else the file the container generated, else a new key, and a new
key only over a database that holds no data_keys row; otherwise it exits
non-zero naming the leaf. The file reaches it read-only through a claim on a
static local volume, because the namespace refuses a hostPath.
This commit is contained in:
atlas 2026-11-28 00:21:37 +01:00
commit bd0cff47f9

View file

@ -1,7 +1,7 @@
# `checks.script-test-grafana-secret-key` — runs
# ../host-modules/lib/grafana-secret-key.nix's `grafana_secret_key` against a
# stub `bao` that keeps its leaves in files. The cases are in
# ./grafana-secret-key.sh.
# stub `bao` that keeps its leaves in files and a real `sqlite3` over small
# databases. The cases are in ./grafana-secret-key.sh.
#
# What runs is the rendered helper, sourced as the unit's script includes it.
{
@ -9,20 +9,16 @@
...
}:
let
# `login` answers from `FAKE_BAO_LOGIN_RC`. `kv get` and `kv put -cas=0` act
# on a file per leaf under `FAKE_BAO_KV`, and answer as bao does: a missing
# `kv get` and `kv put -cas=0` act on a file per leaf under `FAKE_BAO_KV`, and answer as bao does: a missing
# leaf is "No value found at <path>" on stderr, status 2. `FAKE_BAO_DENY_READ`
# and `FAKE_BAO_DENY_WRITE` answer 403 as a policy that grants neither does.
# and `FAKE_BAO_DENY_WRITE` answer 403 as a policy that grants neither does. A call without the pod's
# login token (`BAO_TOKEN`, set by the cases) answers 97.
# `FAKE_BAO_RACE` has another run create the leaf with that value between
# this one's read and its write. Every call is logged without the value
# `put` reads from stdin.
fakeBao = pkgs.writeShellScriptBin "bao" ''
echo "$*" >> "$FAKE_BAO_LOG"
case "$1 $2" in
"login -method=cert")
[ "$FAKE_BAO_LOGIN_RC" = 0 ] || { echo "fake bao: certificate refused" >&2; exit 2; }
printf 's.fake'
;;
"kv get")
[ "''${BAO_TOKEN-}" = s.fake ] || { echo "fake bao: kv without the login's token" >&2; exit 97; }
[ "$3" = -field=value ] || { echo "fake bao: get without -field=value" >&2; exit 95; }
@ -60,7 +56,11 @@ pkgs.runCommand "hyperhive-script-test-grafana-secret-key"
import ../host-modules/lib/grafana-secret-key.nix { }
);
FAKE_BAO_BIN = "${fakeBao}/bin";
nativeBuildInputs = [ pkgs.coreutils ];
nativeBuildInputs = [
pkgs.coreutils
pkgs.gnugrep
pkgs.sqlite
];
}
''
${pkgs.bash}/bin/bash ${./grafana-secret-key.sh}