Optional cache TTL for secrets #401
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Currently, the provider utilizes a non-expiring cache for secrets. This causes an issue where changes made in Vault (such as updated values or new keys added to an existing secret) are not propagated to the application.
This PR resolves this by introducing a new configuration parameter,
cache-ttl, which allows users to define a Time-to-Live (TTL) for cached secrets, ensuring they are periodically refreshed.Implementation
A new configuration parameter,
cache-ttl, has been introduced. This value is an integer specifying the cache duration in seconds.To simplify the implementation and avoid background garbage collection, secrets are not proactively evicted from the cache upon expiry. Instead, a "lazy-expiry" approach is used:
When a secret is requested, its cache timestamp is checked.
If the secret has expired (i.e.,
now > cachedtime + ttl), it is re-fetched from Vault.If the secret has not expired, the cached version is served.
To support this, the underlying data structure for the cache (previously a simple
map) has been modified. It now stores a newstructthat holds both the secret payload and its "cached-at" timestamp.Usage
Command line
# 1 minute TTL vault-csi-provider -cache-ttl=60Kubernetes Deployment