IUCLabs GitHub Actions workflows need read access to their own KV secrets without per-repo role and policy plumbing. - add `auth/jwt/github/iuclabs` JWT mount trusting GitHub Actions OIDC - add org-wide `default` role (mount `default_role`): audience `https://vault.service.consul:8200`, `user_claim=jti`, metadata mappings, 15m/1h TTLs - restrict to `repository_owner=IUCLabs`, events push/release/schedule/pull_request, refs heads/tags/pull-merge; validation rejects anything wider - attach templated read-only policy on `kv/github/<repo>/event/<event>/*` and `kv/github/<repo>/ref/<ref>/.secrets/*` - add `tofu test` cases, run by `make test` and pre-commit - document login, KV layout, event-path scope, `+` ref caveat and entity growth Pairs with the terraform-git ref-name ruleset. Reviewed-on: #175 Co-authored-by: unkin-agent <unkin-agent@unkin.net> Co-committed-by: unkin-agent <unkin-agent@unkin.net>
3.3 KiB
terraform-vault
A repository to manage the configuration of Vault secret engines, authentication modes and policies.
Usage
- Initialize Terraform
Once you have your backend block configured, you need to initialize your Terraform working directory to configure the backend:
terraform init
This command initializes the backend and checks the connection to Consul. If everything is set up correctly, Terraform will start using Consul as its backend for storing the state.
- Common terraform init Errors
If you encounter errors while running terraform init, check the following:
Consul server is reachable: Make sure that the address is correct and that you can connect to the Consul server.
Consul token (if using ACLs): Verify that the token has the correct permissions to write to the specified path in the Consul KV store.
- Example Consul KV Structure
In Consul, the state file will be stored in the KV store under the specified path:
terraform/state
You can check the Consul KV store by accessing the Consul UI or using the consul kv command to see the stored Terraform state:
consul kv get terraform/state
GitHub Actions JWT roles
auth/jwt/github/iuclabs trusts GitHub Actions OIDC tokens. One org-wide role, default (config/auth_jwt_role/jwt/github/iuclabs/default.yaml, the mount's default_role, so workflows needn't name it), accepts any IUCLabs repo for push, release, schedule and pull_request runs on refs/heads/*, refs/tags/* or refs/pull/*/merge. Role validation rejects any other event (pull_request_target, workflow_run, comment events), any other ref glob, and globs in any other claim. Fork pull requests can't mint OIDC tokens unless "Send write tokens to workflows from pull requests" is enabled on the repo.
Workflows log in with audience https://vault.service.consul:8200:
permissions:
id-token: write
contents: read
steps:
- uses: hashicorp/vault-action@v3
with:
url: https://vault.service.consul:8200
method: jwt
path: jwt/github/iuclabs
jwtGithubAudience: https://vault.service.consul:8200
secrets: |
kv/data/github/IUCLabs/<repo>/ref/refs/heads/main/.secrets/deploy token | DEPLOY_TOKEN
The role attaches a templated read-only policy, so each run reads only its own KV-v2 secrets:
kv/github/<org>/<repo>/event/<event_name>/*is not ref-scoped: any run of that event in the repo, on any branch or tag a writer pushes, can read it; keep it for secrets every such run may usekv/github/<org>/<repo>/ref/<full ref>/.secrets/*, e.g.ref/refs/heads/main/.secrets/,ref/refs/tags/v1.2.3/.secrets/; git refnames can't contain a.-prefixed component, so branchxcan never read branchx/y's secrets
On OpenBao older than the fork's v2.6, a ref path component of exactly + acts as a single-segment wildcard in the templated policy. Public IUCLabs repos block such refs via a terraform-git ruleset; private repos are not protected, so a writer in a private repo can read that repo's other refs' secrets.
user_claim is jti, so every run creates its own Vault identity entity; Vault never garbage-collects these, so entity count grows with CI volume.
Extra policies are granted via a policy yaml auth: {jwt/github/iuclabs: [default]}; the KV read policy is attached automatically.