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
In a nutshell
  • 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.

InternetusersPublic subnetALB, NAT gatewayPrivate subnetapplicationIsolated subnetdatabaseEndpointS3, DynamoDB, APIs

How it works

Subnet tiers and routing

Internet users enter through the internet gateway to a load balancer in a public subnet, then an application in a private subnet that reaches the internet through a NAT gateway and S3 through a gateway endpoint, and a database in an isolated subnet with no internet route. 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

FeatureSecurity groupNetwork ACL
Applies toNetwork interface (instance level)Subnet
StateStateful, replies are allowed automaticallyStateless, both directions need rules
Rule typesAllow onlyAllow and deny
EvaluationAll rules togetherRules in number order, lowest first, first match wins
DefaultNo inbound, all outboundDefault network ACL allows all, a custom one denies all
Source can beCIDR, prefix list, another security groupCIDR 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 typeHow it worksServicesCost model
Gateway endpointA route table entry to a prefix listAmazon S3 and DynamoDB onlyNo hourly charge
Interface endpoint (AWS PrivateLink)An elastic network interface with a private IP in your subnetMany AWS services, and your own or partner servicesHourly 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

OptionUse when
VPC peeringA few VPCs need direct, non transitive routing
Transit GatewayMany VPCs and on premises networks need hub and spoke routing
PrivateLinkYou 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.

Private appneeds S3Gateway endpointroute table entryS3 bucketpolicy checks aws SourceVpce

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:SourceVpce build a data perimeter.
  • A subnet is public only if its route table sends 0.0.0.0/0 to 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.
Exam tip

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.

Watch out

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:SourceVpce is 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.