Skip to main content

Maintain a whitelist of IP address blocks to access AWS over SSH

Project description

https://travis-ci.org/geoffreywiseman/awswl.svg?branch=master

A small tool to make it pretty simple to add and remove ip addresses (or CIDR blocks) from an AWS security group. This acts like a sort of oversimplified VPN, where you can quickly give yourself SSH access to a project as you move about from network to network.

Better Solutions

Anyone who knows enough to use a tool like this likely knows that there are better options available, from hardware VPNs to software VPNs hosted on an EC2 instance, and so forth. If you are using this tool and you haven’t even considered using something better, this is your chance: look at the better options, and see if they fit your needs.

Of course, most of those other options require you to get additional hardware or software resources involved and might come with costs. I understand, that’s why I made a little tool to make do.

Installing

This is a python tool, packaged as a python module, so you should be able to just run

$ pip install awswl

Of course, if you don’t know what a python module is, or you don’t have python and pip installed, you may have additional work ahead of you.

The awswl module should be compatible with both python2 and python3; I have Travis building it for Python 2.7, 3.4, 3.5, and 3.6.

Usage

If you want usage help at the command line, try:

$ awswl --help

You can list the IP address blocks that are authorized, including which ip address is current:

$ awswl --list

Authorize your current IP Address:

$ awswl --add-current

Remove authorization for your current IP:

$ awswl --remove-current

Authorize a manually-specified CIDR block:

$ awswl --add 192.168.0.0/24

Remove authorization for a manually-specified CIDR block:

$ awswl --remove 192.168.0.0/24

For each of these commands, you need to tell awswl which security group to use, which you can do with the --sgid command-line option or using an environment variable.

Integration

In order to get your current ip address, --list, --add-current and --remove-current will make a request to api.ipify.org. I may add a switch to disable that for the privacy- inclined, but feel free to vote for it.

Environment

All of these require you to have AWS credentials set up in advance, stored in ~/.aws/credentials, and if you need to use a profile, you can configure it with AWS_PROFILE. If you want to identify the security group using a command-line variable so that you don’t have to put it into each command invocation, you can put it in AWSWL_SGID.

Edge Cases

For simple use cases, awswl does everything I want it to do, but it’s currently a pretty thin wrapper over the AWS API for authorizing and revoking access via security groups, and as a result it doesn’t do much pre-processing or validating of your requests. There are cases that it doesn’t address. What it’s good at is adding and removing simple rules containing a simple CIDR block and a single port from a security group.

For instance if you remove a block that isn’t present, AWS may simply ignore the request, because the result matches the desired state – the block isn’t authorized. AWSWL doesn’t check in advance that the block is present, so it doesn’t add any messaging to explain that the block wasn’t removed because it wasn’t present. This is mostly fine, unless you accidentally mistyped, and you failed to remove a block as a result.

Similarly, if what you’ve asked for requires a complex modification of a rule, AWSWL won’t compare your request against the authorized rules and make a plan of action that achieves the desired result. So if there’s already a permission that authorizes a set of CIDR blocks, and you ask to remove one of those CIDR blocks, AWSWL will pass your request on to AWS, which will check to see if there’s a single permission matching your request to revoke, not find it, and not throw an error, and AWSWL will respond that your action succeeded when in fact, nothing changed, and the CIDR block you specified may still be authorized.

Similarly, if you ask AWSWL to revoke permissions on a CIDR block that is narrower than the authorization, you aren’t likely to get the desired result. For instance, if you authorize 192.168.0.0/16 and then revoke 192.168.0.0/24 you could argue that the result should be 192.168.1.0/24 all the way through 192.168.255.0/24 authorized and 192.168.0.0/24 not authorized, but that’s definitely not what will happen.

Similarly it can’t modify a permission block that includes a bunch of ports, including SSH.

To be honest, I am not sure it makes a lot of sense to address those issues so that it can modify rules like that, but I would prefer it to notice when situations like that are present and warn about the rules that it didn’t modify – essentially, I’d like it to validate a bit better.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

awswl-1.0.0.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

awswl-1.0.0-py2.py3-none-any.whl (11.3 kB view details)

Uploaded Python 2Python 3

File details

Details for the file awswl-1.0.0.tar.gz.

File metadata

  • Download URL: awswl-1.0.0.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for awswl-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0f2fa11dbbc39b0f1996326f6c51a9f3883e4f2a4d97558ba66d1175c574e627
MD5 e0f4b06f67ce34d253ebb919765070d0
BLAKE2b-256 598a7df29db1e3e8cb4ba3f78c8f959c6abf49148bb28f51ff5a43a2fe81368e

See more details on using hashes here.

File details

Details for the file awswl-1.0.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for awswl-1.0.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 db39b22b1df8323906fb0a923cf10b69c8848ba046b17205a371767829cec87f
MD5 67b137c9011465ae64d60e97ea5c3171
BLAKE2b-256 c7c75a6ede01efeb740707e3adf4a1fa30606b6fe8a4304d14ae6d67e69a3d2e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page