Git Product home page Git Product logo

aws-gate's Introduction

aws-gate

Build StatusCode style: blackcodecovCodacy BadgePyPI versionPyPI - Downloads

AWS SSM Session manager client

Documentation

Motivation

I am using AWS a lot and I am tired of dealing with everything that comes with the bastion host (additional instance one has to maintain, distribute SSH keys (shared SSH keys are not an option for me), exposing SSH to the network). A while ago, Amazon released a service to fix this - AWS Systems Manager Session Manager. However, CLI user experience of Session Manager is limited and lacks some features:

  • ability to connect to instances by other means (e.g. DNS, IP, tag, instance name, autoscaling group) as aws cli supports only connecting by instance IDs
  • configuration file support for storing connection information via Session Manager

aws-gate tries to address these issues.

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

  • Python 3.5+ (earlier Python 3 versions should work too)
  • session-plugin-manager from AWS
  • SSM Agent version 2.3.68.0 or later must be installed on EC2 instances we want to connect to
  • Proper IAM permissions for instance profile

Installing

Via pip

pip install aws-gate

or via Homebrew

brew tap xen0l/homebrew-taps
brew install aws-gate

# For installing session-manager-plugin via Homebrew (optional)
brew install --cask session-manager-plugin

or via Docker

docker login docker.pkg.github.com -u $YOUR_GH_USERNAME -p $GH_TOKEN
docker pull docker.pkg.github.com/xen0l/aws-gate/aws-gate:latest

Features

config and config.d support

You can store information about to connect to your instance (name, region and profile) and aws-gate will do everything for you. The config file is stored in ~/.aws-gate/config and has the following YAML syntax:

hosts:
  - alias: backend-pre
    name: backend
    profile: preproduction
    region: eu-west-1
  - alias: backend-pro
    name: backend
    profile: production
    region: eu-west-1

defaults:
  profile: development
  region: eu-west-1

where hosts stores connection information and defaults default configuration settings to use. To connect to instance backend-pre, execute:

aws-gate session backend-pre

You can place additional configuration files in ~/.aws-gate/config.d. This is ideal when you are working on different projects or when you need to share configuration inside your team.

Querying instances by different instance identifiers

aws-gate supports querying for instances with following identifiers:

  • instance id
aws-gate session i-0772e4c1dcdd763b6
  • DNS name
aws-gate session ec2-34-245-174-132.eu-west-1.compute.amazonaws.com
  • private DNS name
aws-gate session ip-172-31-35-113.eu-west-1.compute.internal
  • IP address
aws-gate session 34.245.174.13
  • private IP address
aws-gate session 172.31.35.113
  • tags
aws-gate session Name:SSM-test
  • name (uses tag identifier under the hood)
aws-gate session SSM-test
  • autoscaling group name (uses tag identifier under the hood)
aws-gate session asg:dummy-v001

SSH ProxyCommand support

AWS SSM Session Manager supports tunneling SSH sessions over it. Moreover, aws-gate supports generating ephemeral SSH keys and uploading them via EC2 Instance Connect API. However, to use this functionality, EC2 Instance Connect setup is needed.

To use this functionality, simply run aws-gate ssh-config, which will generate the required ~/.ssh/config snippet for you:

% aws-gate ssh-config
Host *.eu-west-1.default
IdentityFile /Users/xenol/.aws-gate/key
IdentitiesOnly yes
User ec2-user
Port 22
ProxyCommand sh -c "aws-gate ssh-proxy -p `echo %h | sed -Ee 's/^(.*)\.(.*)\.(.*)$/\\3/g'` -r `echo %h | sed -Ee 's/^(.*)\.(.*)\.(.*)$/\\2/g'` `echo %h | sed -Ee 's/^(.*)\.(.*)\.(.*)$/\\1/g'`"

Store the snippet inside ~/.ssh/config:

% aws-gate ssh-config >> ~/.ssh/config

Then connect via ssh:

% ssh ssm-test.eu-west-1.default
Last login: Fri Oct  4 17:17:02 2019 from localhost

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
1 package(s) needed for security, out of 20 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-31-35-173 ~]$

SSH session to instance ssm-test in eu-west-1 AWS region via default AWS profile is opened.

scp works the same way (both ways):

% # local to remote
% scp test_file ssm-test.eu-west-1.glovoapp:test_file    
test_file                                                                                                                                                                 100%    0     0.0KB/s   00:00    
%
% # remote to local
% scp ssm-test.eu-west-1.glovoapp:test_file test_file
test_file                                                                                                                                                                 100%    0     0.0KB/s   00:00    

Please, also note that while scp over SSM works, it can be extremely slow. This is because of the underlying SSM limitations and not caused by aws-gate itself.

SSH support

aws-gate provides a way to open SSH session on the instance directly. This is achieved by wrapping around ssh under the hood. Simply run aws-gate ssh <instance_identifier>:

% aws-gate ssh ssm-test
Last login: Sat Nov  9 10:23:11 2019 from localhost

       __|  __|_  )
       _|  (     /   Amazon Linux 2 AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-2/
28 package(s) needed for security, out of 56 available
Run "sudo yum update" to apply all updates.
[ec2-user@ip-172-31-35-173 ~]$

If you wish to execute a specific command (or plug it into your shell pipelines):

% aws-gate ssh ssm-test uname -a
Linux ip-172-31-35-173.eu-west-1.compute.internal 4.14.123-111.109.amzn2.x86_64 #1 SMP Mon Jun 10 19:37:57 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux

Local ports can be forwarded to another host and port relative to the target instance. This works as if by using ssh's -L option. Instead of executing a command, aws-gate establishes a forwarding session that can be used by other local applications.

For example, you can use this to connect to a private web server by forwarding the instance's local port.

# Terminal 1
% aws-gate ssh -L 8888:localhost:80 ssh-test

# Terminal 2
% curl localhost:8888
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <title>Test Page for the Nginx HTTP Server on Amazon Linux</title>
...

Or you can use it to connect to a private RDS instance by forwarding the remote address and remote port.

# Terminal 1
% aws-gate ssh -L 3306:privatedb.abcdef123456.eu-west-1.rds.amazonaws.com:3306 ssm-test

# Terminal 2
% mysql -h 127.0.0.1 -u root -P 3306 -p -e "SELECT User from mysql.user;"
Enter password: 
+------------------+
| User             |
+------------------+
| root             |
| mysql.infoschema |
| mysql.session    |
| mysql.sys        |
| rdsadmin         |
+------------------+

Debugging mode

If you run into issues, you can get detailed debug log by setting GATE_DEBUG environment variable:

export GATE_DEBUG=1

After setting the environment variable, the debug mode will be automatically enabled:

% aws-gate session test
2019-05-26 01:18:23,535 - aws_gate.config  - DEBUG - Located config file: /Users/xenol/.aws-gate/config
2019-05-26 01:18:23,538 - aws_gate.utils   - DEBUG - Obtaining boto3 session object
2019-05-26 01:18:23,549 - aws_gate.utils   - DEBUG - Obtained configured AWS profiles: default development preproduction production
2019-05-26 01:18:23,550 - aws_gate.utils   - DEBUG - Obtaining boto3 session object
2019-05-26 01:18:23,560 - aws_gate.utils   - DEBUG - Obtained configured AWS profiles: default development preproduction production
2019-05-26 01:18:23,560 - aws_gate.utils   - DEBUG - Obtaining boto3 session object
2019-05-26 01:18:23,574 - aws_gate.utils   - DEBUG - Obtaining ssm client
2019-05-26 01:18:23,608 - aws_gate.utils   - DEBUG - Obtaining boto3 session object
2019-05-26 01:18:23,636 - aws_gate.utils   - DEBUG - Obtaining ec2 boto3 resource
2019-05-26 01:18:23,694 - aws_gate.query   - DEBUG - Querying EC2 API for instance identifier: SSM-test
2019-05-26 01:18:24,029 - aws_gate.query   - DEBUG - Found 1 maching instances
2019-05-26 01:18:24,030 - aws_gate.query   - DEBUG - Matching instance: i-0772e4c1dcdd763b6
2019-05-26 01:18:24,030 - aws_gate.session - INFO  - Opening session on instance i-0772e4c1dcdd763b6 (eu-west-1) via profile default
2019-05-26 01:18:24,030 - aws_gate.session - DEBUG - Creating a new session on instance: i-0772e4c1dcdd763b6 (eu-west-1)
...

Debug mode also enables printing of Python stack traces if there is a crash or some other problem.

License

This project is licensed under the BSD License - see the LICENSE.md file for details

Stargazers over time

Stargazers over time

aws-gate's People

Contributors

adamdodev avatar alanjds avatar awiddersheim avatar becrsh avatar benbridts avatar danmx avatar dansipola avatar dependabot-preview[bot] avatar dependabot[bot] avatar dmedinag avatar fmiquel90 avatar iainelder avatar jvdrean avatar kit494way avatar mbp avatar nitrocode avatar openbankgit avatar samuelbaena avatar svalentino avatar xen0l avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

aws-gate's Issues

Dependency on PyYAML==5.1.2 breaks compatibility with awscli

Currently it seems that awscli depends on PyYAML<=5.1 for Python 3, which means that trying to install aws-gate AND awscli in the same Python environment doesn't work without a manual override.

Perhaps aws-gate should have a relaxed dependency, like eg. PyYAML>=5.1,<5.2 or whatever makes sense for the actual features used?

NOTE: There is a PR for awscli to bump the PyYAML dependency (aws/aws-cli#4355), but it's not there now, and it's so far unclear if it will actually solve this, as right now the aim is 5.1.1, not 5.1.2.

Distribute .exe file of aws-gate on Windows

My other "pip installed" tools that are installed into %USERPROFILE%\AppData\local\Programs\Python\Python39\Scripts are .exe files that can then easily be invoked on command line.

However in this directory aws-gate is just a script file (no extension), with following content:

#!c:\users\xxx\appdata\local\programs\python\python39\python.exe

import aws_gate.cli


def main():
    aws_gate.cli.main()


if __name__ == '__main__':
    main()

Because it is not an executable, you have to run it with py aws-gate and to be in the same directory as the script. This makes it a bit harder to use.

One example of another tool that installs an exe is: https://github.com/mludvig/aws-ssm-tools - maybe it can be used for inspiration.

Turn off SSH host key verification

Currently, aws-gate ssh always asks user to verify the fingerprint of the EC2 instance we are connecting to. However, as instances can come and go, this will result in "Host key verification failed" if connecting to the instance with the same identifier.

Provide MSI for better Windows integration

Since 0.11.1, we are generating self-contained binaries for Windows. However, to make it work, the user has to download the binary, place it in path and this is too much manual effort. It would be great if we built MSI package for Windows, which could take care of everything. However, as I have no required experience with Windows platform nor access to it, this should be provided by the community.

aws-gate install via PyPI is broken on Linux

Maybe requirements/* is missing from MANIFEST.in on the published PyPI package

Collecting aws-gate==0.3.0 (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/75/aa/3afcc4c7f2eea7e5c409cc265d7b0fd9f2ad9b59cdb28aa3f06bd205a221/aws-gate-0.3.0.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-fbxF6Y/aws-gate/setup.py", line 31, in <module>
        install_requires=get_install_requirements('requirements/requirements.txt'),
      File "/tmp/pip-install-fbxF6Y/aws-gate/setup.py", line 13, in get_install_requirements
        with open(os.path.join(__location__, path), 'r') as f:
    IOError: [Errno 2] No such file or directory: '/tmp/pip-install-fbxF6Y/aws-gate/requirements/requirements.txt'

Type annotations

aws-gate should have type annotations, so we can do more linting and discover design issues.

Support AWS-StartInteractiveCommand

If this falls under the scope of #256 then feel free to close it, but this feature would allow me to let my developers open consoles for whatever language they're using, instead of forcing them to navigate the instance filesystem to whatever application they are working on. It also would allow a user to use whatever shell they wanted by default, while still providing the logging that the SSH sessions don't provide. I might take a stab at creating a PR for this myself, but I wanted to let you know that the desire for this existed.

asg querying is still broken

asg querying support fixed and support added in 0.8.3 is broken as we found out that : is an allowed character for tags resulting in broken parsing logic. We should add more tests for this.

Move to Github Actions

The following actions should be moved to Github Actions:

  • testing
  • PyPI package publishing

MFA

Dear,

I can connect to an instance using this command for MFA and profile usage:

aws-gate session server1 --profile profile1

However, I get prompted for my MFA token twice when using the Name tag, not when using instance ID. And they need to be different. Which is a pain. How can this be solved?

Thanks,
Tom

Flaky tests

Some tests that use hypthesis are flaky and need to be fixed.

`aws-gate bootstrap` is broken

I upgraded aws-gate and started to get errors. I guess is because, after #41 got pushed, it no longer accept session-manager-plugin to be provided by the host system. However, most of our users already have it installed by other ways.

OSError: session-manager-plugin not found

Trying to aws-gate bootstrap gives error because the needed folder is not yet created

$ aws-gate -v bootstrap
[Errno 2] No such file or directory: '/Users/alanjds/.aws-gate/bin'

After creating manually, the installation can succeed:

$ mkdir -p /Users/alanjds/.aws-gate/bin
$ aws-gate -v bootstrap
1.1.26.0
session-manager-plugin (version None) installed successfully!

After #41, aws-gate no longer accept the plugin to be provided by system.
For curiosity, why is it allowing only owned version to be used?

What about allowing usage of existing one if available, maybe with a deprecation or warning message?

when using mfa, OTP code needs to be entered twice

Hi,

Found your tool and it would cover our use case perfectly. but we are using mfa and every request triggers a new session creation (and also a new mfa request). In this case we need to enter 2 codes to do an ls or a session.

Created a pull request that would solve this by adding the credential cache to it (and pointing it to the same as the cli)

Extend list output

We have a function get_instance_details, which provides us with a lot of information about the instance. We should extend aws_gate list output to include more attributes such as VPC ID, Availability zone, instance IPs and DNS names.

Add arguments for region and profile

So that it isn't required to use an entry in ~/.aws-gate/config for every managed instance in a multi account environment it would be good if we had optional arguments to pass the region & profile similar to the aws cli.

eg:

aws-gate session --profile staging --region eu-west-2 i-1234567890
aws-gate session --profile production --region eu-west-2 i-1234567890
aws-gate list --profile staging --region eu-west-2

Add support for executing custom documents

Session Manager supports running custom documents that could be mapped to specific command that people need to be able to execute. Some use cases:

  • create a thread dump of a Java application
  • incident response evidence gathering
  • restarting/starting crashed service

We should extend aws-gate to support this either via session or a completely new subcommand. AWS SSM Document creation is out of scope.

Flaky tests

Recently, the test suite started to failed recently because of flaky test. We should investigate deeper and ensure the test suite is reliable.

Allow SSH tunnelling to other VPC resources

My use case: I have a MySQL RDS instance and an EC2 Amazon Linux 2 instance in a private subnet in a VPC. The EC2 instance can connect to the RDS instance. I want to connect to the RDS instance from my desktop so I can query it using familiar GUI tools such as DBeaver.

The EC2 instance is enabled for EC2 instance connect and Session Manager, so I can use aws-gate ssh to connect to it automatically. However, this only gets me halfway.

I would like to create an SSH tunnel through the EC2 instance from a port on my desktop to the RDS instance. I don't see a way to set that up with aws-gate.

Charlie Belmer published a script that allows me to do what I need. As far as I can tell, it uses the same AWS APIs as aws-gate does to solve the problem, and extends the solution by using ssh's -L option to create a tunnel over which database tools can connect. I've pasted the code from the article below.

Would it be possible to add the -L option to aws-gate ssh?

ssh-keygen -t rsa -f temp -N ''
aws ec2-instance-connect send-ssh-public-key --instance-id i-07cec3c515bcb2e61 --availability-zone us-east-1b --instance-os-user ssm-user --ssh-public-key file://temp.pub
ssh -i temp -N -f -M -S temp-ssh.sock -L 3306:echodb-dev.cju92986bx4i.us-east-1.rds.amazonaws.com:5432 ssm-user@i-07cec3c515bcb2e61 -o "UserKnownHostsFile=/dev/null" -o "StrictHostKeyChecking=no" -o ProxyCommand="aws ssm start-session --target %h --document-name AWS-StartSSHSession --parameters portNumber=%p"
read -rsn1 -p "Press any key to close session."; echo
ssh -O exit -S temp-ssh.sock *
rm temp*
$ psql -h localhost -p 3306 -U master postgres
Password for user master: 
psql (12.2 (Ubuntu 12.2-1.pgdg19.10+1), server 10.6)
SSL connection (protocol: TLSv1.2, cipher: ECDHE-RSA-AES256-GCM-SHA384, bits: 256, compression: off)
Type "help" for help.

postgres=> \q

Rewrite documentation on SSH

The current documentation is insufficient in terms of explaining different SSH features in aws-gate. It should contain the following:

  • clear explanation when to use aws-gate ssh, aws-gate ssh-proxy and ssh ProxyCommand
  • how to use scp with aws-gate and why it's not always the good idea
  • why we might not accept functionality to aws-gate ssh which can be easily used with native ssh command

Extend aws-gate user agent

aws-gate should have a modified user agent to contain the aws-gate/<version> string. This will allow monitoring of version being used as well as better identity client in CloudTrail.

Error encountered while trying to open session with aws-gate

Hello,

I am fairly new to session manager and came across aws-gate and I believe I have configured things correctly, however when attempting to establish a session to my test instance with aws-gate results in the below. I'm not sure that it matters, but I am using aws-vault to manage my aws credentials. Full debug output is at the bottom.

aws-gate session <instance-name>
----------ERROR-------
Encountered error while initiating handshake. Handshake timed out. Please ensure that you have the latest version of the session manager plugin.

I have ensured that I have the latest version of the session manager plugin on my laptop as well as the agent on the instance I'm connecting to.

I have also verified that I can establish a session with the aws cli with

aws ssm start-session --target <instance-id>

I have tried enabling debug output and the only thing that stood out was this, note the eu-west-1 at the end:

2020-05-13 11:57:43,789 - aws_gate.utils               - DEBUG - Executing "session-manager-plugin {"SessionId": "1589389053774966000-073e2ab90c4664979", "TokenValue": "token", "StreamUrl": "wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/1589389053774966000-073e2ab90c4664979?role=publish_subscribe", "ResponseMetadata": {"RequestId": "requestid", "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "requestid", "content-type": "application/x-amz-json-1.1", "content-length": "646", "date": "Wed, 13 May 2020 16:57:43 GMT"}, "RetryAttempts": 0}} us-east-1 StartSession eu-west-1 {"Target": "instanceid"} https://ssm.us-east-1.amazonaws.com"

I have ensured that nothing in my environment has eu-west-1 configured, so I am not sure where that is coming from or if thats even related to the issue. Any help would be much appreciated.

Full debug output(redacted):

2020-05-13 11:57:42,891 - aws_gate.config              - DEBUG - Located config file: /Users/user/.aws-gate/config
2020-05-13 11:57:42,893 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:42,903 - aws_gate.utils               - DEBUG - Obtained configured AWS profiles: default profile
2020-05-13 11:57:42,904 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:42,912 - aws_gate.utils               - DEBUG - Obtained configured AWS profiles: default profile
2020-05-13 11:57:42,912 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:42,920 - aws_gate.cli                 - DEBUG - aws-vault usage detected, defaulting to the AWS profile from $AWS_VAULT
2020-05-13 11:57:42,920 - aws_gate.cli                 - DEBUG - Using AWS profile "profile" in region "us-east-1"
2020-05-13 11:57:42,921 - aws_gate.utils               - DEBUG - Deferring signal: SIGHUP
2020-05-13 11:57:42,921 - aws_gate.utils               - DEBUG - Deferring signal: SIGINT
2020-05-13 11:57:42,921 - aws_gate.utils               - DEBUG - Deferring signal: SIGTERM
2020-05-13 11:57:42,921 - aws_gate.utils               - DEBUG - Executing "session-manager-plugin --version"
2020-05-13 11:57:42,927 - aws_gate.utils               - DEBUG - Restoring signal: SIGHUP
2020-05-13 11:57:42,928 - aws_gate.utils               - DEBUG - Restoring signal: SIGINT
2020-05-13 11:57:42,928 - aws_gate.utils               - DEBUG - Restoring signal: SIGTERM
2020-05-13 11:57:42,928 - aws_gate.decorators          - DEBUG - session-manager-plugin version: 1.1.61.0 (required version: 1.1.23.0)
2020-05-13 11:57:42,928 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:42,937 - aws_gate.utils               - DEBUG - Obtained configured AWS profiles: default profile
2020-05-13 11:57:42,937 - aws_gate.utils               - DEBUG - No entry found in configuration file for host: instance-name
2020-05-13 11:57:42,937 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:42,945 - aws_gate.utils               - DEBUG - Obtaining ssm client
2020-05-13 11:57:43,045 - aws_gate.utils               - DEBUG - Obtaining boto3 session object
2020-05-13 11:57:43,056 - aws_gate.utils               - DEBUG - Obtaining ec2 boto3 resource
2020-05-13 11:57:43,169 - aws_gate.query               - DEBUG - Querying EC2 API for instance identifier: instance-name
2020-05-13 11:57:43,169 - aws_gate.query               - DEBUG - Identifier type chosen: name
2020-05-13 11:57:43,530 - aws_gate.query               - DEBUG - Found 1 maching instances
2020-05-13 11:57:43,530 - aws_gate.query               - DEBUG - Matching instance: instance-id
2020-05-13 11:57:43,530 - aws_gate.session             - INFO  - Opening session on instance instanceid (us-east-1) via profile prev-admin
2020-05-13 11:57:43,530 - aws_gate.session_common      - DEBUG - Creating a new session on instance: instance-id (us-east-1)
2020-05-13 11:57:43,788 - aws_gate.session_common      - DEBUG - Received response: {'SessionId': '1589389053774966000-073e2ab90c4664979', 'TokenValue': 'Token', 'StreamUrl': 'wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/1589389053774966000-073e2ab90c4664979?role=publish_subscribe', 'ResponseMetadata': {'RequestId': 'requestid', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'request-id', 'content-type': 'application/x-amz-json-1.1', 'content-length': '646', 'date': 'Wed, 13 May 2020 16:57:43 GMT'}, 'RetryAttempts': 0}}
2020-05-13 11:57:43,788 - aws_gate.utils               - DEBUG - Deferring signal: SIGHUP
2020-05-13 11:57:43,788 - aws_gate.utils               - DEBUG - Deferring signal: SIGINT
2020-05-13 11:57:43,788 - aws_gate.utils               - DEBUG - Deferring signal: SIGTERM
2020-05-13 11:57:43,789 - aws_gate.utils               - DEBUG - Executing "session-manager-plugin {"SessionId": "1589389053774966000-073e2ab90c4664979", "TokenValue": "token", "StreamUrl": "wss://ssmmessages.us-east-1.amazonaws.com/v1/data-channel/1589389053774966000-073e2ab90c4664979?role=publish_subscribe", "ResponseMetadata": {"RequestId": "requestid", "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "requestid", "content-type": "application/x-amz-json-1.1", "content-length": "646", "date": "Wed, 13 May 2020 16:57:43 GMT"}, "RetryAttempts": 0}} us-east-1 StartSession eu-west-1 {"Target": "instanceid"} https://ssm.us-east-1.amazonaws.com"

Starting session with SessionId: 1589389053774966000-073e2ab90c4664979


SessionId: 1589389053774966000-073e2ab90c4664979 :
----------ERROR-------
Encountered error while initiating handshake. Handshake timed out. Please ensure that you have the latest version of the session manager plugin.

2020-05-13 11:58:03,082 - aws_gate.utils               - DEBUG - Restoring signal: SIGHUP
2020-05-13 11:58:03,083 - aws_gate.utils               - DEBUG - Restoring signal: SIGINT
2020-05-13 11:58:03,083 - aws_gate.utils               - DEBUG - Restoring signal: SIGTERM
2020-05-13 11:58:03,083 - aws_gate.session_common      - DEBUG - Terminating session: 1589389053774966000-073e2ab90c4664979
2020-05-13 11:58:03,200 - aws_gate.session_common      - DEBUG - Received response: {'SessionId': '1589389053774966000-073e2ab90c4664979', 'ResponseMetadata': {'RequestId': 'requestid', 'HTTPStatusCode': 200, 'HTTPHeaders': {'x-amzn-requestid': 'requestid', 'content-type': 'application/x-amz-json-1.1', 'content-length': '53', 'date': 'Wed, 13 May 2020 16:58:02 GMT'}, 'RetryAttempts': 0}}```

"Invalid profile provided: default" when using environment variables

I'm using environment variables to configure the AWS credentials for aws-gate and don't have a default profile in .aws/config because of that. (I'm using https://github.com/99designs/aws-vault (eg aws-vault exec profile_name -- aws-gate list), but any tool that sets environment variables will work the same).

This leads to the error "Invalid profile provided: default" when running aws-gate (even though valid credentials are available in the environment). I can work around this by adding a dummy default profile in the configuration file, but it would be nice if that wasn't needed.

eu connectivity fails via KMS

Hi, xen0l. Love the tool, use it constantly. Not sure what AWS changed network side, but eu connections are failing KMS handshakes. Pretty straightforward:

# aws-gate version

Package          Version
---------------- ---------
aws-gate         0.9.3

# eu-central-1

> aws-gate session bastioneu
Starting session with SessionId: me@work-some-session-id
SessionId: me@work-some-session-id:
----------ERROR-------
Encountered error while initiating handshake. Handshake timed out. Please ensure that you have the latest version of the session manager plugin.

# us-east-1
> aws-gate session bastion

Starting session with SessionId: me@work-some-session-id
sh-4.2$ exit
Exiting session with sessionId: me@work-some-session-id


# eu via awscli
> aws ssm start-session --target some-instance-id --profile eu --region eu-central-1

Starting session with SessionId: me@work-some-session-id
This session is encrypted using AWS KMS.
sh-4.2$ exit
Exiting session with sessionId: me@work-some-session-id

Bootstrapped plugin not found in PATH

The current behaviour is that plugin found in the PATH will be used the first. However, if there is no plugin present in the PATH and we have plugin installed via aws-gate bootstrap we should use it as a last resort.

plugin_version decorator doesn't work properly on Python 3.6

A user reported a problem that aws_gate is failing with capture_output=True in plugin_version on Python 3.6. That's possible because capture_output=True was added in Python 3.7.

We should fix this and come up with a better test.

2020-03-20 10:46:33,106 - aws_gate.cli                 - DEBUG - Using AWS profile "saml2aws" in region "eu-west-1"
2020-03-20 10:46:33,106 - aws_gate.utils               - DEBUG - Deferring signal: SIGHUP
2020-03-20 10:46:33,106 - aws_gate.utils               - DEBUG - Deferring signal: SIGINT
2020-03-20 10:46:33,106 - aws_gate.utils               - DEBUG - Deferring signal: SIGTERM
2020-03-20 10:46:33,107 - aws_gate.utils               - DEBUG - Executing "session-manager-plugin --version"
2020-03-20 10:46:33,107 - aws_gate.utils               - DEBUG - Restoring signal: SIGHUP
2020-03-20 10:46:33,107 - aws_gate.utils               - DEBUG - Restoring signal: SIGINT
2020-03-20 10:46:33,107 - aws_gate.utils               - DEBUG - Restoring signal: SIGTERM
Traceback (most recent call last):
  File "/home/david/.local/bin/aws-gate", line 11, in <module>
    main()
  File "/home/david/.local/bin/aws-gate", line 7, in main
    aws_gate.cli.main()
  File "/home/david/.local/lib/python3.6/site-packages/aws_gate/cli.py", line 262, in main
    key_size=args.key_size,
  File "/home/david/.local/lib/python3.6/site-packages/aws_gate/decorators.py", line 30, in plugin_required
    return wrapped_function(*args, **kwargs)
  File "/home/david/.local/lib/python3.6/site-packages/aws_gate/decorators.py", line 38, in wrapper
    version = execute_plugin(["--version"], capture_output=True)
  File "/home/david/.local/lib/python3.6/site-packages/aws_gate/utils.py", line 143, in execute_plugin
    return execute(PLUGIN_NAME, args, **kwargs)
  File "/home/david/.local/lib/python3.6/site-packages/aws_gate/utils.py", line 125, in execute
    result = subprocess.run([cmd] + args, env={"PATH": env}, check=True, **kwargs)
  File "/usr/lib/python3.6/subprocess.py", line 423, in run
    with Popen(*popenargs, **kwargs) as process:
TypeError: __init__() got an unexpected keyword argument 'capture_output'

Add ssh support

aws-gate should be able to directly open SSH session for you (no prior configuration required)

Document ssh lowercasing behaviour

User reached out that when using aws-gate ssh OpsPublic everything works as expected. However, when you try to use scp OpsPublic.eu-west-1.default, OpenSSH automatically lowercases the host name and it case sensitivess matters. We shoudl document this.

As an alternative, it's possible to use SCP via id, e.g. scp i-123141.eu-west-1.default.

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.