Review wildcard principals in IAM policies

Use principals appropriate to the IAM policy type and limit role trust to intended identities.

Description

A role's trust policy names who can assume it. An IAM managed policy grants actions to the identity it is attached to. AWS rejects Principal in that managed policy.

Potential impact

The first task can fail at deployment. In a valid trust policy, a wildcard can let unintended callers use the role's permissions.

Remediation

Put approved role ARNs or service principals in the role's trust policy. For cross-account access, check the caller's permission and the trust conditions. Require a provider-issued ID per customer for a provider serving multiple customers. Test that the intended workload runs and unapproved callers are denied.

Examples

These tasks define different policy types. Review existing trust and permissions before updating the role.

Before

yaml
- name: IAM 정책 생성
  community.aws.iam_managed_policy:
    policy_name: ManagedPolicy
    policy:
      Version: "2012-10-17"
      Statement:
        - Effect: Allow
          Action: logs:CreateLogGroup
          Resource: "*"
          Principal:
            Service: ec2.amazonaws.com
            AWS: "*"
    make_default: false
    state: present

logs:CreateLogGroup is a logging permission. Placing Principal here neither grants it correctly nor creates role trust.

After

yaml
- name: Configure EC2 role trust
  amazon.aws.iam_role:
    name: ec2-service-role
    assume_role_policy_document: >
      {
        "Version": "2012-10-17",
        "Statement": [
          {
            "Effect": "Allow",
            "Action": "sts:AssumeRole",
            "Principal": {"Service": "ec2.amazonaws.com"}
          }
        ]
      }
    state: present

The role trusts ec2.amazonaws.com for sts:AssumeRole. Attach the role through an instance profile and grant the EC2 workload only the actions it needs.

References