AWS Networking: How It Differs From Your Data Center
AWS networking shares a lot in common with the way you run things locally; we'll discuss some differences.In this article, I'm going to break AWS...Learn More
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.
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.
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’
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’
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’.
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.
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.
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.
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:
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.
AWS's WaitCondition can be used with CloudFormation templates to ensure required resources are running.As you may already be aware, AWS CloudFormation is used for infrastructure automation by allowing you to write JSON templates to automatically install, configure, and bootstrap your ...
As companies increasingly shift workloads to the public cloud, cloud computing has moved from a nice-to-have to a core competency in the enterprise. This shift requires a new set of skills to design, deploy, and manage applications in cloud computing.As the market leader and most ma...
The announcements at re:Invent just keep on coming! Let’s look at what benefits these two new EC2 instance types offer and how these two new instances could be of benefit to you. If you're not too familiar with Amazon EC2, you might want to familiarize yourself by creating your first Am...
Google Cloud Platform (GCP) has evolved from being a niche player to a serious competitor to Amazon Web Services and Microsoft Azure. In 2018, research firm Gartner placed Google in the Leaders quadrant in its Magic Quadrant for Cloud Infrastructure as a Service for the first time. In t...
In order to understand AWS VPC egress filtering methods, you first need to understand that security on AWS is governed by a shared responsibility model where both vendor and subscriber have various operational responsibilities. AWS assumes responsibility for the underlying infrastructur...
Is it possible to create an S3 FTP file backup/transfer solution, minimizing associated file storage and capacity planning administration headache?FTP (File Transfer Protocol) is a fast and convenient way to transfer large files over the Internet. You might, at some point, have conf...
Microservices are a way of breaking large software projects into loosely coupled modules, which communicate with each other through simple Application Programming Interfaces (APIs).Microservices have become increasingly popular over the past few years. The modular architectural style,...
There are many use cases for tags, but what are the best practices for tagging AWS resources? In order for your organization to effectively manage resources (and your monthly AWS bill), you need to implement and adopt a thoughtful tagging strategy that makes sense for your business. The...
Amazon S3 is the most common storage options for many organizations, being object storage it is used for a wide variety of data types, from the smallest objects to huge datasets. All in all, Amazon S3 is a great service to store a wide scope of data types in a highly available and resil...
One of the main promises of cloud computing is access to nearly endless capacity. However, it doesn’t come cheap. With the introduction of Spot Instances for Amazon Web Services’ Elastic Compute Cloud (AWS EC2) in 2009, spot instances have been a way for major cloud providers to sell sp...
A Comparison of Machine Learning Services on AWS, Azure, and Google CloudArtificial intelligence and machine learning are steadily making their way into enterprise applications in areas such as customer support, fraud detection, and business intelligence. There is every reason to beli...
The AWS Command Line Interface (CLI) is for managing your AWS services from a terminal session on your own client, allowing you to control and configure multiple AWS services.So you’ve been using AWS for awhile and finally feel comfortable clicking your way through all the services....