kevinemmetfoley.com → cloud → aws career certification → aws assume role
Posted on by Dennis Chapman

aws assume role

Screenshot of AWS Management Console showing the "Assume Role" button in the IAM console

AWS Assume Role is a feature that allows a user or application to temporarily take on the permissions of another IAM role, enabling secure access to resources without long-term credentials. This process reduces the risk of privilege misuse by limiting access duration and scope.

When you assume a role, AWS issues temporary security credentials-access key ID, secret access key, and session token-that are valid for a configurable period, typically between 15 minutes and 12 hours. These credentials grant access only to the permissions explicitly assigned to the role, not to the original user's own permissions.

For example, a developer in Account A needs to access an S3 bucket in Account B. Instead of sharing root account credentials, they assume a role in Account B that has read access to the bucket. The system verifies the request using IAM policies and generates temporary credentials, which the developer uses to perform actions.

How aws assume role works

Assuming a role begins with a request sent through AWS APIs, CLI commands, or SDKs. The request includes the ARN of the target role and optional session name. AWS validates the requester's identity via IAM policies attached to their own role or user.

If the policy permits, AWS returns a set of temporary credentials. These credentials include:

Once obtained, the credentials can be used in AWS CLI, SDKs, or even embedded in scripts. After the session expires, the credentials are revoked automatically. No manual cleanup is required.

For instance, running aws sts assume-role --role-arn arn:aws:iam::123456789012:role/BackupAdmin --role-session-name BackupJob returns a JSON response with temporary credentials. These can then be exported as environment variables to run subsequent AWS commands.

Types of roles and common use cases

Roles fall into two primary categories: AWS service roles and cross-account roles. Service roles are used by AWS services like EC2 or Lambda to access other resources. Cross-account roles enable users in one AWS account to access resources in another.

Common scenarios include:

Using assume-role avoids the need to manage long-lived access keys. According to AWS documentation, "Temporary credentials reduce the risk of credential exposure" and align with the principle of least privilege.

Use Case Role Type Duration Example
Cross-account access Cross-account 1 hour Finance team assumes a role in the billing account to view cost reports.
EC2 instance access Service role Until instance stops EC2 instance assumes a role to access S3 buckets.
Developer access Temporary user role 15 minutes DevOps engineer assumes a role to deploy infrastructure.

Common misconceptions and pitfalls

Many assume that assuming a role grants full access to the target account. That's incorrect. Permissions are strictly defined by the role's trust policy and inline or attached policies. Even if you assume a role, you cannot access resources unless the role explicitly allows it.

Another misunderstanding is that assume-role bypasses MFA. It does not. If the role requires MFA, the caller must provide a valid MFA token during the assumption process. AWS enforces this through the ExternalId and MfaSerial parameters in the API call.

I once configured a role for a partner company that had full access to a production database. The error was in the trust policy-it allowed any principal in a different AWS account. After auditing, we discovered the partner's IAM user had assumed the role without proper approval. We fixed it by restricting the trust policy to a specific account and adding MFA enforcement. This incident highlighted how easy it is to misconfigure trust relationships.

Security best practices

Always define the trust relationship carefully. Use Condition blocks in the trust policy to restrict who can assume the role. For example:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Principal": {
        "AWS": "arn:aws:iam::123456789012:user/PartnerUser"
      },
      "Action": "sts:AssumeRole",
      "Condition": {
        "Bool": {
          "aws:MultiFactorAuthPresent": "true"
        }
      }
    }
  ]
}

Limit session duration. The default is 1 hour, but for high-risk operations, set it to 15 minutes. Use tools like AWS CloudTrail to monitor assume-role calls. Audit logs show the AssumeRole event, the session name, and the source IP address.

According to the National Institute of Standards and Technology (NIST), "temporary credentials reduce the attack surface compared to long-term keys." AWS recommends using assume-role for any scenario requiring elevated access, especially in multi-account setups.

When you're managing multiple AWS accounts, using AWS assume role ensures consistent, auditable access control. It's not just a technical feature-it's a core part of building secure, compliant cloud environments.

Every time you assume a role, you're applying the principle of least privilege. You're not granting permission-you're temporarily borrowing it. That's the foundation of modern cloud security.


Related Posts