Session Duration and Token Lifecycle
You'll learn how to configure credential expiration, implement token refresh strategies, and manage credential rotation to minimize security risk windows.
The Core Idea
When applications request temporary credentials (like those from AWS STS), those credentials don't last forever—they expire after a session duration you configure. The lifecycle of these tokens involves three phases: issuance, active usage, and expiration. Managing this lifecycle correctly prevents both security gaps (tokens living too long) and operational failures (tokens expiring mid-operation).
Think of temporary credentials like a day pass to a building: you specify how long it's valid when issued, the holder uses it during that window, and when it expires, they must request a new one.
Configuring Session Duration
When assuming a role, you specify how long credentials should remain valid:
- AWS STS allows 15 minutes to 12 hours (or up to 36 hours for role chaining in some configurations)
- Shorter durations reduce the blast radius if tokens leak
- Longer durations reduce refresh overhead but increase risk
The sweet spot depends on your workload: batch jobs might need hours, while API requests might need just 15-30 minutes.
Token Refresh Strategies
Applications must refresh credentials before expiration:
- Proactive refresh: Check expiration time and refresh at 80% of lifetime
- SDK-managed refresh: Cloud SDKs often handle this automatically
- Cached credentials: Store and reuse tokens until near-expiration, then fetch new ones
- Graceful failure: Implement retry logic when refresh fails
Credential Rotation
Rotate service account keys and long-term credentials regularly (e.g., every 90 days) even if using temporary credentials, as part of defense-in-depth.
Key Takeaway: Configure the shortest practical session duration for your use case, implement proactive token refresh before expiration, and regularly rotate all credential types to limit exposure windows.