Vault Lost Non-Root Tokens
Hi, I have a Vault server with the "file" backend. Previously I have created the tokens and assigned the policies. All worked well, until today, when Vault suddenly "lost" all non-root tokens I have created and rejected all the auth request with "Invalid Token" response. The root token works, however. The server was not restarted. Note: This happened twice already. Is this a known issue or should I provide more information ? Thanks !
Hi @bigmyx
I'm sorry to hear you're having issues with Vault. As you describe the issue, this might not be a bug, but it's difficult to say without more information.
When you create a token in Vault, it's part of a tree, like so:
root-token
abcd1234 <- Your token
defg5678
hijkl9101
# ...
With the exception of root tokens, all tokens have a default expiration of 30 days. Tokens must renew with Vault before the 30 day expiration or they will expire. I suspect if you work backwards, you'll find the tokens are 30 days old.
When you create a token, the system using that token needs to renew itself with Vault occasionally. We recommend lease_duration/2 (so 15 days by default), but there is no harm in renewing more frequently. If the renewal fails, the application should request a new token; if that fails, that means credentials have been rejected.
Now, since tokens exist in a tree, each token has it's own expiration, but they are also tied to their parent's expiration. This means, even if you are renewing token defg5678 above regularly, if the parent token abcd1234 happens to expire, the entire tree will expire as well.
Does that make sense?
@bigmyx it would also help diagnose this issue if you were to send us the logs as a GitHub gist.
Hi @sethvargo, Thanks for your reply !
From the log I see messages like these:
[INFO] expire: revoked 'auth/token/create/XXX'
...
[INFO] expire: revoked 'secret/XXX/XXXX'
When I am trying to renew my token, I get the following error:
> vault token-renew XXXXXXXX-XXXX-XXXX-XXXX
Error renewing token: Error making API request.
URL: PUT https://vault.example.com:8200/v1/auth/token/renew/XXXXXXXX-XXXX-XXXX-XXXX
Code: 400. Errors:
* token not found
Can you tell what should I do next to renew both secrets and tokens ?
Hi @bigmyx
Those looks seem to indicate the second point - when a parent expires, all the children also expire. You can work around this by creating orphan tokens.
You can no longer renew a token after it has been expired, you can only renew an active token. It's like a DHCP ping. Does that make sense?
@sethvargo, That makes sense, Let me know if I understand it correctly:
- Both secrets and tokens expire (after X days not being renewed), is that correct ? If so, why I see that tokens are gone, but the secrets are still there (I can read them by using the root token) ?
- I don't think the tokens I have created had any "parent" token, so they already were "orphan" ?
I have created the tokens using
vault token-createcommand. - We wrote a small library for "talking" to Vault and retrieve a secrets, do you recommend to renew the token (and secret ? ) as a part of the retrieve call ?
@bigmyx
- Secrets and tokens are the same thing to vault - they are both forms of a secret. Without knowing your setup, it's difficult to answer your question, but it's possible that those secrets have not yet expired. Please note that the transit backend never expires.
- How did you create the tokens? When you create a token, it's parent is the current token you are authenticated as unless you specify the
-orphanflag.vault token-createrequires that you are authenticated with Vault. At some point you have runvault auth, set VAULT_TOKEN in the environment, or have a vault token in~/.vault-token - We generally recommend renewing at lease_duration/2. When you first fetch a secret, you should inspect the lease duration, divide that by 2, and then start a background process with a timer that makes a call to renew the token at that interval.
@sethvargo, Thanks for these guidelines! I forgot to mention: when I created a tokens I was authenticated as 'root' .
Hi @bigmyx
Even if you create the tokens as root, they still expire in 30 days. The only tokens with no expiration are root tokens themselves.
@sethvargo , Thanks for your help !