VPC security group inbound rules should not permit ingress from any address to all ports and protocols

Description

Security groups provide stateful filtering of ingress/egress network traffic to AWS resources. AWS recommends that no security groups explicitly allow inbound ports.

Console Remediation Steps

  • Navigate to VPC.

  • In the left navigation, select Security Groups.

  • For each security group, perform the steps described below.

  • Select the Security Group, click the Inbound Rules tab, and and click Edit rules.

  • Remove any rules that permits ingress from any address to all ports and protocols.

  • Click Save.

CLI Remediation Steps

  • Remove all ingress rules which allow connectivity from a CIDR block to all ports and protocols:

    • aws ec2 revoke-security-group-ingress --group-id <id> --ip-permissions 'FromPort=0,IpProtocol=tcp,IpRanges=[{CidrIp=<cidr>}],Ipv6Ranges=[{CidrIpv6=<v6-cidr>}],ToPort=65535'

    • aws ec2 revoke-security-group-ingress --group-id <id> --ip-permissions 'FromPort=0,IpProtocol=udp,IpRanges=[{CidrIp=<cidr>}],Ipv6Ranges=[{CidrIpv6=<v6-cidr>}],ToPort=65535'

    • aws ec2 revoke-security-group-ingress --group-id <id> --ip-permissions 'FromPort=-1,IpProtocol=icmp,IpRanges=[{CidrIp=<cidr>}],Ipv6Ranges=[{CidrIpv6=<v6-cidr>}],ToPort=-1'

    • aws ec2 revoke-security-group-ingress --group-id <id> --ip-permissions 'FromPort=-1,IpProtocol=icmpv6,IpRanges=[{CidrIp=<cidr>}],Ipv6Ranges=[{CidrIpv6=<v6-cidr>}],ToPort=-1'

    • aws ec2 revoke-security-group-ingress --group-id <id> --ip-permissions 'FromPort=-1,IpProtocol=-1,IpRanges=[{CidrIp=<cidr>}],Ipv6Ranges=[{CidrIpv6=<v6-cidr>}],ToPort=-1'