VPC Network Controls
Security groups, network ACLs and VPC traffic telemetry. The layering and stateful versus stateless questions the exam repeats.
Exam tasks: 3.3 (network controls that permit or prevent traffic: security groups, network ACLs, Network Firewall; north/south and east/west protection)
The decision: does the control need to understand connections, names or payloads, and must it apply to one workload, one subnet, or every packet leaving the VPC?
A VPC filters traffic in layers. A network ACL guards the subnet edge. A security group guards each network interface. Neither inspects payloads, so they pair with WAF and Network Firewall for deeper checks.
Security group versus network ACL
| Security group | Network ACL | |
|---|---|---|
| Applies to | Network interface (instance, ENI, load balancer, endpoint) | Whole subnet |
| State | Stateful. Replies are allowed automatically | Stateless. Allow the reply traffic explicitly, including ephemeral ports |
| Rule types | Allow only. No deny | Allow and deny |
| Evaluation | All rules together | Lowest rule number first (1 to 32766). First match wins |
| Association | Many per interface | One per subnet. Each subnet always has one (default if none chosen) |
| Source can be | CIDR, prefix list or another security group | CIDR only |
| Default (new custom one) | Deny all in, allow all out | Deny all in and out. The VPC's default NACL allows everything |
| Best for | Least-privilege per tier | Coarse subnet guardrails, blocking a specific CIDR fast |
More on security groups and network ACLs
- Reference security groups, not CIDRs, between tiers. The app tier allows 8443 only from the ALB's security group, and it keeps working as instances scale.
- Removing a security group rule doesn't cut tracked connections that are already open. They continue until they go idle (up to days for an established TCP session). Only untracked flows stop at once. To cut an attacker's live session immediately, add a NACL deny, because NACLs don't track connections.
- Default quotas are 60 inbound and 60 outbound rules per security group and 5 security groups per interface (adjustable, but the product of the two is capped). NACLs have 20 rules per direction by default, adjustable to 40.
- Security Group VPC Associations let you use one security group in several VPCs of the same account and Region. Shared security groups follow shared subnets across accounts.
- NACL return traffic and ephemeral port ranges are covered on Network ACLs and ephemeral ports.
Exam signal
"Block this one attacking IP range now, including sessions already open" is a NACL deny (or a WAF IP set at the edge). Security groups can't deny. "Only the load balancer may reach the instances" is a security group that references the load balancer's security group.
What neither one filters
Security groups and network ACLs both skip traffic to and from the Route 53 Resolver (Amazon DNS), DHCP, instance metadata, ECS task metadata, the Time Sync Service, Windows license activation and the reserved addresses used by the default VPC router.
- Filter DNS with Route 53 Resolver DNS Firewall.
- Restrict instance metadata with IMDS options on the instance, not with a firewall rule.
Exam trap
"Block the malicious domain with a network ACL" does not work for queries sent to the VPC resolver. The resolver is exempt from both layers.
VPC endpoints and endpoint policies
| Gateway endpoint | Interface endpoint (PrivateLink) | |
|---|---|---|
| Services | S3 and DynamoDB only | Most AWS services, S3, your own and partner services |
| How it works | Prefix-list route in the route table | ENIs with private IPs in your subnets |
| Security group | No | Yes |
| Reachable from on-premises or peered VPCs | No | Yes, over VPN or Direct Connect |
| Cost | Free | Hourly per AZ plus data processed |
- An endpoint policy is a resource policy on the endpoint. It limits which principals, actions and resources can be reached through that endpoint. The default policy allows everything. It never grants permissions on its own: IAM and the resource policy still have to allow the call.
- Use it for data perimeters: allow
s3:*through the endpoint only on buckets owned by your organization (aws:ResourceOrgID), so a compromised instance can't copy data to an attacker's bucket. - On the resource side, require the network path with conditions in bucket policies, key policies, SCPs or RCPs:
| Condition key | Checks |
|---|---|
aws:SourceVpce | The request came through a specific endpoint |
aws:SourceVpc | The request came through an endpoint in a specific VPC |
aws:VpceAccount, aws:VpceOrgPaths, aws:VpceOrgID | The endpoint belongs to your account, OU path or organization, so one policy scales across hundreds of VPCs |
aws:SourceIp | Public source address. Not present for requests through a VPC endpoint |
Locking a bucket to the endpoint with aws:SourceIp
Requests through a VPC endpoint carry private addresses, so aws:SourceIp conditions don't match them. A bucket
policy that allows only your corporate CIDR through aws:SourceIp will block your own EC2 instances using the
gateway endpoint. Use aws:SourceVpce or aws:SourceVpc for that path.
Publishing your own service with PrivateLink
- Put an NLB (or GWLB) in front of the service and create an endpoint service. Consumers create interface endpoints in their VPCs. Traffic stays one-directional: consumers reach the service, the provider can't reach into consumer VPCs.
- Control who can connect with allowed principals and acceptance required. Overlapping CIDRs don't matter, since there's no routing between the VPCs.
- Interface endpoints can now reach services in other Regions (cross-Region PrivateLink), so check the question's Region constraints before assuming a peering or transit gateway answer.
Telemetry that explains a block
| Tool | Use |
|---|---|
| VPC Flow Logs | Records accepted and rejected IP flows per VPC, subnet or network interface. Goes to CloudWatch Logs or S3. Shows whether a security group or NACL dropped a flow |
| Traffic Mirroring | Copies packets from an ENI to an out-of-band security appliance for payload inspection |
| Reachability Analyzer | Static path analysis between two resources. Names the blocking component |
| Network Access Analyzer | Finds unintended network paths against requirements you define |
Which one to use
| Need | Pick |
|---|---|
| Per-resource allow rules, stateful | Security group |
| Subnet-wide deny of an address | Network ACL |
| Layer 7 attacks such as SQL injection | AWS WAF |
| Deep packet inspection and domain allow lists in the VPC | Network Firewall |
| Keep S3 or DynamoDB traffic off the internet | Gateway VPC endpoint |
| Enforce rules across many accounts | Firewall Manager |
Scenarios
The endpoint policy is evaluated for every request through the endpoint, whoever's credentials sign it, so limiting resources to the organization blocks uploads to outside buckets. A bucket policy on the company's own bucket can't restrict access to other buckets. The default endpoint policy allows everything. The S3 prefix list covers every bucket in the Region, including an attacker's.