# GR-02

every IAM role carries a permissions boundary (hkb-pipeline-boundary or hkb-workload-boundary; D81, DQ-75, DQ-76).

| Property | Value |
| --- | --- |
| Runs on | Every CloudFormation template, in CI on each change and in the pipeline's Validate stage |
| Source | `guard/rules/gr-02-role-boundary.guard` |
| Exceptions | 1 in the [exception register](/controls/accepted/) |

## Rule text

```
# GR-02: every IAM role carries a permissions boundary (hkb-pipeline-boundary or hkb-workload-boundary; D81, DQ-75, DQ-76).
# Only the AWS-mandated Control Tower roles are exempt. They mirror guard/exceptions.yaml; keep the two in step.
let exempt_roles = [
  'AWSControlTowerAdmin', 'AWSControlTowerCloudTrailRole', 'AWSControlTowerStackSetRole',
  'AWSControlTowerConfigAggregatorRoleForOrganizations'
]
let roles = Resources.*[ Type == 'AWS::IAM::Role' ]

rule GR_02 when %roles !empty {
  %roles {
    when Properties.RoleName not exists or Properties.RoleName !in %exempt_roles {
      Properties.PermissionsBoundary exists
        <<GR-02: IAM role must set PermissionsBoundary (hkb-pipeline-boundary or hkb-workload-boundary), or be listed in guard/exceptions.yaml>>
    }
  }
}
```
