Short-Lived Credentials: STS, Dynamic Secrets, and Why Static Keys Die
Static keys leak and live forever. Short-lived credentials from STS and Vault expire on their own. Here is the token-exchange machinery and the TTL math that make it work.
Key takeaways
- Short-lived credentials expire on their own, so a leaked one is already half-dead.
- AWS STS exchanges an identity, such as an OIDC token, for temporary keys lasting 15 minutes to 12 hours.
- Vault dynamic secrets create a per-workload database user with a lease and revoke it when the TTL ends.
On this page
Short-lived credentials are minted on demand and expire on their own: AWS STS trades a proven identity for keys that last 15 minutes to 12 hours, and Vault dynamic secrets create a per-workload database user that is dropped when its lease ends. A leaked credential stops working without anyone rotating anything. That is why they beat static keys.
Verified against
AWS STS API (2011-06-15), Vault 2.2.1, against the AWS STS AssumeRoleWithWebIdentity reference, the IAM role-session and identifier docs, and the Vault database secrets engine docs. Checked October 2026.
A static access key has no idea it's been stolen. It works for the attacker exactly as well as it works for you, and it keeps working until a human notices and revokes it. The fix isn't better rotation. It's credentials that die an hour after they're minted. Once you internalize that, most of the secrets-in-CI, keys-in-git, and token-in-Slack incidents stop being possible.
This is the machinery underneath keyless authentication: the token exchange that hands you temporary credentials, and the lease model that reclaims them.
Token exchange: you prove identity, you get a short ticket
The pattern is always the same. You show up holding something that proves who you are (an OIDC token from your CI provider, a signed instance identity, an existing session) and a broker hands back a fresh set of credentials with an expiry stamped on them. You never store the result. When it dies, you exchange again.
AWS STS is the canonical broker. AssumeRole takes an existing AWS identity and returns temporary creds for a role. AssumeRoleWithWebIdentity takes an OIDC token from outside AWS (GitHub Actions, a Kubernetes service account, GCP) and does the same with no stored AWS key anywhere in the chain.
$ aws sts assume-role-with-web-identity \
--role-arn arn:aws:iam::123456789012:role/ci-deploy \
--role-session-name gha-build-4192 \
--web-identity-token "$OIDC_TOKEN" \
--duration-seconds 3600
What comes back is the important part:
{
"Credentials": {
"AccessKeyId": "ASIA...",
"SecretAccessKey": "...",
"SessionToken": "...",
"Expiration": "2026-07-12T15:04:07Z"
}
}
Three things instead of two. The SessionToken is what marks these as temporary: a request without it is rejected, and it carries the same expiry. The ASIA prefix (versus AKIA for static keys) is a giveaway you can grep for in logs and CloudTrail to confirm nobody's using long-lived keys where they shouldn't.
Session duration is a real dial, and you should turn it down
--duration-seconds defaults to 3,600 seconds (one hour), accepts a minimum of 900 seconds, and caps at the role's maximum session duration, which you can set from 1 to 12 hours (as of October 2026). Ask for more than the role allows and the call fails rather than quietly shortening the session. Role chaining (assuming a role from an already-assumed session) caps at one hour regardless of what you ask for, which trips people up constantly.
The instinct is to crank duration up so nothing expires mid-job. Resist it. A shorter session is a smaller blast radius. If a token leaks, the attacker's window is measured against how long it had left, not against how long until someone rotates a key. For CI we set 15 to 30 minutes for most jobs. If a deploy legitimately runs longer than an hour, that's usually a signal the job should be split, not that the session should live half a day.
Vault dynamic secrets: the same idea for databases
STS handles AWS. For everything with a username and password (Postgres, MySQL, RabbitMQ, cloud APIs), HashiCorp Vault does the equivalent with dynamic secrets. Instead of storing a database password, the app asks Vault at request time and Vault creates a brand-new database user, scoped to a role, with a lease and a TTL. When the lease expires (or you revoke it), Vault runs the revocation SQL and the user is gone.
# terraform/vault-db-role.tf
# connection: Vault holds ONE privileged cred, apps never see it
resource "vault_database_secret_backend_role" "app_ro" {
backend = "database"
name = "app-ro"
db_name = "app-postgres"
creation_statements = [
"CREATE ROLE \"{{name}}\" WITH LOGIN PASSWORD '{{password}}' VALID UNTIL '{{expiration}}';",
"GRANT SELECT ON ALL TABLES IN SCHEMA public TO \"{{name}}\";"
]
revocation_statements = ["DROP ROLE IF EXISTS \"{{name}}\";"]
default_ttl = "1h"
max_ttl = "24h"
}
Reading a credential is one call:
$ vault read database/creds/app-ro
Key Value
lease_id database/creds/app-ro/8Yx...
lease_duration 1h
username v-token-app-ro-x7Qp2f9k
password A1b-c3D...
Every app instance gets a distinct username. That alone changes incident response: a leaked credential is traceable to exactly one workload and one lease, and revoking it touches nothing else.
Why TTL plus revocation beats a rotation schedule
Rotation is a batch job that pretends to be security. Between rotations, the credential is just as static and just as valid as before. You're betting that 30 days is short enough to matter and long enough not to break anything, and you're usually wrong in both directions.
TTL flips the default. The credential is dead unless something actively keeps renewing it. There's no rotation calendar to miss, no "we forgot this key existed" three years later. Revocation is immediate and per-lease instead of a mass invalidation that takes out half the fleet. Leak detection becomes less urgent because the leak has an expiry baked in.
Caching and refresh, without shooting yourself in the foot
You don't call STS on every API request; that's a throttle waiting to happen and it adds latency to everything. The AWS SDKs cache the session in memory and refresh it automatically a few minutes before Expiration. Vault's Agent and the various SDK helpers do the same with lease renewal. If you're wiring this yourself, the rule is refresh before expiry, not on the failure. Waiting for the first 403 to trigger a refresh means real requests eat the failure while the retry warms up.
A few things that will bite you:
- Clock skew. Expiry is absolute time. A host running minutes fast will reject creds that the issuer thinks are still valid, or trust ones that just died. Run NTP and treat drift as a real alert, not a nuisance.
- Refresh-before-expiry margin. Leave 5+ minutes of headroom. Refreshing at expiry minus 10 seconds guarantees a race under load.
- Never log temp creds. They feel safe because they're short-lived, so people get sloppy and dump the whole credential object into debug logs. A one-hour window is still an hour, and CI logs live a lot longer than that. Scrub
SecretAccessKey,SessionToken, and Vault passwords at the logging boundary. - Max session duration mismatches. If your job needs 90 minutes and the role caps at 60, you won't find out until it fails 60 minutes in. Match the role config to the real workload.
Questions people ask
How long do AWS STS temporary credentials last?
By default, one hour. With DurationSeconds you can request anything from 900 seconds (15 minutes) up to the role's maximum session duration, which an administrator sets between 1 and 12 hours. Requests above that setting fail. Role chaining is the exception: a session created from another assumed-role session is limited to one hour regardless of the role's setting.
How do I tell temporary AWS keys from long-term keys?
Look at the access key ID prefix. Long-term IAM user keys start with AKIA; temporary STS credentials start with ASIA and always come with a session token. Grepping CloudTrail and application configs for AKIA is a quick way to find static keys that should have been replaced by role-based access.
What happens when a Vault dynamic secret lease expires?
Vault revokes it. For the database engine that means running the role's revocation statements, typically dropping the generated user, so the username and password stop working. Each lease has a lease_duration capped by the role's max_ttl; clients that need longer renew the lease before it ends, up to that maximum, and then request fresh credentials.
The call we'd make
Kill static keys everywhere they can be killed, and make short-lived the only path that works, not merely the recommended one. STS for anything talking to AWS, Vault dynamic secrets for databases and everything else with a password. Set sessions to the shortest duration the workload tolerates, run NTP so expiry math stays honest, and grep your logs for AKIA and raw secrets until both come back empty. The goal isn't credentials that rotate faster. It's credentials that a thief inherits already half-dead.
Sources
Cite this article
Kiril Urbonas (2026). Short-Lived Credentials: STS, Dynamic Secrets, and Why Static Keys Die. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/short-lived-credentials-sts-dynamic-secrets
[Short-Lived Credentials: STS, Dynamic Secrets, and Why Static Keys Die](https://www.devopsness.com/blog/short-lived-credentials-sts-dynamic-secrets) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)
More from Cloud
Explore more articles in this category
.NET 8 Support Ends November 10: The Lambda and Azure Functions Checklist
.NET 8, .NET 9, the Lambda dotnet8 runtime and the Azure Functions in-process model all lose support on November 10, 2026. Inventory commands, the isolated-worker migration and a CI gate.
Google Cloud's europe-west2 Outage: One Zone Lost Power and the Region Stalled for 6 Hours
On October 20, 2026, europe-west2-b lost power when its generators never started. Cross-zone control-plane timeouts then degraded the whole London region. What happened and the gcloud audit to run now.
Lambda Python 3.10 Is Deprecated Today: Find Every Function and Move to 3.13
AWS deprecated the Lambda python3.10 runtime on October 31, 2026. Functions keep running, patches stop. The inventory commands, IaC diffs and AL2023 gotchas for moving to python3.13.
You might have missed
Evergreen posts worth revisiting.