# IAM policy example: let a team create roles under one path, with a least privilege rewrite

Facts read 16 Nov 2026. Page reviewed 16 Nov 2026.

Allows a team lead to create roles under the path /app-team/ and to attach only a short list of managed policies to them. The iam:PolicyARN condition key limits which policy ARNs can be attached. The original allows attaching any policy to roles on that path.

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "TeamRoles",
      "Effect": "Allow",
      "Action": [
        "iam:CreateRole",
        "iam:DeleteRole",
        "iam:AttachRolePolicy",
        "iam:DetachRolePolicy",
        "iam:PutRolePolicy"
      ],
      "Resource": "arn:aws:iam::111122223333:role/app-team/*"
    }
  ]
}
```

## What it allows

- Allows creating and deleting roles under /app-team/ and attaching or writing any policy on them.

- Allows 5 actions (iam:CreateRole, iam:DeleteRole, iam:AttachRolePolicy, iam:DetachRolePolicy, iam:PutRolePolicy) on arn:aws:iam::111122223333:role/app-team/*.

Checks:
- No flags.

A team member can create a role under the path, attach AdministratorAccess to it and assume it, which makes this a route to full access.

## Least privilege rewrite

```json
{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Sid": "CreateTeamRoles",
      "Effect": "Allow",
      "Action": [
        "iam:CreateRole",
        "iam:DeleteRole",
        "iam:DetachRolePolicy"
      ],
      "Resource": "arn:aws:iam::111122223333:role/app-team/*"
    },
    {
      "Sid": "AttachApprovedPolicies",
      "Effect": "Allow",
      "Action": "iam:AttachRolePolicy",
      "Resource": "arn:aws:iam::111122223333:role/app-team/*",
      "Condition": {
        "ArnEquals": {
          "iam:PolicyARN": [
            "arn:aws:iam::aws:policy/ReadOnlyAccess",
            "arn:aws:iam::111122223333:policy/app-team-baseline"
          ]
        }
      }
    }
  ]
}
```

The rewrite removes PutRolePolicy and limits AttachRolePolicy to two named policy ARNs. A member can no longer attach an administrator policy.

- Allows 3 actions (iam:CreateRole, iam:DeleteRole, iam:DetachRolePolicy) on arn:aws:iam::111122223333:role/app-team/*.
- Allows 1 action (iam:AttachRolePolicy) on arn:aws:iam::111122223333:role/app-team/* when iam:PolicyARN ArnEquals arn:aws:iam::aws:policy/ReadOnlyAccess or arn:aws:iam::111122223333:policy/app-team-baseline.

Checks:
- No flags.

- [Paste it into the workbench](/)
- [Every IAM action and its access level](/actions/iam/)

## Related pages

- [IAM policy example: read IAM configuration for an audit](/examples/iam-read-only-audit/)
- [IAM policy example: use one KMS key to encrypt and decrypt](/examples/kms-encrypt-decrypt-one-key/)
- [IAM policy example: use a KMS key only through S3](/examples/kms-use-key-through-s3-only/)
- [All of them](/examples/)

## Sources

- IAM User Guide: grant a user permissions to pass a role: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_passrole.html (read 16 Nov 2026)
- IAM User Guide: create a role to delegate permissions to an IAM user: https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_create_for-user.html (read 16 Nov 2026)
- AWS Service Authorization Reference, programmatic access (fetched 16 Nov 2026): https://docs.aws.amazon.com/service-authorization/latest/reference/service-reference.html (read 16 Nov 2026)

Last reviewed 16 Nov 2026. Canonical: https://iampolicygenerator.com/examples/iam-delegate-role-management-by-path/

This site is not affiliated with Amazon Web Services. AWS service and product names are used only to describe AWS services.
