Introduction
Vault tokens have both a TTL (time-to-live) and a max_ttl (maximum total lifetime). While tokens can be renewed before their TTL expires, the total lifetime cannot exceed the max_ttl. When an application repeatedly renews a token and eventually hits the max_ttl, further renewal attempts are rejected, and the token becomes invalid.
Symptoms
- Application receives
400 Bad Requestwhen attempting to renew a token - Vault logs show
token max TTL reachedorcannot renew token - Application authentication fails as the token is no longer valid
- Token renewal worked for days or weeks before suddenly failing
- Error message:
Error renewing token: max TTL exceeded
Common Causes
- Token created with
max_ttlthat is too short for the application's expected lifetime - Long-running application continuously renewing a single token without rotation
- Auth method configuration setting a low
max_ttlfor the token role - Token created with
ttl=0(no expiry) butmax_ttlstill enforced - Periodic tokens (with
periodparameter) not configured, causing max TTL accumulation
Step-by-Step Fix
- 1.Check the token's current TTL and max TTL: Inspect the token state.
- 2.```bash
- 3.vault token lookup
- 4.# Check:
- 5.# ttl: remaining seconds
- 6.# max_ttl: maximum total lifetime
- 7.# policies: attached policies
- 8.
` - 9.Authenticate with a fresh token: Obtain a new token from the auth method.
- 10.```bash
- 11.# For Kubernetes auth
- 12.vault write auth/kubernetes/login role=my-app jwt=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)
- 13.# For AppRole auth
- 14.vault write auth/approle/login role_id=<role-id> secret_id=<secret-id>
- 15.
` - 16.Update the token role to allow longer max TTL: If the current max TTL is too restrictive.
- 17.```bash
- 18.vault write auth/kubernetes/role/my-app \
- 19.bound_service_account_names=my-app-sa \
- 20.bound_service_account_namespaces=default \
- 21.policies=my-app-policy \
- 22.max_ttl=768h # 32 days
- 23.
` - 24.Use periodic tokens for long-running services: Prevent max TTL accumulation.
- 25.```bash
- 26.vault token create -period=24h -policy=my-app-policy
- 27.# Periodic tokens renew indefinitely without hitting max TTL
- 28.
` - 29.Implement token rotation in the application: Automatically obtain new tokens before expiry.
- 30.```java
- 31.// Vault SDK: re-authenticate when token TTL is low
- 32.if (tokenInfo.getTtl() < 3600) { // Less than 1 hour remaining
- 33.VaultAuthenticationResponse newToken = vault.auth.login(authMethod);
- 34.vault.setToken(newToken.getClientToken());
- 35.}
- 36.
`
Prevention
- Use periodic tokens (
periodparameter) for long-running services that need continuous Vault access - Set
max_ttlto at least 7 days for production applications - Implement automatic token rotation in applications before the token reaches 80% of its lifetime
- Monitor token renewal failure rates and alert on max TTL rejections
- Use Vault Agent with
auto_authfor automatic token management and renewal - Configure appropriate
max_ttlper auth method role based on the service's expected lifetime