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.
New Content: AWS Terraform, Java Programming Lab Challenges, Azure DP-900 & DP-300 Certification Exam Prep, Plus Plenty More Amazon, Google, Microsoft, and Big Data Courses
This month our Content Team continues building the catalog of courses for everyone learning about AWS, GCP, and Microsoft Azure. In addition, this month’s updates include several Java programming lab challenges and a couple of courses on big data. In total, we released five new learning...
Where Should You Be Focusing Your AWS Security Efforts?
Another day, another re:Invent session! This time I listened to Stephen Schmidt’s session, “AWS Security: Where we've been, where we're going.” Amongst covering the highlights of AWS security during 2020, a number of newly added AWS features/services were discussed, including: AWS Audit...
AWS re:Invent: 2020 Keynote Top Highlights and More
We’ve gotten through the first five days of the special all-virtual 2020 edition of AWS re:Invent. It’s always a really exciting time for practitioners in the field to see what features and services AWS has cooked up for the year ahead. This year’s conference is a marathon and not a...
WARNING: Great Cloud Content Ahead
At Cloud Academy, content is at the heart of what we do. We work with the world’s leading cloud and operations teams to develop video courses and learning paths that accelerate teams and drive digital transformation. First and foremost, we listen to our customers’ needs and we stay ahea...
Excelling in AWS, Azure, and Beyond – How Danut Prisacaru Prepares for the Future
Meet Danut Prisacaru. Danut has been a Software Architect for the past 10 years and has been involved in Software Engineering for 30 years. He’s passionate about software and learning, and jokes that coding is basically the only thing he can do well (!). We think his enthusiasm shines t...
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...