AssumeRole permission targets all roles

Limit role assumption permissions to required role ARNs.

Description

In a caller's sts:AssumeRole policy, Resource: "*" leaves the target role unrestricted. A cross-account request must also meet the target role's trust policy and conditions.

Potential impact

A caller may gain broader access by assuming an unintended role that trusts it.

Remediation

Set Resource to the required role ARNs. Check that each target role trusts the intended caller.

Examples

The second policy limits access to ReadOnlyApplicationRole. It also changes mypolicy to MyPolicy and replaces SomeUser with two groups. Define the group referenced by !Ref mygroup if using that example. To narrow an existing policy, keep its logical ID and intended attachments, then review the change set.

Before

yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: A sample template
Resources:
  mypolicy:
    Type: AWS::IAM::Policy
    Properties:
      PolicyName: mygrouppolicy
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action: ["sts:AssumeRole"]
            Resource: "*"
      Users: ["SomeUser"]

After

yaml
AWSTemplateFormatVersion: "2010-09-09"
Description: A sample template
Resources:
  MyPolicy:
    Type: AWS::IAM::Policy
    Properties:
      PolicyName: mygrouppolicy
      PolicyDocument:
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action:
              - sts:AssumeRole
            Resource:
              - arn:aws:iam::123456789012:role/ReadOnlyApplicationRole
      Groups:
        - myexistinggroup1
        - !Ref mygroup

References