Watch
0
0
Fork
You've already forked hyperhive
0

wg-hive: derive test keys from a fixed seed so every store agrees

This commit is contained in:
atlas 2026-11-09 15:51:10 +01:00 • committed by mara
commit 4b71bd97eb

View file

@ -2,10 +2,10 @@
# Unlike ../module-eval, which only reads the rendered `networking.wireguard`
# options, this boots both hosts and sends packets.
#
# Keys are minted by a throwaway derivation at build time and nothing is
# committed. The module takes peer public keys as eval-time strings
# (`swarm.hives.<name>.wireguardPublicKey`), so they are read back from
# the derivation's output.
# Keys are derived from a fixed per-host seed, so every store builds the
# same bytes and nothing is committed. The module takes peer public keys
# as eval-time strings (`swarm.hives.<name>.wireguardPublicKey`), so they
# are read back from the derivation's output.
{
pkgs,
self,
@ -13,11 +13,19 @@
let
mkKey =
name:
pkgs.runCommand "wg-hive-test-key-${name}" { nativeBuildInputs = [ pkgs.wireguard-tools ]; } ''
mkdir $out
wg genkey > $out/private
wg pubkey < $out/private > $out/public
'';
pkgs.runCommand "wg-hive-test-key-${name}"
{
nativeBuildInputs = [
pkgs.wireguard-tools
pkgs.openssl
];
}
''
# Test-only key: base64 of sha256(seed); wg clamps the scalar itself.
mkdir $out
printf '%s' 'hyperhive-wg-hive-test-${name}' | openssl dgst -sha256 -binary | base64 > $out/private
wg pubkey < $out/private > $out/public
'';
keys = {
h1 = mkKey "h1";
h2 = mkKey "h2";