AWS
STS
AssumeRole
cloud security
access management

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

  1. Navigate to IAM Dashboard:
    • Sign in to the AWS Management Console.
    • Open the IAM console at https://console.aws.amazon.com/iam/.
  2. 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).
  3. 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.
  4. Set Permissions:
    • Attach appropriate permissions policies. These policies determine what actions can be performed by the assumed role.
  5. 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:
json
1   {
2     "Version": "2012-10-17",
3     "Statement": [
4       {
5         "Effect": "Allow",
6         "Principal": {
7           "AWS": "arn:aws:iam::123456789012:role/ExampleRole"
8         },
9         "Action": "sts:AssumeRole"
10       }
11     ]
12   }

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:

json
1{
2  "Version": "2012-10-17",
3  "Statement": [
4    {
5      "Effect": "Allow",
6      "Action": "sts:AssumeRole",
7      "Resource": "arn:aws:iam::123456789012:role/ExampleRole"
8    }
9  ]
10}

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:

bash
aws sts assume-role \
  --role-arn arn:aws:iam::123456789012:role/ExampleRole \
  --role-session-name ExampleSession

Environment Setup:

Once the above command is executed successfully, set up your environment variables with the returned security credentials:

bash
export AWS_ACCESS_KEY_ID=AccessKeyIdReturned
export AWS_SECRET_ACCESS_KEY=SecretAccessKeyReturned
export AWS_SESSION_TOKEN=SessionTokenReturned

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

AspectDetail
Role CreationDefine trusted entities and attach permissions policies.
Policy SetupAttach policies that allow sts:AssumeRole.
CLI/SDK UsageUse AWS CLI or SDKs to assume and manage role sessions.
Security Best PracticesUtilize 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.


Course illustration
Course illustration

All Rights Reserved.