Manage the agent API service account and token in Terraform #30
Reference in New Issue
Block a user
Delete Branch "benvin/agent-api-token-iac"
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?
Why
The Authentik API token used by estate automation was created by hand in the UI and pasted into Vault. It is undocumented, unauditable, and cannot be rotated reproducibly. First consumer:
agentvault seed-outpost, which readskv/service/authentik/agent-api-token(keytoken) to fetch outpost tokens.How
config/service_accounts/<username>.yaml, wired throughconfig/config.hcl+ terragrunt inputs exactly like the existing kinds.authentik_user(type = service_account), anauthentik_rbac_roleholding its global permissions,authentik_rbac_permission_rolegrants,authentik_tokens, and avault_kv_secret_v2write publishing each token key.config/service_accounts/sa-agent-api.yaml: grantsauthentik_outposts.view_outpost,authentik_core.view_token,authentik_core.view_token_key; tokenagent-api-token, intentapi,expiring = false, key written tokv/service/authentik/agent-api-token.Merge order — terraform-vault first
This PR must not be applied before
terraform-vaultPRbenvin/tf-authentik-kv-writeis applied. This repo's Vault role currently only reads kv; the newvault_kv_secret_v2needs a write grant onkv/data/service/authentik/agent-api-token. Plan here passes (new resource, no prior state, no read of the path), but apply will 403 until that grant lands.Notes
authentik_rbac_permission_useris deprecated in provider 2026.5 ("Migrate toauthentik_rbac_permission_role"), so permissions attach to a per-account RBAC role and the role attaches to the account — same effective global grants, non-deprecated path.retrieve_key = trueis required for the provider to populate the tokenkey; without it the attribute is empty and nothing reaches Vault.