Automatic Deployment Through a Bastion (Gateway) Server
Making infrastructure secure is difficult. Let's rephrase that; building a secure infrastructure needs time, experience, and can be expensive. There are however some best practices that can help get there quicker and cheaper. Using Bastion servers is one of them.
Join the DZone community and get the full member experience.Join For Free
making infrastructure secure is difficult. let's rephrase that; building a secure infrastructure needs time, experience, and can be expensive. there are however some best practices that can help get there quicker and cheaper. using bastion servers is one of them.
what is a bastion server?
a bastion server (sometimes called a gateway server—not to be confused with an aws internet gateway) is a server that sits between the public internet and your servers behind a firewall. it protects and controls access to your servers. all ssh access will go through this server via a tunnel, allowing you to control admission to all your servers, by controlling access to only the bastion server. you can read more about bastion servers here .
in this example, we're going to use aws vpc (virtual private cloud), however it's worth noting that cloud 66 support for bastion servers works with all of our cloud providers .
using aws vpc as an example
if your application lives on amazon ec2 and you haven’t yet used vpc , i’d suggest you spend your next geeky weekend playing with the basic concepts of its security model.
until five years ago, most medium-sized tech companies had a network admin in their team to deal with cryptic routing tables and vlans.
nowadays, we enjoy fancy web dashboards and wizards, that build you a network with public/private subnets on the amazon cloud, with just a couple of clicks!
far from the sdn (software defined networking) approach of old school, in-house infrastructures, aws vpc works great, is the best out there, and is cheap.
once convinced that moving your application into a dmz is the right thing to do, you won’t need to worry about your devops. cloud 66 will deploy your application into your dmz and maintain it for you.
first thing to do is to define a deployment gateway in your cloud 66 account and add some information about your bastion server.
once you've got your bastion servers defined in your cloud 66 account, you need to just open the bastion for cloud 66 during deployment by calling a single toolbelt command .
let's go through the process step-by-step and see it in action:
i have a vpc with two subnet and a nat instance (as the bastion server) in my aws account:
vpc-id : vpc-d23154b6 private subnet id : subnet-ced13f96 public subnet id : subnet-cfd13f97 bastion server private ip : 10.0.0.37 bastion server public ip : 188.8.131.52 bastion server username : ec2-user
1. define deployment gateway
i can use cx to add the new gateway to my account:
$ cx gateways add --name aws_bastion --address 184.108.40.206 --username c2-user --private-ip 10.0.0.37 gateway added successfully!
now, if i list my deployment gateways, i can see
$ cx gateways list name username address private ip open until state aws_bastion c2-user 220.127.116.11 10.0.0.37 n/a close
2. open deployment gateway
to be able to use the gateway, i first need to open it for a set amount of time:
$ cx gateways open --name aws_bastion --key ~/keys/bastion_key --ttl 1h gateway opened successfully!
you will see the change in status:
$ cx gateways list name username address private ip open until state aws_bastion c2-user 18.104.22.168 10.0.0.37 mar 2 18:36 open
3. deploy stack
now, i can use the above information to deploy my stack through the bastion server. first, i should add the configuration information into the stack manifest:
--- docker: configuration: version: 1.10.2 weave_version: 1.4.5 vpc_id: vpc-d23154b6 servers: - server: unique_name: cheetah size: t2.small region: us-east-1 vendor: aws key_name: default subnet_id: subnet-ced13f96 gateway: name: aws_bastion
as you can see, i specified the vpc and subnet i want my server deploys in and added
as my gateway name.
note: bastion servers are supported for both cloud 66 for rails and cloud 66 for docker stacks. read more about cloud 66 manifest file .
4. closing the deployment gateway
we had opened the gateway for an hour, therefore the gateway will close automatically after the specified period. you also have the option of manually closing the gateway like this:
$ cx gateways close --name aws_bastion
note: once you close a gateway, cloud 66 cannot access your servers unless you open it again.
and, that's it. my servers are deployed behind the bastion server!
bonus point: ssh servers behind a bastion server
as the last tip, if you need to connect to your server via terminal, you can still use the
command by providing the key of your bastion server :
$ cx ssh --gateway-key ~/keys/bastion_key -s my-stack-name my-server-name
is represented by your private ssh key for the bastion server.
Published at DZone with permission of ShaB, DZone MVB. See the original article here.
Opinions expressed by DZone contributors are their own.