aws-ec2-replace-instance-profile
Swap the role an existing instance runs as.
match
A conjunctive graph pattern. Variables (?x) bind node ids; every clause must hold.
where
?principal has EFFECTIVE ec2:ReplaceIamInstanceProfileAssociation on ?instance
?role trust policy allows ec2.amazonaws.com; PassedToService includes ec2
emit
| source type | Identity |
|---|---|
| target type | Compute |
| source | <principal> |
| target | <EC2 instance> |
| permissions | iam:PassRole ec2:ReplaceIamInstanceProfileAssociation |
| conditions | role_compatibility iam_permission |
Narrative
{principal.name} can replace the instance profile on {instance.name} with role {role.name} (ec2:ReplaceIamInstanceProfileAssociation + iam:PassRole).
Raw rule rules/derived/aws/ec2.yaml
id: aws-ec2-replace-instance-profile
emits: CanAttachIdentity
description: Swap the role an existing instance runs as.
match:
- - principal: null
- CanPassIdentity
- role: null
where:
- ?principal has EFFECTIVE ec2:ReplaceIamInstanceProfileAssociation on ?instance
- ?role trust policy allows ec2.amazonaws.com; PassedToService includes ec2
emit:
source_type: Identity
target_type: Compute
source: <principal>
target: <EC2 instance>
permissions:
- iam:PassRole
- ec2:ReplaceIamInstanceProfileAssociation
conditions:
- role_compatibility
- iam_permission
false_positive_note: Same PassedToService/trust gating as associate. Newly attached creds surface on
the next IMDS credential refresh, not instantly.
narrative: '{principal.name} can replace the instance profile on {instance.name} with role {role.name}
(ec2:ReplaceIamInstanceProfileAssociation + iam:PassRole).'