Assuming roles with STS

Intermediate · 7 min

Temporary credentials from AWS STS: trust policies, sessions and durations, cross-account access, role chaining, external IDs and the confused deputy.

Before thisIAM users, groups, roles and policiesPolicy documents and evaluation logicThe AWS CLI, SDKs and credential profiles

Cybr · 7 min

Assuming roles with STS

The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.

Taught by CybrReport a problem with this video
Not started
Set this lesson's status

What you'll learn

  • AssumeRole returns three temporary values (access key ID, secret key and session token) with an expiry. The session has the role's permissions, not yours added to them.
  • The role's trust policy must allow the caller. Across accounts the caller also needs permission to call sts:AssumeRole on that role.
  • Sessions default to one hour, can be 15 minutes up to the role's maximum (12 hours at most), and are limited to one hour when role chaining.
  • The role session name appears in the ARN and in CloudTrail, so put something there that identifies the caller.
  • An external ID protects you when a third party assumes roles for many customers: it stops the confused deputy.
  • Let profiles and SDKs assume roles for you so credentials refresh, and don't copy session keys into files.

Borrowing an identity

Suppose you need to read logs in the production account. One way is to create a user there with its own password and keys, and repeat for every person and account. The keys pile up and nobody remembers to remove them.

The other way is to keep one identity and borrow permissions when needed. The production account defines a role. You ask the Security Token Service (STS) to let you assume it. STS checks that you may, and hands back temporary credentials. They expire by themselves.

It works like a hotel key card: issued at the desk to someone already identified, opens specific doors, dead after checkout without anyone having to collect it.

Two permissions, two places

The role carries a trust policy:

{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
 "Principal":{"AWS":"arn:aws:iam::111122223333:root"},
 "Action":"sts:AssumeRole",
 "Condition":{"StringEquals":{"sts:ExternalId":"cust-7f3a9c"}}}]}

The caller, in account 111122223333, needs an identity policy allowing sts:AssumeRole on the role’s ARN. Across accounts you need both: the owner opens the door, and the visitor’s employer says who may walk through.

The call and what comes back

aws sts assume-role \
  --role-arn arn:aws:iam::123456789012:role/audit-read \
  --role-session-name ana-ticket-42 \
  --external-id cust-7f3a9c \
  --duration-seconds 900

The response holds an access key ID beginning ASIA (long-lived user keys begin AKIA), a secret key, a session token that must accompany every request, and an expiry. Using them:

$ aws sts get-caller-identity
{
    "UserId": "AROARZPUZDIKFI3G5ZFQA:ana-ticket-42",
    "Account": "123456789012",
    "Arn": "arn:aws:sts::123456789012:assumed-role/audit-read/ana-ticket-42"
}

Note the ARN. It is not the role (arn:aws:iam::...:role/audit-read) but a session of it, with the session name on the end. Policies can tell the two apart, and logs show the name. A session called session1 tells an investigator nothing.

While assumed, you have the role’s permissions only. Your own are set aside, not merged.

Durations and chaining

  • Default session: 1 hour.
  • Request from 900 seconds up to the role’s maximum session duration, itself 1 to 12 hours.
  • Role chaining, assuming a role while already using role credentials, caps the new session at 1 hour regardless.

You can’t easily recall issued credentials. To cut off live sessions after a leak, IAM can attach a deny for tokens issued before a given time (“revoke sessions” on the role).

Narrowing and tagging a session

Pass a session policy to get less than the role allows, for example access to one customer’s prefix for one job. It can only subtract. Session tags attach attributes such as team=payments that policies can test, and source identity records the original person through a chain of roles.

You can require more in the trust policy: aws:MultiFactorAuthPresent for sensitive roles, or aws:PrincipalOrgID to accept only callers from your organization.

The confused deputy

You hire a vendor to analyse your bills. You create a role trusting their account and give them its ARN. The vendor has many customers. Suppose another customer enters your role ARN into the vendor’s form. The vendor, which you trust, dutifully assumes it and shows that customer your data. The vendor is a deputy, confused about whom it is acting for.

The fix: the vendor assigns each customer a unique external ID and always sends the one belonging to the customer making the request. Your trust policy requires yours. The impostor’s request arrives with their ID and fails. It is not a password, and it works only because the vendor, not the customer, controls it.

When the deputy is an AWS service acting for you, the equivalent conditions are aws:SourceArn and aws:SourceAccount.

Let the tool do it

You rarely call assume-role by hand. A profile with role_arn and source_profile does it and refreshes the session, as shown in credential profiles. SDKs have matching credential providers. Use your Region’s STS endpoint (sts.eu-west-1.amazonaws.com); current SDKs do by default.

About the video

The embed is Cybr’s “Cross-account access with roles”, February 2026, 7 minutes, from a security certification course with a sponsor mention. Its chapters create a cross-account role, configure the source user, test the assumption and recap. It doesn’t cover external IDs or chaining, which are in the text. I judged it from chapters and description, since transcripts couldn’t be fetched. Rahul Wagh’s longer console walkthrough is in deeper.

What was run: the role, the assume-role call and the caller identity ran against moto, a local emulator. It issued credentials even though the trust policy named a different account, which real AWS would refuse, so treat the output as the shape of a response only. Durations, chaining and the confused deputy are from AWS documentation, checked in November 2026.

Where this fits

People and accounts can assume roles. So can software, without any stored secret: workload identity for EC2, Lambda and CI.

Check yourself

  1. 01You have administrator rights and assume a read-only role. Can you still delete things during that session?

    No. The session has only the role's permissions, possibly narrowed further by a session policy. Your original permissions return when you use your own credentials again.

  2. 02A trust policy names account 111122223333 as principal. Can every identity in that account assume the role?

    Only those that their own account also allows to call sts:AssumeRole on it. Naming the account delegates the decision to that account's administrators.

  3. 03A monitoring vendor asks for a role in your account. Why should the trust policy require an external ID that the vendor generates?

    Without it, another customer of the vendor who learns your role ARN could have the vendor assume your role on their behalf. The vendor sends each customer's own ID, so the other customer's request would not match yours.

  4. 04A script assumes role A, then from that session assumes role B with a 4 hour duration. What happens?

    The call fails. Assuming a role from a role session is role chaining, which limits the new session to one hour.

Go deeper

Notes

Private to you

Esc
↑↓ navigate↵ open? shortcuts

Keyboard shortcuts

Press Esc to close

Anywhere

⌘K
Search and commands
/
Search
?
This sheet
Esc
Close

Reading a lesson

J
Next lesson
K
Previous lesson
B
Bookmark