A database password or cloud access key that never expires stays useful to an attacker for as long as it sits in a repository, a log or a stolen laptop image, and rotation schedules only shorten that window from years to weeks. Dynamic secrets take a different approach: a broker creates a unique credential when a workload asks for it, attaches a lease, and deletes or invalidates it when the lease ends, so there is nothing long-lived to leak. This guide explains how dynamic and ephemeral credentials work for databases, AWS, Google Cloud, X.509 certificates and SSH, how to choose between dynamic secrets, managed rotation and workload identity federation, and how to roll them out without breaking applications. It is written for platform, security and database teams replacing static non-human credentials. For Vault architecture and operations in general, see the HashiCorp Vault Guide; this page focuses on the credential patterns.
Key takeaways
- Dynamic means created on demand and unique per consumer. Each request yields a new username, key or certificate with its own lease, so one leak exposes one instance for a short time, and audit logs name the consumer.
- The lease is the control. TTL, maximum TTL, renewal and revocation decide the real exposure window; Vault database roles default to a 1 hour TTL and a 24 hour maximum unless you change them.
- Federation beats a stored broker credential where it exists. If the platform can exchange a workload identity for cloud credentials (AWS STS, Google short-lived tokens, Entra workload identity), use that before adding a secrets broker in the middle.
- Revocation must be tested, not assumed. Prefix revocation and token-hierarchy revocation give you an emergency stop for a whole engine; rehearse it before an incident.
- The broker's own root credential becomes the crown jewel. Rotate it immediately after configuration so no human knows it, scope it to user creation only, and monitor its use.
What dynamic and ephemeral credentials are
The terms overlap, so it helps to separate four patterns that are often all called "short-lived".
| Pattern | How it works | Typical lifetime | Unique per consumer | Residual risk |
|---|---|---|---|---|
| Static secret, manual rotation | One credential shared by every instance, changed on a schedule | Months to never | No | Leaks stay valid until the next rotation; rotation causes outages |
| Managed rotation (static roles) | A broker owns an existing account and changes its password on a period | Hours to days | No | Shared credential; good for legacy apps that cannot change usernames |
| Dynamic secret | A broker creates a new account, key or certificate per request with a lease and deletes it on expiry | Minutes to hours | Yes | Broker root credential; consumer must handle renewal |
| Federated ephemeral token | The platform exchanges a workload identity token for temporary credentials, no stored secret | Minutes to hours | Yes (per session) | Trust policy quality; see the Workload Identity Federation Guide |
OWASP lists long-lived secrets as NHI7:2025 and recommends automated rotation, short-lived credentials that platforms issue and refresh, re-authentication for sensitive actions and least privilege. Dynamic secrets and federation are the two ways to meet the short-lived recommendation; static-role rotation is the fallback. See the OWASP NHI Top 10 NHI7 Long-Lived Secrets Guide.
How leases, renewal and revocation work
HashiCorp Vault is the most widely documented dynamic secrets broker, so its model is used here; other brokers implement similar ideas.
- Lease: Vault creates a lease for every dynamic secret and service token, recording its duration and whether it can be renewed. Reading a dynamic secret returns a
lease_id. - Renewal:
vault lease renew -increment=3600 <lease_id>requests a new TTL measured from now, not from the old expiry. The secrets engine may grant less than requested, so clients must read the returned lease duration rather than assume it. - Maximum TTL: renewals cannot extend a lease past the role's maximum TTL. When it is reached the consumer must request a fresh credential, so applications need a reconnection path.
- Revocation:
vault lease revoke <lease_id>invalidates a secret immediately.vault lease revoke -prefix aws/revokes every lease under a path, which Vault documents as an intrusion containment tool. - Token hierarchy: when a Vault token is revoked, Vault revokes all leases created with it. Revoking a compromised application's token therefore removes every database user and cloud key it obtained.
Clients usually handle this through an agent or SDK that renews in the background and re-reads credentials before the maximum TTL. See the Secrets Rotation Runbook Template for the operational steps around changes.
Dynamic credentials by target system
| Target | Mechanism | Key settings and limits | Notes |
|---|---|---|---|
| Databases (Vault database engine) | Dynamic roles run creation_statements with {{username}} and {{password}} to create a user per request | default_ttl 1h and max_ttl 24h by default; password policies (default 20 characters) | Plugins include PostgreSQL, MySQL/MariaDB, MSSQL, Oracle, MongoDB, Redshift, Snowflake and others |
| Databases, legacy accounts | Static roles: 1-to-1 mapping to an existing user whose password Vault rotates | rotation_period default 24h, or rotation_schedule | Use when an application cannot handle changing usernames |
| AWS (Vault AWS engine) | assumed_role, federation_token, session_token (STS) or iam_user | STS credentials work immediately; iam_user needs a 5 to 10 second delay for eventual consistency and is deleted at TTL | Prefer STS types; iam_user creates real IAM users and long-lived keys during the lease |
| AWS (native STS) | AssumeRole and web identity federation | DurationSeconds 900 to 43,200 seconds, capped by the role's MaxSessionDuration (1 to 12 hours); role chaining capped at 1 hour | Use SourceIdentity so CloudTrail can trace the original caller across chained sessions |
| Google Cloud (native) | Service Account Credentials API issues OAuth 2.0 access tokens, ID tokens and self-signed JWTs | Access tokens expire after 1 hour by default | Replaces downloaded service account keys; see the Google Cloud Service Account Keys Security Guide |
| X.509 (Vault PKI engine) | Short-lived leaf certificates per instance, held in memory | no_store=true for short TTLs (under 30 days) or high volume; leaf guidance of roughly 30 to 90 days | Short lifetimes make revocation rarely needed and keep CRLs small |
| SSH (Vault SSH engine) | The CA signs the user's public key; hosts trust the CA through TrustedUserCAKeys | Role ttl (example 30 minutes), allowed_users, valid_principals | Removes static authorized_keys sprawl; see the SSH Protocol and Certificate Authority Guide |
Database specifics
- Creation statements: grant the minimum role, for example membership of a read-only group, rather than privileges per user. Avoid statements that grant ownership of objects, because revocation then fails or leaves orphaned objects.
- Revocation statements: define them explicitly so expired users are dropped and their sessions terminated; test against a database with active connections.
- Connection pools: pools that hold connections past the credential's maximum TTL keep working on the database side until disconnected. Set pool maximum lifetime below
max_ttlso connections recycle onto fresh credentials. - Username format: include the role and a short consumer identifier in generated usernames where the plugin supports username customisation, so database audit logs can be tied back to the workload.
For database access patterns beyond credentials, see the Database Credential and Access Security Guide.
Certificate specifics
Vault's PKI considerations recommend cascading lifetimes (roots roughly 2 to 10 years, intermediates 6 months to 2 years, leaves 30 to 90 days) and setting leaf_not_after_behavior to err or truncate so a leaf cannot outlive its issuer. With no_store=true Vault stops storing each certificate, which raises throughput but removes serial-based revocation unless you supply the certificate. Vault notes that 50,000 to 100,000 stored long-lived certificates start to cause CRL problems; short-lived, unstored certificates avoid that. Enable auto-tidy and automatic CRL rebuilding either way. See the Machine Identity, PKI and Certificate Lifecycle Guide.
Securing the broker itself
- Root credentials: Vault supports rotating the root credential for every database plugin except MongoDB Atlas (which uses an API key pair) with
vault write -force database/rotate-root/<name>, and for AWS withvault write -f aws/config/rotate-root. Scheduled root rotation is an Enterprise feature; on other editions, automate the manual call. - No stored cloud keys: where the broker itself runs in a cloud, give it plugin workload identity federation or an instance role instead of an IAM user key in its configuration. Note that the
federation_tokentype requires IAM user credentials as the root, so preferassumed_role. - Least privilege for the broker account: the database account Vault uses should be able to create and drop users and grant predefined roles, nothing more. In AWS, scope the broker's policy to the roles it may assume.
- Availability: applications depend on the broker at start-up and at each renewal. Run it clustered, monitor lease counts, and size TTLs so a short broker outage does not expire every live credential at once.
Choosing the right pattern
| Situation | Recommended pattern | Why |
|---|---|---|
| Workload runs on a cloud platform and calls that cloud | Native workload identity (instance role, managed identity, attached service account) | No secret to store or broker; the platform rotates |
| Workload on one platform calls another cloud or SaaS that supports OIDC federation | Federated ephemeral token | No stored credential; trust is a policy you can review |
| Application needs a database login | Dynamic database role | Unique user per instance, revoked automatically |
| Legacy application with a hard-coded username | Static role with managed rotation | Removes human knowledge of the password without code changes |
| Service-to-service TLS | Short-lived certificates from an internal CA | Expiry replaces revocation; see the SPIFFE and SPIRE Guide |
| Human or automation SSH to servers | Signed SSH certificates | Minutes-long access, no keys left on hosts |
| Third-party API that only issues static keys | Vault-stored secret with rotation via API where offered, tight scope and monitoring | Dynamic issuance is impossible; contain instead |
Small organisations should start with native cloud identity and federation, which need no extra infrastructure, and add a broker only for databases. Large organisations with many database engines, on-premises systems and multiple clouds benefit from a central broker that gives one audit trail and one revocation point, but must run it as tier-0 infrastructure with high availability, since an unavailable broker means applications cannot get credentials. Keep TTLs as short as the consumer can reliably renew: an hour is common for databases, minutes for CI jobs, and the length of the job for batch work.
Implementation: a phased rollout
- Inventory and rank static secrets. Use secret scanning and vault exports to list static credentials by system, privilege and age. Prioritise high-privilege database and cloud keys. See the Secret Sprawl Measurement Guide.
- Remove what federation can replace. Move CI/CD and cloud-to-cloud access to federated tokens first, deleting the old keys. These migrations need no broker.
- Stand up the broker for one database. Configure the connection with a dedicated broker account that can only create and drop users, then run
rotate-rootimmediately so nobody knows its password. - Pilot with one application in non-production. Use an agent or SDK for renewal, set pool lifetimes below
max_ttl, and test: credential expiry mid-transaction, broker unavailable, and revocation of the application's token. - Run in parallel, then cut over. Keep the old static credential valid but unused while the application reads dynamic credentials in production; watch database logs to confirm no use of the old account.
- Roll back if needed. Rollback is switching the application configuration back to the static credential, which is why it stays valid during the parallel period. Disable and then delete the static account only after an agreed quiet period.
- Scale out by template. Standardise role definitions (read-only, read-write, migration) per engine, enforce them with policy as code, and onboard applications in waves.
- Rehearse emergency revocation. Quarterly, revoke a prefix in a test environment and confirm applications recover with new credentials.
Where identity fits
Dynamic secrets move the authentication problem rather than removing it: the workload still has to prove who it is to the broker. If that proof is itself a static token in an environment variable, you have one long-lived secret guarding many short-lived ones. Authenticate workloads to the broker with platform identity (Kubernetes service account tokens, cloud instance identity, OIDC from CI) and bind each broker role to the narrowest identity possible. See the Kubernetes Service Account Token Guide and the WIMSE Workload Identity Architecture Guide for where workload identity standards are heading.
Detection and measurement
- Broker audit logs: log every credential issue, renew and revoke with the requesting identity and role. Alert on requests from identities not mapped to that role, sudden issuance spikes and revocation failures.
- Target-side logs: in the database or cloud, alert on any use of the broker's root account outside the broker host, on generated users that survive past their maximum TTL, and on logins by retired static accounts.
- AWS CloudTrail: watch
AssumeRoleandCreateAccessKeyevents by the broker's principal, and useSourceIdentityto trace sessions.
Metrics that show progress:
- Percentage of non-human credentials that are dynamic or federated, by system tier.
- Median and 95th percentile credential lifetime across the estate.
- Number of static high-privilege credentials remaining, trending to zero.
- Count of credentials that outlived their lease (should be zero).
- Time to revoke all credentials issued to a compromised workload, measured in rehearsals.
Framework mapping
| Framework | Reference | How dynamic credentials support it |
|---|---|---|
| OWASP NHI Top 10 | NHI7:2025 Long-Lived Secrets; NHI2 Secret Leakage | Short lifetimes make leaked secrets expire; unique credentials limit reuse |
| NIST CSF 2.0 | PR.AA-01, PR.AA-05 | Managed credentials for services; least privilege per role |
| NIST SP 800-53 Rev. 5 | IA-5, IA-5(13), AC-2, AC-6, SC-12, AU-12 | Authenticator management, expiry of cached authenticators, account management, least privilege, key management, audit generation |
| ISO/IEC 27001:2022 Annex A | 5.17, 8.2, 8.24 | Authentication information, privileged access rights, cryptographic key use |
| MITRE ATT&CK | T1552.001, T1552.004, T1078.004 | Credentials in files and private keys lose value when they expire; stolen cloud accounts have short windows |
Common failure patterns
- Maximum TTL set to months: a dynamic secret with a 30 day maximum is a static secret with extra steps. Keep maximum TTLs close to the workload's real session length.
- Broker root credential left as configured: if the DBA who set up the connection still knows the password, the broker adds risk instead of removing it. Rotate root on day one.
- Static fallback never removed: teams keep the old key "just in case" and it leaks later. Long-lived keys left in code are what the Toyota T-Connect key exposure shows: an access key sat on public GitHub for almost five years.
- Using
iam_userwhere STS works: the IAM user type creates real access keys that exist for the whole lease and need propagation delays; STS types expire on their own inside AWS. - Applications that cache credentials forever: code that reads the secret once at start-up fails at maximum TTL or, worse, keeps a pooled connection alive indefinitely.
- Broad roles behind short lifetimes: a short-lived credential with write access to every bucket still enables destruction in minutes, as stolen long-lived keys did in the Codefinger S3 ransomware campaign. Short lifetimes and least privilege are both needed.
Practitioner checklist
- Inventory static non-human credentials and rank them by privilege and age.
- Replace cloud and CI credentials with native identity or federation before deploying a broker.
- Use dynamic database roles with explicit creation and revocation statements and minimal grants.
- Set TTL and maximum TTL to the consumer's real need, and connection pool lifetimes below the maximum.
- Rotate the broker's root credential immediately and restrict it to account management.
- Authenticate workloads to the broker with platform identity, not a static token.
- Prefer STS-based AWS credential types and set
SourceIdentityfor traceability. - Issue short-lived certificates with
no_storewhere revocation by serial is not required. - Rehearse prefix and token revocation quarterly and measure recovery time.
- Track the share of dynamic or federated credentials and remaining static high-privilege secrets monthly.
Standards and references
- OWASP: NHI7:2025 Long-Lived Secrets
- HashiCorp: Vault lease, renew, and revoke
- HashiCorp: Vault database secrets engine
- HashiCorp: Vault AWS secrets engine
- HashiCorp: Vault PKI secrets engine considerations
- AWS: STS AssumeRole API reference
- Google Cloud: Service account credentials
- HashiCorp: Vault signed SSH certificates
Related NHI Mgmt Group resources: HashiCorp Vault Guide · Secrets Management Guide · OWASP NHI Top 10 NHI7 Long-Lived Secrets Guide · Cloud Secrets Managers Guide