Infrastructure Security · Topic 6 of 7
VPC Segmentation and Endpoints
Design VPC network security with subnet tiers, security groups versus network ACLs, route tables, gateway and interface endpoints and endpoint policies.
- 6 min
- Includes a diagram
- Security groups are stateful allow lists on the interface. Network ACLs are stateless, ordered, and can deny.
- A custom network ACL denies everything until you add rules, and return traffic needs ephemeral port rules.
- Gateway endpoints work for S3 and DynamoDB only, via a route table entry and at no hourly charge.
What it is
A Virtual Private Cloud (VPC) is your private network in AWS. Network security in a VPC means dividing it into tiers, controlling traffic between them with security groups and network ACLs, and keeping AWS service traffic off the public internet with endpoints.
The exam gives you a symptom or a requirement and asks which control to change, so you need a clear picture of what each control does and how they differ.
How it works
Subnet tiers and routing
Place resources by exposure.
Public subnets have a route to an internet gateway and hold only load balancers or NAT gateways. Private subnets reach the internet only through a NAT gateway. Isolated subnets have no internet route at all, and hold databases.
Route tables decide where traffic can go. A subnet is public only because its route table points to an internet gateway, not because of its name. Keep sensitive subnets on separate route tables so a change to one does not expose others.
Security groups versus network ACLs
| Feature | Security group | Network ACL |
|---|---|---|
| Applies to | Network interface (instance level) | Subnet |
| State | Stateful, replies are allowed automatically | Stateless, both directions need rules |
| Rule types | Allow only | Allow and deny |
| Evaluation | All rules together | Rules in number order, lowest first, first match wins |
| Default | No inbound, all outbound | Default network ACL allows all, a custom one denies all |
| Source can be | CIDR, prefix list, another security group | CIDR only |
Use security groups as the main control, and referencing another security group as source gives tier to tier rules that survive IP changes. Use network ACLs for broad subnet level rules and explicit denies, such as blocking a known bad address range.
Because network ACLs are stateless, return traffic needs an outbound rule for ephemeral ports (the high numbered client ports). A frequent fault is allowing port 443 inbound while denying the return ports outbound.
Inbound rule 100 TCP 443 0.0.0.0/0 ALLOW
Outbound rule 100 TCP 1024-65535 0.0.0.0/0 ALLOW
VPC endpoints
Endpoints let resources in a VPC reach AWS services privately, without an internet gateway or NAT.
| Endpoint type | How it works | Services | Cost model |
|---|---|---|---|
| Gateway endpoint | A route table entry to a prefix list | Amazon S3 and DynamoDB only | No hourly charge |
| Interface endpoint (AWS PrivateLink) | An elastic network interface with a private IP in your subnet | Many AWS services, and your own or partner services | Hourly and data charges |
A gateway endpoint adds a route, so it affects every subnet whose route table carries the entry. An interface endpoint is reached by a private IP and DNS name, and it has a security group that must allow the clients.
Endpoint policies and data perimeter
An endpoint policy is a resource policy on the endpoint that limits which principals can use it and which actions and resources are allowed through it.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Allow",
"Principal": "*",
"Action": ["s3:GetObject", "s3:PutObject"],
"Resource": "arn:aws:s3:::amzn-s3-demo-bucket/*"
}]
}
This endpoint lets traffic through to one bucket only. The bucket can in turn insist on private access by checking the endpoint.
{
"Version": "2012-10-17",
"Statement": [{
"Effect": "Deny",
"Principal": "*",
"Action": "s3:*",
"Resource": ["arn:aws:s3:::amzn-s3-demo-bucket", "arn:aws:s3:::amzn-s3-demo-bucket/*"],
"Condition": { "StringNotEquals": { "aws:SourceVpce": "vpce-0123456789abcdef0" } }
}]
}
Be careful with this deny pattern, because it also blocks access from the console and from administrators outside the VPC. Add an exception for a trusted administrative role if you still need that access.
The combination of endpoint policies, bucket policies with aws:SourceVpce, aws:SourceVpc or aws:PrincipalOrgID, and SCPs is called a data perimeter. It keeps your data in trusted identities, from expected networks, and to trusted resources.
Connecting VPCs
| Option | Use when |
|---|---|
| VPC peering | A few VPCs need direct, non transitive routing |
| Transit Gateway | Many VPCs and on premises networks need hub and spoke routing |
| PrivateLink | You expose one service to consumers without exposing the whole network |
PrivateLink is the most restrictive choice, because consumers reach only the service and cannot route into your VPC. It also works with overlapping address ranges.
Outbound control and public access
Block unnecessary public IP assignment, and control outbound traffic through NAT gateways with firewall inspection. VPC Block Public Access can block internet gateway traffic for all VPCs in an account Region, with exclusions for the VPCs or subnets that need internet access.
What to remember for the exam
- Security groups are stateful allow lists on the interface. Network ACLs are stateless, ordered, and can deny.
- A custom network ACL denies everything until you add rules, and return traffic needs ephemeral port rules.
- Gateway endpoints work for S3 and DynamoDB only, via a route table entry and at no hourly charge.
- Interface endpoints use PrivateLink with network interfaces, and need a security group that allows the client.
- Endpoint policies and bucket policies with
aws:SourceVpcebuild a data perimeter. - A subnet is public only if its route table sends
0.0.0.0/0to an internet gateway. - PrivateLink exposes a single service and works with overlapping CIDR blocks. Peering and Transit Gateway need routes.
- Reference security groups as sources instead of IP ranges for tier to tier rules.
To block one malicious IP address quickly across a subnet, the answer is a network ACL deny rule, because security groups cannot deny.
Common mistakes
Trying to deny with a security group. There are no deny rules, so use a network ACL or a firewall.
Forgetting the return path. A stateless network ACL that allows requests but not the ephemeral port reply breaks the connection.
Expecting a gateway endpoint to work from on premises. It applies only inside the VPC route tables, so on premises needs another approach, such as an interface endpoint for S3.
Blocking yourself with a SourceVpce deny. Administrators outside the VPC lose access unless the policy has an exception.
Rule numbers matter in a network ACL, and a broad deny with a low number overrides any allow with a higher number.
Check yourself
Which control is stateless and supports explicit deny?
The network ACL, which applies at the subnet and evaluates numbered rules in order.
Which services can use a gateway endpoint?
Amazon S3 and Amazon DynamoDB only.
How do you make an S3 bucket reachable only through a specific VPC endpoint?
Use a bucket policy that denies requests where
aws:SourceVpceis not that endpoint, with an exception for needed administrators.
Topic 6 of 7 in Infrastructure Security
Test yourself on Infrastructure Security
The full AWS SCS-C03 question bank has 858 questions, with timed practice exams and an explanation for every answer.
This study guide is independent and is not affiliated with, endorsed by, or sponsored by AWS. Vendor names, certification names and exam codes are trademarks of their respective owners and are used for identification only.