Description
For a service that listens on one port, set FromPort and ToPort to the same value. If it needs several TCP or UDP ports, allow the required range. For ICMP these fields specify the type and code.
Potential impact
A broad range can give allowed clients access to other listening services. Leaving out a required port can interrupt legitimate connections.
Remediation
Restrict sources to the service’s clients and check allowed ports across all attached groups. After removing unused permissions, test connectivity, authentication and authorization from an intended client.
Examples
Both excerpts omit the group receiving the rule, TargetSG, and the source. Define the group and supply one source CIDR, prefix list or security group.
Before
Resources:
InboundRule:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 0
ToPort: 65535
GroupId: !GetAtt TargetSG.GroupId
With a source specified, the first rule permits TCP 0–65535.
After
Resources:
InboundRule:
Type: AWS::EC2::SecurityGroupIngress
Properties:
IpProtocol: tcp
FromPort: 443
ToPort: 443
GroupId: !GetAtt TargetSG.GroupId
The second permits only TCP 443. Configure the TLS and authentication the listening service requires.