01 / 20

Cloud Network
Controls

Understand how Security Groups and Network ACLs protect cloud resources by filtering traffic at different layers of your virtual network.

Cyber Security

What Is a Virtual Network?

When you deploy servers in the cloud, they don't sit on a physical wire you can touch. Instead, the cloud provider creates a Virtual Private Cloud (VPC): your own isolated section of the cloud with its own IP address range, subnets, and routing rules.

VPC (Your Virtual Network) Public Subnet Web API Private Subnet DB Cache

Why Network Controls Matter

In a physical data center, you have physical firewalls and routers. In the cloud, those are replaced by virtual network controls that you configure through software. They are your first line of defense.

✓ Block Attackers
Deny traffic from unauthorized IP addresses or malicious ports before it reaches your servers.
✓ Limit Exposure
Only open the exact ports your application needs: close everything else by default.
✓ Segment Networks
Isolate sensitive databases from public-facing web servers so a breach in one zone doesn't spread.

The Two Main Controls

Cloud providers (AWS, Azure, GCP) all offer two layers of network filtering. In AWS terminology, they are called Security Groups and Network Access Control Lists (NACLs).

Security Group
A virtual firewall attached to individual instances (servers). It controls inbound and outbound traffic at the instance level.
Network ACL
A rule-based filter attached to an entire subnet. It controls traffic entering or leaving the subnet level.

Security Groups: Instance-Level Firewall

Security Group EC2 Instance Port 443 ✓ Port 22 ✕ Response ✓ Stateful: return traffic auto-allowed Internet Internet
1
Allow-only rules: You can only create rules that allow traffic. Everything not explicitly allowed is denied by default.
2
Stateful: If inbound traffic is allowed, the response is automatically allowed out: no separate outbound rule needed.
3
Instance-level: Each instance can have one or more Security Groups. Multiple instances can share the same group.

NACLs: Subnet-Level Filter

NACL Boundary (Subnet) Server A Server B Server C Allow Allow Deny
1
Allow and Deny rules: NACLs can explicitly allow or deny traffic: giving you finer control.
2
Stateless: Inbound and outbound rules are evaluated independently. You must create separate rules for responses.
3
Numbered rules: Rules are processed in order from lowest number to highest. The first match wins.

Security Group vs NACL

Security Group Network ACL
Level Instance Subnet
State Stateful Stateless
Rule Types Allow only Allow and Deny
Rule Processing All rules evaluated Ordered: first match wins
Default Behavior Deny all inbound Allow all traffic
Applied To Assigned to instance Auto-applies to entire subnet

Defense in Depth

Internet NACL Layer 1 Rule 100: Allow 443 Rule 200: Deny all Security Group Layer 2 Allow: TCP 443 From: 0.0.0.0/0 App Subnet perimeter Instance perimeter

How to Configure Controls

1
Identify your application's ports: Determine which ports your app needs (e.g., 443 for HTTPS, 5432 for PostgreSQL).
2
Create Security Groups per role: Make a "Web Server" SG allowing port 443 from 0.0.0.0/0, and a "Database" SG allowing port 5432 only from the Web SG.
3
Set NACL rules by subnet: Add numbered allow rules for expected traffic, then a high-numbered deny-all rule as a backstop.
4
Remember return traffic: For NACLs, allow ephemeral ports (1024-65535) outbound so responses can flow back to clients.
5
Test and audit: Use VPC Flow Logs to verify that only expected traffic is reaching your instances.

Example: Web Server Security Group

A company wants to host a public website. They need to allow HTTPS traffic from the internet while blocking everything else.

Direction Protocol Port Source / Dest
Inbound TCP 443 0.0.0.0/0
Inbound TCP 80 0.0.0.0/0
Outbound All All 0.0.0.0/0

Example: Database Security Group

The database server should only accept connections from the web servers, never directly from the internet. We reference the Web Server Security Group as the source.

Direction Protocol Port Source
Inbound TCP 5432 sg-webserver
Outbound All All 0.0.0.0/0

Example: NACL for Public Subnet

Since NACLs are stateless and use numbered rule ordering, we must carefully define both inbound and outbound rules.

Rule # Direction Port Action
100 Inbound 443 Allow
200 Inbound 80 Allow
* Inbound All Deny
100 Outbound 1024-65535 Allow
* Outbound All Deny

Stateful vs Stateless

Stateful (Security Group) Request IN Allowed by rule Response OUT Auto-allowed ✓ No extra rule needed Stateless (NACL) Request IN Allowed by rule Response OUT Needs explicit rule! Must allow ephemeral ports

Rule Processing Order

Security Group
All rules evaluated at once. If any rule matches, the traffic is allowed. There is no ordering or priority among rules.
NACL
Rules evaluated in number order. The first rule that matches determines the outcome. Lower-numbered rules take priority.

Common Mistakes

✕ Forgetting Ephemeral Ports
NACLs are stateless: if you only allow inbound 443 but don't allow outbound 1024-65535, responses can't leave the subnet.
✕ Overly Permissive Rules
Setting a Security Group to allow all traffic from 0.0.0.0/0 on all ports defeats the purpose of having the control.
✕ Wrong Rule Order in NACL
Placing a deny-all rule at a low number (like Rule 50) before any allow rules blocks everything: order matters.

Summary at a Glance

Feature Security Group Network ACL
Operates At Instance (ENI) Subnet
Stateful? Yes No
Supports Deny? No Yes
Rule Processing All evaluated First match wins
Default Deny all in, Allow all out Allow all in and out
Best For Per-app access control Subnet-wide blocking

Question 1 of 5

A Security Group is stateful. What does this mean in practice?

Question 2 of 5

A NACL has these inbound rules:
Rule 100: Allow TCP port 80
Rule 150: Deny all traffic
Rule 200: Allow TCP port 443
What happens to HTTPS (port 443) traffic?

Question 3 of 5

You configure a NACL to allow inbound traffic on port 443, but clients cannot receive responses. What is the most likely cause?

Question 4 of 5

Which of the following is a key difference between Security Groups and NACLs?

Question 5 of 5

A database server should only accept connections from web servers. What is the most secure way to configure the database Security Group?