swarmctl bao init: save bao's raw output before parsing, and accept null key lists
This commit is contained in:
parent
479cdd6efb
commit
870a0a6697
1 changed files with 395 additions and 73 deletions
|
|
@ -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 "
|
||||
|
|
|
|||
Loading…
Reference in a new issue