EC2 instances with a public IP address and an attached instance profile (IAM role) are identified.
Instances lacking public exposure or without an instance profile are excluded.
Risk
Publicly reachable instances with IAM role credentials expand the blast radius. Remote exploits or misconfigurations can steal credentials via the instance metadata service, enabling unauthorized API calls, data exfiltration, and lateral movement, impacting confidentiality, integrity, and availability.
prowler aws --checks ec2_instance_internet_facing_with_instance_profile
Recommendation
Avoid direct Internet exposure. Place workloads behind an Application Load Balancer and protect HTTP apps with WAF. Remove public IPs or restrict ingress to trusted sources. Apply least privilege to instance profiles and enforce IMDSv2. Use bastion hosts or Session Manager for admin access.
Remediation
aws ec2 disassociate-iam-instance-profile --association-id <ASSOCIATION_ID>
- In the AWS Console, go to EC2 > Instances and select the instance
- Choose Actions > Security > Modify IAM role
- Set IAM role to None and click Update IAM role
- Verify the instance no longer lists an IAM role (instance profile)
Alternative (if you need the role): remove internet exposure
- Select the instance > Networking tab
- If an Elastic IP is attached, choose Disassociate Elastic IP
- For auto-assigned public IPv4, stop the instance and relaunch without a public IP or in a subnet without auto-assign public IPv4
Source Code
Resource Type
AwsEc2Instance
References
- https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_switch-role-ec2_instance-profiles.html
- https://aws.amazon.com/blogs/aws/aws-web-application-firewall-waf-for-application-load-balancers/
- https://support.icompaas.com/support/solutions/articles/62000127121-ensure-instance-profile-is-attached-for-internet-facing-ec2-instances