Description
When an outbound service needs one port, set FromPort and ToPort to the same value. Use a range for consecutive TCP or UDP ports the service needs. For ICMP, these fields specify type and code.
Potential impact
Too broad a range permits connections to unnecessary services. Too narrow a range can interrupt required dependencies.
Remediation
Match the rule to the destination and ports the workload uses. Check permissions in other attached groups and test a connection to the dependency. Replies to permitted inbound connections do not need an outbound port range.
Examples
Define the omitted SourceSG and specify one destination CIDR, prefix list or security group.
Before
Resources:
OutboundRule:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 0
ToPort: 65535
GroupId: !GetAtt SourceSG.GroupId
The first rule would allow TCP 0–65535 to that destination.
After
Resources:
OutboundRule:
Type: AWS::EC2::SecurityGroupEgress
Properties:
IpProtocol: tcp
FromPort: 443
ToPort: 443
GroupId: !GetAtt SourceSG.GroupId
The second sets both bounds to 443. Configure the TLS and authentication the application needs on that port.