Virtual Private Cloud
Virtual Private Cloud
Virtual Private Cloud
http://blog.flux7.com/blogs/aws/vpc-best-configuration-practices
As we at Flux7 Labs work on deployments for our AWS customers, many ask
questions about basic security issues, including those addressed by using
Virtual Private Clouds (VPCs). So in this post we provide a guide for setting
up and using VPCs in order to help guide your AWS setup. This tutorial is
based on our experience from using VPN in AWS deployments both for Flux7
Labs internal systems and for our customers systems. VyScale, our costand performance-management solution, is an excellent tool for setting up
systems inside of VPCs.
1. Create VPC
Log in to the AWS console.
2. Create Subnets
In the navigation pane click on Subnets.
Click Create Subnet.
Before we create a subnet, lets understand the best practices for creating
them.
You should create subnets across multiple availability zones, with each
subnet residing within a single zone. Creating subnets in and launching
instances across multiple availability zones will ensure a high-availability
environment.
When creating separate subnets for ELB, EC2 and RDS instances, each tier
should have at least 2 subnets across availability zones.
For this example, we created subnets using zones us-east1b and us-east-1d.
These subnets are called private subnets because the instances we launch
are not accessible from the Internet. In other words, these instances dont
have a public IP unless you assign an EIP.
App Tier: 10.0.1.0/24(zone-b), 10.0.2.0/24(zone-d)
ELB: 10.0.51.0/24(zone-b), 10.0.52.0/24(zone-d)
Database (RDS): 10.0.11.0/24(zone-b), 10.0.12.0/24(zone-d)
Always choose the same availability zones for all tiers. For example, if you
choose two zones for high availability and use us-east-1a and us-east1b,
then maintain those same 1a and 1b zones for all tiers. This will minimize
data transfer charges because data transfers between instances within the
same availability zone are free.
Now attach the gateway to a VPC by right clicking on VPC and selecting
Attach to VPC.
As a best practice create separate route tables for each tier. This will provide
more control in maintaining the security of each subnet.
Now associate the subnets to the route tables.
2.
3.
1.
APP_SG01
2.
NAT_SG01
3.
ELB_SG01
4.
DB_SG01
Allow Inbound rules for ELB, DB and APP to suit your needs. Well address
NAT security group rules later in this post.
In the Launch Wizard select Community AMIs and search for ami-vpcnat. Select the first AMI from the results list to launch the instance into
the VPC created in section #1. Choose the subnet 10.0.0.0/24 and then
check the Assign public IP box. You can also assign an EIP, if needed. On
the Configure Security Group page, choose Select an existing security
group and select the NAT_SG security group that you created earlier.
The NAT instance must be able to send and receive traffic from sources or
destinations other than itself, so youll need to deselect the
source/destination check boxes.
You can find more details here
Now navigate to Security Groups to add rules for inbound traffic.
Go to the Inbound tab for NAT_SG01. These rules will allow app servers to
talk to the NAT instance on the 80 and 443 ports.
1.
Select HTTP from the Create a new rule list. In the Source box,
specify the IP address range of your private subnet (App server subnets)
and then click Add Rule.
2.
Select HTTPS from the Create a new rule list. In the Source box,
specify the IP address range of your private subnet, and then click Add
Rule.
On the Routes tab, specify 0.0.0.0/0 in the Destination box, specify the
instance ID of the NAT instance in the Target box, and then click Add.
If you dont need an additional instance for NAT, you can minimize cost by
assigning a public IP to the instance that needs Internet access. That will
allow the instance to access the Internet directly.
You now might ask, How can I access from my desktop an instance that was
created in a private subnet and has no assigned public IP? The answer is
that you cant. To do so, youll need a bastion box in the public subnet. You
can use a NAT instance as a bastion server (also known as a jump box).
Log in to the bastion (NAT) server first. You can access any instance from this
server that was created in a private subnet.
For
more
details,
see
here.
8. Create RDS
Navigate to Services->RDS
Go to Subnet Groups in the navigation pane and click Create DB Subnet
Group.
Select the VPC ID from the drop down menu.
Select Availability Zone and choose the Subnet IDs of 10.0.11.0/24 and
10.0.12.0/24. Then click Add
Click Yes, Create to create the subnet group.
To make sure that your RDS instance is launched in subnets 10.0.11.0/24 and
10.0.12.0/24, select the mydb-subgroup01 subnet group.
All other steps for creating an RDS are as usual.
9. Create ELB
Now its time to create the load balancer. The load balancer will be the
frontend and will be accessible from the Internet, which means that the ELB
will be launched in public subnets 10.0.51.0/24 and 10.0.52.0/24.
At this point the two subnets cant access the Internet. To make them public
subnets, update the route table that these subnets are associated to.
Navigate to Services->VPC->Route Tables
Select the ELB route table.
On the Routes tab, specify 0.0.0.0/0 in the Destination box, select the
Internet gateway in the Target box, and then click Add.
Navigate to Services-> EC2-> Load Balancers
Click Create Load Balancer.
In the Launch Wizard, select Create LB inside as your VPC ID.
Do not select Create an internal load balancer.
Click Continue
In Add EC2 Instances select the subnets where you want the load balanced
instances to be. Select 10.0.51.0/24 and 10.0.52.0/24.
In the next window select Choose from your existing security group and
then select the ELB_SG01 security group that you created previously. Click
Continue.
In the next window select the App servers. Click Continue.
Review the details and click Create.
Make sure that youve enabled the APP_SG01 inbound ports (80/443) to
ELB_SG01 so that the ELB can route traffic to backend app servers. Also
make sure that ELB_SG01 HTTP and HTTPS ports are publicly accessible
(0.0.0.0/0).
VPC
A "Virtual Private Cloud" is a sub-cloud inside the AWS public cloud. Sub-cloud means it is inside an
isolated logical network. Other servers can't see instances that are inside a VPC. It is like a vlan
AWS infrastructure inside a vlan.
In non-VPC AWS cloud, the normal one all servers get a public ip. This is used to access the
instance from outside. But if you run `ip addr show` you'll see it has a private ip. The instance itself is
not aware of its public ip (its probably NAT-ed with the public ip in their switch). The information about
private ip is also important as communications using private and public ip's incur different cost
schemes (public ip based communications incur some cost). But the point is every single instance is
visible, their names are and ips are reused. These things have significant impact on how you design
and implement your network security as well. Security groups, which selectively allow individual
types of ingress or incoming traffic, becomes more important.
A VPC is denoted by a subnet mask. For example, when one says VPC-x is 10.123.0.0/16 , that
means any instances inside this VPC will have an ip 10.123.X.Y where X and Y can be anything
between 2 to 254. A VPC can have following global components:
instance, to be publicly available means you need both an elastic ip as well as a routing table that
directs non-local traffic to the internet gateway). Here's an example of a private subnet:
CIDR --- target
10.123.0.0/16 --- local
0.0.0.0/0 - i-abcdef (instance ip of the NAT box)
Network ACLs, or network access control lists: Apart from routing tables, each subnet also assigned
a network ACL. Network ACLs specify what type of traffic is allowed inside the subnet. By default it
might have the following rules:
rule number --- port --- protocol --- source
100 ---- ALL --- ALL
-- action
This means that all traffic is allowed within this network. You can think of Network ACLs as subnetwide security groups. They are effective while isolating subnets from each other, reducing the
collision of domains, etc.
Entities such as RDS's and ELB's can be provisioned within VPC as well. The same rule applies for
them as other ec2 instances. If they belong to public a subnet, they can be accessed from the
internet.
In a typical web application example, you will be spawning the ELB and a NAT box inside the public
subnet and your db servers (or RDS instances) and web servers in the private subnet. Since you
have a NAT gateway (and a routing table attached to the private subnet that routes traffic via this
NAT gateway), instances from private subnets can access the internet. But the reverse is not
possible. If you do not want the instances from private subnets to access the internet, you can
remove the NAT box from the private subnet's routing table. Since all this can be done dynamically
via the web browser based console, command line tools, or AWS webservices api, you can
temporarily allow the instances from private subnets to access the internet (like while provisioning)
and then revoke it later (before joining the elb).
I'll be writing another post on how you can set up cross-availability zones highly available services
using AWS VPC from a network standpoint. This will serve the foundation of that post.