Skip to Content
Asterrr's Handbook
3 · Infrastructure security

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.

VPCPublic subnetPrivate subnetHTTPSHTTPprivateNACL statelessALB with SGNACL statelessApp instancewith SGInternet gatewayS3 gatewayendpointInternetAmazon S3
Internet traffic crosses the subnet NACL first, then the load balancer security group, then the app security group. Private subnets reach S3 through a gateway endpoint instead of the internet.

Security group versus network ACL

Security groupNetwork ACL
Applies toNetwork interface (instance, ENI, load balancer, endpoint)Whole subnet
StateStateful. Replies are allowed automaticallyStateless. Allow the reply traffic explicitly, including ephemeral ports
Rule typesAllow only. No denyAllow and deny
EvaluationAll rules togetherLowest rule number first (1 to 32766). First match wins
AssociationMany per interfaceOne per subnet. Each subnet always has one (default if none chosen)
Source can beCIDR, prefix list or another security groupCIDR only
Default (new custom one)Deny all in, allow all outDeny all in and out. The VPC's default NACL allows everything
Best forLeast-privilege per tierCoarse 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.

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 endpointInterface endpoint (PrivateLink)
ServicesS3 and DynamoDB onlyMost AWS services, S3, your own and partner services
How it worksPrefix-list route in the route tableENIs with private IPs in your subnets
Security groupNoYes
Reachable from on-premises or peered VPCsNoYes, over VPN or Direct Connect
CostFreeHourly 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 keyChecks
aws:SourceVpceThe request came through a specific endpoint
aws:SourceVpcThe request came through an endpoint in a specific VPC
aws:VpceAccount, aws:VpceOrgPaths, aws:VpceOrgIDThe endpoint belongs to your account, OU path or organization, so one policy scales across hundreds of VPCs
aws:SourceIpPublic 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.

  • 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

ToolUse
VPC Flow LogsRecords 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 MirroringCopies packets from an ENI to an out-of-band security appliance for payload inspection
Reachability AnalyzerStatic path analysis between two resources. Names the blocking component
Network Access AnalyzerFinds unintended network paths against requirements you define

Which one to use

yesnoyesno: by domain name,payload or signatureyesno, the traffic itselfnoyesTraffic must be allowed orblockedDecide by IP, port andprotocol only?Need an explicit DENY or asubnet-wide rule?Security groupNetwork ACLOnly DNS lookups?Route 53Resolver DNSFirewallMust use a specific vendorappliance?AWS NetworkFirewallGateway LoadBalancer +third-party
Decision tree for picking the control
NeedPick
Per-resource allow rules, statefulSecurity group
Subnet-wide deny of an addressNetwork ACL
Layer 7 attacks such as SQL injectionAWS WAF
Deep packet inspection and domain allow lists in the VPCNetwork Firewall
Keep S3 or DynamoDB traffic off the internetGateway VPC endpoint
Enforce rules across many accountsFirewall Manager

Scenarios

Scenario
A logistics company's EC2 instances in private subnets write shipment manifests to an S3 bucket through an S3 gateway endpoint. After a penetration test, the security team wants to ensure that code running on those instances can't upload data to S3 buckets outside the company's AWS organization, even with valid credentials from another account. What should the engineer do?

Further reading

On this page