Traditional network firewalls serve as the first line of defense, primarily controlling traffic at the perimeter between networks or subnets based on IP addresses, ports, and protocols. In a cloud context, while virtual firewall appliances continue to protect larger network segments or provide advanced features like IDS/IPS, the fundamental role of Network Access Control Lists (NACLs) often mirrors traditional firewall rules. NACLs are stateless, operating at the subnet level, evaluating traffic both inbound and outbound based on explicit allow or deny rules, and are crucial for segmenting traffic between different logical network zones within your Virtual Private Cloud (VPC).
Moving beyond the subnet, cloud environments introduce Security Groups (SGs) – stateful, instance-level virtual firewalls. Unlike NACLs, SGs operate at the Elastic Network Interface (ENI) level, meaning they protect individual compute instances, containers, or even database endpoints. Traffic permitted outbound by an SG is automatically allowed back in, and vice-versa, simplifying management compared to stateless NACLs. This allows you to define granular ingress and egress rules directly tied to the workloads, ensuring that only necessary traffic can reach or leave a specific application component, embodying the principle of "least privilege" at the resource level.
Micro-segmentation takes the concept of Security Groups to its logical extreme, providing granular isolation of individual workloads and applications within the same network segment. Instead of relying solely on subnet-level firewalls, micro-segmentation defines security policies down to the application tier or even individual process level. This strategy drastically reduces the "blast radius" in case of a breach, preventing an attacker from moving laterally between compromised systems even if they reside in the same subnet. Achieved through extensive use of Security Groups, Network Security Groups (in Azure), or Kubernetes Network Policies, micro-segmentation is a cornerstone of Zero Trust architectures in the cloud, ensuring East-West traffic is as rigorously controlled as North-South traffic.
Key Takeaways
- Network Firewalls (NACLs, virtual appliances) primarily enforce perimeter and subnet-level security, often stateless.
- Security Groups are stateful, instance-level firewalls, providing granular protection for individual cloud resources.
- Micro-segmentation applies fine-grained, workload-centric security policies to prevent lateral movement and reduce blast radius.
- Cloud security fundamentally shifts from a network perimeter focus to a workload-first, identity-driven approach.
- Effective cloud architecture combines all three for defense-in-depth: NACLs for subnet boundaries, SGs for instance protection, and micro-segmentation for isolating individual workloads.
Code Example
resource "aws_security_group" "web_server_sg" {
name = "web_server_sg"
description = "Allow HTTP and SSH inbound traffic"
vpc_id = aws_vpc.main.id # Assuming aws_vpc.main is defined
ingress {
description = "Allow HTTP from anywhere"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
description = "Allow SSH from specific IP"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["203.0.113.0/32"] # Replace with your office IP
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1" # -1 means all protocols
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "WebServerSecurityGroup"
}
}How this code works
This code defines an AWS Security Group, acting as a virtual firewall for cloud resources. Its primary job is to establish precise inbound (ingress) and outbound (egress) network rules for a web server. This is a foundational step in micro-segmentation, ensuring only authorized traffic reaches specific application components.
The resource "aws_security_group" block creates this firewall. Within it, two ingress blocks specify allowed incoming connections: one permits HTTP traffic on port 80 from 0.0.0.0/0 (anywhere), essential for a public web server. The second ingress block demonstrates stricter control, allowing SSH on port 22 only from a specific IP address using a /32 CIDR block, limiting administrative access. A subtle but important detail for beginners is how the egress block operates: setting from_port = 0, to_port = 0, protocol = "-1", and cidr_blocks = ["0.0.0.0/0"] explicitly permits all outbound traffic. Without this explicit egress rule, AWS Security Groups would, by default, deny all outgoing connections, a key security behavior distinct from some traditional firewalls.