by Valts Ausmanis · October 5, 2024
Unless you are fully committed to using serverless approach to run your applications and workloads, you are most likely using AWS VPC to define your own virtual network for launching AWS resources (such as EC2 instances, load balancers, RDS databases, NAT gateways, etc.). Securing your AWS VPC and its resources is crucial for protecting your cloud infrastructure and data. I have compiled 19 best practices to help you secure your VPC environment effectively. From choosing the right VPC type to monitoring network traffic, these tips will provide a solid foundation for maintaining a robust and secure cloud environment. Let's get started!
AWS Virtual Private Cloud (VPC) allows you to define your own virtual network for launching AWS resources, such as EC2 instances, load balancers, RDS databases, NAT gateways, and more. A VPC essentially resembles a traditional network that you would manage in your data center but with all the scalability and high availability benefits of using the AWS cloud.
The main building blocks of an Amazon VPC are:
Every AWS region comes with a default VPC that is automatically created for you. This provides a quick way to start using it immediately and deploy your VPC resources. While it may be tempting to use the default VPC, it’s often recommended to create a custom VPC specifically designed for your use case. This approach allows you to make more informed decisions about the configuration of your virtual network. Now, let’s take a look at the VPC security best practices that everyone should consider when setting up a new VPC or updating an existing VPC configuration.
Before you start creating your VPC and its related resources, it’s important to first understand what type of VPC is best suited for your use case. These are main VPC types that cover most of the AWS cloud architectures:
By understanding which VPC type or combination of types (in the case of using multiple VPCs) fits into your AWS network architecture, you will be able to perform the initial VPC setup more efficiently (e.g., by creating only the subnets that will actually be used by your application).
Another important task is to choose the right CIDR block . When setting up a VPC, you first define a CIDR block (size must be between /16 and /28) for the entire VPC and then create smaller CIDR blocks for each of the VPC subnets you will use in your virtual network.
There are several reasons why this is important for VPC security:
An availability zone in AWS refers to an isolated location, which is a logical grouping of one or more data centers that reside in a specific part of the world (referred to as a region). Each region in AWS has two or more availability zones that you can use.
Utilizing multiple availability zones in a VPC enhances high availability, scalability, disaster recovery, and compliance. It ensures that your applications remain available even if one of the availability zones becomes unavailable.
To start using a specific availability zone in your VPC, create a new subnet and choose the availability zone where this subnet should be located. After that, you can begin deploying resources like EC2 instances in that specific subnet, and behind the scenes, these instances will be deployed in the corresponding availability zone.
AWS Identity and Access Management (AWS IAM) is used to control and manage access to your AWS resources. Regardless of whether you use IAM roles (e.g., cross-account roles, service roles), users, or identity federation for accessing and deploying VPC resources in the AWS cloud, you should always create least-privilege IAM policies. By limiting access rights to the minimum necessary to perform specific tasks, you improve the overall security posture of your VPC.
AWS offers managed VPC policies that provide permissions for several common use cases (e.g., granting full access to VPC resources, granting read-only access to VPC resources) that you can assign to your users, roles, or identities. These policies provide a good starting point for creating more customized VPC policies later on.
Whether you are using the AWS console or assuming an IAM role via the AWS Command Line Interface (CLI) to access and manage VPC resources, MFA should always be enabled by default. This adds an additional layer of security and ensures that you are indeed the person authorized to access these resources.
Nowadays, most of our AWS infrastructure, including VPC-related components, is managed as infrastructure as code (IaC) using various tools like CDK, Terraform, and Serverless Framework . This allows us to easily deploy consistent cloud infrastructures that can be used for development, quality assurance, staging, pre-production, and production environments.
To improve VPC security (e.g., reduce the attack surface, prevent cross-environment access, limit user access, and prevent accidental data compromise), it’s important to separate these environments by having fully isolated VPC setups for each one. It’s often recommended to have a separate AWS account for each environment your application requires (e.g., one account for development, one for pre-production, and one for production).
AWS security groups play an important role in VPC security and should be considered the primary approach for controlling inbound and outbound traffic to your VPCs.
Similar to security groups, network access control lists (NACLs) control inbound and outbound traffic to your VPCs at the subnet level. NACLs are primarily used when there is a need to enable or disable specific traffic (e.g., SSH on port 22 or blacklist a specific IP address) for a particular subnet/s.
VPC endpoints enable you to connect privately to AWS services (e.g., S3, DynamoDB, EC2, CloudWatch, etc.).
How does this improve VPC security? By using VPC endpoints, communication with other AWS services occurs over private IP addresses, ensuring that traffic between your Amazon VPC and the service remains within the AWS network and doesn’t leave it.
There can be different VPC network architectures (e.g., central egress VPC, shared services VPC) where there is a requirement to route traffic from one VPC to other VPCs. To route traffic privately between two VPCs, thereby improving overall VPC security, we can use one of the following AWS services:
Depending on the type of application you are building, there is a solid chance it will consist of databases (like RDS, Aurora), application and business logic compute resources (like EC2, ECS), elastic file storage (EFS), etc. It’s a VPC security best practice to deploy these resources in private subnets without public IP addresses so that they are not directly accessible from the public internet.
If your application needs to be accessible publicly then use a public ALB or NLB to route traffic to the EC2 instances that are deployed in private subnets and do not have public IP addresses.
There are various use cases where your deployed resources (such as EC2 instances) in private subnets still require outbound internet access:
You can use a NAT gateway to allow instances in private subnets to connect to the public internet while preventing unsolicited inbound connections.
You can use traffic mirroring to enhance overall VPC network security by copying network traffic from an elastic network interface to your security and monitoring appliances. This approach allows for deep packet inspection, real-time threat detection, and non-intrusive performance monitoring.
While this provides many VPC security-related benefits, be aware that there are additional costs associated with using this functionality, which can significantly increase depending on your AWS network architecture.
Data encryption in transit and at rest is now the default standard. Most VPC-related resources (such as EBS volumes and RDS databases) have data encryption at rest enabled by default, but it should still be on everyone’s checklist when designing secure VPC environments.
Use Transport Layer Security (TLS) to encrypt data in transit when communicating with VPC resources.
Amazon VPC flow logs help capture information about the traffic flowing into and out of network interfaces in your VPC.
One flow log record contains:2 123456789012 eni-abc123de 192.168.1.10 203.0.113.1 443 49152 6 10 840 1622476800 1622476860 ACCEPT OK
2
- The version of the VPC Flow Logs format.123456789012
- The AWS account ID where the flow log was created.eni-abc123de
- The ID of the network interface for which the traffic is recorded.192.168.1.10
- The source IP address of the traffic.203.0.113.1
- The destination IP address of the traffic.443
- The source port of the traffic.49152
- The destination port of the traffic.6
- The protocol number (6 for TCP).10
- The number of packets transferred during the flow.840
- The number of bytes transferred during the flow.1622476800
- The start time of the flow (Unix timestamp).1622476860
- The end time of the flow (Unix timestamp).ACCEPT
- Indicates whether the traffic was accepted or rejected.OK
- The status of the flow log record.Whenever you use Amazon VPC for your back-end services, consider enabling Flow Logs. This will help identify and respond to potential security threats, ensuring a more secure VPC environment.
Network Access Analyzer helps identify unintended network access to your VPC resources. This is especially useful in complex AWS network architectures that include VPC peering connections, transit gateways, VPN connections, or VPC endpoints. AWS Network Access Analyzer enhances VPC security by providing visibility into network paths how your instances can be accessed.
Using a consistent and descriptive naming convention for VPC resources (ex. {env}-{purpose}-vpc
) helps in managing and identifying resources easily. It improves clarity, especially in complex environments with multiple VPCs and resources.
In addition to consistent naming, you should use tags to enhance VPC security by improving visibility and organization. Example tags:
Environment=Production
, Stage=Development
Role=CentralEgress
, Role=Spoke
Owner=SecurityTeam
Project=ERP
Use AWS Config to monitor configuration changes in your AWS infrastructure. This provides visibility into changes in your AWS architecture and can be highly beneficial for security, audit, and compliance teams. Additionally, you can use AWS Config rules to continuously evaluate whether your VPC resources comply with specific security standards like AWS Foundational Security Best Practices v1.0.0 (FSBP) or the CIS AWS Foundations Benchmark.
You should also use AWS CloudTrail to track user activity and API usage when accessing VPC-related resources. This will give your security team a clear understanding of who accessed what (e.g., a user listing all VPCs in a specific region or creating an EC2 instance).
Use AWS Shield and AWS WAF to protect your applications from Distributed Denial of Service (DDoS) attacks and other web application threats.
AWS Shield Standard is enabled by default for all AWS customers at no additional cost. It provides automatic protection against the most common and frequently occurring network and transport layer DDoS attacks. There is also a paid tier that offers more advanced functionality to enhance the security of your application.
Additionally, I recommend using AWS WAF rate-based rules to limit the number of requests from a single IP address, helping to mitigate DDoS attacks that aim to overwhelm your application with traffic. I would apply these rules to any publicly available application or endpoint.
There is no magic button to turn it on and have your VPC and its resources automatically secured. Improving the cloud security posture for your VPC is a continuous journey for your development and security teams. This process consists of many smaller and larger tasks and checks that will take time to efficiently incorporate into your applications and services.
How should I start? Take this list of 19 VPC security best practices to your development and security teams—schedule a brainstorming session, go through this list, and evaluate which practices should be enabled (if not already) for your use case, implementing them one by one.
Looking for a tool to automatically visualize your AWS VPCs?
Try out Cloudviz.io and visualize your AWS cloud environment in seconds
As experienced AWS architects and developers, our goal is to provide users an easy way to create stunning AWS architecture diagrams and detailed technical documentation. Join us to simplify your diagramming process and unleash the beauty of your cloud infrastructure
Support
Contact
Copyright © 2019 - 2024 Cloudviz Solutions SIA