Browse the Repo

file-type-icon.circleci
file-type-iconexamples
file-type-iconmodules
file-type-icon_docs
file-type-iconnetwork-acl-inbound
file-type-iconnetwork-acl-outbound
file-type-iconvpc-app-network-acls
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconvpc-app
file-type-iconvpc-dns-forwarder-rules
file-type-iconvpc-dns-forwarder
file-type-iconvpc-flow-logs
file-type-iconvpc-interface-endpoint
file-type-iconvpc-mgmt-network-acls
file-type-iconvpc-mgmt
file-type-iconvpc-peering-cross-accounts-accepter
file-type-iconvpc-peering-cross-accounts-requester
file-type-iconvpc-peering-external
file-type-iconvpc-peering
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...

Browse the Repo

file-type-icon.circleci
file-type-iconexamples
file-type-iconmodules
file-type-icon_docs
file-type-iconnetwork-acl-inbound
file-type-iconnetwork-acl-outbound
file-type-iconvpc-app-network-acls
file-type-iconREADME.md
file-type-iconmain.tf
file-type-iconoutputs.tf
file-type-iconvariables.tf
file-type-iconvpc-app
file-type-iconvpc-dns-forwarder-rules
file-type-iconvpc-dns-forwarder
file-type-iconvpc-flow-logs
file-type-iconvpc-interface-endpoint
file-type-iconvpc-mgmt-network-acls
file-type-iconvpc-mgmt
file-type-iconvpc-peering-cross-accounts-accepter
file-type-iconvpc-peering-cross-accounts-requester
file-type-iconvpc-peering-external
file-type-iconvpc-peering
file-type-icontest
file-type-icon.gitignore
file-type-icon.pre-commit-config.yaml
file-type-iconCODEOWNERS
file-type-iconLICENSE.txt
file-type-iconREADME.md
file-type-iconterraform-cloud-enterprise-private-module-...
Virtual Private Cloud (VPC)

Virtual Private Cloud (VPC)

Create a Virtual Private Cloud (VPC). Includes multiple subnet tiers, NACLs, NAT gateways, Internet Gateways, and VPC peering.

Code Preview

Preview the Code

mobile file icon

README.md

down

VPC-App Network ACLs Terraform Module

This Terraform Module adds a default set of Network ACLs to a VPC created using the vpc-app module. The ACLs enforce the following security settings (based on A Reference VPC Architecture):

  • Public subnet: Allow all requests.
  • Private app subnet: Allow all requests to/from the public subnets, private persistence subnets, and the Mgmt VPC. Allow all outbound TCP requests plus return traffic from any IP for those TCP requests on ephemeral ports.
  • Private persistence subnet: Allow all requests to/from the private app subnets and the Mgmt VPC.

How do you use this module?

Check out the vpc-network-acls example.

Check out variables.tf for all the configuration options available.

What's a VPC?

A VPC or Virtual Private Cloud is a logically isolated section of your AWS cloud. Each VPC defines a virtual network within which you run your AWS resources, as well as rules for what can go in and out of that network. This includes subnets, route tables that tell those subnets how to route inbound and outbound traffic, security groups, firewalls for the subnet (known as "Network ACLs"), and any other network components such as VPN connections.

What's a Network ACL?

Network ACLs provide an extra layer of network security, similar to a security group. Whereas a security group controls what inbound and outbound traffic is allowed for a specific resource (e.g. a single EC2 instance), a network ACL controls what inbound and outbound traffic is allowed for an entire subnet.

How do I configure the Network ACLs for public ELB access?

The recommended configuration for public Elastic Load Balancers is to deploy the public facing ELB (Application Load Balancer/ALB or Network Load Balancer/NLB) in the public subnet tier, and the applications in the private app subnet tier. For the most part, the Network ACLs configured in this module should be sufficient for exposing access to the private services through the public ELB.

However, for NLBs, the default network ACLs in the module would restrict access to the private services routed from the NLB if the application is listening on a privileged port (port numbers less than 1024, e.g. HTTP port 80). This is because unlike ALBs, NLBs do not do address translation, and thus the VPC firewalls end up seeing the client IP address instead of the NLB IP address. This triggers the firewall rules in the network ACLs that will block access to the private service in the private app subnet, as the traffic will not appear to come from the public subnet tier.

To ensure the NLB traffic can make it to the private service, you must expose access to the privileged port from the client IP address in the network ACL rules. To do this, you can use the private_app_allow_inbound_ports_from_cidr input variable. For example, to allow access to a service listening on port 443 (HTTPS):

module "network_acls" {
  # other arguments omitted for brevity

  private_app_allow_inbound_ports_from_cidr = {
    AllowAnyPublicHTTP = {
      client_cidr_block = "0.0.0.0/0"
      protocol          = "tcp"
      from_port         = 443
      to_port           = 443

      # We pick rule number 99 to ensure it has the highest priority.
      rule_number = 99
    }
  }
}

Questions? Ask away.

We're here to talk about our services, answer any questions, give advice, or just to chat.

Ready to hand off the Gruntwork?