Temporary credentials are one of the most powerful — and misunderstood — access mechanisms in AWS. They’re essential for enabling short-lived, tightly scoped access without the long-term baggage of static IAM user credentials. But with this flexibility comes a new surface for mistakes, misuse, and oversights.
In this post, I’ll walk through the core use cases for temporary credentials, how they work, where they go wrong, and the best ways to keep them secure in your environment.
What Are Temporary Credentials, Really?
AWS uses temporary credentials via the Security Token Service (STS) to grant access to resources for a limited duration. These credentials are usually assumed via IAM roles, either directly (e.g., sts:AssumeRole
) or through identity federation setups (like AWS IAM Identity Center, formerly SSO).
They consist of an access key ID, a secret access key, and a session token — all tied to an expiration time. Once expired, they’re useless.
Compared to static IAM user keys, this is a huge win: there’s no need to rotate them manually, and there’s less risk of long-term exposure. But only if you manage them correctly.
When Should You Use Temporary Credentials?
Temporary credentials make the most sense in scenarios like:
- Cross-account access: Letting resources or users in one AWS account access another securely
- Federated users: Providing temporary AWS access to users authenticated through an external IdP (Google, Okta, Azure AD)
- Machine access: Giving containers, EC2 instances, and Lambda functions the credentials they need to operate — without hardcoding anything
The key principle is this: temporary credentials are disposable. That makes them ideal for anything short-lived or session-based.
Where Things Go Wrong
For all their advantages, temporary credentials can cause problems if:
- Roles are overly permissive
- Session durations are maxed out unnecessarily
- You’re not logging and reviewing their use
- Developers extract them and re-use them outside their intended context
These are common missteps. I’ve seen production credentials with full AdministratorAccess
scoped to 12-hour sessions being used in CI/CD pipelines with zero monitoring. That defeats the purpose.
Best Practices for Securing Temporary Credentials
Let’s walk through the most effective ways to keep temp creds from turning into a liability:
Scope Your IAM Roles Carefully
Start with least privilege — always. Define roles that include only the permissions required for a specific task, service, or automation. Use condition keys like aws:SourceIp
, aws:RequestTag
, or aws:PrincipalTag
to make them even tighter.
Avoid using wildcard *
actions or resources unless you have an ironclad reason.
Set Conservative Session Durations
Just because STS lets you issue credentials for up to 12 hours doesn’t mean you should. Match the session duration to the activity. For ephemeral workloads (like a GitHub Action), keep it down to 15–30 minutes.
Shorter sessions reduce the time window for abuse if credentials are leaked.
Log and Monitor Usage with CloudTrail
Every STS call — including AssumeRole
and GetSessionToken
— should be logged in CloudTrail. These logs will tell you:
- Who assumed which role
- When the session started and ended
- What actions were taken using the temp credentials
Consider layering this with CloudWatch or a SIEM (like Wazuh) to alert on suspicious behavior.
Enforce MFA for Sensitive Role Assumption
If a human user is assuming a role with sensitive permissions (e.g. break-glass access), make sure MFA is required to perform role assumption. You can enforce this via IAM policy conditions.
Pro tip: MFA should be enforced always.
It adds friction — but that’s the point.
Use Automation to Rotate and Invalidate
Temporary credentials are naturally short-lived, but if you’re generating them programmatically (via custom scripts or credential vending tools), ensure they’re:
- Revoked or expired after use (you don’t need to do this if you tailor TTL for each role)
- Not stored in shared volumes or persistent config files
- Generated with limited scopes
AWS SDKs handle a lot of this for you automatically if you’re using instance profiles or OIDC-based IAM roles for service accounts.
Advanced Topics: IAM Roles Anywhere and Federation
If you’re extending access to on-prem or external systems, consider IAM Roles Anywhere — which issues temporary credentials to workloads outside of AWS using signed X.509 certs.
For workforce-level federation (like connecting Okta to AWS), make sure the trust policy on your roles includes constraints on who can assume them, and ideally matches on StringEquals
or StringLike
conditions.
Wrap Up
Temporary credentials are meant to improve security — not complicate it. But like everything in AWS, it comes down to how they’re implemented.
If you stick to short lifespans, minimal permissions, solid monitoring, and tight boundaries, they’ll serve you well.
If not, they’ll become just another attack surface.