Vault IaC: bootstrap AppRole + config vars + import state (steps 2-4 of #1515) #1519
Labels
No labels
epic
fleet:hub
fleet:identity
fleet:ingress
fleet:offload
fleet:sveltos
needs-triage
ready-for-agent
ready-for-human
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
lab/clusters#1519
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Vault IaC: bootstrap AppRole, config vars, and import state (steps 2–4 of #1515)
Claim me. One-time manual Vault-admin work to get
vault-configreconciling on mini.Prerequisites
vault-policy-adminpolicy + ability to writeauth/approle/*,sys/policy/*).VAULT_ADDR=https://vault.animeteamspeak.moeandVAULT_TOKEN=<root>exported for everyvaultcommand below.kubectlpointed at mini (KUBECONFIG=~/.kube/mini).../iac/vault/terraform.tfstatestill present.Order: (2) bootstrap AppRole → (3) create
vault-config-varssecret → (4) import state. Do not proceed past a gate until its verification passes.Stage 2 — Bootstrap the runner AppRole (ADR 0004)
The runner AppRole + its policy are excluded from the IaC: create a dedicated admin-breadth policy here — do not reuse the IaC-managed
vault-policy-admin(a tofu-managed policy the runner depends on is the self-lockout risk ADR 0004 exists to prevent).Create a policy file, e.g.
/tmp/vault-runner.hcl:Do not add these to
infra/vault/. This is the one manual Vault-admin step; everything after is code.Stage 3 — Create the
vault-config-varssecret on miniThe
vault-configTerraform object readsvarsFroma Secret namedvault-config-varsinflux-system. Create it directly withkubectl— not via ESO (see note at the bottom).The
oidc_client_secretis the OAuth2 client secret for thevaultapplication in Kanidm (auth.animeteamspeak.moe). If you don't have it:scripts/newOAuth.shcreated the app and prints the secret; or re-fetch from the Kanidm OAuth2 app config.Why kubectl, not ESO: not circular today (ESO authenticates via the independent
vault-token), but it would require first writing the AppRole creds into Vault KV — a wider blast radius than a one-shot secret. Circularity only becomes real when ESO itself moves to AppRole auth in #1518; the bootstrap creds for that must come from out-of-band anyway. Direct secret = simplest, matches ADR 0004.Stage 4 — Import existing state so tofu owns it, not recreates it
The following already exist live in Vault and are declared in
infra/vault/; tofu must import them or the first apply will try to create them and conflict:vault_jwt_auth_backend.animeteamspeakoidcvault_jwt_auth_backend_role.animeteamspeak_roleoidc/animeteamspeak_defaultvault_identity_group.super_admins_groupe2e95fdd-f5bf-6a6b-7ecf-59d76def6399vault_identity_group_alias.super_admins_group_aliasf768dc8e-898b-3eca-c7d4-bf7cdd983a8fvault_policy.vault_policy_adminvault-policy-adminvault_policy.managermanagervault_policy.readerreadervault_mount.secretsecretThe 4 OIDC/identity resources are already in
../iac/vault/terraform.tfstate— restore that state into the cluster secret, which carries their IDs forward. The controller's default backend (verified incontrollers/tf_controller_backend.go) writes to secrettfstate-${workspace}-${secretSuffix}in the Terraform object's namespace — heretfstate-default-vault-configinflux-system(NOTdefault):Do the remaining imports BEFORE re-enabling the controller. The restored state carries only 4 of the 8 resources; the policies + KV mount exist live in Vault but not in state. Import them locally against the same backend so the state secret ends up complete — otherwise the first plan wants to create them and
vault_mount.secret's create fails (path is already in use).Use the
tofu(OpenTofu) binary, notterraform. The kubernetes backend'sencoding: gzipstate annotation is honoured bytofubut NOT by the Hashicorpterraformbinary —terraformmisreads the gzip state as empty and clobbers the secret. Import from a scratch copy ofinfra/vault/with a kubernetes backend block added (never add it to the committedprovider.tf— the controller injects its own backend each reconcile):The 4 policy/mount imports complete the state;
tofu state listshould show all 8 resources. The runner-exec alternative (below) also usestofu(the runner ships OpenTofu). Prefer the local import path over runner-exec — it must finish before the controller is re-enabled, and runner-exec fights the controller's own reconcile loop for the state lock.If the runner-exec route is awkward, the alternative is to pull the state back out, run local imports against a copy of
infra/vault/with a kubernetes backend pointing at the same secret, and restore. Prefer whichever you can verify end-to-end; document the choice on this issue.After Stage 4 — first apply (not part of this issue)
Watch the plan, set
spec.approvePlanto the generated plan name to apply. Record anything that drifts unexpectedly as a comment here.Out of scope
Correction applied (Stage 4): the tfstate secret goes in flux-system, not
default— the controller's default kubernetes backend writes totfstate-${workspace}-${secretSuffix}in the Terraform object's namespace (verified incontrollers/tf_controller_backend.go). Restore command now has-n flux-system.Also: do the 4 policy/mount imports locally against the same backend BEFORE re-enabling the tofu-controller deployment. The restored
../iac/vaultstate only carries the 4 OIDC/identity resources; policies + KV mount exist live but not in state. If the controller reconciles first, the plan wants to create them andvault_mount.secret's create fails with "path is already in use". Prefer the localterraform init -reconfigure -backend-config=...+terraform importpath over runner-exec (avoids state-lock contention with the controller).Stage 4 imports completed using
tofu(OpenTofu 1.12.1), with the gzip-annotated state secret restored intoflux-system(this is the key fix:terraformmisreads theencoding: gzipstate as empty and clobbers the secret;tofuhonours it).All 8 resources are now in
tfstate-default-vault-config(verified live):../iac/vault: the 4 OIDC/identity resourcestofu import(env token, scratch copy ofinfra/vault/with a kubernetes backend block):vault_policy.vault_policy_admin,vault_policy.manager,vault_policy.reader,vault_mount.secretRemaining for the claimer: Stage 2 (AppRole bootstrap) and Stage 3 (
vault-config-varssecret) are still outstanding — the controller reconcile is currently erroring onsecrets "vault-config-vars" not found. Once Stage 2+3 are done, re-enable the tofu-controller deployment and watch the plan.All stages complete. Stages 2-3 confirmed:
vault-config-varssecret holds approle_role_id/approle_secret_id/oidc_client_secret. Stage 4: all 8 resources intfstate-default-vault-config(4 OIDC/identity restored from../iac/vault+ 4 policy/mount imported viatofu). First apply succeeded (plan-master-7f2dc887b1) with the approval loop verified — the IaC now lives inlab/iac(see #1515 comment).