Course contentsShow
← Security
Lesson 1331 of 3,05227. Application Security - Secrets ManagementFree lesson

Dynamic Secrets and Leasing

How Vault generates short-lived database credentials and other dynamic secrets with automatic revocation.

Dynamic Secrets and Leasing

What You'll Learn

You'll learn how secret management systems like Vault generate temporary, automatically-expiring credentials instead of storing static passwords forever.


The Problem with Static Secrets

Imagine giving someone a house key that works forever. If they lose it or someone steals it, your house remains vulnerable until you change the locks. Traditional secrets work this way—database passwords, API keys, and tokens are created once and remain valid indefinitely.

What Are Dynamic Secrets?

Dynamic secrets are credentials generated on-demand when an application requests them. Instead of storing a permanent database password, a secret manager like Vault creates a brand new database user with a unique password, grants it the necessary permissions, and returns those credentials to your application.

The magic happens through leasing: each dynamic secret comes with an expiration time (a "lease"). When the lease expires, Vault automatically revokes the credentials—deleting the database user, invalidating the token, or whatever cleanup is appropriate.

How It Works

  1. Your application authenticates to Vault
  2. Vault contacts the database and creates a temporary user with credentials
  3. Vault returns these credentials along with a lease (e.g., "valid for 1 hour")
  4. Your application uses the credentials
  5. When the lease expires, Vault automatically deletes that database user

This is like a hotel giving you a key card that only works during your reservation—no manual cleanup needed, and the window of risk is dramatically smaller.

Why This Matters

If credentials are compromised, they're already nearly expired. There's no need to hunt down every place a password is stored, because it was never meant to last. Rotation happens automatically with every new request.

Key Takeaway: Dynamic secrets with leasing transform long-lived, risky credentials into short-lived, automatically-expiring ones that significantly reduce your attack surface and eliminate manual rotation workflows.