Other Articles

EC2 VPC – Restrict Default Security Group Traffic

Secure Configuration Checks > AWS

This check ensures that the default security group of every VPC has no inbound and no outbound rules. Resources that are launched without a security group are placed in the default group. If it allows traffic, these resources are open to more traffic than their owners expect.

Check Details

  • Resource: EC2 VPC (default security group)
  • Check: Restrict default security group traffic (DefaultSecurityGroupRestrictsAll)
  • Risk: Resources placed in the default group by mistake can talk to each other and to the internet without anyone deciding that they should

What the default group allows

  • Inbound: All traffic from other resources that use the same default security group.
  • Outbound: All traffic to 0.0.0.0/0, and to ::/0 in a VPC with IPv6.
  • You cannot delete the default security group. You can only remove its rules.

Remediation via AWS Console

  1. Open the Amazon EC2 console.

    Amazon EC2 Console
  2. Go to Security Groups, filter by the name default, and select the affected VPC's default security group.

    Default security group in the EC2 console
  3. Copy the security group ID. Go to Network & Security > Network Interfaces and search for that ID. Identify the associated resources.

  4. Move each resource to an appropriate security group. For managed network interfaces, make this change through the relevant AWS service console.

  5. Under Inbound rules, click Edit inbound rules, delete all rules, and save.

    Delete inbound rules
  6. Under Outbound rules, click Edit outbound rules, delete all rules, and save.

    Delete outbound rules
  7. Repeat for every VPC's default security group.

Remediation via AWS CLI

  1. Log in to the AWS Management Console and click the CloudShell icon (>_) in the top-right corner.

    AWS CloudShell
  2. List the default security groups that still have rules. The output shows the group ID, the VPC ID, the number of inbound rules and the number of outbound rules:

    aws ec2 describe-security-groups \
    --filters Name=group-name,Values=default \
    --output json | \
    jq -r '.SecurityGroups[]
      | select((.IpPermissions | length) > 0 or (.IpPermissionsEgress | length) > 0)
      | [.GroupId, .VpcId, (.IpPermissions | length), (.IpPermissionsEgress | length)]
      | @tsv'
    

    The command covers one region. Add --region <region> to check another.

  3. Find the network interfaces that still use the default group:

    aws ec2 describe-network-interfaces \
    --filters Name=group-id,Values=<default-security-group-id> \
    --query 'NetworkInterfaces[].[NetworkInterfaceId,Description,Attachment.InstanceId]' \
    --output table
    

    Move each interface to a security group of its own. This replaces all of its security groups, so list every group that it should keep:

    aws ec2 modify-network-interface-attribute \
    --network-interface-id <eni-id> \
    --groups <new-security-group-id>
    
  4. Remove all inbound and outbound rules from the default group:

    aws ec2 revoke-security-group-ingress \
    --group-id <default-security-group-id> \
    --ip-permissions "$(aws ec2 describe-security-groups \
      --group-ids <default-security-group-id> \
      --query 'SecurityGroups[0].IpPermissions')"
    
    aws ec2 revoke-security-group-egress \
    --group-id <default-security-group-id> \
    --ip-permissions "$(aws ec2 describe-security-groups \
     --group-ids <default-security-group-id> \
     --query 'SecurityGroups[0].IpPermissionsEgress')"
    
    

    Run each command only if the group has rules of that kind. An empty rule list can return an error.

  5. Verify that both rule lists are empty:

    aws ec2 describe-security-groups \
    --group-ids <default-security-group-id> \
    --query 'SecurityGroups[0].[IpPermissions,IpPermissionsEgress]'
    

    The expected output is [[], []].

Replace <default-security-group-id> with the ID of the default group, for example sg-0123456789abcdef0. Replace <eni-id> with the network interface ID, for example eni-0123456789abcdef0. Replace <new-security-group-id> with the group that the resource should use instead. Repeat steps 3 to 5 for every default security group that the list shows.

Updated on 03 November, 2026