# Ensure Security Groups do not allow unrestricted ingress access to any port

- Source: https://support.icompaas.com/support/solutions/articles/62000127014-ensure-security-groups-do-not-allow-unrestricted-ingress-access-to-any-port
- Section: [Solutions](https://support.icompaas.com/support/solutions) › [Security Controls](https://support.icompaas.com/support/solutions/62000065178) › [VPC Policies](https://support.icompaas.com/support/solutions/folders/62000097631)
- Last updated: 2026-06-08
- Publisher: iCompaas, Inc. (https://www.icompaas.com)

Description:

Security groups provide stateful filtering of ingress/egress network traffic to AWS resources. It is recommended that no security group allow unrestricted ingress access to any port.

If restricted ingress access to any port means we do not allow any port to access my AWS or cloud service, Its means that any services or application which use any particular port we do not allow any. It is very secure on the cloud.

  

Rationale:

Removing unfettered connectivity to remote console services, such as SSH, reduces a server’s exposure to risk. Ensure no security groups allow ingress from 0.0.0.0/0 or::/0 to any port.

Impact:

If we do not allow unrestricted ingress/inbound access to any ports It can have minimized the opportunities for malicious activity such as hacking, data loss, and all multiple types of attacks( brute-force attacks, Denial of Service (DoS) attacks, etc). 

  

Default Value:

Inbound default value:

<table style="border-width:medium;border-style:none;border-color:currentcolor;border-image:initial"><colgroup><col><col><col><col><col></colgroup><tbody><tr style="height:54pt"><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Type</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Protocol</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Port Range</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Source</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Description</span></p></td></tr><tr style="height:66.75pt"><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">All traffic</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">All</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">All</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">Security Group ID</span><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap"><br></span><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">(e.g.:- sg-dedc3c97 / default)</span></p></td><td style="border-left:solid #000000 1pt;border-right:solid #000000 1pt;border-bottom:solid #000000 1pt;border-top:solid #000000 1pt;vertical-align:top;padding:6pt 6pt 6pt 6pt;overflow:hidden;overflow-wrap:break-word"><p dir="ltr" style="line-height:1.2;margin-top:0pt;margin-bottom:0pt"><span style="font-size:10.5pt;font-family:&quot;Times New Roman&quot;, serif;color:rgb(0, 0, 0);background-color:transparent;font-variant:normal;vertical-align:baseline;white-space:pre-wrap">For the associated instances, inbound traffic allows from network interfaces that are assigned to the same security group.</span></p></td></tr></tbody></table>

Pre-Requisite

1.  Before starting the below implementation steps write all configurations which IP and which port in the 
    

inbound.

2.  Avoid the login through the Root user.
    
3.  Only authorized persons (i.e, admins) can access the Security Groups.
    
4.  You cannot delete the default security groups but you can edit and modify them here so you can create security groups and create your own rules in them.
    
5.  Do not attach the default security group to any EC2 instance if you do not modify any default rules in 
    

inbound or outbound.

  

Remediation:

Test Plan:

The following steps to determine if the account is configured as prescribed:

1.  Log in to AWS Management Console and go to VPC [https://console.aws.amazon.com/vpc/home](https://console.aws.amazon.com/vpc/home)
    

2.  Go on Security Groups in the left navigation.
    

3.  For each security group, perform the following.
    
4.  Select the Security group.
    

5.  Click the Inbound Rules tab.
    

6.  Ensure no rule exists that has a port range that includes any port and has a Source of 0.0.0.0/0.
    

  

Using the AWS CLI:

The following command describes a security group; the command you can use for each security group individual to check which IP or ports are inbound or outbound:

aws ec2 describe-security-groups --group-ids <secuiryt\_group\_id>

Implementation Steps:

Perform the following steps to implement the prescribed state:

1.  Log in to AWS Management Console and go to VPC [https://console.aws.amazon.com/vpc/home](https://console.aws.amazon.com/vpc/home%C2%A0) 
    

  

2.  Go on Security Groups in the left navigation.
    

  

3.  For each security group, perform the following:
    
4.  Select the Security group.
    

5.   Click on the Inbound Rules tab.
    

6.  Remove any rules that allow to inbound from 0.0.0.0/0 for any port.
    

7.  Click Edit inbound rules button delete rule which allows to ingress any port and save it .
    

  

Using the AWS CLI:

List all security groups with an ingress rule of 0.0.0.0/0:

aws ec2 describe-security-groups --filters Name=ip-permission.cidr,Values='0.0.0.0/0' \\  
    --query "SecurityGroups\[\*\].{Name:GroupName,ID:GroupId}"

Remove the rule 22 port used only for e.g. you can revoke any port : 

aws ec2 revoke-security-group-ingress \\  
  --group-id <value> --protocol <protocol> --port 22 --cidr 0.0.0.0/0

or we also can write as below.

aws ec2 revoke-security-group-ingress \\  
  --group-id sg-026c12253ce15eff7 --ip-permissions \\  
  IpProtocol=icmp,FromPort=3,ToPort=4,IpRanges=\[{CidrIp=0.0.0.0/0}\]

Backout Plan:

1.  If you want to proceed with previous settings go through the Implementation steps section and set all previous policies. You can delete your new security group by following the steps:
    
2.  Open the Amazon VPC console [https://console.aws.amazon.com/vpc/](https://console.aws.amazon.com/vpc/)
    
3.  In the navigation pane, choose Security Groups.
    
4.  Select one or more security groups and choose Security Group Actions, Delete Security Group.
    
5.  In the Delete Security Group dialogue box, choose Yes, Delete
    
6.  or if any issue to access your resources then assign the CIDR 0.0.0.0/0 in the inbound to the security group
    

  

Using the AWS CLI:

The following command is used to delete created security group id in the security\_group\_id enter the security group id which you show on your console.

aws ec2 delete-security-group --group-id <security\_group\_id>

Reference:

-   [Control traffic to resources using security groups - Amazon Virtual Private Cloud](https://docs.aws.amazon.com/vpc/latest/userguide/VPC_SecurityGroups.html) 
    
-   [revoke-security-group-ingress — AWS CLI 1.27.87 Command Reference](https://docs.aws.amazon.com/cli/latest/reference/ec2/revoke-security-group-ingress.html) 
    
-   [get-instance-port-states — AWS CLI 1.27.89 Command Reference](https://docs.aws.amazon.com/cli/latest/reference/lightsail/get-instance-port-states.html) 
    
-   [describe-security-groups — AWS CLI 1.27.89 Command Reference](https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-security-groups.html) 
    
-   [AWS::EC2::SecurityGroupIngress - AWS CloudFormation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-ingress.html)

## Related compliance guidance

- [SOC 2 compliance: a practical implementation guide for cloud-native SaaS teams](https://support.icompaas.com/compliance/soc-2-trust-services-criteria): Configuration checks like this one are the technical half of a SOC 2 / ISO 27001 programme — the guide shows where they fit, what else an auditor expects, and how to evidence them.
- [ISO/IEC 27001:2022 compliance: a practical implementation guide](https://support.icompaas.com/compliance/iso-27001-2022): ISO 27001 Annex A.8 (technological controls) is where cloud hardening evidence lands; the guide shows how to run the ISMS around it.
