Skip to main content

openSeSSHIAMe

Intro

openSeSSHIAMe (picture Adam Sandler singing "open sesame") allows SSH access to an instance behind the great AWS firewall (security group for the instance) for authorized users from their current location.

Given the credentials for an AWS IAM (Identity and Access Management) user, it:

  • Obtains the current machine's public IP address
  • Uses the AWS Python SDK (boto3) to allow incoming traffic to the instance on port 22 from the public IP address
  • Revokes previous ingress rules for this IAM user

Disclaimer

Use at your own risk, and only with trusted users. Follow best practices to secure your EC2 instance and AWS account. Feedback, suggested improvements, and contributions will be most appreciated. See Notes for known issues with the current implementation.

AWS Prerequisites

  • An EC2 instance with at least one associated security group that openSeSSHIAMe can operate on. It's probably a good idea to keep a dedicated security group for use with this tool.
  • For each openSeSSHIAMe user, an IAM user that:
    • Has an attached tag with Key=openSeSSHIAMe-ID and a unique Value among all openSeSSHIAMe users
    • Allows the following EC2 actions only on that particular security group:
      • DescribeSecurityGroups (List)
      • AuthorizeSecurityGroupIngress (Write)
      • RevokeSecurityGroupIngress (Write)
    • Allows the following IAM actions only on that particular IAM user (this can be achieved by using ${aws:username} in the ARN when specifying resources):
      • ListUserTags (List)

Notes

  • The IAM user will be able to describe security groups other than the one used by openSeSSHIAMe! This is because DescribeSecurityGroups cannot be restricted to a particular resource (the security group used by openSeSSHIAMe).
  • The service used to determine the current public IPv4 address could return an incorrect address, thus giving someone else access!

Requirements

  • Python 3+
  • boto3 (>= 1.9.121)
  • docopt (>= 0.6.2)
  • requests (>= 2.21.0)

Installation

To install from source, execute the following in the directory containing setup.py:

pip install [--user] [--upgrade] .

To install from PyPI:

pip install [--user] [--upgrade] openSeSSHIAMe

Usage

The openSeSSHIAMe CLI can be executed for oneshot authorization of the user's current public IPv4 address:

openSeSSHIAMe --verbose --config /path/to/config.json

Here, config.json should look like etc/openSeSSHIAMe-config.json, found in this repo and the installed package. It consists of the IAM credentials and username for the current openSeSSHIAMe user, the ID of the security group to use, and the region the EC2 instance is running in.

openSeSSHIAMe can be run at the time of starting an SSH session, just like port-knockers. One way is using ProxyCommand in your SSH client config:

Host foo
HostName ...
...
ProxyCommand bash -c 'openSeSSHIAMe --verbose --config ...; sleep 1;
                      exec nc %h %p'

This technique should also work with autossh.

Alternatively (or additionally), a sample systemd service and timer for periodic execution are included in etc/.

Finally, feel free to import and use the openSeSSHIAMe class after installing this package:

from openSeSSHIAMe import openSeSSHIAMe
sesame = openSeSSHIAMe(config_filename='...', verbose=True)
# See main() in openSeSSHIAMe.py for further usage

TODO

  • If an existing rule for the current public IP address exists, don't revoke and re-authorize it -- just to reduce entries in CloudTrail. However, calls to DescribeSecurityGroups and ListUserTags are unavoidable.
  • Allow ports other than 22 and multiple ports. Might do this if and when the need arises.
  • Allow for multiple address per IAM user. Ditto.
  • Use PID file to handle concurrent runs for same IAM user.
  • Add option to use IPv6 addresses.

License

openSeSSHIAMe is distributed under the terms of the MIT license. Please see COPYING.

Release files for openSeSSHIAMe 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openSeSSHIAMe 0.1.0
File Size Uploaded
openSeSSHIAMe-0.1.0.tar.gz 8.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openSeSSHIAMe 0.1.0
File Interpreter ABI Platform
openSeSSHIAMe-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 20.9 kB

Release files / openSeSSHIAMe-0.1.0.tar.gz

Download URL openSeSSHIAMe-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
a05c5fee76da08200b113cec860f3c96df04107f779dde421047133c357b0c4f
BLAKE2b-256 checksum
How to use checksums
d26ee6b5a16a2ea7a39fd1857c79884eac6892ec3a7ded40997505d0ccb53fa1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

Release files / openSeSSHIAMe-0.1.0-py3-none-any.whl

Download URL openSeSSHIAMe-0.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60b69a8800282850e79bd00fb0c6143c15308388a56f37d65fcb6b9cf8df57a0
BLAKE2b-256 checksum
How to use checksums
3f33110a6a381c8bb21572421f78c3f28bba0c05d75d673bd2c81f9dd1583d2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.9.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page