GithubHelp home page GithubHelp logo

lucasproclc / aws-terraform-squid-proxy-vpc Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sverze/aws-terraform-squid-proxy-vpc

0.0 3.0 0.0 641 KB

AWS Terrafor Squid Proxy VPC

HCL 92.98% Shell 7.02%

aws-terraform-squid-proxy-vpc's Introduction

AWS / Terraform Squid Proxy VPC

This project puts together a public network containing an auto scaled group of Squid Proxy servers configured to access the internet using NAT Gateways and an Internet Gateways. A private VPC is also created and peered with the public VPC with proxy traffic routed to the Squid Proxy Elastic Load Balancer. The provisioning of all the infrastructure and services is done using Terraform. All compute servers use T2 micros with Amazon Linux, note that the architecture shown below requires a region with a minimum of 3 availability zones.

Resilent VPC

Squid Configuration

The Squid Proxy has been configured for testing purposes. The following changes have been made to the configuration found in /etc/squid/squid.conf

Network Configuration

The network can be configured to accept single IP addresses or CIDR ranges. In our case we grant access all local traffic in the public and private VPC

acl localnet src 10.1.0.0/16
acl localnet src 10.2.0.0/16

Access Control

We can control access to domains and websites, in our example we control access to the AWS SQS service and the Amazon AWS website it self.

acl whitelist dstdomain sqs.us-east-1.amazonaws.com
acl whitelist dstdomain sqs.us-east-2.amazonaws.com
acl whitelist dstdomain sqs.us-west-1.amazonaws.com
acl whitelist dstdomain sqs.us-west-2.amazonaws.com
acl whitelist repo.us-east-1.amazonaws.com
acl whitelist repo.eu-west-1.amazonaws.com
acl whitelist repo.eu-west-2.amazonaws.com
acl whitelist packages.us-east-1.amazonaws.com
acl whitelist packages.eu-west-1.amazonaws.com
acl whitelist packages.eu-west-2.amazonaws.com
acl whitelist dstdomain www.amazonaws.com

Set-Up

You will need the following tools and accounts to make it happen

AWS Account

You will need an AWS account, if you don't have one then just Sign-Up You will need a development user with admin access and security access keys in order to use the AWS CLI

Install the AWS CLI and set-up a profile using your access keys

SSH Key

You will need to set-up your desired AWS region with a secure key pair. This project is using London (eu-west-2) as the region I suggest you keep this the same as there are AMI's referenced that are region sensitive.

EC2 Key Pairs has instructions on how to set-up your key pair.

Once you have set-up a key pair you will should have access to the PEM file that needs to be stored safely. Terraform assumes that the PEM is available in your local key chain, you can add it it to your key-chain by running the following command

ssh-add -K your-key.pem

Terraform

Install terraform command line tool. Depends on your OS, Install Terraform has some descent instructions.

If you are using OSX I suggest you use Homebrew to install the terraform package.

Building / Running

Plan

I suggest that you run a plan to determine that access to your AWS account is as expected. Run the following command in the root of the terraform source src/main/terraform Note that it is recommended that you override the default values for aws_profile and the bastion_network_cidr

terraform plan -var "aws_key_name=your-key-name" -var "aws_region=us-east-1"

The output of this command will detail all the resources that will be created once applied. Note that it is recommended that you override the default values for aws_region (eu-west-1), aws_profile (default) and the bastion_network_cidr (0.0.0.0/0) e.g.

terraform plan -var "aws_key_name=you-key" -var "aws_profile=squid-lab" -var "bastion_network_cidr=199.250.200.0/24"

Apply

Once you are happy with the plan apply and decided on what variables to override you can apply your plan e.g.

terraform apply -var "aws_key_name=your-key"

Testing

The best way to test the application is to SSH on to the test host and attempt accessing the internet.

  1. Copy your EC2 key to the bastion host - scp -i <YOUR_KEY>.pem <YOUR_KEY>.pem ec2-user@<BASTION_HOST_IP>:.ssh/
  2. SSH to the bastion host - ssh ~/.ssh/<YOUR_KEY>.pem ec2-user@<BASTION_HOST_IP>
  3. SSH to the application host - ssh ~/.ssh/<YOUR_KEY>.pem ec2-user@<APPLICATION_HOST_IP>
  4. cURL a valid website; you should see output that looks like the following
>curl -I http://www.amazonaws.com
HTTP/1.1 302 Found
...
Via: 1.1 ip-10-1-3-240 (squid/3.5.20)
Connection: keep-alive
  1. cURL an invalid website; you should see output that looks like the following
>curl -I http://www.google.com
HTTP/1.1 403 Forbidden
Server: squid/3.5.20
...
Via: 1.1 ip-10-1-3-240 (squid/3.5.20)
Connection: keep-alive

The above test proves that access to the internet fromthe private VPC hosted application server can only be achieved through the white listed proxy. To prove this you could remove the export for the http_proxy settings and retry cURL test above; you will find that it timesout because there is no valid route to the internet gateway.

Destroy

Clean up your environment by detroying, this will remove all traces:

terraform destroy -var 'aws_key_name=your-key.pem'

Troubleshooting

TODO - add FAQ for potential issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.