Learn how to secure your VPC using an AWS Network ACL and subnets. Network ACLs act as a firewall for controlling traffic in and out of a VPC subnet.
Welcome to part three of my AWS Security overview. Last week, we discussed instance level security. In this post, we’ll focus on security at the network level. I will cover two topics: private and public subnets and AWS Network ACLs (Network Access Control Lists, or NACLs).
Segmenting your VPC into different networks is important both from a deployment/design perspective and also for security. Segmentation allows you to better refine your security profile as appropriate for each of the services operating within each subnet.
A subnet is a distinct network segment with its own IP address range within the larger VPC CIDR (Classless Inter-Domain Routing) range. As an example, if your VPC was created with a CIDR range of 172.16.0.0/16, you could choose to create subnets with a /24 mask allowing you to create networks – each with 256 available IP addresses – following this pattern: 172.16.1.0/24, 172.16.2.0/24, 172.16.3.0/24…
Note, that the first four addresses (between .0 and .3) and the last IP address (.255) of any subnet are not available, as they are reserved for router, DNS, Broadcast, and Network addresses, along with future capabilities. This leaves you with 252 addresses to use in the above example in each subnet. You can always use one of the many subnet calculators available online to help you plan and manage your addressing.
When planning your subnets, take the time to properly anticipate how many nodes you might actually need in the future: once you create a subnet, it can’t be resized. Also, remember that AWS won’t let you create masks lower than /16 or higher than /28.
Public and Private Subnets
Splitting up your CIDR address space into subnets means that each subnet will have its own ACL and Routing Table. You will have to decide whether each subnet should be public or private. A public subnet is defined by its connection (through a Routing Table) to an Internet Gateway (IGW) within your VPC . The IGW provides a doorway from your environment out to the Public Internet. Any subnet without a route to the IGW is considered private, as there is no practical way for instances on this subnet to directly reach the public Internet.
Creating a Public Subnet
From the AWS Console, select ‘VPC > Subnets > Create Subnet‘
Enter the name for your subnet, select the VPC within which you want to create the subnet, select an Availability Zone, and finally enter the CIDR block you’d like to use. Click ‘Yes, Create’
Add an Internet Gateway
Select ‘Internet Gateways > Create Internet Gateway’
Enter a name for your IGW and click ‘Yes, Create’. Your newly created IGW will show as ‘Detached’. To attach it to a VPC, click ‘Attach to VPC’.
Select the VPC you want to attach to your new IGW to and click ‘Yes, Attach’
Adding a route to the IGW from your Subnet
Select ‘Route Tables > Create Route Table‘
Enter a name for your public Route Table and select your VPC, then select ‘Yes, Create’. You now need to edit your Route Table and give it a route to the outside world. To do this, select your Route Table and click ‘Routes > Edit > Add Another Route‘.
Enter ‘0.0.0.0/0’ in Destination (to allow access to any Internet address) and enter your IGW ID in the ‘Target’ field. Click ‘Save’.
Associate your Route Table with your Subnet
Select ‘Subnet Associations’
Select the Subnet(s) you wish to associate with this Route Table using the check box and click ‘Save’.
Your new Subnet now has a Route Table associated with it that allows access to the outside world via your Internet Gateway. This Subnet is now public.
When setting up your infrastructure, you will most likely be deploying services across multiple regions and availability zones (AZs) for high availability. It’s important to remember that subnets are unique and can’t be deployed across multiple AZs. If you plan to implement VPC peering, you should be aware that the peered subnets must not use overlapping CIDR blocks!
For tighter security, I would suggest keeping the number of instances within your public subnet(s) to a minimum, using Elastic Load Balancing and Autoscaling for increased availability while, at the same time, minimizing exposure. Only place instances that require public access in your public subnet. ALL other instances – like back end databases or application services – should live within private subnets. You will, of course, need to ensure proper routing between the two subnets.
The AWS Network ACL
AWS Network ACLs are the network equivalent of the security groups we’ve seen attached to EC2 instances. NACLs provide a rule-based tool for controlling network traffic ingress and egress at the protocol and subnet level. In other words, ACLs monitor and filter traffic moving in and out of a network.
You can attach an ACL to one or more subnets within your Virtual Private Cloud (VPC). If you haven’t created a custom ACL, then your subnets will automatically be associated with your VPC’s default ACL which ‘Allows’ all traffic to flow into and out of the network.
You will notice that the AWS Network ACL rule base works much the same way as the rules within security groups. However, ACL rules include an additional field called ‘Rule #’, which allows you to number your rules. This is important, because ACL rules are read in ascending order, with each rule applied against matching packets regardless of whether a later rule might also match. For this reason, you will want to carefully sequence your rules with an organized numbering system.
You can number of your rules starting at one (which will be read first), and going as high as 32766. I would suggest that you leave a gap of at least 50 numbers between each of your rules (i.e., 50, 100, 150…) to allow you to more easily add new rules in sequence later, if it should be necessary.
From the above example, you will also notice that each list includes a final entry with an asterisk (*) in the ‘Rule #’ column, rather than a number. This rule appears at the end of every rule base and can not be removed or edited. Its job is to act as an automatic fail-safe, to ensure that traffic that doesn’t match any of your custom ACL rules is dropped.
If you read my previous post, you will remember that security groups are stateful by design. ACLs, on the other hand, are stateless. Therefore, when creating your rules, you may need to apply an outbound reply rule to permit responses to inbound requests – if desired.
Creating an AWS Network ACL
To create an ACL from the AWS Console, select ‘VPC > Network ACLs > Create Network ACL’. Enter a name for your ACL and select the VPC in which you want it to reside. Then select ‘Yes, Create’.
That’s it: your first custom ACL is born. To view the details of your newly created ACL, select the Summary tab.
You will see that Amazon automatically generates an AWS ACL ID and that your new ACL is not yet associated with any subnets in your chosen VPC. To associate it to one or more subnets, select the Subnet Associations tab, and then Edit. Then, select the subnets you wish to be associated and click Save. Those Subnets will then use your NACL for all inbound and outbound traffic.
Now it’s time to create some custom rules. Until you do, there will only be a default rule that will ‘Deny’ all traffic that’s either inbound or outbound (as opposed to a default AWS Network ACL which starts off fully open). Unless you tell the ACL otherwise, it will block everything.
To configure your ACL’s Inbound and Outbound rules, click on the appropriate tab, and then on Edit.
Let’s explain these fields, one at a time.
Rule #. As we mentioned, ACL rules are read in ascending order, but only until a rule matching the packet is found. Care should be taken to number your rules appropriately when creating your rule base.
Type. This drop down list allows you to select from a list of common protocol types, including SSH, RDP, HTTP, and POP3. You can alternatively specify custom protocols such as varieties of ICMP.
Protocol. Based on your choice for ‘Type’, the Protocol option might be greyed out. For custom rules like TCP/UDP however, you should provide a value.
Port Range. If you do create a custom rule, you’ll need to specify the port range for the protocol to use.
Source. This can be a network subnet range, a specific IP address, or even left open to traffic from anywhere (using this value: 0.0.0.0/0).
Allow/Deny. Each rule must include an action specifying whether the defined traffic will be allowed to pass or not.
AWS Network ACL Limitations
When creating your ACLs be aware that there is a default limit of 20 inbound and 20 outbound rules per list. You can request a higher limit from AWS, but the absolute maximum is 40, and network performance could be affected by any increase. There is also a top end limit of 200 ACLs per VPC.
All AWS Network ACL configurations – including adding and deleting rules and subnet associations – can also be applied using the AWS CLI, PowerShell, and AWS EC2 CLI.
As you can see, there’s nothing complicated about implementing ACLs, so I would definitely recommend you take a look at your own setup to see if you can improve it. You should at least try to avoid the default ACL setting that allows all traffic through using all protocols: this is very insecure for a live production environment.
I have seen ACLs used very effectively to prevent DDOS attacks. If, for example, traffic somehow manages to get past AWS’s own DDOS protection undetected and you are now being attacked from a single IP address – say 188.8.131.52 – you can create an ACL rule that will drop all traffic from that source. For better performance, I would place this rule at very start of your rule base:
Your ACLs will require updating from time to time, and you should regularly review them to ensure they are still optimised for your environment. Network security is an ongoing struggle and needs our regular attention to ensure its effectiveness.
Let’s summarise some key points:
- Remove (or edit) the default AWS Network ACL that is associated with the subnets in your VPC.
- Set up tighter restrictions on custom ACLs and apply them to your subnets.
- Segment your VPC into different subnets across different AZs and Regions for increased availability.
- If you have public-facing services, keep these in their own public subnet and move all other services into private subnets.
- Set up different routing tables for different subnets.
Next week, I’ll look at how to create Bastion Hosts, NAT Instances. We’ll also introduce VPC Peering.
Thank you for taking the time to read my article. If you have any feedback please do leave a comment below.
Top 5 AWS Salary Report Findings
At the speed the cloud tech space is developing, it can be hard to keep track of everything that’s happening within the AWS ecosystem. Advances in technology prompt smarter functionality and innovative new products, which in turn give rise to new job roles that have a ripple effect on t...
New on Cloud Academy: Red Hat, Agile, OWASP Labs, Amazon SageMaker Lab, Linux Command Line Lab, SQL, Git Labs, Scrum Master, Azure Architects Lab, and Much More
Happy New Year! We hope you're ready to kick your training in overdrive in 2020 because we have a ton of new content for you. Not only do we have a bunch of new courses, hands-on labs, and lab challenges on AWS, Azure, and Google Cloud, but we also have three new courses on Red Hat, th...
Cloud Academy’s Blog Digest: Azure Best Practices, 6 Reasons You Should Get AWS Certified, Google Cloud Certification Prep, and more
Happy Holidays from Cloud Academy We hope you have a wonderful holiday season filled with family, friends, and plenty of food. Here at Cloud Academy, we are thankful for our amazing customer like you. Since this time of year can be stressful, we’re sharing a few of our latest article...
Google Cloud Platform Certification: Preparation and Prerequisites
Google Cloud Platform (GCP) has evolved from being a niche player to a serious competitor to Amazon Web Services and Microsoft Azure. In 2019, research firm Gartner placed Google in the Leaders quadrant in its Magic Quadrant for Cloud Infrastructure as a Service for the second consecuti...
New Lab Challenges: Push Your Skills to the Next Level
Build hands-on experience using real accounts on AWS, Azure, Google Cloud Platform, and more Meaningful cloud skills require more than book knowledge. Hands-on experience is required to translate knowledge into real-world results. We see this time and time again in studies about how pe...
New on Cloud Academy: AWS Solution Architect Lab Challenge, Azure Hands-on Labs, Foundation Certificate in Cyber Security, and Much More
Now that Thanksgiving is over and the craziness of Black Friday has died down, it's now time for the busiest season of the year. Whether you're a last-minute shopper or you already have your shopping done, the holidays bring so much more excitement than any other time of year. Since our...
Understanding Enterprise Cloud Migration
What is enterprise cloud migration? Cloud migration is about moving your data, applications, and even infrastructure from your on-premises computers or infrastructure to a virtual pool of on-demand, shared resources that offer compute, storage, and network services at scale. Why d...
6 Reasons Why You Should Get an AWS Certification This Year
In the past decade, the rise of cloud computing has been undeniable. Businesses of all sizes are moving their infrastructure and applications to the cloud. This is partly because the cloud allows businesses and their employees to access important information from just about anywhere. ...
AWS Regions and Availability Zones: The Simplest Explanation You Will Ever Find Around
The basics of AWS Regions and Availability Zones We’re going to treat this article as a sort of AWS 101 — it’ll be a quick primer on AWS Regions and Availability Zones that will be useful for understanding the basics of how AWS infrastructure is organized. We’ll define each section,...
Application Load Balancer vs. Classic Load Balancer
What is an Elastic Load Balancer? This post covers basics of what an Elastic Load Balancer is, and two of its examples: Application Load Balancers and Classic Load Balancers. For additional information — including a comparison that explains Network Load Balancers — check out our post o...
Advantages and Disadvantages of Microservices Architecture
What are microservices? Let's start our discussion by setting a foundation of what microservices are. Microservices are a way of breaking large software projects into loosely coupled modules, which communicate with each other through simple Application Programming Interfaces (APIs). ...
Kubernetes Services: AWS vs. Azure vs. Google Cloud
Kubernetes is a popular open-source container orchestration platform that allows us to deploy and manage multi-container applications at scale. Businesses are rapidly adopting this revolutionary technology to modernize their applications. Cloud service providers — such as Amazon Web Ser...