Externally allowed port range needs review

Identify the services behind externally allowed ports and permit only required services and sources.

Description

For each public port, identify the listener, its owner and the clients that need it. Keep only the port range the service uses. Limit administration to a private path or managed access service.

Potential impact

A temporary service or management function can remain reachable after its original use ends. Without an owner it is harder to decide which permission to remove.

Remediation

Review IPv4 and IPv6 rules, all attached security groups and the host firewall. Remove unused grants and test a required and a denied connection from the relevant client networks.

Examples

Supply the VPC ID and attach the group to the service. To change only the rule on an existing group, keep its GroupDescription. Changing the group description as shown makes CloudFormation replace it.

Before

yaml
Parameters:
  VpcId:
    Type: AWS::EC2::VPC::Id
Resources:
  InstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Unrestricted source access to a port range
      VpcId: !Ref VpcId
  PortIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !Ref InstanceSecurityGroup
      IpProtocol: tcp
      FromPort: 23
      ToPort: 25
      CidrIpv6: "::/0"

The first rule allows TCP 23–25 from all IPv6 sources. Ports 23 and 25 are commonly used by Telnet and SMTP. Check the actual listeners.

After

yaml
Parameters:
  VpcId:
    Type: AWS::EC2::VPC::Id
Resources:
  InstanceSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow only a required application port
      VpcId: !Ref VpcId
  PortIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !Ref InstanceSecurityGroup
      IpProtocol: tcp
      FromPort: 443
      ToPort: 443
      CidrIp: 10.10.10.0/24

The second assumes only internal HTTPS is needed. It permits TCP 443 from 10.10.10.0/24. Configure service TLS and authentication, and add a restricted IPv6 rule if IPv6 clients also need access.

References