Identity and Access Management · Topic 3 of 6

IAM Roles, STS and MFA

Use IAM roles, trust policies, STS AssumeRole, external IDs, MFA conditions, session limits and IAM Roles Anywhere for temporary, tightly scoped access.

  • 5 min
In a nutshell
  • A role needs a trust policy (who may assume) and permission policies (what they can do).
  • External ID guards third party cross account access. aws:SourceArn and aws:SourceAccount guard service access.
  • Role chaining limits the session to one hour.

What it is

An IAM role is an identity with permissions but no password or long term keys. A trusted principal assumes the role, and the AWS Security Token Service (STS) returns temporary credentials that expire.

Roles are the core mechanism for service access, cross account access and federation. The exam tests who can assume a role, how long the session lasts, and how to add protection such as MFA (multi factor authentication).

Principaluser, service, other accountAssumeRoleSTSchecks trust policytemporary keysRole sessionlimited permissions and time

How it works

Two policies on every role

A role has a trust policy that says who may assume it, and permission policies that say what the session can do. Both must be right. A frequent mistake is to fix permissions when the problem is the trust policy.

A cross account trust policy names the other account, and adds conditions for safety, such as an external ID for a third party.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Allow",
    "Principal": { "AWS": "arn:aws:iam::444455556666:root" },
    "Action": "sts:AssumeRole",
    "Condition": {
      "StringEquals": { "sts:ExternalId": "a1b2c3-unique-value" }
    }
  }]
}

Naming the account root as principal delegates the decision to that account, where its administrators must still allow their principals to call sts:AssumeRole on this role. Name a specific role ARN as principal for tighter control.

Cross account access and the external ID

When a third party assumes a role in your account, the external ID prevents the confused deputy problem. The third party assigns you a unique value and must supply it when assuming the role, so another of its customers cannot trick it into using your role. For AWS services, use aws:SourceArn and aws:SourceAccount conditions for the same purpose.

STS operations

APIUse
AssumeRolePrincipals in the same or another account assume a role
AssumeRoleWithSAMLFederated users with a SAML assertion
AssumeRoleWithWebIdentityFederated users or workloads with an OIDC token
GetSessionTokenAn IAM user obtains temporary credentials, often with MFA
GetFederationTokenA custom broker issues credentials for a user
GetCallerIdentityShows which identity the credentials belong to
# AWS CLI: assume a role and show the caller identity
aws sts assume-role \
  --role-arn arn:aws:iam::111122223333:role/AuditRole \
  --role-session-name audit-2026-10 \
  --external-id a1b2c3-unique-value

aws sts get-caller-identity

Session controls

  • Duration. A role has a maximum session duration that you set. Role chaining, where one role assumes another, is limited to a one hour session.
  • Session policy. A policy passed when assuming the role can only reduce permissions for that session, never add any.
  • Session tags and source identity. Tags pass attributes for ABAC, and sts:SourceIdentity records the original user across role chains, so CloudTrail shows who really acted.
  • Revocation. You cannot cancel a single session, but you can revoke all sessions issued before a time, as the incident response chapter showed.

MFA

MFA adds a second factor. AWS supports passkeys and FIDO security keys, virtual authenticator apps and hardware TOTP tokens. FIDO based factors resist phishing best.

To require MFA for sensitive actions, use the aws:MultiFactorAuthPresent condition key, and aws:MultiFactorAuthAge to require a recent MFA check.

{
  "Version": "2012-10-17",
  "Statement": [{
    "Effect": "Deny",
    "Action": ["ec2:TerminateInstances", "ec2:StopInstances"],
    "Resource": "*",
    "Condition": { "BoolIfExists": { "aws:MultiFactorAuthPresent": "false" } }
  }]
}

The BoolIfExists operator also denies requests where the key is absent, such as long term access key calls that never used MFA. A plain Bool against false would miss them.

For API or CLI users, the principal calls GetSessionToken or AssumeRole with the MFA device serial number and a token code, and uses the returned session credentials.

IAM Roles Anywhere

IAM Roles Anywhere lets workloads outside AWS, such as servers in a data centre, obtain temporary credentials by presenting an X.509 certificate from a trusted certificate authority (CA). It removes the need for long term access keys on those servers. You create a trust anchor, a profile and a role that trusts the Roles Anywhere service.

Service roles and instance profiles

AWS services assume roles to act for you. EC2 uses an instance profile to pass a role to an instance. Passing a role to a service needs the iam:PassRole permission, and it is a key control to limit, because it can allow privilege escalation.

Best practices

  • Prefer roles and short sessions to IAM user access keys.
  • Scope trust policies to specific principals and add conditions.
  • Use external IDs for third parties and source conditions for AWS services.
  • Require MFA for human access to sensitive roles.
  • Limit iam:PassRole to specific role ARNs and services.

What to remember for the exam

  • A role needs a trust policy (who may assume) and permission policies (what they can do).
  • External ID guards third party cross account access. aws:SourceArn and aws:SourceAccount guard service access.
  • Role chaining limits the session to one hour.
  • A session policy can only restrict permissions. It never adds any.
  • Require MFA with aws:MultiFactorAuthPresent, and use BoolIfExists in deny statements.
  • sts:SourceIdentity carries the original user through role chains.
  • IAM Roles Anywhere gives on premises workloads temporary credentials using certificates.
  • Limit iam:PassRole, because passing a powerful role is a common escalation path.
Exam tip

For "a vendor needs access to our account and must not be able to be tricked by another customer", the answer is a cross account role with an external ID.

Common mistakes

Fixing permissions when the trust policy is the problem. An AccessDenied on AssumeRole means the trust policy or the caller's permission to assume is wrong.

Using Bool for an MFA deny. Calls without the key are not matched, so the deny does nothing for them.

Assuming a session policy can grant access. It can only narrow what the role allows.

Granting iam:PassRole on *. A user can then pass an administrator role to a service they control.

Watch out

The account root principal in a trust policy trusts every principal the other account allows, so use a specific role ARN when you know which role should assume.

Check yourself

  • What protects against the confused deputy problem for a third party role?

    An external ID in the trust policy condition, supplied by the third party when it assumes the role.

  • Why use BoolIfExists in an MFA deny policy?

    It also denies requests where the MFA key is missing, such as calls using long term access keys.

  • How long can a role chained session last at most?

    One hour.

Topic 3 of 6 in Identity and Access Management

Test yourself on Identity and Access Management

The full AWS SCS-C03 question bank has 858 questions, with timed practice exams and an explanation for every answer.

This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.