For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/terraform-aws-sensitive-port-is-exposed-to-small-public-network.md.
A documentation index is available at /llms.txt.
Opening sensitive ports such as port 23 (Telnet) or port 110 (POP3) to even small public network ranges in security groups allows untrusted or unauthorized traffic to reach services that are known to have vulnerabilities or lack modern security protections. Attackers can exploit these open ports to gain unauthorized access, launch brute-force attacks, or intercept sensitive data, depending on the service listening on these ports. If this misconfiguration is left unaddressed, it increases the attack surface of your cloud environment and heightens the risk of data breaches, lateral movement within the network, or full system compromise. Properly restricting access to sensitive ports by limiting source IP ranges and disabling unused services is critical for maintaining a secure environment.
Compliant Code Examples
resource"aws_security_group""negative1"{name="allow_tls1"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=2383to_port=2383protocol="tcp"cidr_blocks=[aws_vpc.main.cidr_block]}}resource"aws_security_group""negative2"{name="allow_tls2"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=2384to_port=2386protocol="tcp"cidr_blocks=["/0"]}}resource"aws_security_group""negative3"{name="allow_tls3"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=25to_port=2500protocol="tcp"cidr_blocks=["1.2.3.4/0"]}}resource"aws_security_group""negative4"{name="allow_tls4"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=25to_port=2500protocol="tcp"cidr_blocks=["1.2.3.4/5"]}}resource"aws_security_group""negative5"{name="allow_tls5"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=25to_port=2500protocol="udp"cidr_blocks=["1.2.3.4/5","0.0.0.0/12"]}}resource"aws_security_group""negative6"{name="allow_tls6"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=0to_port=0protocol="-1"cidr_blocks=["1.2.3.4","0.0.0.0/0"]}}
Non-Compliant Code Examples
resource"aws_security_group""positive1"{name="allow_tls1"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=2200to_port=2500protocol="-1"cidr_blocks=["12.0.0.0/25"]}}resource"aws_security_group""positive2"{name="allow_tls2"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=20to_port=60protocol="tcp"cidr_blocks=["1.2.3.4/26"]}}resource"aws_security_group""positive3"{name="allow_tls3"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=5000to_port=6000protocol="-1"cidr_blocks=["2.12.22.33/27"]}}resource"aws_security_group""positive4"{name="allow_tls4"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=20to_port=22protocol="tcp"cidr_blocks=["10.92.168.0/28"]}}resource"aws_security_group""positive5"{name="allow_tls5"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=445to_port=500protocol="udp"cidr_blocks=["1.1.1.1/29","0.0.0.0/0","2.2.3.4/12"]}}resource"aws_security_group""positive6"{name="allow_tls6"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=135to_port=170protocol="udp"cidr_blocks=["10.68.0.0","0.0.0.0/28"]}}resource"aws_security_group""positive7"{name="allow_tls7"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=2383to_port=2383protocol="udp"cidr_blocks=["/0","1.2.3.4/27"]}}resource"aws_security_group""positive8"{name="allow_tls8"description="Allow TLS inbound traffic"vpc_id=aws_vpc.main.idingress{description="TLS from VPC"from_port=0to_port=0protocol="-1"cidr_blocks=["10.68.0.0/26"]}}
1
2
rulesets:- Terraform / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.