aws / aws-ec2-instance-connect-cli

This is an all-in-one client for EC2 Instance Connect that handles key brokerage and establishing connection to EC2 Instances through an interface near-identical to standard system ssh, sftp, and other utilities.
Apache License 2.0
160 stars 42 forks source link

Allow seamless integration with Session Manager tunneling #5

Open ghost opened 5 years ago

ghost commented 5 years ago

Provide a flag so that if you do 'mssh instance_id' that the eventual ssh command executed continues to use the instance_id and not the ip address of the instance. This should allow for seamless integration with Session Manager ssh tunneling.

ghost commented 5 years ago

Hard coded on my end for now, in EC2InstanceConnectCommand.py, in the _get_target function, change:

if instance_bundle.get('host_info', None): target = "{0}@{1}".format(instance_bundle['username'], instance_bundle['host_info'])

To:

if instance_bundle.get('host_info', None): target = "{0}@{1}".format(instance_bundle['username'], instance_bundle['instance_id'])

LordAlfredo commented 5 years ago

Thank you for the feature and pull request. We have discussed this the SSM team and are open to accepting the option. We will review and test this once we have a chance and will merge it into the CLI if all goes well.

lkolchin commented 4 years ago

Could we use ssh config file or at least being able to script SSH via SSM tunneling similar to this:

Host *
TCPKeepAlive yes
ServerAliveInterval 30
ConnectTimeout 10

host i-*.* mi-*.*
  ProxyCommand bash -c "aws ssm start-session --target $(echo %h|cut -d'.' -f1) --region $(echo %h|/usr/bin/cut -d'.' -f2) --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
  User ec2-user
host i-* mi-*
  ProxyCommand bash -c "aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters 'portNumber=%p'"
  User ec2-user

Then you would just:

mssh ec2-user@i-0ded1d8c2282ee39e.ap-southeast-2

or

mssh i-0ded1d8c2282ee39e.ap-southeast-2
Maks3w commented 3 years ago

I've written an implementation can work entirely inside of ssh_config and does not need a wrapper

https://gist.github.com/Maks3w/de72b0160d5e6af958adc42eab014624