
AWS VPC Security: Building a Secure and Segmented Cloud Network
Explore how AWS networking controls protect cloud infrastructure from unauthorized access and network-based threats. Learn practical approaches to subnet isolation, traffic filtering, routing, and network monitoring.
AWS VPC Security: Building a Secure and Segmented Cloud Network
Introduction
Networking is one of the most important foundations of cloud infrastructure. Every application, virtual machine, database, and cloud service requires a network environment to communicate with other resources.
In Amazon Web Services (AWS), the Virtual Private Cloud (Amazon VPC) provides a logically isolated network where organizations can deploy and manage their cloud resources.
However, simply creating a VPC does not guarantee a secure network.
Incorrect routing configurations, unrestricted firewall rules, publicly exposed resources, and insufficient network monitoring can introduce security risks.
For example, an EC2 instance hosting an internal application may accidentally become accessible from the public internet because of an incorrectly configured route table or Security Group.
This is where network segmentation, traffic filtering, and continuous monitoring become important.
In this article, we will explore how AWS VPC networking works, understand common network security risks, and examine practical approaches to building a more secure cloud network.
1. Understanding Amazon VPC
Amazon VPC allows organizations to create an isolated network environment within AWS.
When creating a VPC, administrators can define:
- IPv4 and IPv6 address ranges.
- Subnets.
- Route tables.
- Internet gateways.
- NAT gateways.
- Security Groups.
- Network Access Control Lists (NACLs).
These components work together to control how resources communicate with one another and with external networks.
Understanding VPC architecture
Consider an application deployed using three main components:
- A public-facing web server.
- An internal application server.
- A database server.
Instead of placing all three resources in a single publicly accessible subnet, they can be separated into different network segments.
A simplified architecture:
INTERNET | | INTERNET GATEWAY | | PUBLIC SUBNET | WEB SERVER | | PRIVATE SUBNET | APPLICATION SERVER | | DATABASE SUBNET | DATABASEIn this architecture:
- The web server handles incoming public traffic.
- The application server handles internal application requests.
- The database is isolated from direct internet access.
This approach reduces unnecessary exposure and helps control communication between different application components.
2. Public and Private Subnets
Subnets divide a VPC's IP address range into smaller network segments.
AWS subnets are associated with a single Availability Zone.
One of the most important network security decisions is determining whether a resource needs direct internet connectivity.
Public Subnets
A subnet is considered public when its associated route table has a route to an Internet Gateway.
For example:
Destination Target10.0.0.0/16 local0.0.0.0/0 igw-xxxxxxxxResources in a public subnet may communicate directly with the internet if they also have the necessary public addressing and security configurations.
Typical use cases include:
- Public-facing web servers.
- Load balancers.
- Bastion hosts, when required.
Private Subnets
Private subnets do not have a direct route to an Internet Gateway.
They are commonly used for resources that should not be directly accessible from the internet.
Examples include:
- Application servers.
- Internal services.
- Databases.
- Backend workloads.
Private resources may still require outbound internet access for software updates or external API communication.
A NAT Gateway can provide outbound internet connectivity for IPv4 workloads without allowing unsolicited internet-initiated connections through the NAT Gateway.
Security recommendation: Avoid placing databases and internal application servers in publicly routed subnets unless there is a clearly justified requirement.
3. Securing Traffic with Security Groups
Security Groups act as virtual firewalls associated with EC2 network interfaces and other supported AWS resources.
They control inbound and outbound traffic based on configured rules.
Security Groups are stateful, meaning response traffic for permitted connections is automatically allowed.
Example: A web application
Suppose an EC2 instance hosts a public web application.
A basic Security Group configuration could look like this:
Traffic | Protocol | Port | Source |
|---|---|---|---|
HTTPS | TCP | 443 | 0.0.0.0/0 |
HTTP | TCP | 80 | 0.0.0.0/0, if required |
SSH | TCP | 22 | Trusted administrator IP |
Application | TCP | 8080 | Web server Security Group |
The application server should ideally accept traffic from the web server's Security Group rather than allowing connections from every IP address.
Example: Restricting SSH access
An unrestricted SSH rule:
Type: SSHProtocol: TCPPort: 22Source: 0.0.0.0/0This exposes the SSH service to the entire IPv4 internet.
A better configuration restricts access to a trusted administrative IP range or uses AWS Systems Manager Session Manager to avoid exposing SSH publicly.
AWS CLI: Inspect Security Groups
aws ec2 describe-security-groups \ --output tableThis command displays Security Group information, including configured inbound and outbound rules.
Security teams can use it to identify unrestricted access and unnecessary exposed ports.
Best practice: Use the smallest possible set of network permissions required for each workload.
4. Understanding Network ACLs
Network Access Control Lists (NACLs) provide another layer of network traffic filtering within a VPC.
Unlike Security Groups, NACLs operate at the subnet level.
They are stateless, meaning inbound and outbound traffic must be allowed through their respective rules.
Security Groups vs Network ACLs
Feature | Security Group | Network ACL |
|---|---|---|
Scope | Network interface | Subnet |
Stateful | Yes | No |
Rules | Allow rules | Allow and deny rules |
Rule evaluation | All applicable rules | Rules evaluated by number |
Default behavior | Deny inbound; allow outbound by default | Default NACL allows traffic by default |
When should Network ACLs be used?
NACLs can provide an additional network filtering layer.
For example, an organization may want to deny traffic from a known malicious IP range at the subnet boundary.
However, NACL configurations require careful planning because they are stateless.
Return traffic, including the necessary ephemeral port ranges, must be permitted where required.
Security recommendation: Use Security Groups as the primary workload-level access control mechanism and NACLs for additional subnet-level restrictions when appropriate.
5. Secure Network Routing
Route tables determine where network traffic is directed within a VPC.
Incorrect routing can unintentionally expose internal resources or create unexpected communication paths.
For example, a private subnet should not have a direct route to an Internet Gateway if the intention is to keep its resources from direct internet connectivity.
Inspecting route tables
Use the AWS CLI:
aws ec2 describe-route-tables \ --output tableThis command displays route table information and associated destinations.
Administrators should review:
- Default routes.
- Internet Gateway associations.
- NAT Gateway routes.
- Routes to peered VPCs.
- Transit Gateway routes.
- Unexpected network destinations.
Use VPC Endpoints
VPC Endpoints allow supported AWS services to be accessed from a VPC without requiring traffic to traverse the public internet.
For example, an S3 Gateway Endpoint allows supported S3 traffic to use a private route within the AWS network.
This can reduce internet exposure and simplify network access control.
Other services support Interface Endpoints through AWS PrivateLink.
Security recommendation: Evaluate VPC Endpoints for workloads that need access to AWS services without requiring general internet connectivity.
6. Monitoring Network Traffic with VPC Flow Logs
Preventing unauthorized network access is important, but organizations also need visibility into network communication.
VPC Flow Logs capture information about IP traffic to and from supported network interfaces.
They can help security teams investigate unusual communication patterns and identify potential network security issues.
What information do Flow Logs provide?
Depending on the configured format, Flow Logs can include:
- Source IP address.
- Destination IP address.
- Source port.
- Destination port.
- Protocol.
- Packet count.
- Byte count.
- Traffic start and end times.
- Traffic acceptance or rejection status.
Example investigation
Imagine an EC2 instance begins communicating with an unfamiliar external IP address.
A security analyst can review available Flow Logs to identify:
- Which instance generated the traffic.
- The destination IP address.
- The destination port.
- The communication protocol.
- Whether the traffic was accepted or rejected.
- When the communication occurred.
This information can help determine whether further investigation is necessary.
Enable VPC Flow Logs
An example AWS CLI command:
aws ec2 create-flow-logs \ --resource-type VPC \ --resource-ids vpc-xxxxxxxx \ --traffic-type ALL \ --log-destination-type cloud-watch-logs \ --log-group-name VPCFlowLogsThis creates a Flow Logs configuration for the specified VPC, delivering the logs to the configured CloudWatch Logs destination.
The command assumes that the required IAM permissions and CloudWatch Logs destination configuration are in place.
Important: VPC Flow Logs provide network metadata, not packet payloads. They should be combined with other telemetry when deeper network investigation is required.
7. Detecting Network-Based Threats in AWS
Network monitoring becomes more valuable when it is combined with threat detection.
AWS provides several services that help organizations identify potentially suspicious network activity.
Amazon GuardDuty
GuardDuty analyzes supported data sources, including VPC Flow Logs and DNS query logs, to identify potentially malicious activity.
It can generate findings associated with:
- Suspicious network communication.
- Reconnaissance activity.
- Potentially compromised EC2 instances.
- Communication with known malicious infrastructure.
- Unusual behavior involving cloud resources.
AWS Network Firewall
AWS Network Firewall is a managed network protection service that helps control and inspect traffic entering, leaving, and moving between supported VPC network segments.
It supports stateful and stateless traffic filtering and can be used to implement more advanced network security policies.
Organizations can use it to enforce network controls beyond basic Security Group configurations.
AWS Security Hub
AWS Security Hub helps centralize and manage security findings from supported AWS security services.
It can provide security teams with a consolidated view of security issues across their AWS environments.
Together, these services can help improve network visibility and strengthen cloud threat detection.
8. Common AWS Network Security Misconfigurations
The following table summarizes common network security issues and recommended mitigations.
Misconfiguration | Potential risk | Recommended mitigation |
|---|---|---|
SSH open to the internet | Unauthorized access attempts | Restrict trusted source IPs |
RDP publicly exposed | Increased remote access attack surface | Restrict RDP access |
Database in a public subnet | Unnecessary internet exposure | Use private subnets |
Unrestricted Security Groups | Excessive network access | Apply least privilege |
Incorrect route tables | Unintended connectivity | Review network routes |
Missing Flow Logs | Limited network visibility | Enable VPC Flow Logs |
Unnecessary internet access | Increased attack surface | Use VPC Endpoints where appropriate |
Weak subnet segmentation | Excessive internal communication | Separate workloads by function |
These examples demonstrate why cloud network security requires careful planning and regular configuration reviews.
9. Practical AWS VPC Security Checklist
Before deploying workloads into an AWS VPC, consider the following checklist.
Network Architecture
- Separate public and private workloads.
- Place databases in appropriately isolated subnets.
- Review route table configurations.
- Avoid unnecessary public IP assignments.
- Plan network segmentation across Availability Zones.
Traffic Filtering
- Restrict unnecessary inbound traffic.
- Avoid unrestricted SSH and RDP access.
- Use Security Groups with least-privilege rules.
- Review NACL configurations.
- Restrict communication between application tiers.
Network Monitoring
- Enable VPC Flow Logs where appropriate.
- Monitor unusual network communication.
- Enable Amazon GuardDuty.
- Review suspicious traffic patterns.
- Retain relevant network logs.
Additional Protection
- Evaluate VPC Endpoints.
- Consider AWS Network Firewall where required.
- Review public-facing resources.
- Regularly audit network configurations.
- Document approved network communication paths.
Conclusion
Network security is a fundamental part of protecting cloud infrastructure.
Amazon VPC provides several capabilities that allow organizations to isolate workloads, control traffic, and monitor network communication.
However, these capabilities must be configured correctly to provide effective protection.
By implementing subnet segmentation, restricting Security Group rules, reviewing route tables, using appropriate NACL configurations, and enabling network monitoring, organizations can significantly reduce unnecessary exposure.
AWS services such as GuardDuty, VPC Flow Logs, Network Firewall, and Security Hub provide additional capabilities for identifying and managing network security risks.
For cybersecurity professionals and aspiring cloud security analysts, understanding VPC networking is essential because many cloud investigations involve identifying exposed services, examining communication patterns, and determining how network configurations contributed to an incident.
The key takeaway: A secure cloud network is not built by allowing everything to communicate. It is built by ensuring that every connection has a purpose, every route is intentional, and every exposed service is properly protected.
References and Further Reading
Disclaimer: This article is intended for educational purposes. The commands and configurations are illustrative. AWS service availability, pricing, and capabilities may vary by Region and configuration. Test network changes in a controlled environment before applying them to production workloads.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article