A Better Way to SSH in AWS
Hate to say it. Don’t SSH at all.
The article is about SSH’ing through EC2 Instance Connect with SSM, which is the standard for RDS port forwarding
In the real world, there are still many cases where SSHing into an instance is the only practical means of accomplishing a task (e.g. running strace on a problematic process; wireshark to diagnose network issues, configuring a new system to know how/what you need to add to your puppet/ansible/chef tooling, etc, etc). We have 700+ instances. While the need to ssh into any of them is rare, it still happens several times a month. I’d love to know what solutions you have to these kinds of tasks that don’t involve SSH.
I have found from working with a number of people that they struggle to get this working, which is what prompted me to write this in the first place. Almost every company I know of uses SSH, and frequently either a Bastion host or just directly opens up SSH ports, so hopefully this helps some of those teams migrate.
What’s your work flow where you don’t use SSH? Do you just use another protocol to do the same thing or do you use some completely different interface for EC2?
While the first few items on your list are valid, the one for installing puppet/ ansible / chef tooling could be covered ahead of time via baking it into the AMI and setting configurables via tagging. Additionally, using Session Manager would allow you the benefits of SSH access without having to open up the port, and you’d have full audit logging
And you do Ansible over telepathy?
For the config management example, I mean the manual work to build and install the new thing that you’re wanting to be managed by puppet, etc. I don’t know about most people but I can’t craft a fully fledged recipe without having done the necessary actions by hand first to understand what needs to be managed and how.
Oh for sure, I struggled with this not long ago so thanks for taking the time to make this resource. I actually had the same idea and wrote https://codelabs.transcend.io/codelabs/aws-ssh-ssm-rds/index.html, but I really appreciate the extra details you went into with some of the SSM documents I hadn’t seen. And seeing CloudFormation is wonderful, as I did my tutorial all in terraform so it was easy to compare how things are done with the different tools
Depending on your case, SSM is an alternative:
https://cloudonaut.io/goodbye-ssh-use-aws-session-manager-instead/
Ideally, you would want to write your code in a local instance -something like Test Kitchen.
ansible can run from SSM
Session Manager is OK. It will get the job done but it’s not as fully featured as an SSH connection.
I have some notes somewhere on it but for speed in diagnosing and troubleshooting I vastly prefer SSH.
Maybe In a few years the service will be able to match.
I run ansible locally on each instance. I technically never need ssh. I use it for other reasons, but ansible is just triggered through Userdata and then periodically via a cloud watch cron expression via SSM.
Sure, but you are not understanding what I’m saying. Could you write an ansible recipe to fully install and configure a service that you’d never used before, and all it’s dependencies, from scratch by only writing ansible code? I’ve been doing similar work since the 90’s. Anyone that says they can do anything above a simple service without having to SSH into a box, install that service and understand it before writing configuration management recipes for it is lying or so inefficient as to call into question their suitability for such a role.
Also, yes, SSM has ssh proxying which is the entire point of OPs post. I was responding to the comment that SSH was unnecessary, period.
Going to agree here, barring poorly developed apps which require direct access to the DB (which is inexcusable in itself) there should be zero reason to ssh into a cloud environment… aside from negligence/inexperience.
ansible supports winrm
interesting - you can cron an ssm connection and have it run ansible pull?
Absolutely! Check out the docs but it would be something like this.
In the document store create a script that of run locally on your target server would perform the action you desire.
Create an SSM command that runs the document/script you just saved.
Create a cloud watch cron as the schedule, and have it trigger the SSM command.