How enable access to AWS STS AssumeRole
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
AWS Security Token Service (STS) provides temporary security credentials for AWS users. One of the key features is the ability to assume roles, granting permissions based on trust relationships, providing flexibility in managing and using AWS resources. Here's a technical walkthrough on enabling access to AWS STS to assume roles:
Overview of STS AssumeRole
AWS Identity and Access Management (IAM) roles allow users to temporarily assume them via AWS STS, obtaining a set of temporary security credentials (access key, secret key, and session token) that grant permissions within AWS. This mechanism is often used for cross-account access, application permissions without storing long-term credentials, and federated IAM roles for users outside of AWS.
How to Enable Access to AssumeRole
1. Creating an IAM Role
- Navigate to IAM Dashboard:
- Sign in to the AWS Management Console.
- Open the IAM console at
https://console.aws.amazon.com/iam/.
- Create a New Role:
- Click on Roles in the left sidebar.
- Choose Create role.
- Optionally select a trusted entity type (AWS account, web identity, etc. based on requirement).
- Configure the Role:
- In the Select trusted entity section, choose the service (e.g., another AWS account) that you want to allow to assume this role.
- If you’re allowing another AWS account, provide its account ID.
- Set Permissions:
- Attach appropriate permissions policies. These policies determine what actions can be performed by the assumed role.
- Define Trust Relationship:
- Edit the trust relationship to specify who can assume the role. This is done by modifying the role's trust policy, which looks like:
Replace "123456789012" with the actual AWS account ID or role ARN that needs permission to assume this role.
2. Modify IAM Policies for AssumeRole
To allow an IAM user or role to assume another role, you must attach a policy granting sts:AssumeRole. Here's an example IAM policy that can be attached to a user allowing them to assume a specific role:
3. Assuming a Role
SDK/CLI:
AWS provides multiple ways to assume a role, including using AWS CLI and SDKs. Here’s an example using AWS CLI:
Environment Setup:
Once the above command is executed successfully, set up your environment variables with the returned security credentials:
These credentials can work in place of standard AWS credentials in your scripts and commands.
Uses and Best Practices
Security Practices
- Least Privilege Principle: Construct your policies such that users have only the permissions necessary for their tasks.
- Session Duration: Be mindful of the duration an assumed role's credentials are valid. For sensitive operations, configure shorter durations.
Logging and Auditing
Utilize AWS CloudTrail to log and monitor AssumeRole actions in your AWS accounts. This enhances security by ensuring all actions can be audited effectively.
Cross-Account Access
Providing cross-account access is a common use of assume role. The trust policy defines which AWS accounts can assume a role, requiring careful setup to ensure only intended entities have access.
Key Points Summary
| Aspect | Detail |
| Role Creation | Define trusted entities and attach permissions policies. |
| Policy Setup | Attach policies that allow sts:AssumeRole. |
| CLI/SDK Usage | Use AWS CLI or SDKs to assume and manage role sessions. |
| Security Best Practices | Utilize least privilege, and monitor with CloudTrail. |
This guide brings clarity to enabling access to AWS STS's AssumeRole, assisting in implementing secure and efficient access paradigms within your AWS environments. By adhering to outlined steps and best practices, your IAM role management can be robust and compliant with organizational security standards.

