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 126.96.36.199 – 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.
New Content: AWS Data Analytics – Specialty Certification, Azure AI-900 Certification, Plus New Learning Paths, Courses, Labs, and More
This month our Content Team released two big certification Learning Paths: the AWS Certified Data Analytics - Speciality, and the Azure AI Fundamentals AI-900. In total, we released four new Learning Paths, 16 courses, 24 assessments, and 11 labs. New content on Cloud Academy At any ...
New Content: Azure DP-100 Certification, Alibaba Cloud Certified Associate Prep, 13 Security Labs, and Much More
This past month our Content Team served up a heaping spoonful of new and updated content. Not only did our experts release the brand new Azure DP-100 Certification Learning Path, but they also created 18 new hands-on labs — and so much more! New content on Cloud Academy At any time, y...
AWS Certification Practice Exam: What to Expect from Test Questions
If you’re building applications on the AWS cloud or looking to get started in cloud computing, certification is a way to build deep knowledge in key services unique to the AWS platform. AWS currently offers 12 certifications that cover major cloud roles including Solutions Architect, De...
Overcoming Unprecedented Business Challenges with AWS
From auto-scaling applications with high availability to video conferencing that’s used by everyone, every day — cloud technology has never been more popular or in-demand. But what does this mean for experienced cloud professionals and the challenges they face as they carve out a new p...
Constant Content: Cloud Academy’s Q3 2020 Roadmap
Hello — Andy Larkin here, VP of Content at Cloud Academy. I am pleased to release our roadmap for the next three months of 2020 — August through October. Let me walk you through the content we have planned for you and how this content can help you gain skills, get certified, and...
New Content: Alibaba, Azure AZ-303 and AZ-304, Site Reliability Engineering (SRE) Foundation, Python 3 Programming, 16 Hands-on Labs, and Much More
This month our Content Team did an amazing job at publishing and updating a ton of new content. Not only did our experts release the brand new AZ-303 and AZ-304 Certification Learning Paths, but they also created 16 new hands-on labs — and so much more! New content on Cloud Academy At...
Blog Digest: Which Certifications Should I Get?, The 12 Microsoft Azure Certifications, 6 Ways to Prevent a Data Breach, and More
This month, we were excited to announce that Cloud Academy was recognized in the G2 Summer 2020 reports! These reports highlight the top-rated solutions in the industry, as chosen by the source that matters most: customers. We're grateful to have been nominated as a High Performer in se...
Which Certifications Should I Get?
The old AWS slogan, “Cloud is the new normal” is indeed a reality today. Really, cloud has been the new normal for a while now and getting credentials has become an increasingly effective way to quickly showcase your abilities to recruiters and companies. With all that in mind, the s...
New Content: AWS, Azure, Typescript, Java, Docker, 13 New Labs, and Much More
This month, our Content Team released a whopping 13 new labs in real cloud environments! If you haven't tried out our labs, you might not understand why we think that number is so impressive. Our labs are not “simulated” experiences — they are real cloud environments using accounts on A...
Kickstart Your Tech Training With a Free Week on Cloud Academy
Are you looking to make a jump in your technical career? Want to get trained or certified on AWS, Azure, Google Cloud Platform, DevOps, Kubernetes, Python, or another in-demand skill? Then you'll want to mark your calendar. Starting Monday, June 22 at 12:00 a.m. PDT (3:00 a.m. EDT), ...
New Content: AZ-500 and AZ-400 Updates, 3 Google Professional Exam Preps, Practical ML Learning Path, C# Programming, and More
This month, our Content Team released tons of new content and labs in real cloud environments. Not only that, but we introduced our very first highly interactive "Office Hours" webinar. This webinar, Acing the AWS Solutions Architect Associate Certification, started with a quick overvie...
Azure vs. AWS: Which Certification Provides the Brighter Future?
More and more companies are using cloud services, prompting more and more people to switch their current IT position to something cloud-related. The problem is most people only have that much time after work to learn new technologies, and there are plenty of cloud services that you can ...