Chapter 94: HashiCorp Vault and Secrets Management
94.11 Dynamic secrets and leases — not KV expiry
Story (fictional teaching scenario). At a fictional Hyderabad school app, Fatima from Cairo studies how one short-lived database user per job differs from copying the same stored password.
Why
The credential can be tied to one consumer and a revocation lifecycle, but only if the provider integration is configured and working.
What
- Dynamic secrets engine generates credentials through a configured provider, such as a database.
- Lease tracks validity and renewability for generated credentials.
- Lease ID identifies a generated secret’s lifecycle, not its password.
- Renew requests a fresh remaining duration from now; the requested increment is advisory.
- KV stores arbitrary values and does NOT issue leases for those stored secrets.
How
-
Design provider roles and least privilege before enabling an integration.
-
Make clients renew or replace credentials before expiry.
-
Monitor revocation failures; a disconnected provider complicates cleanup.
-
Do not claim a KV TTL automatically disables a password in an external database.
Example 1: Dynamic response shape, values omitted
- Read the command or request.
GET /v1/database/creds/training-readonly
- Read the result.
Output (illustrative; NOT executed against Vault)
{"lease_id":"database/creds/training-readonly/DEMO","lease_duration":300,"renewable":true,"data":"CREDENTIALS OMITTED"}
- Line by line: The role name selects provider rules. The lease ID is used to manage validity. The generated username/password are intentionally absent here. No real database, account, credential or provider was created.
Example 2: Renewal increment from now
- Read the command or request.
At t=120 request increment300seconds
If accepted, remaining TTL becomes about300seconds
- Read the result.
Output (illustrative; NOT executed against Vault)
Not: add300seconds to the old expiry automatically.
- Line by line: The server/plugin may cap or ignore the requested increment. Always inspect the actual returned lease. Revocation asks the provider to invalidate generated credentials; operations must track failures instead of assuming success.
Ravindra Bagale's Tip
KV versions and dynamic-secret leases are different lifecycles.
KV versions आणि dynamic-secret leases यांचं lifecycle वेगळं असतं.
KV versions और dynamic-secret leases अलग lifecycles हैं.
Did you understand? Let us try it once more.