← Cloud Practitioner study path

Technology and services · 12 min

Security groups and network ACLs

In this lesson you will learn how security groups and network ACLs filter the traffic of a VPC, how they differ in where they filter, which rules they accept and whether they remember connections, and what Amazon Inspector checks.

Security groups and network ACLs are the two traffic filters a has, that is, they decide which connections can reach your resources and which can leave them. Both decide which traffic gets through, but they work at different levels: the network ACL filters at the edge of each , and the security group filters at each resource. For example, in an online store, the network ACL checks everything that comes into the part of the network where its servers are, and the security group checks what reaches each server.

Security groups

A security group decides who can reach a resource, for example an EC2 instance, which is a computer you rent on AWS. It works like a virtual attached to the resource, with inbound rules and outbound rules, where each rule states the protocol, which is the type of communication, the and where the traffic comes from or goes to.

Security group of a web server with inbound rules for HTTPS and SSH

A web server, for example, can have two inbound rules: one that lets HTTPS in, which is the secure way to request web pages, from anywhere, and another that lets in only from the office . Traffic that doesn't match any rule doesn't get in. That way, the store's customers can see the site, but only the office team can get in to manage the server.

cloud path tip: AWS recommends opening SSH or RDP, which is the way to get into a Windows computer remotely, only to specific IP ranges and never to the whole internet. When you do a lab, limit those rules to your IP.

Security group rules

A new security group has no inbound rules, so it doesn't let anything in until you add one. However, it does come with an outbound rule that lets everything out. Also, the security group only accepts allow rules, so deny rules don't exist in it and everything that isn't allowed is blocked. For example, the store can't write a rule in its security group to block a visitor, and the only thing it can do is write rules for what it does let in, such as HTTPS from anywhere.

The security group is also stateful, that is, it remembers connections. That is why, if it let a request in, the response goes out even if there is no outbound rule for it. For example, when a customer requests a product page, the group lets that HTTPS request in, and the page goes back out to the customer without needing another rule.

True or false?

0 of 4
  1. A new security group lets everything in until you add rules.

  2. You can add a rule to a security group that denies an IP.

  3. If the group let a request in, the response goes out even if there is no outbound rule for it.

  4. Opening SSH to the whole internet is fine if the instance has a password.

Network ACLs

A network ACL (network access control list) filters what goes in and out of an entire subnet, so a single network ACL protects all the resources in that subnet. Unlike the security group, it accepts deny rules, so it can explicitly block an IP range, which is a group of consecutive addresses written all at once. For example, if the store is getting attacks from many addresses on the same network, a single network ACL rule blocks that whole range for all the servers in the subnet.

Rule order

The rules of a network ACL are numbered and are evaluated in order, from the lowest to the highest. As soon as a rule matches, it is applied and the rest are no longer evaluated. That is why, if you want to block a range within the traffic you allow, the deny rule has to have a lower number than the allow rule. For example, if a rule with a low number allows HTTPS and another with a higher number denies it, the HTTPS gets through, because the low-numbered rule is evaluated first and has already matched.

At the end of that list, every network ACL has a rule marked with an asterisk, which denies everything that didn't match any other rule. This rule can't be deleted. For example, if no rule in the network ACL mentions SSH, an attempt to get in through SSH reaches the asterisk rule and is denied.

What number do you give it?

Your network ACL has rule 100, which allows HTTPS from anywhere. You want to block an IP range you are being attacked from. What number do you give the deny rule?

Default network ACL and new network ACL

Each VPC comes with a default network ACL, that is, the one AWS creates for you, which lets all traffic through. On the other hand, a network ACL that you create starts out blocking all inbound and outbound traffic until you add rules to it. For example, if the store creates a new network ACL and attaches it to its site's subnet without adding rules, the site stops receiving visits.

Stateless

Unlike the security group, the network ACL is stateless, that is, it doesn't remember connections. That is why, if you allow inbound traffic to port 443, you also have to allow the response to go out, because otherwise the request gets in but the response doesn't get out. For example, a store customer requests a product page and the request reaches the server, but the page never makes it back and their browser keeps waiting.

How do they filter traffic together?

A packet goes through the internet gateway, the route table, the network ACL and the security group

The two filters work one after the other along the path of a that arrives from the internet. The packet comes in through the and the sends it to the subnet. Then the subnet's network ACL decides whether it gets through and, finally, the security group decides whether it reaches the instance. It only takes one of the two filters blocking it for the packet not to arrive. For example, if the network ACL lets HTTPS through but the server's security group doesn't allow it, the store's customer doesn't see the page.

According to AWS, in most cases security groups are enough, and the network ACL remains as an extra layer of defense. The Amazon VPC guide tells the two filters apart on four points:

Security group Network ACL
Where it filters At each resource At the subnet
Rules Allow only Allow and deny
How it evaluates them All of them before deciding In order, until one matches
Responses Stateful: they go out on their own Stateless: they need their own rule

Security group or network ACL?

0 of 6

Tap the correct column for each characteristic.

  1. Filters traffic at each resource

  2. Accepts deny rules

  3. Evaluates the rules in order until one matches

  4. Lets the response out without an outbound rule

  5. Needs a rule for the response to go out

  6. Evaluates all its rules before deciding

Amazon Inspector

Besides the two filters, the exam guide places Amazon Inspector within VPC security. Inspector continuously scans your EC2 instances, your container images in Amazon ECR, which are templates ready to run an application, and your Lambda functions, which are pieces of code that AWS runs for you. In them it looks for software and unintended network exposure, that is, ports open to the internet without anyone meaning them to be. It delivers each problem it finds as a finding with a recommendation to fix it. For example, if the store's server has an old version of a program with a known security flaw, Inspector reports it and recommends how to fix it.

On the exam

When the question compares the two filters or asks for a VPC security service, the question usually includes a phrase that decides the answer. For example, if it asks you to block an IP for all the servers in a subnet, the answer is the network ACL, because it is the filter that accepts deny rules. These phrases point to each answer:

  • "Instance level" or "resource level", which point to the security group, and "subnet level", which points to the network ACL.
  • "Block an IP" or "deny rule", which point to the network ACL.
  • "Stateful", which points to the security group, and "stateless", which points to the network ACL.
  • "Find software with known vulnerabilities" or "unintentionally exposed ports", which point to Amazon Inspector.

If you use an account with the new AWS experience, security groups and network ACLs come with VPC, which is included in the free plan. On the other hand, Amazon Inspector doesn't appear in the list of services for that account.

Review question

A company detects malicious traffic arriving from the range 198.51.100.0/24 at all the instances in a subnet. It wants to block that range with a single rule. What does it use?