AWS Bites Podcast

78. When do you need a bastion host?

Harken, good sir! Art thou aware of the arcane art of safeguarding thy AWS instances from malevolent threats whilst keeping them accessible for thy travels? There exists a mighty tool for such purpose, and it is hight the "bastion host."

In this pamphlet, we shalt unravel the mysteries of the bastion host and showeth thee how to useth it to safeguard thy web space. We shall commence by presenting a shadowy example architecture and introducing thee to the definition of a bastion host. We shalt then delve into the question of whether bastion hosts could be a security liability and explore the enigmatic concept of port-knocking.

We shalt also take thee on a valiant journey of how to provision a bastion host on AWS, and explaineth the cryptic basics of SSH and tunnels. Thou shalt discover the dark side of managing SSH keys and auditing SSH connections, and we shall reveal the secrets of AWS EC2 Instance Connect and AWS Session Manager (SSM) as solutions.

Thou shalt learn how to accept connections without exposing a port on the public internet, and we shall introduce thee to a mysterious tool called "basti" that can make it easier to provision SSM-based bastion hosts and connect to thy databases.

We shalt wrap up by revealing alternative security measures to the mysterious bastion host and provide thee with cryptic closing notes to summarize the key takeaways from this video. Heed our call to this intriguing guide to securing thy web space, and may the forces of the internet be in thy favor!

Harken, good folk! We would like to offer our deepest gratitude to our noble sponsor, fourTheorem, an AWS Consulting Partner that doth offer training, cloud migration, and modern application architecture. Thanks to their generosity, we are able to continue on our journey of imparting wisdom and knowledge regarding AWS.

Verily, in this episode, we hath made mention of the following resources:

Let's talk!

Do you agree with our opinions? Do you have interesting AWS questions you'd like us to chat about? Leave a comment on YouTube or connect with us on:

00:04:46

So there are some things that are very common that people would do to try to keep it as secure as possible. Of course, you need to use an up-to-date operative system and have things in place to always update the operative system every time there is a new security patch available. You need to install only the bare minimum software needed. Traditionally, that's just an SSH server. You don't need much more than that. And you need to open only the ports that are really needed for accepting connections on that SSH server. And you need to... Basically, if you can limit the IP addresses that can connect to that machine, that's even better. Most likely you will want only your own personal IP, so your own laptop, to be able to connect on that port. So you can create a security group that is restrictive. Or maybe if you are using that and sharing it with your own office, you can have a list of IPs that are authorized. But the idea there is don't make it open to any possible IP. Just limit to the ones that you trust. And don't use SSH through password, but use SSH keys. That's another common best practice. And one more thing is you don't necessarily need to have these instances running all the time, because we know in AWS you can spin things up and down when you need them. So it would be nice if you have a process that allows you to provision really quickly a bastion host only when you want to do a connection, and then tear it down when you don't need it anymore. I think that's an even better security practice, because then you are limiting the exposed surface only for the time when you are actually using it. And there are other tricks like port knocking, and maybe, oh, and you are more familiar with it, so you want to mention something about that.

00:08:08

And you would also make sure that the instance gets a public IP and is reachable from the internet. So you might have to update your routing tables and add internet gateway and all that kind of stuff. You also should make sure that the security group on your database can accept connections from this bastion host. And then you should be able to connect to this instance using SSH and create a tunnel to your database. So you could open a shell on the bastion and then go to your database, or you can tunnel. We might talk about that in a bit. If people aren't really familiar with SSH, many people would have seen it, but maybe not used it that much. It stands for secure shell and it's a common tool that's existed since 1995. OpenSSH is pretty widespread implementation. It allows you to manage a shell session in a remote machine and also to create tunnels. If you've used GitHub and you've had a repository of your own and you've pushed code to it, you've probably used SSH at some point, especially if you don't want to manage passwords all the time. So you can have a server application running on the machine you're connecting to, and you also need a client application. So OpenSSH is generally available on most platforms these days, including Windows, but you often see people using PuTTY on Windows as well. And it supports lots of different types of authentication. We mentioned username and password, but public and private keys with various levels of encryption are also possible. So that's SSH. And one of the cool things about SSH is its ability to tunnel. So Luciano, what the heck is a tunnel?

00:12:56

So there's a bit of work involved in that but the link for the IP range will also be in the show notes. So that's EC2 instance connect and that uses SSH so it might be a bit more familiar to people how that works. The other one which I think I've used a lot more often and is much more exciting in my view is Session Manager and it's a bit more advanced and a broader solution. It works on Linux and it works on Windows and it even works on premises and on edge devices like IoT Greengrass. And Session Manager what it does is it provides this a whole suite of things so it's not just connecting but it provides like auditable node management without the need to have sockets open and have SSH keys and all of that and you're just relying on IAM for authorization for everything. So you don't have to run any ports no SSH no RDP the only thing you need to have for your EC2 instances is to have the AWS Session Manager agent installed. So this is an agent-based approach and once you have it all set up you can create a connection from either a web browser or from the AWS CLI. All of the commands you issue can be logged then and made available in an S3 bucket or in cloud which logs for auditing purposes. The connection creation is also logged in CloudTrail as well. So you need because it's IAM based you need to make sure that the instance profile your EC2 instance is running has specific permissions there's a managed policy for that and you can also put in the permissions yourself. There's actually three kind of resources you need to deal with so you'll see it when you put in your actions in the IAM policy you've got SSM for systems manager EC2 messages and SSM messages so you actually have three namespaces in your actions that you need to use so it's actually if you if you look at the traffic it's actually talking to three different hosts in the background and once you have that set up you can actually create SSH tunnels through Session Manager sessions as well so all of the stuff we talked about with SSH port forwarding can also work over Session Manager as well. So it might seem like okay how does this work it doesn't use like normal TCP stuff it just uses IAM and AWS actions what kind of black magic is this how does it work in practice do you have any idea?

Help us to make this transcription better! If you find an error, please submit a PR with your corrections.