Table of Contents
- Overview
- Security Groups
- Network ACLs (NACLs)
- Core Components
- Configuration Table
- Example Rule
- Network ACLs (NACLs)
- Security Groups vs. Network ACLs
- Best Practices
- Conclusion
AWS Networking: Security Groups & Network ACLs — Overview
What Is It?
AWS Security Groups and Network ACLs (Access Control Lists) are core networking security features offered by Amazon Web Services. They serve as firewalls—Security Groups operate at the instance level, while Network ACLs operate at the subnet level within a Virtual Private Cloud (VPC). Together, they control traffic flowing in and out of your AWS-hosted applications and services, protecting them from unauthorized access and potential security threats.
Why You Need to Know About It
- Critical Security Layer: These tools are the foundation of AWS network security. Misconfigurations can expose sensitive systems to the internet or block essential business connectivity, directly impacting your security posture.
- Compliance Requirements: Many regulatory frameworks (e.g., HIPAA, PCI DSS) require strict network access controls. Using Security Groups and Network ACLs helps meet these requirements.
- Operational Flexibility: Mastering these controls allows you to implement granular access policies, safely expose certain resources, and quickly adapt to changing application or security needs.
- Layered Defense: They enable a "defense in depth" strategy—if one layer is misconfigured, the other can still provide protection, minimizing the risk of unauthorized access.
How It Works
Security Groups
- Instance-Level, Stateful Firewalls: Security Groups are attached to EC2 instances, Lambda functions (in VPC), and other AWS resources. They use allow rules to explicitly permit inbound and outbound traffic. Their stateful nature means that once a connection is allowed in, the return traffic is automatically permitted.
- No Deny Rules: Only "allow" rules are specified—any traffic not explicitly allowed is denied by default.
- Dynamic Management: Changes to Security Groups take effect immediately and propagate to all associated resources without downtime.
Network ACLs (NACLs)
- Subnet-Level, Stateless Firewalls: NACLs are associated with entire subnets within a VPC. They control both inbound and outbound traffic and support both allow and deny rules.
- Rule Order Matters: NACLs process rules in number order, stopping at the first match. Because they are stateless, you must set rules for both inbound and outbound directions—even for return traffic.
- Use Cases: NACLs are well-suited for establishing broad subnet-wide policies, such as blocking specific IP ranges or enforcing open/closed zones.
In summary, knowing how to configure and combine AWS Security Groups and Network ACLs is essential for anyone running workloads in the AWS cloud. They empower you to securely expose services, comply with regulations, and maintain visibility and control over all network interactions within your environment.
Security Groups
Security Groups are a core AWS networking feature, acting as virtual firewalls to control traffic to and from your cloud resources. Each security group contains rules that manage both inbound and outbound network connectivity at the instance (ENI) level. Here’s how Security Groups work, in a structured, step-by-step approach:
- Definition: Security Groups operate as stateful firewalls for AWS resources such as EC2 instances, RDS, and Lambda (in VPC). You attach them to resource network interfaces to control network traffic.
- Default Behavior: By default, all inbound traffic is denied, and all outbound traffic is allowed. You must explicitly define the types of traffic you want to allow in or out[1][6].
-
Rule Types:
- Inbound Rules: Specify what traffic is allowed to reach the resource. For example, allowing SSH access over TCP port 22 from just your office’s IP.
- Outbound Rules: Define what traffic can leave the resource, such as allowing all outbound internet access for software updates.
-
Rule Components:
- Protocol: TCP, UDP, ICMP, etc.
- Port Range: A single port, or a range (e.g., 443 or 1024-2048)
- Source/Destination: IP ranges (CIDR), single IP, another security group, or AWS resources.
- (Optional) Description: Add context for each rule for clarity and auditability[3][11].
- Stateful Nature: Traffic allowed in one direction automatically permits response traffic in the opposite direction—no need to define separate rules for return traffic[7][12].
- Allow-Only Philosophy: Security groups only support allow rules; you cannot explicitly deny traffic. Any traffic not allowed is denied by default[12].
- Dynamic Rule Changes: Changes to security group rules are effective immediately and apply to all associated resources, without requiring restarts[8][12].
-
Typical Examples:
Type Protocol Port Range Source Description Inbound TCP 22 (SSH) 203.0.113.0/24 SSH from Office Inbound TCP 80 (HTTP) 0.0.0.0/0 Web Traffic Outbound TCP 443 (HTTPS) 0.0.0.0/0 Access Internet -
Best Practices:
- Use the principle of least privilege: Allow only the minimum necessary traffic[4].
- Restrict sources to trusted IPs where possible; avoid allowing 0.0.0.0/0 for sensitive ports like SSH.
- Document rule purposes in the description field.
- Review and audit rules regularly to maintain a secure environment.
Network ACLs (NACLs)
Network ACLs (Access Control Lists) are a critical component of AWS networking that act as stateless firewalls at the subnet level. They manage traffic entering and leaving one or more subnets within a Virtual Private Cloud (VPC), providing an additional layer of security beyond security groups. Here’s a step-by-step overview of how Network ACLs function and are configured:
- Definition: Network ACLs operate at the subnet level, controlling which traffic is allowed or denied as it enters or leaves any subnet associated with the ACL[1][5].
- Default Behavior: Every VPC comes with a default Network ACL that allows all inbound and outbound traffic. Custom Network ACLs, on the other hand, start with all traffic denied (implicit deny) until you add explicit allow rules[13][5][7].
-
Rule Types:
- Inbound Rules: Govern traffic coming into the subnet. Each rule specifies criteria like protocol, port range, and source IP.
- Outbound Rules: Manage traffic leaving the subnet and similarly define allowed or denied destinations[3][12].
- Stateless Nature: Unlike security groups, Network ACLs are stateless. This means if you allow inbound traffic, you must also write an explicit rule to allow the corresponding outbound response traffic, and vice versa[1][7][8].
-
Rule Evaluation:
- Each rule is numbered. Rules are processed in ascending order, starting from the lowest number.
- Once traffic matches a rule, the action (allow or deny) is applied, and no further rules are evaluated.
-
Rule Components:
- Rule Number: Determines order of evaluation (lowest first).
- Type/Protocol: TCP, UDP, ICMP, or all protocols.
- Port Range: Specifies single port or range (e.g., 80 or 1024-65535).
- Source (Inbound) / Destination (Outbound): Defines IP addresses or CIDR blocks.
- Action: Allow or Deny traffic that matches the rule[3][12].
- Subnet Association: Each subnet in a VPC must be associated with a single Network ACL. A NACL can be linked to multiple subnets, but each subnet can have only one NACL at a time[1][5].
-
Typical Example Rules:
Rule # Type Protocol Port Range Source/Destination Allow/Deny Description 100 Inbound TCP 22 (SSH) 203.0.113.0/24 Allow Allow SSH from trusted office 110 Inbound TCP 80 (HTTP) 0.0.0.0/0 Allow Permit web traffic 120 Inbound All All 0.0.0.0/0 Deny Deny all other inbound traffic 100 Outbound TCP 1024-65535 203.0.113.0/24 Allow Allow ephemeral port responses 110 Outbound All All 0.0.0.0/0 Deny Deny all other outbound traffic -
Best Practices:
- Start with a default-deny approach: Explicitly allow only the required traffic for both inbound and outbound rules[12][11].
- Ensure rules for responses are in place (due to stateless design), e.g., allow ephemeral (high) port ranges for outbound traffic responses.
- Number rules in increments (e.g., by tens) to allow future insertions.
- Document the purpose of each rule for better auditability.
- Regularly review NACL rules and associations for compliance and least privilege.
Core Components
The foundation of AWS networking is built upon several core components that allow you to design, secure, and manage cloud resources efficiently. Here’s a step-by-step breakdown of the essential components you’ll typically encounter:
-
Virtual Private Cloud (VPC):
The VPC is your own isolated network within AWS, where you deploy and organize resources, define IP address ranges, and control connectivity and security aspects[1][2][3]. -
Subnets:
Subnets divide your VPC’s IP address space into smaller segments, typically by availability zone. You can create public subnets (with internet access) or private subnets (without direct internet access)[1][2][5]. -
Route Tables:
Route tables hold a set of rules (routes) that determine where network traffic from your subnets or gateways is directed. Common targets include internet gateways, NAT gateways, and peering connections[1][5]. -
Internet Gateway (IGW):
An IGW allows resources in your VPC to communicate with the internet. Attach it to your VPC, and update route tables to direct outbound traffic from public subnets[2][5]. -
NAT Gateway / NAT Instance:
Provides internet access for resources in private subnets while keeping them unreachable from the public internet. The NAT device forwards traffic from private subnets to the internet and back[2][5]. -
Network Interfaces (ENI):
Logical network adapters attached to AWS resources (like EC2 instances), providing connectivity and allowing you to assign IPs, attach security groups, and manage network traffic[5]. -
Security Groups:
Stateful, instance-level firewalls attached to resources. They control inbound and outbound traffic using allow rules and are evaluated as a group for each resource[5][6]. -
Network ACLs (NACLs):
Stateless firewalls at the subnet level, allowing or denying inbound and outbound traffic based on ordered rules. Use NACLs to enforce subnet-wide access policies as an extra layer of security[5][7][13]. -
Elastic IP (EIP):
Static, public IPv4 addresses that you can allocate and associate with AWS resources such as EC2 instances or network interfaces for high-availability scenarios[5]. -
VPC Peering:
Establishes private connectivity between two VPCs, allowing resources in different VPCs (same or different AWS accounts) to communicate securely without traversing the public internet[1][5]. -
VPC Endpoints:
Provide private connections from your VPC to AWS services and other resources, bypassing internet gateways or NAT devices for enhanced security[1]. -
Virtual Private Gateway (VGW) & VPN Connections:
A VGW enables secure site-to-site VPN connections between your AWS VPC and on-premises networks, supporting hybrid cloud environments[1][5]. -
Flow Logs:
Provide network traffic monitoring by capturing IP traffic to and from network interfaces in your VPC for security and troubleshooting purposes[1]. -
Transit Gateway:
A scalable hub used for connecting multiple VPCs, VPNs, and on-premises networks, greatly simplifying large network architectures[1].
Component | Purpose |
---|---|
VPC | Isolated cloud network for AWS resources |
Subnet | Divides VPC into segments across AZs |
Route Table | Directs traffic within and outside VPC |
Internet Gateway | Provides internet access for public subnets |
NAT Gateway | Allows private subnets outbound internet access |
ENI | Virtual network adapter for AWS resources |
Security Group | Instance-level, stateful firewall |
NACL | Subnet-level, stateless firewall |
Elastic IP | Persistent public IPv4 address for resources |
VPC Peering | Connects two VPCs privately |
VPC Endpoint | Private connection to AWS services |
Virtual Private Gateway & VPN | Enables secure hybrid connectivity |
Flow Logs | Records and monitors network traffic |
Transit Gateway | Central hub for large, multi-VPC environments |
Configuration Table
This section breaks down the key configuration attributes and limits for both AWS Security Groups and Network ACLs (NACLs). Refer to these tables when designing AWS networking security policies for your cloud environment.
Security Group Configuration
Attribute | Description |
---|---|
Scope | Applied at the resource (instance/ENI) level |
Rules Supported | Allow rules only; explicit deny is not supported |
Stateful/Stateless | Stateful – return traffic is automatically allowed |
Default Configuration | All inbound traffic denied, all outbound traffic allowed by default |
Maximum per VPC | 500 security groups per VPC[1] |
Rules per Group | 60 inbound and 60 outbound rules per group (can request limit increases)[1] |
Rule Evaluation | All rules are evaluated; if one allows, traffic is accepted[1] |
Assignment | Can assign multiple security groups to a resource |
Network ACL Configuration
Attribute | Description |
---|---|
Scope | Applied at the subnet level |
Rules Supported | Allow and Deny rules supported |
Stateful/Stateless | Stateless – response traffic must be explicitly allowed[6][9] |
Default Configuration | Default ACL allows all inbound and outbound traffic; custom ACLs deny all until rules are added[6] |
Maximum per VPC | 200 network ACLs per VPC |
Rules per ACL | 20 inbound and 20 outbound rules per ACL (default, can be increased) |
Rule Evaluation | Processed in order from lowest to highest rule number, stops at the first match[6][9] |
Subnet Association | Each subnet can be associated with only one NACL at a time, but one NACL can associate with many subnets[6] |
Example Rule
In this section, we’ll walk through step-by-step examples of typical configuration rules for both Security Groups and Network ACLs (NACLs). These examples demonstrate how to allow or restrict access to AWS resources in a secure and scalable way.
Security Group Example
This example shows how to allow SSH and web access to an EC2 instance from specific sources, and outbound internet access for updates and API calls.
Direction | Protocol | Port Range | Source/Destination | Description |
---|---|---|---|---|
Inbound | TCP | 22 | 203.0.113.0/24 | SSH access from corporate office |
Inbound | TCP | 80 | 0.0.0.0/0 | Allow HTTP from internet |
Outbound | TCP | 443 | 0.0.0.0/0 | HTTPS access to external services |
Network ACL Example
The following NACL rules allow inbound web and SSH traffic, and ensure return traffic is explicitly allowed due to NACLs being stateless. These rules are applied to a public subnet hosting EC2 instances.
Rule # | Direction | Protocol | Port Range | Source/Destination | Action | Description |
---|---|---|---|---|---|---|
100 | Inbound | TCP | 22 | 203.0.113.0/24 | Allow | Allow SSH from trusted IP range |
110 | Inbound | TCP | 80 | 0.0.0.0/0 | Allow | Allow HTTP traffic from internet |
120 | Inbound | All | All | 0.0.0.0/0 | Deny | Deny all other inbound traffic (default fallback) |
100 | Outbound | TCP | 1024–65535 | 0.0.0.0/0 | Allow | Allow return traffic for HTTP/SSH responses |
110 | Outbound | All | All | 0.0.0.0/0 | Deny | Deny all other outbound traffic |
Note: Remember, Security Groups are stateful—return traffic is automatically allowed. NACLs are stateless—each direction must be explicitly allowed.
Network ACLs (NACLs)
Network ACLs (Access Control Lists) in AWS are stateless firewalls applied at the subnet level to control traffic entering or leaving subnets within a VPC. They provide an additional layer of security distinct from Security Groups, with their own configuration specifics. Here is a step-by-step explanation of how Network ACLs work and how to configure them:
- Definition: Network ACLs operate as subnet-level firewalls that allow or deny specific inbound and outbound traffic, reinforcing security alongside instance-level Security Groups[1][5].
- Default Behavior: Every VPC comes with a default Network ACL that allows all inbound and outbound traffic. When you create a custom Network ACL, it starts with a default "deny all traffic" policy—meaning no traffic is permitted until explicit rules are created[1][3][6].
-
Rule Types:
- Inbound Rules: Govern incoming traffic to the subnet.
- Outbound Rules: Govern traffic leaving the subnet[5][13].
- Stateless Nature: Network ACLs are stateless: return traffic must be explicitly allowed via corresponding rules in the opposite direction. Allowing inbound traffic for a port does not automatically allow outbound response traffic; separate rules are required[1][6][13].
- Rule Evaluation Order: Each rule is assigned a number (from 1 to 32766) and evaluated in ascending order. The first rule that matches the traffic determines the action (allow or deny), and evaluation stops. Leaving gaps in rule numbering (e.g., increments of 10 or 100) is a best practice to accommodate future changes[1][11][16][13].
-
Rule Components:
- Rule Number: Sets the processing priority.
- Protocol: Specifies the protocol (TCP, UDP, ICMP, or all).
- Port Range: Defines which port(s) the rule covers.
- Source/Destination: For inbound rules, it's the source; for outbound, it's the destination (use CIDR blocks).
- Action: Allow or Deny traffic[1][6][13].
- Subnet Association: Each subnet must be associated with a single Network ACL; one NACL can be linked to multiple subnets, but a subnet can only use one NACL at a time[1][5][13].
-
Example NACL Rules:
Rule # Direction Protocol Port Range Source/Destination Action Description 100 Inbound TCP 22 203.0.113.0/24 Allow Allow SSH from office IPs 110 Inbound TCP 80 0.0.0.0/0 Allow Allow HTTP from anywhere 120 Inbound All All 0.0.0.0/0 Deny Deny all other inbound traffic 100 Outbound TCP 1024-65535 0.0.0.0/0 Allow Allow responses for HTTP/SSH 110 Outbound All All 0.0.0.0/0 Deny Deny all other outbound traffic -
Best Practices:
- Begin with a restrictive (deny-all) approach and explicitly allow only necessary traffic[8][13][16].
- Ensure matching inbound and outbound rules for bidirectional traffic due to statelessness.
- Leave gaps in rule numbering for easier future edits[1][11][16].
- Keep rules concise and document their purposes for better auditability.
- Regularly review NACL configurations to remove unused or redundant rules[8].
Security Groups vs. Network ACLs
In AWS networking, Security Groups and Network ACLs (Access Control Lists) both serve to control traffic to and from your resources but differ significantly in their scope, behavior, and use cases. This section explains their differences step-by-step to help you understand how and when to use each.
-
Level of Application:
- Security Groups: Operate at the instance (network interface) level. You attach security groups directly to EC2 instances, load balancers, RDS databases, and other resources.
- Network ACLs: Function at the subnet level. They control traffic entering and leaving entire subnets within a VPC.
-
Stateful vs. Stateless:
- Security Groups: Are stateful. If inbound traffic is allowed, response traffic is automatically permitted without needing explicit outbound rules.
- Network ACLs: Are stateless. Return traffic must be explicitly allowed via separate outbound (or inbound) rules.
-
Rule Types:
- Security Groups: Support allow rules only. All unspecified traffic is implicitly denied.
- Network ACLs: Support both allow and deny rules, enabling explicit blocking of traffic.
-
Rule Evaluation:
- Security Groups: Evaluate all rules for both inbound and outbound traffic; if one rule allows the traffic, it passes.
- Network ACLs: Evaluate rules in numerical order, applying the action of the first matching rule and stopping further evaluation.
-
Association and Scope:
- Security Groups: Can be associated with multiple instances or resources. Each network interface can have multiple security groups attached for granular control.
- Network ACLs: Each subnet can only have one Network ACL at a time, but one Network ACL can be associated with multiple subnets.
-
Default Behavior:
- Security Groups: By default, deny all inbound traffic and allow all outbound traffic.
- Network ACLs: The default Network ACL allows all inbound and outbound traffic; custom NACLs deny all traffic until you add rules to allow it.
-
Use Cases:
- Security Groups: Best suited for precise, instance-level traffic filtering. Used for fine-grained access control to individual AWS resources.
- Network ACLs: Used for broader subnet-level traffic filtering or blocking. Useful as an additional security layer to restrict traffic to/from subnets or block known malicious IPs explicitly.
- Combining both provides defense in depth and stronger AWS network security.
Comparison Table
Aspect | Security Groups | Network ACLs |
---|---|---|
Scope | Instance / Network Interface level | Subnet level |
Statefulness | Stateful (return traffic auto-allowed) | Stateless (return traffic must be explicitly allowed) |
Rule Types | Allow rules only | Allow and Deny rules |
Rule Evaluation | All rules evaluated; any allow permits | Rules evaluated in number order; first match applies |
Default Behavior | Deny all inbound, allow all outbound | Default ACL allows all traffic; custom ACL denies all until allowed |
Associations | Multiple security groups per resource; reusable | One ACL per subnet; one ACL can span multiple subnets |
Typical Use | Fine-grained, instance-level access control | Coarse-grained, subnet-level access control and blocking |
Summary: Use Security Groups as your primary mechanism for controlling access to individual AWS resources due to their flexibility and stateful behavior. Use Network ACLs as a secondary layer of security to enforce broader subnet-level rules or explicit deny rules for known threats. Together, they provide a robust security posture for your AWS environment.
Best Practices
Adopting AWS Security Groups and Network ACLs (NACLs) effectively requires more than just knowing their settings. Follow these best practices, step by step, to ensure strong, scalable, and auditable cloud network security:
-
Principle of Least Privilege:
Always grant the minimum level of access necessary. For Security Groups, allow only the ports, protocols, and source/destination addresses required. For NACLs, start with a default-deny and only add specific allow rules. -
Avoid Broad Permits:
Don’t use wide CIDR blocks such as0.0.0.0/0
except where absolutely necessary (e.g., for public web servers on HTTP/HTTPS ports). Restrict sensitive management ports like SSH (22) or RDP (3389) to specific IP addresses or ranges. -
Layer Security Controls:
Combine Security Groups (for instance-level control) with Network ACLs (for subnet-level restrictions) to build a layered, defense-in-depth architecture. Use NACLs to block specific attack vectors at the subnet boundary and Security Groups for finer control at each instance. -
Document Rule Purposes:
Use the description fields for every rule in both Security Groups and NACLs. This makes maintenance, troubleshooting, and audits much easier. -
Regular Audits and Reviews:
Periodically review all Security Groups and NACL rules. Remove unused rules and verify that all permissions are still needed. Schedule security reviews after launches, migrations, or architecture changes. -
Monitor and Log Traffic:
Enable VPC Flow Logs to monitor network traffic for abnormal connections or unauthorized attempts. Use logging to investigate incidents and refine rules. -
Strategically Number NACL Rules:
Leave gaps between NACL rule numbers (e.g., increments of 10 or 100). This allows easy insertion of new rules and helps maintain a logical, organized rule set as requirements change. -
Be Aware of Default Settings:
Remember that Security Groups by default deny all inbound traffic and allow all outbound traffic. Default NACLs allow all traffic, while new (custom) NACLs deny all traffic until you configure rules. -
Test After Changes:
After implementing or modifying Security Group or NACL rules, verify that applications and systems function as expected from all intended sources and that access is properly restricted elsewhere. -
Automate with Infrastructure as Code (IaC):
Use tools like AWS CloudFormation or Terraform to define and track all Security Group and NACL configurations as code, ensuring consistency, version control, and easier rollback.
Practice | Why It Matters |
---|---|
Least privilege | Reduces attack surface and accidental exposure |
Restrict management ports | Limits risk of unauthorized server access |
Layer controls | Prevents a single misconfiguration from causing major exposure |
Document every rule | Streamlines audits and collaboration |
Periodic review | Keeps configurations aligned with actual business needs |
Log and monitor traffic | Detects threats and supports incident response |
Use gap rule numbering | Makes future rule additions/simple and organized |
IaC automation | Provides repeatability, traceability, and version control |
Following these practices will strengthen your AWS network security and simplify operations as your cloud environment grows.
Conclusion
Throughout this post, we explored the foundational elements of securing your AWS environment using Security Groups and Network ACLs (NACLs). These critical tools form the first line of defense in a well-architected cloud network, and understanding their differences, configurations, and best practices is essential for every AWS practitioner.
Here’s a quick recap of what we learned:
- Security Groups are stateful firewalls applied at the instance level. They only allow traffic that you explicitly permit and automatically manage return traffic, making them ideal for fine-grained control over individual resources.
- Network ACLs are stateless firewalls applied at the subnet level, requiring you to explicitly define both inbound and outbound rules. They’re excellent for broader access control policies and can be used to explicitly deny unwanted traffic.
- We broke down the core components of AWS networking, such as subnets, VPCs, route tables, and NAT gateways to set a strong contextual foundation.
- A clear configuration table compared attributes and limitations of security groups and NACLs for quick reference.
- Our example rules demonstrated real-world scenarios of how to allow (and deny) traffic securely using both tools.
- The Security Groups vs. NACLs section provided a side-by-side comparison to help you make informed decisions based on your specific use case.
- Finally, we outlined best practices such as following the least privilege principle, monitoring with VPC Flow Logs, documenting rules carefully, and automating configurations using Infrastructure as Code (IaC).
Do you need to use both Security Groups and NACLs? Not always—but using them together creates a layered security model that reduces risks and gives you more flexibility as your cloud infrastructure grows.
Thanks for joining us on this deep dive into AWS network security! If you found this blog helpful, feel free to share it with your team or colleagues, and stay tuned for more in-depth explorations of cloud best practices.