No history yet

Secure Network Design

Building Your Fortress

A Virtual Private Cloud (VPC) is more than just a container for your AWS resources; it's the foundation of your security architecture. A well-designed VPC acts like a fortress, with layers of defense to protect your applications and data. We'll skip the basics of IP addresses and focus on how to build a multi-layered, secure, and scalable network.

Think of your VPC as the property line for your house in the cloud. Subnets are the different rooms, each with a specific purpose.

A common and effective design is the multi-tier architecture. This approach separates your application into different layers, each residing in its own type of subnet. This separation limits the blast radius if one part of your system is compromised.

  • Public Subnets: This is your lobby. It's the only part of your architecture that should be directly accessible from the public internet. Web servers and load balancers live here. They connect to the outside world through an Internet Gateway (IGW).
  • Private Subnets: This is the back office. Application servers and backend services run here. They can initiate connections to the internet for things like software updates or calling external APIs, but the internet cannot initiate connections to them. This outbound access is managed by a NAT Gateway.
  • Isolated Subnets (or Private Subnets without NAT): This is the vault. It's for your most sensitive data, like databases. These subnets have no route to the internet at all, either inbound or outbound. They only communicate with other resources within your VPC.

Guards at the Gate

Once you have your rooms, you need guards. AWS provides two types of virtual firewalls: Security Groups and Network Access Control Lists (NACLs). They work together to create a defense-in-depth strategy.

Security Group

noun

A stateful firewall for your EC2 instances that controls inbound and outbound traffic. Think of it as a bouncer for a specific virtual machine.

Security Groups are stateful. This is a key concept. If you allow an inbound connection (like a user visiting your website on port 443), the return traffic is automatically allowed out, regardless of outbound rules. You don't have to manage the response connection. Security Groups only have allow rules; anything not explicitly allowed is denied.

NACL

noun

A stateless firewall for your subnets that controls inbound and outbound traffic. It's like a guard at the entrance to an entire neighborhood (the subnet).

NACLs are stateless. If you allow inbound traffic, you must also explicitly create a rule to allow the return outbound traffic. They have both allow and deny rules, which are evaluated in order, starting from the lowest numbered rule. The first rule that matches the traffic is applied. This makes them useful for blocking specific malicious IP addresses at the subnet level.

FeatureSecurity GroupNetwork ACL
ScopeInstance LevelSubnet Level
StateStatefulStateless
RulesAllow onlyAllow and Deny
EvaluationAll rules are evaluatedRules are evaluated in number order
DefaultDenies all inbound, allows all outboundAllows all inbound and outbound

Controlling Traffic Flow

How do resources in private subnets talk to the outside world? And how do you securely connect to other AWS services without sending traffic over the public internet?

The goal is to provide necessary access while maintaining the principle of least privilege.

NAT Gateways A NAT (Network Address Translation) Gateway lives in a public subnet and allows instances in private subnets to send outbound traffic to the internet while preventing unsolicited inbound traffic. It's a managed, highly available AWS service. This is the modern replacement for the older NAT Instance, which was simply an EC2 instance you had to manage yourself.

VPC Endpoints Sometimes, your private instances don't need to talk to the whole internet, just other AWS services like S3 or DynamoDB. VPC Endpoints create a private connection between your VPC and supported AWS services, powered by AWS PrivateLink. Traffic never leaves the Amazon network, which is more secure and can be cheaper.

There are two types:

  • Gateway Endpoints: These are a target for a route in your route table. They are used for S3 and DynamoDB only and are free.
  • Interface Endpoints: These place an Elastic Network Interface (ENI) with a private IP address inside your subnet. They support many AWS services but come with an hourly cost and data processing charges.

By using VPC endpoints, communication with other AWS services occurs over private IP addresses, ensuring that traffic between your Amazon VPC and the service remains within the AWS network and doesn’t leave it.

Egress-only Internet Gateways This is a specific tool for IPv6. Since every IPv6 address is public, you can't use a NAT Gateway. An Egress-only Internet Gateway is stateful and allows outbound communication over IPv6 from your instances while blocking any inbound IPv6 traffic from the internet.

Finally, to keep an eye on everything, you can enable VPC Flow Logs. These logs capture information about the IP traffic going to and from network interfaces in your VPC. You can analyze them to troubleshoot connectivity issues, monitor for unusual traffic, or perform security analysis. They are an essential tool for network visibility.

Quiz Questions 1/7

What is the primary security benefit of placing a database server in an isolated subnet?

Quiz Questions 2/7

A Security Group is configured to allow inbound traffic on port 443 from any IP address. An application server receives a request on this port. What must be configured for the server's response to be sent back to the user?

Designing a secure VPC is a foundational skill. By layering subnets, firewalls, and controlled access points, you create a resilient environment that protects your applications from the outside in.