0%
AWS Solutions Architect Associate (SAA-C03) Exam Prep: Secure, Resilient, High-Performing and Cost-Optimized Architectures
Domain 2: Design Resilient Architectures
Domain 3: Design High-Performing Architectures
Domain 4: Design Cost-Optimized Architectures
Final Review and Mock Exams
Network Security in a VPC
The secure architectures domain includes designing secure network access. Most questions in this area come down to a handful of building blocks: security groups, network ACLs, public and private subnets, NAT, VPC endpoints, AWS WAF, AWS Shield, AWS Network Firewall and Firewall Manager. This lesson covers each and, more importantly, when each is the right answer. It assumes you know what a VPC, a subnet and a route table are; for a refresher, see VPC subnets and route tables in the AWS in Practice course.
Security groups
A security group is a virtual firewall attached to an elastic network interface, which in practice means attached to an EC2 instance, a load balancer, an RDS database, a Lambda function in a VPC, an interface endpoint or any other resource with a network interface in the VPC. Security groups have only allow rules. Anything not allowed is denied. Each rule specifies a protocol, a port range and a source for inbound rules or a destination for outbound rules. The source or destination can be an IPv4 or IPv6 range, a prefix list or another security group.
Security groups are stateful. If an inbound rule allows a request, the response is allowed out automatically, whatever the outbound rules say, and the same is true in the other direction. A newly created security group has no inbound rules, so it denies all inbound traffic, and one outbound rule allowing everything. Changes apply immediately to existing connections and new ones. A network interface can have several security groups, and the effective rules are the union of all of them.
Network ACLs
A network ACL is a firewall at the subnet boundary. Every subnet is associated with exactly one network ACL, and a network ACL can be associated with many subnets. Network ACLs have numbered rules, both allow and deny, evaluated in order from the lowest number; the first rule that matches decides, and a final rule denies anything not matched.
Network ACLs are stateless. Return traffic is not allowed automatically, so for every inbound rule that allows a request there must be an outbound rule allowing the response, and the response goes to an ephemeral port chosen by the client, typically in the range 1024 to 65535. Forgetting ephemeral ports is the classic network ACL mistake: the request arrives but the response is dropped, and the connection times out.
The default network ACL that comes with a VPC allows all traffic in both directions. A custom network ACL that you create denies all traffic until you add rules. That difference explains a familiar exam scenario: a team creates a new network ACL, associates it with a subnet and everything stops working.
Choosing between them
Security groups are the primary control and the one you should use for almost everything. They are attached to resources, stateful, easy to reason about and can reference other security groups. Network ACLs are a coarse, secondary layer. Their one capability that security groups lack is explicit deny, which makes them the right answer when a question asks how to block a specific IP address or range from reaching a subnet, for example a range that is attacking a public web tier. Security groups cannot do that, because they have no deny rules.
A useful summary for the exam: security groups are stateful, allow only and attached to network interfaces; network ACLs are stateless, allow and deny, ordered and attached to subnets. Questions frequently test exactly these four differences.
Referencing security groups
Rules that reference another security group, rather than an IP range, are one of the most useful features of security groups. A rule in the database's security group that allows port 5432 from the application's security group lets in traffic from any network interface that has the application security group attached, wherever it runs and whatever its IP address. As the application tier scales in and out, the rule keeps working without changes.
This chaining pattern is the standard design for a three tier application: the load balancer's group allows HTTPS from anywhere, the application's group allows the application port only from the load balancer's group, and the database's group allows the database port only from the application's group. Nothing else can reach the application servers or the database, even from inside the VPC. Security group references also work across peered VPCs in the same Region and across VPCs attached to the same Transit Gateway in some configurations, and security groups can be shared across accounts using VPC sharing.
Common security group mistakes
Several mistakes appear in exam distractors. Allowing SSH or RDP from 0.0.0.0/0 opens administration ports to the entire internet; the correct answers use Session Manager with no inbound ports at all, or at least restrict the source to a known range. Allowing all traffic between all resources in a VPC removes the benefit of tiered groups. Using IP addresses of individual instances in rules breaks when instances are replaced. Trying to block an attacker with a security group fails because security groups cannot deny. Recognising these lets you discard options quickly.
Security groups for managed services
Managed services that run in your VPC also use security groups. An RDS database, an ElastiCache cluster, an EFS mount target, an Application Load Balancer and a Lambda function attached to a VPC all have security groups you control. When a scenario says a Lambda function in a VPC cannot connect to a database, check that the database's security group allows the function's security group on the database port. When an EC2 instance cannot mount an EFS file system, check that the mount target's security group allows NFS on port 2049 from the instance's security group. These connection problems are common exam questions, and the fix is almost always a security group rule that references the caller's group.
Outbound rules deserve attention too
Because a new security group allows all outbound traffic, many teams never look at outbound rules. In a sensitive environment, narrowing outbound rules limits what a compromised instance can reach. A database server, for example, rarely needs to open connections anywhere, and its group can have no outbound rules at all, since responses to allowed inbound connections still flow because the group is stateful. An application tier might be allowed outbound only to the database group, the cache group and the VPC endpoints it uses. Tight outbound rules are one of the cheapest ways to contain an incident, and the exam occasionally rewards an option that adds them.
Prefix lists
A managed prefix list is a named set of CIDR blocks that can be referenced in security group rules and route tables. Customer managed prefix lists let a team maintain, for example, the list of office ranges in one place and reference it from many security groups, so a new office range is added once rather than in every group. AWS managed prefix lists exist for services such as S3, DynamoDB and the CloudFront origin facing addresses. The CloudFront list is the standard way to allow only CloudFront to reach an ALB, which comes up again in the WAF section.
Rule limits and quotas
Security groups have quotas on the number of rules per group and groups per network interface, and network ACLs have a quota on the number of rules per ACL, which is small by default. These limits matter when a design tries to list hundreds of IP addresses. The answer is usually to use a prefix list, a security group reference or, for web traffic, a WAF IP set, which holds thousands of addresses.
Rule evaluation in practice
For a security group, AWS evaluates every rule and allows the traffic if any rule permits it, so the order you write rules in has no effect. For a network ACL, a rule numbered 100 that allows a range is checked before a rule numbered 200 that denies part of it, so the deny never applies. To block one address inside an allowed range, give the deny a lower number than the allow. Leaving gaps between rule numbers, such as 100, 200 and 300, makes it easy to insert a new rule later.
Security groups: stateful, allow only, on network interfaces, all rules evaluated. Network ACLs: stateless, allow and deny, on subnets, rules evaluated in number order. Only a network ACL can block a specific IP range.