Skip to content

Vault setup

OpenBao auto-init produces unseal keys in a sidecar volume. Capture them to 1Password, delete the on-disk copy, then write the static creds.

Terminal window
op item get --vault "HomeLab" "K8s Homelab Vault" --format json \
| jq --arg new_value "$(kubectl exec -n openbao openbao-0 -c vault-autoinit \
-- cat /vault/init-token/cluster-keys.json \
| jq '.' | sed '1s/^/```json\n/;$s/$/\n```/')" \
'.fields |= map(if .id == "notesPlain" then .value = $new_value else . end)' \
| op item edit "K8s Homelab Vault" --vault "HomeLab" 2>&1 > /dev/null

Then delete the on-disk copy:

Terminal window
kubectl exec -n openbao openbao-0 -c vault-autoinit -- rm /vault/init-token/cluster-keys.json
Terminal window
export VAULT_TOKEN=$(op item get --vault "HomeLab" "K8s Homelab Vault" --format json \
| jq -r '.fields[] | select(.id == "notesPlain") | .value' \
| sed 's/^```json[[:space:]]*//;s/[[:space:]]*```$//' \
| jq -r '.root_token')
export VAULT_ADDR=https://vault.services.homelab.muehlena.de
# FIXME: remove once cert pinning is sorted
export VAULT_SKIP_VERIFY=true
./scripts/set-vault-static-creds.bash

Idempotent — safe to re-run if a piece needs to be retried:

Terminal window
kubectl exec vault-0 -n vault -- /bin/sh -c \
"VAULT_TOKEN=$(op item get --vault "HomeLab" "K8s Homelab Vault" --format json \
| jq -r '.fields[] | select(.id == "notesPlain") | .value' \
| sed 's/^```json[[:space:]]*//;s/[[:space:]]*```$//' \
| jq -r '.root_token') /vault/userconfig/scripts/vault-k8s-setup.sh"

Combine raw unseal-key files into a JSON array

Section titled “Combine raw unseal-key files into a JSON array”

If you ever have the individual key files on disk and want a single JSON array:

Terminal window
jq -Rn '[inputs]' < <(for f in *; do cat "$f"; echo; done)