Scripts and CI
Run tvault and read credentials from scripts and CI with a headless agent key or a least-privilege tvkey_ API key.
Two headless identities:
| Identity | Use it when | Made with |
|---|---|---|
Agent key (tvagent_) | The job only reads credentials it was granted. | Agents, New Agent |
API key (tvkey_) | The job also creates credentials or agents. Give it only the scopes it needs. | Settings > API keys, or tvault keys create |
Both log in without a browser.
Read a credential with curl
curl -i 'https://api.tokenvault.uk/api/agents/credentials?service=github' \
-H 'Authorization: Bearer tvagent_...'HTTP/1.1 307 Temporary Redirect
Location: https://tv-webhook.example.workers.dev/v1/credential?ticket=eyJ...<elided>.9c1e...&service=githubToken Vault checked the key, the access and your policies, then signed a ticket (60 seconds; the reference webhook accepts it once) and redirected. Follow it with -L; curl drops the Authorization header on a cross-host redirect, which is what you want, because the webhook trusts the ticket:
curl -sL 'https://api.tokenvault.uk/api/agents/credentials?service=github' \
-H 'Authorization: Bearer tvagent_...'{ "token": { "accessToken": "ghp_..." } }A tvkey_ key reads the same way, with Authorization: Bearer tvkey_... only. An agent key also goes in Authorization: Bearer only: X-Agent-Key is refused on this endpoint (400 AGENT_KEY_HEADER_NOT_ACCEPTED) because clients forward a custom header to your webhook on the redirect. It needs credentials:read and Value access on the credential. An MCP-only agent gets 403 GRANT_TOOLS_ONLY here. Omit service to list live access as {"grants": [...]}.
Log in the CLI
printf %s "$AGENT_KEY" | tvault login --key-stdin --as ci
tvault whoami
tvault get github--as is required for a key login. The key is stored in ~/.config/tvault/contexts.yaml (mode 0600) until you rotate it.
Create a scoped API key
Run this once, as yourself:
tvault keys create --name ci --scopes tokens:create-read,credentials:read,agents:create --expires 90d
# tvkey_... <- printed once, never retrievabletokens:create-read lets the key add credentials and gives it a read grant on each one it creates. Reading a value also needs credentials:read, so the scope list includes both (without it, tvault get exits 8, SCOPE_DENIED). The read grant is not retroactive. Keys hold Value access only. Grant a key a credential with tvault keys grant ci github.
gh secret set TVAULT_KEY --body "tvkey_..."GitHub Actions
jobs:
provision:
runs-on: ubuntu-latest
steps:
- name: Install tvault
run: npm i -g @tvault/cli
- name: Log in
env:
TVAULT_KEY: ${{ secrets.TVAULT_KEY }}
run: printf %s "$TVAULT_KEY" | tvault login --key-stdin --as ci
- name: Store a credential
env:
DEPLOY_VALUE: ${{ secrets.DEPLOY_VALUE }}
run: printf %s "$DEPLOY_VALUE" | tvault add deploy-svc
- name: Use one
run: curl -fsS -H "Authorization: Bearer $(tvault get deploy-svc)" https://example.com/deployThe value goes from the runner straight to your webhook on a signed store ticket. Token Vault never sees it. tvault add needs tokens:create. Requires tvault 0.14.0 or later.
Mint a scoped agent for a job
With agents:create, a key can create agents limited to a subset of its own scopes:
tvault agents create --name job-agent --kind scoped --scopes tokens:createScopes that only a human may hand out fail with SCOPE_NOT_DELEGABLE.
Rotate and revoke
tvault keys rotate <id> # then update the TVAULT_KEY secret
tvault keys revoke <id> # kills this key only; what it created keeps working--force (aliases --yes, -y) skips the confirmation in scripts. A key can rotate itself with no scope:
printf %s "$TVAULT_KEY" | tvault login --key-stdin --as ci
NEW_KEY=$(tvault keys rotate --self)
# Store $NEW_KEY in your secret manager as TVAULT_KEY, then discard it. Never log it.Rotating another key is a human action. Revoking another key needs keys:revoke, which only a human can give. Revoking a key does not revoke what it created.
Failure handling
A failing step exits with a distinct code: 7 rate limited, 8 scope denied, 9 human only, 10 expired, 11 suspended, 12 invalid key, 13 policy denied, 14 no grant. See exit codes and tvault explain <CODE>.
Related
tvault CLI
Install tvault, sign in, switch contexts and run the everyday commands for credentials, access, labels and MCP servers.
Policies
Write ABAC rules (time window, rate limit, lifetime cap, IP, country, channel), attach them to credentials, labels, agents, keys or MCP servers, and read the denials.