Secrets Engines · Topic 2 of 4

Static vs Dynamic Secrets and Short-Lived Credentials

Vault Associate (003): compare static and dynamic secrets, their use cases, and why short-lived, dynamically generated credentials reduce risk.

  • 4 min
In a nutshell
  • Static secrets are stored by a person or tool and do not expire on their own; KV is the standard example.
  • Dynamic secrets are generated on demand when a client reads a role, for example database/creds/my-role.
  • Every dynamic secret has a lease; Vault revokes it automatically when the lease expires.

What it is

A static secret is a value that someone stores in Vault and that stays the same until a person changes it. An API key kept in the KV engine is the classic example.

A dynamic secret does not exist until a client asks for it. Vault generates a new credential on demand, gives it a lease, and revokes it automatically when the lease ends.

Staticstored valuereadSame value for every readerDynamicroleread credsNew unique credentiallease expiresRevoked by Vault

How it works

Static secrets

The KV engine stores and versions arbitrary static secrets in Vault storage. You write a value and read it back. Vault does not create the value and does not change it for you.

KV does not issue leases, although it will sometimes return a lease duration. Because nothing expires on its own, the value stays valid until someone rotates it in the system that uses it.

Dynamic secrets

Engines for external systems, such as the database and AWS engines, generate credentials when a client reads from a role. The AWS engine generates access credentials dynamically based on IAM policies, and the database engine generates database credentials based on configured roles.

vault read database/creds/my-role

The response includes a lease_id, a lease_duration and lease_renewable. All dynamic secrets in Vault are required to have a lease, and when a lease expires Vault automatically revokes it. In the database engine, a dynamic role sets its own TTL and max TTL; the UI defaults are 1 hour and 24 hours, while the API falls back to the mount or system defaults.

You can also revoke a lease early, which invalidates that one credential before its time is up.

Rotated static roles

The database engine also supports static roles. A static role is a one-to-one mapping between a Vault role and an existing database user.

Vault stores that user's password and rotates it on a rotation_period (24 hours by default in the UI) or a rotation_schedule. The credential is fixed to one user but still changes over time.

Comparison

PointStatic (KV)Dynamic (database, AWS)
Who creates the valueA person or tool writes itVault generates it on read
LeaseNone issuedAlways has a lease
LifetimeUntil someone changes itUntil the lease expires or is revoked
Who shares itEvery reader sees the same valueEach request gets unique credentials
Typical useAPI keys, config values, third-party tokensDatabase logins, cloud access keys

Why short-lived credentials help

  • Smaller exposure window. A leaked credential stops working when its lease ends.
  • Unique per client. Each service gets its own credentials, so audit logs can trace activity to one client.
  • Revocable on demand. You can revoke one lease without touching other clients.
  • Less manual rotation. Vault creates and removes the credentials, so people do not keep long-lived passwords.

Choosing between them

Use a static secret when the value comes from outside Vault and Vault cannot create it, such as a vendor-issued API key. Use a dynamic secret when Vault can create the credential in the target system itself.

How the exam asks about this

  • "An application needs a database login that disappears after an hour." A dynamic secret from the database secrets engine.
  • "Which statement about KV is true?" It stores static secrets and does not issue leases.
  • "Why prefer dynamic secrets?" They are short-lived, unique per client and revoked automatically.

What to remember for the exam

  • Static secrets are stored by a person or tool and do not expire on their own; KV is the standard example.
  • Dynamic secrets are generated on demand when a client reads a role, for example database/creds/my-role.
  • Every dynamic secret has a lease; Vault revokes it automatically when the lease expires.
  • Dynamic credentials are unique per request, which makes auditing and targeted revocation easier.
  • The value of short-lived secrets is a smaller window of exposure if a credential leaks.
  • Database static roles are rotated by Vault, but they are still tied to one fixed database user.
Watch out

"Static" does not mean "KV only" in every sense. A static role in the database engine is rotated by Vault, so read the question for whether Vault generates or only stores the value.

Common mistakes

Assuming KV secrets expire. KV does not issue leases. A secret there stays until it is deleted or overwritten.

Thinking dynamic credentials are shared. Each read of a role gives a new, unique credential. Two applications reading the same role get two different logins.

Forgetting the lease. The credential is only valid for its lease. A lease that is not renewed expires, and renewal cannot extend it past the max TTL; either way Vault revokes the credential and the application must request a new one.

Check yourself

  • Which kind of secret always comes with a lease?

    Dynamic secrets. Every dynamic secret requires a lease, and Vault revokes it automatically when the lease expires.

  • Why does KV not suit generating a fresh database login per request?

    KV only stores and versions values you write. A database or similar engine must generate credentials on demand.

  • Name two benefits of short-lived credentials.

    A leaked credential stops working after its lease ends, and unique per-client credentials make auditing and targeted revocation easier.

Topic 2 of 4 in Secrets Engines

Test yourself on Secrets Engines

The full HashiCorp Vault Associate 003 question bank has 600 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by HashiCorp. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.