Security Groups
AWS Security Groups operate as stateful, virtual firewalls that secure your cloud resources at the individual network interface layer. They intercept and evaluate every incoming and outgoing network packet to determine whether it is permitted to pass through to your infrastructure.
Unlike traditional network firewalls that guard the entire perimeter of a private network subnet, a Security Group acts as a localized shield wrapped directly around a specific resource.
Core Structural Characteristics
Resource-Level Association: Security Groups are explicitly attached to Elastic Network Interfaces (ENIs). This means they guard not only Amazon EC2 instances but also Application Load Balancers (ALBs), Amazon RDS database instances, AWS Lambda functions running inside a VPC, and Amazon ElastiCache clusters.
Exclusive Whitelisting: Security Group rules are strictly permissive. You can only write rules that explicitly allow traffic. There is no concept of a "deny" rule. By default, a newly created custom Security Group blocks all incoming traffic and allows all outbound traffic.
Rule Aggregation: You can attach multiple distinct Security Groups to a single compute resource. When multiple groups are mapped to an asset, AWS automatically aggregates the entire ruleset into a single evaluation matrix. If any individual rule across any attached group permits the packet, it is allowed through.
VPC Bound Architecture: A Security Group is physically bound to the specific Virtual Private Cloud (VPC) where it was created. However, modern network topologies can leverage Security Group VPC Associations, allowing a centrally defined Security Group to be linked across multiple VPC networks within the same region to unify structural rule baselines.
The Mechanism of Statefulness
The defining behavioral characteristic of an AWS Security Group is that it is stateful.
When a client initiates a connection to an EC2 instance, the Security Group processes the packet against its Inbound ruleset. If an Inbound rule permits the connection, the firewall's internal tracking engine automatically registers an entry in its connection state table.
Because the connection is tracked, the corresponding outbound return traffic is allowed to exit the instance immediately, completely bypassing the Outbound ruleset.
The reverse is also true: if an EC2 instance initiates an outbound request (such as fetching an OS software patch from an external repository) and it is permitted by an Outbound rule, the incoming response packet from that repository is automatically allowed back inside, completely ignoring the Inbound rules.
Rule Structural Anatomy
Every security rule you construct must explicitly define four precise parameters:
Protocol: The underlying network communication protocol type (e.g., TCP, UDP, ICMP, or All Protocols).
Port Range: The specific destination port or block of ports being targeted (e.g., a single port like 443 for HTTPS, a range like 3000-3010, or All Ports).
Description: A text field used to supply operational context for administrative audit reviews.
Source / Destination: The origin (for Inbound rules) or target (for Outbound rules) of the network packet. This can be expressed in three distinct ways:
CIDR Block: A specific IPv4 or IPv6 network range (e.g.,
192.168.1.50/32to allow one explicit machine, or0.0.0.0/0to allow the entire public internet).Prefix List: A managed reference containing a collection of IP address ranges (such as a system-maintained list of all public AWS CloudFront edge IPs).
Security Group Reference (Security Group Nesting): Instead of pinning rules to volatile, shifting IP addresses, you can input the ID of another Security Group (e.g.,
sg-0abc123XYZ). This allows any resource attached to the referenced group to communicate with your target resource automatically, scaling fluidly as infrastructure expands.
Micro-Architectural Pattern: Security Group Nesting
Hardcoding static IP addresses into firewalls causes breaking points when systems auto-scale or fail over. Production three-tier architectures rely on Security Group nesting to enforce strict network isolation boundaries without managing individual server IPs:
[ Public Internet ]
│
▼ (Permits Port 443 from 0.0.0.0/0)
┌─────────────────────────┐
│ Load Balancer │ ── Associated with: sg-alb
└─────────────────────────┘
│
▼ (Permits Port 80 ONLY from Source: sg-alb)
┌─────────────────────────┐
│ Web App EC2 Fleet │ ── Associated with: sg-web-app
└─────────────────────────┘
│
▼ (Permits Port 3306 ONLY from Source: sg-web-app)
┌─────────────────────────┐
│ RDS Database │ ── Associated with: sg-database
└─────────────────────────┘
The Web App Tier (
sg-web-app): Configures an Inbound rule that allows TCP traffic on Port 80, setting the Source directly tosg-alb. No matter how many load balancer nodes spin up or down, only traffic that has successfully passed through the load balancer's entry gate can reach the web servers.The Database Tier (
sg-database): Configures an Inbound rule allowing TCP traffic on Port 3306, setting the Source directly tosg-web-app. This guarantees that even if an attacker attempts to scan the database port from the public internet, the connection is instantly dropped at the interface layer because it did not originate from a server carrying thesg-web-apptoken.
Operational Auditing and Blast-Radius Assessment
Managing changes to security rules requires strict visibility to ensure that modifications to a single rule do not unintentionally expose broader infrastructure.
The console includes a dedicated Related Resources view directly within the Security Group detail page. When an administrator or security operator selects a Security Group, this panel displays a unified, real-time inventory of every single asset currently using that group—including active EC2 instances, Elastic Network Interfaces (ENIs), Load Balancers, and database nodes. This allows engineers to conduct an instantaneous blast-radius assessment before modifying or deleting rules, eliminating the need to search through separate service panels manually.
Architectural Matrix: Security Groups vs. Network ACLs (NACLs)