VPC Security groups should only allow unrestricted incoming traffic for authorized ports¶
This control checks whether the VPC security groups that are in use allow unrestricted incoming traffic. Optionally the rule checks whether the port numbers are listed in the authorizedTcpPorts parameter. The default values for authorizedTcpPorts are 80 and 443.
How to fix¶
Attribute from_port of aws_vpc_security_group_ingress_rule must be one of: 80, 443.
Implementation options¶
Choose the option that matches how you manage Terraform. All options satisfy this control.
Option 1: Compliance.tf module (recommended)¶
Use the compliance.tf registry module to get this control enforced by default. This control is mapped to the frameworks shown in the tabs above. To begin, see get started with compliance.tf.
module "ec2_instance" {
source = "cccsmedium.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "cisv80ig1.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "fedrampmoderate.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "iso27001.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "nist800171.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "nist80053.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "nydfs23.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "pcidssv321.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
module "ec2_instance" {
source = "pcidss.compliance.tf/terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
Option 2: Open source module (terraform-aws-modules)¶
If you use terraform-aws-modules/ec2-instance/aws, configure the required module inputs to satisfy this control. You can later migrate to the compliance.tf module with minimal changes because it is compatible by design.
module "ec2_instance" {
source = "terraform-aws-modules/ec2-instance/aws"
version = ">=6.0.0"
instance_type = "t3.nano"
subnet_id = "subnet-abc123"
security_group_ingress_rules = {
from_port = 80
}
}
Option 3: Terraform AWS provider resources¶
If you manage resources directly, configure the relevant Terraform AWS provider resources to meet this control. See docs for the resources involved: aws_vpc_security_group_ingress_rule.
resource "aws_vpc_security_group_ingress_rule" "this" {
cidr_ipv4 = "0.0.0.0/0"
ip_protocol = "tcp"
security_group_id = "sg-abc12345"
to_port = 443
from_port = 80
}
Which option should I choose?
- Compliance.tf module (recommended): controls enforced by default and mapped to frameworks.
- Open source module (
terraform-aws-modules): compatible by design with compliance.tf. Same variable names for an easy, low-change migration path when you are ready. - Terraform AWS provider resources: manage Terraform resources directly.
Tool mappings¶
Use these identifiers to cross-reference this control across tools, reports, and evidence.
Compliance.tf (CTF) Control:
vpc_security_group_allows_ingress_authorized_portsAWS Config Managed Rule:
VPC_SG_OPEN_ONLY_TO_AUTHORIZED_PORTSPowerpipe Control:
aws_compliance.control.vpc_security_group_allows_ingress_authorized_ports