Hi,
I am learning to use Vault, I have installed the Vault agent on my Windows PC as a service and am using it to generate certificates and rotate these certificates on a regular basis.
However I am struggling to understand the purpose of the agent, after a certain amount of time (max 10hrs), the token that it generates expires, then the agent becomes useless as it can no longer access the vault.
Is there some means to have the Vault agent generate a new token after the old one has expired?
Thus keeping the agent able to perform it’s tasks indefinitely, without manual intervention?
Is there some means to log why it fails to renew the token?
Currently the only way to renew the token is to put in the root token and re-export the secret-id, then restart the service, which uses that secret-id to create a new valid token.
Or even better is there a command that forces Vault to issue a new token with the ttl restarted.
@mikegreen appreciate the response, I understand the idea behind the timings and that makes perfect sense, it does what it says, I have no issue with that.
My problem is that there seems to be no means to keep the agent authenticated long term (beyond 10 hours) even if you set all values to zero, after 10 hours the token expires and the agent fails, it seems to have no in-built function to retrieve a new token to restart the timer.
This doesn’t seem like the design intent (what would be the point of having an agent), so it must be my setup, the question I need to answer now is what is wrong with my setup that prevents the agent from getting new tokens once the old token has expired.
This I guess is what I am struggling with, a means to log this (beyond just the failing authentication) or a command to run (like vault get new token), perhaps the answer will become obvious in time.
In the mean time, I will implement a scheduled task to restart the service every hour or so to generate a brand new token.
Here is a Powershell script that reflects my current setup (needs to be run as administrator, requires a valid vault URL and a token that can create policies and roles):
I think the remove_secret_id_after_reading = true line might be one thing that’s tripping you up. Once that is gone (after initial authentication) the agent has nothing to send a re-authentication request with when the current auth session expires. However, this obviously comes at the cost of having a credential on disk, which may be mitigated by setting strict ACLs to prevent casual users from viewing it.
Otherwise you may want to consider using the token_period parameter instead of the token_max_ttl. This is basically a keep-alive value and will/should keep the auth token alive until the process stops requesting a renewal. The token_num_uses parameter on your AppRole role would need to be removed or set to 0 otherwise you’ll run into the same problem.
Apologies @aram I was just reflecting the code from the guide: Vault Agent Windows Service | Vault - HashiCorp Learn
You will have to forgive me I know neither json nor hcl, if you could tell me what to change (or should I just name the file .json?) I will change it.
No big deal, it’s just a pet peeve of most admins.
Yes, just rename the file to .json and change your system unit file to match. Or change the content to HCL2 language – more work but I believe this is the recommended config.
If you run it from the CLI, it logs right to the terminal. Unsure how that works in Windows. But the logs at the non-renewal point are key to troubleshooting this.
I’m working on integrating HashiCorp Vault into our application using Vault Agent for authentication. The initial setup works well, where the application reads the Vault token from a file generated by Vault Agent and uses it to authenticate with the Vault server.
However, I’m concerned about handling scenarios where the token’s max TTL is reached, and a new token is generated by Vault Agent.
Currently, our application reads the token once during initialization and uses it for subsequent operations. If the token expires and a new one is generated, the application wouldn’t automatically know about the new token, which could lead to failed operations.
To address this, I am thinking to implement a file watcher that monitors the token file for changes. When a new token is generated, the watcher reloads the token and updates the Vault client. While this seems to work in theory, I want to ensure that we’re following best practices and not missing any important considerations.
Here are the specific questions I have:
Is monitoring the token file for changes and reloading the token dynamically the recommended approach for handling token renewal with Vault Agent?
Are there any potential pitfalls or edge cases I should be aware of when implementing this solution?
Are there more efficient or reliable methods to ensure the application always has access to a valid token, especially in high-availability or production environments?
I’d appreciate any feedback or suggestions on improving this implementation.