Watch
0
0
Fork
You've already forked hyperhive
0

swarmctl bao init: save bao's raw output before parsing, and accept null key lists

This commit is contained in:
atlas 2026-11-24 15:35:57 +01:00
commit 870a0a6697
2 changed files with 395 additions and 73 deletions

View file

@ -3,7 +3,7 @@
# docs/1-getting-started/setup.md until the agents are deployed and need a login.
#
# Steps of setup.md, as the script runs them:
# 1 secret store `bao operator init`, the granter bootstrap with the root
# 1 secret store `swarmctl bao init`, the granter bootstrap with the root
# token, then the policy units reset and restarted.
# 4 unseal `bao operator unseal` (`deploy.bao.seal` is "shamir"; pkcs11
# needs a TPM). A pkcs11 store unseals itself at init, so here

View file

@ -9,7 +9,8 @@ HIVE = os.environ["FULL_SETUP_HIVE"]
TOPLEVELS = json.loads(os.environ["FULL_SETUP_TOPLEVELS"])
REPO = os.environ["FULL_SETUP_HYPERHIVE_REPO"]
CONTROL_NIX = os.environ["FULL_SETUP_CONTROL_NIX"]
INIT = "/root/bao-init.json"
# Where `swarmctl bao init` saves what `bao operator init` printed, for root.
INIT = "/root/.local/state/swarmctl/bao-init.json"
# The host's swarmctl defaults to the swarm's gateway, where each controller verb needs a
# `swarmctl login`, which a VM without a browser cannot do. An empty `SWARMCTL_SWARM` puts a
# verb on the controller socket.
@ -114,16 +115,36 @@ with subtest("the agents' toplevels are in the store, and the daemon builds noth
)
# setup.md step 1: the secret store.
with subtest("step 1: bao operator init"):
with subtest("step 1: swarmctl bao init"):
machine.wait_until_succeeds(
'[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=600
)
machine.succeed("swarmctl bao init >/root/bao-init.out 2>/root/bao-init.err")
# The keys file is saved before swarmctl parses, at mode 0600, and holds what it printed.
machine.succeed(f'[ "$(stat -c %a {INIT})" = 600 ]')
machine.succeed(
f"umask 077 && bao operator init -key-shares=1 -key-threshold=1 -format=json > {INIT}"
f"jq -e '(.unseal_keys_b64 | length) == 5 and (.root_token | length) > 0' {INIT}"
)
machine.succeed(
f'grep -qxF "Initial root token: $(jq -r .root_token {INIT})" /root/bao-init.out'
)
machine.succeed(f"grep -qF {INIT} /root/bao-init.err")
# Control: an initialised store is refused, and the keys file is left as it was.
before = machine.succeed(f"sha256sum {INIT}")
machine.fail("swarmctl bao init")
assert machine.succeed(f"sha256sum {INIT}") == before
with subtest("step 4: bao operator unseal, with the shamir seal"):
machine.succeed(f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\"")
def unseal():
# swarmctl's init uses bao's default of 5 shares with a threshold of 3.
for i in range(3):
machine.succeed(
f"bao operator unseal \"$(jq -r '.unseal_keys_b64[{i}]' {INIT})\""
)
with subtest("step 4: bao operator unseal, with the shamir seal, from the saved keys"):
unseal()
machine.succeed("bao status")
with subtest("step 1: the granter bootstrap"):
@ -168,9 +189,7 @@ with subtest("step 1: the policy units that waited for the granter are restarted
machine.wait_until_succeeds(
'[ "$(bao status >/dev/null 2>&1; echo $?)" = 2 ]', timeout=600
)
machine.succeed(
f"bao operator unseal \"$(jq -r '.unseal_keys_b64[0]' {INIT})\""
)
unseal()
settle(POLICY_UNITS_ACTIVE, 1200, "swarm-bao-*-policy")
machine.succeed(
"journalctl -u swarm-bao-controller-policy --no-pager "