Tokens: TTLs, Renewal & Hierarchy
Every auth method ends in the same place: a token. It carries policies, a time to live, and a position in a tree of tokens. Understanding tokens explains most "why did my app suddenly get 403?" incidents.
| Property | Meaning |
|---|---|
policies |
what the token may do (always includes default unless created with -no-default-policy) |
ttl |
seconds left before it expires |
renewable |
whether vault token renew can extend it |
explicit_max_ttl / max TTL |
a hard ceiling: renewals never go past it |
period |
a periodic token is renewed to the full period each time, forever, as long as it is renewed in time |
| parent | the token that created it; revoking a parent revokes all children |
| accessor | a handle to look up or revoke a token without knowing the token itself |
TTL, renewal and the ceiling
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
vault token create -policy=default -ttl=10m -explicit-max-ttl=20m -format=json \
| jq '.auth | {policies, lease_duration, renewable}'
T=$(vault token create -policy=default -ttl=10m -explicit-max-ttl=20m -field=token)
echo "--- renew by 1h"
vault token renew -increment=1h -format=json $T | jq -c '{asked: "1h", ttl_within_20m: (.auth.lease_duration <= 1200), warning: .warnings[0][0:40]}'
echo "--- periodic token"
vault token create -policy=default -period=24h -format=json | jq '.auth | {lease_duration, renewable}'{
"policies": [
"default"
],
"lease_duration": 600,
"renewable": true
}
--- renew by 1h
{"asked":"1h","ttl_within_20m":true,"warning":"TTL of \"1h\" exceeded the effective max_t"}
--- periodic token
{
"lease_duration": 86400,
"renewable": true
}
The renewal asked for an hour and got capped at the token's ceiling. A long-running service with a normal token eventually hits its max TTL and must log in again; Vault Agent does that automatically (Vault Agent). Periodic tokens (-period) have no max TTL as long as they are renewed within the period, which is useful for long-lived services that can't re-authenticate, and risky for the same reason.
The token tree
Tokens created with another token become its children. Revoking the parent revokes the whole subtree, which is how Vault can say "everything that identity created is gone now". Orphan tokens have no parent and survive:
vault server -dev -dev-root-token-id=root -dev-listen-address=127.0.0.1:8200 > vault.log 2>&1 &
for i in $(seq 50); do vault status > /dev/null 2>&1 && break; sleep 0.2; done
export VAULT_TOKEN=root
# a policy that lets a CI token create child tokens for the jobs it starts
vault policy write ci-parent - > /dev/null <<'HCL'
path "auth/token/create" {
capabilities = ["update"]
}
HCL
PARENT=$(vault token create -policy=ci-parent -ttl=1h -field=token)
CHILD=$(VAULT_TOKEN=$PARENT vault token create -policy=default -ttl=30m -field=token)
ORPHAN=$(vault token create -policy=default -orphan -ttl=30m -field=token)
alive() { VAULT_TOKEN=$1 vault token lookup > /dev/null 2>&1 && echo alive || echo revoked; }
echo "before: parent=$(alive $PARENT) child=$(alive $CHILD) orphan=$(alive $ORPHAN)"
vault token revoke $PARENT
echo "after: parent=$(alive $PARENT) child=$(alive $CHILD) orphan=$(alive $ORPHAN)"
echo "--- revoke by accessor (no need to know the token)"
ACC=$(VAULT_TOKEN=$ORPHAN vault token lookup -format=json | jq -r .data.accessor)
vault token revoke -accessor $ACC
echo "orphan=$(alive $ORPHAN)"before: parent=alive child=alive orphan=alive
Success! Revoked token (if it existed)
after: parent=revoked child=revoked orphan=alive
--- revoke by accessor (no need to know the token)
Success! Revoked token (if it existed)
orphan=revoked
Accessors are safe to log and store: an operator can list them (vault list auth/token/accessors with sudo), look up their metadata and revoke them, but cannot use them to make requests.
Service tokens vs batch tokens
Service token (hvs. prefix) |
Batch token (hvb. prefix) |
|
|---|---|---|
| Stored in Vault | yes | no: an encrypted blob validated on use |
| Renewable, revocable individually | yes | no; they expire at their TTL |
| Can create children, have accessors | yes | no |
| Cost | storage write per token | almost free |
| Use for | long-lived services | huge numbers of short jobs (serverless, CI shards) |
Choose with vault token create -type=batch or token_type=batch on an auth role.
Practical rules
- Short TTLs, renewal by an agent. A 20-minute token renewed by Vault Agent leaks for at most 20 minutes.
- Never hand out the root token. Generate one with
vault operator generate-rootfor an emergency, then revoke it. - Log accessors, not tokens. Vault's audit log HMACs tokens; your own logs should do the same or use the accessor.
- Revoke on exit. A CI job that logs into Vault should
vault token revoke -selfat the end, so its token doesn't outlive the job.
Test yourself
A token has ttl=10m and explicit_max_ttl=20m. You renew with -increment=1h. What TTL do you get?
- 1 hour
- At most what remains of the 20-minute ceiling, with a warning
- 10 minutes
- An error
What happens to child tokens when their parent token is revoked?
- Nothing
- They are revoked too, unless they are orphans
- They become root tokens
- They are renewed
What is a token accessor for?
- Making requests faster
- Looking up and revoking a token without being able to use it
- Encrypting the token
- Renewing the root token