STS, roles and cross-account access
Choosing the right STS API, cross-account role assumption, external ID, session tags, source identity, role chaining, IAM Roles Anywhere and revoking sessions.
Exam tasks: 4.1 (Skills 4.1.2 mechanisms that issue temporary credentials, 4.1.3 troubleshooting authentication with CloudTrail), 4.2 (Skills 4.2.1 role trust policies and IAM Roles Anywhere, 4.2.3 session policies)
The decision: who (or what) is asking for credentials, what have they already proved, and which STS call turns that proof into the shortest-lived, narrowest session that works?
AWS STS issues temporary credentials (access key, secret key, session token). It is API-only, with a global endpoint and Regional endpoints. Calls are logged in CloudTrail. Roles are the main way to delegate access across accounts, to services and to federated identities.
Cross-account role assumption
After assuming, the caller gives up its own permissions and acts with the role permissions. Services with resource-based policies offer an alternative that needs no role switch, but then both accounts must allow the request.
Which STS API
| API | Caller signs with | Lifetime (default / max) | MFA in call | Session policy | Watch out for |
|---|---|---|---|---|---|
AssumeRole | User or role creds | 1 h / role max (up to 12 h) | Yes | Yes | Role chaining caps at 1 hour |
AssumeRoleWithSAML | Nothing (assertion) | 1 h / role max | No, done by IdP | Yes | Trust policy checks SAML:aud |
AssumeRoleWithWebIdentity | Nothing (JWT) | 1 h / role max | No, done by IdP | Yes | Trust policy must pin aud and sub |
GetSessionToken | IAM user (or root) | 12 h / 36 h (root 1 h) | Yes | No | Can't call IAM without MFA, can only call AssumeRole in STS |
GetFederationToken | IAM user (or root) | 12 h / 36 h (root 1 h) | No | Yes, required to get any permission | Can't call IAM or STS through the API |
AssumeRoot | Management or delegated admin principal | 15 min max | n/a | Task policy (fixed list) | Regional endpoint only |
- Every session is at least 15 minutes. Set the role's maximum session duration from 1 to 12 hours.
sts:GetCallerIdentityneeds no permission and cannot be denied. It's the first call when debugging "who am I?"sts:DecodeAuthorizationMessageneeds explicit permission. It decodes the reason behind an access denied.- Credentials already issued stay valid until they expire, even if you change the role. See revoking sessions.
Restrictions on the results:
AssumeRole, SAML and web identity credentials cannot callGetFederationTokenorGetSessionToken.GetFederationTokencredentials cannot call IAM through CLI or API, and cannot call STS exceptGetCallerIdentity.GetSessionTokencredentials cannot call IAM APIs unless MFA is included, and cannot call STS exceptAssumeRoleandGetCallerIdentity. They cannot be used for console single sign-on.- Passkeys and security keys cannot be passed to STS MFA parameters.
aws loginsupplies CLI credentials instead.
Exam trap
Role chaining (a role session assuming another role) caps the new session at 1 hour, whatever the role maximum is. Asking for a longer DurationSeconds in a chain makes the call fail.
Exam signal
"CI system (GitHub Actions, GitLab) must deploy without stored keys" means an IAM OIDC provider and
AssumeRoleWithWebIdentity, with a trust policy that pins the repository in the sub claim. "Servers in our data
centre with certificates from our PKI" means IAM Roles Anywhere.
Trust policies and the confused deputy
A role has two policies: the trust policy (who may assume it) and the permissions policies (what the session may do). Both must be right.
- Third party assumes your role: require an
sts:ExternalIdthe vendor generates per customer. Without it, another customer of the same vendor could trick the vendor into using your role. That's the confused deputy. - AWS service acts on your resource: in resource policies, condition on
aws:SourceArnoraws:SourceAccountso the service only acts for your resource, not someone else's.aws:SourceOrgIDandaws:SourceOrgPathswork too, and an RCP can enforce them. - OIDC: never trust a provider without conditions on
audandsub. A GitHub trust with nosubcondition lets any repository on GitHub assume the role.
{
"Effect": "Allow",
"Principal": { "AWS": "arn:aws:iam::210987654321:root" },
"Action": "sts:AssumeRole",
"Condition": { "StringEquals": { "sts:ExternalId": "fernhill-7Q2K9" } }
}External ID as a secret
The external ID isn't a password, and you shouldn't generate it yourself. It stops the vendor being confused between customers. Protection against someone stealing the vendor's credentials comes from the vendor's own security, not the external ID.
Shaping a session
| Feature | Passed as | What it does |
|---|---|---|
| Session policy | Policy (inline) and up to 10 PolicyArns | Caps the session to the intersection with the role's policies |
| Session tags | Tags, or SAML/OIDC attributes | Become aws:PrincipalTag/... for ABAC. Need sts:TagSession in the trust policy |
| Transitive tags | TransitiveTagKeys | Survive role chaining |
| Source identity | SourceIdentity | Set once, can't be changed down the chain, logged in CloudTrail. Needs sts:SetSourceIdentity |
| Session name | RoleSessionName | Appears in the session ARN and CloudTrail. Condition on sts:RoleSessionName to force a username |
- Session tags can't be passed in the console switch-role. Role tags can't be made transitive.
aws:PrincipalTagholds IAM tags plus session tags. Session tags override same-key role tags.sts:SetSourceIdentitymust be allowed in the caller policy and the trust policy (both, for cross-account). Source identity persists through chaining and appears asaws:SourceIdentity.
Exam signal
"Know which human used a shared role in CloudTrail" is source identity. "Pass department from the IdP for ABAC" is session tags. "Third party SaaS with access to our account" is a role with an external ID.
Session limits
| Item | Value |
|---|---|
| Role maximum session duration | 1 to 12 hours, default 1 hour |
| Session policy | One JSON doc or up to 10 managed ARNs, 2,048 characters combined |
| Session tags | Up to 50. Key 128, value 256 characters |
| Role session name | 64 characters |
ExternalId | 2 to 1,224 characters |
SourceIdentity | 2 to 256 characters, cannot start with aws: |
| STS request quota | 600 per second per account per Region, shared by AssumeRole, GetCallerIdentity, GetFederationToken, GetSessionToken and others |
IAM Roles Anywhere
- For workloads outside AWS (on-prem servers, other clouds, edge devices) that hold an X.509 certificate.
- Trust anchor: your CA, either AWS Private CA or an uploaded external CA bundle. Profile: which roles can be
assumed and an optional session policy. Role: trusts
rolesanywhere.amazonaws.com, ideally withaws:SourceArnpinned to the trust anchor and conditions on certificate attributes. - The credential helper signs
CreateSessionwith the private key and returns standard temporary credentials. - Import a CRL to revoke certificates. Protect the private key, ideally in a TPM or HSM.
- It is Regional and per account. The alternatives for workloads outside AWS are IAM user access keys (last resort, rotate and scope) and OIDC federation, see federation.
Presigned URLs
- S3 presigned URLs let someone without AWS credentials GET or PUT one object until expiry.
- The URL carries the signer's permissions. If those credentials are temporary, the URL dies when they expire, whatever expiry you set. Maximum 7 days with SigV4 and long-term keys.
- Restrict their use with bucket policy conditions such as
s3:signatureAgeoraws:SourceIp.
Revoking sessions
- Revoke active role sessions: "Revoke active sessions" on the role adds an inline deny with
aws:TokenIssueTimeearlier than now. Fixing the policy alone doesn't end sessions already issued. See compromised credentials.
Scenarios
The external ID ties the vendor's session to your company, so another customer can't get the vendor to assume your role by supplying your role ARN. The vendor's automation can't satisfy MFA. PrincipalOrgID would exclude the vendor, who is outside your organization. An IP condition limits where calls come from but doesn't stop the vendor being misused on behalf of a different customer.
When a role session assumes another role, the new session is capped at one hour, whatever role B allows, and requesting more fails. Cross-account role sessions aren't limited to 15 minutes, role A's own maximum doesn't govern role B, and MFA isn't required unless a trust policy demands it.
Related
- Federation with SAML, OIDC and IAM Identity Center
- Credentials, MFA and root access
- RBAC versus ABAC
- IAM identities and policy types
- Central security management and root access
- IAM and STS fundamentals cheat sheet
Further reading
- Request temporary security credentials
- Compare AWS STS credentials
- Role terms and concepts
- Provide access to AWS accounts owned by third parties
- The confused deputy problem
- Pass session tags in AWS STS
- Monitor and control actions taken with assumed roles
- IAM and AWS STS quotas
- AWS multi-factor authentication in IAM
- What is IAM Roles Anywhere?
- AWS STS API actions
- Centrally manage root access for member accounts
Federation with SAML, OIDC and IAM Identity Center
Pick between IAM Identity Center, IAM SAML and OIDC providers, custom brokers and Active Directory options, and trace each token flow.
Credentials, MFA and root access
Credential reports, access key hygiene, MFA types and enforcement, and centralized root access for member accounts.