Skip to main content

Python Yubikey AWS signature library

Project description

Exile stores your AWS access key on your YubiKey device and uses it to sign your AWS API requests, protecting you against credential theft.

Installation

pip install exile

Synopsis

import base64, logging
import boto3, botocore.auth
from exile import YKOATH, SCardManager

logging.basicConfig(level=logging.INFO)

ykoath = YKOATH(SCardManager())

def write_active_aws_key_to_yubikey():
    credentials = boto3.Session().get_credentials()
    secret_name = "exile-" + credentials.access_key[len("AKIA"):]
    # This is for SigV4 only. Other formats will require a separate secret
    secret = b"AWS4" + credentials.secret_key.encode()
    print("Writing YubiKey OATH credential", secret_name, "for", credentials.access_key)
    ykoath.put(secret_name, secret, algorithm=YKOATH.Algorithm.SHA256)

write_active_aws_key_to_yubikey()

class YKSigV4Auth(botocore.auth.SigV4Auth):
    def signature(self, string_to_sign, request):
        key_name = "exile-" + self.credentials.access_key[len("AKIA"):]
        k_date = ykoath.calculate(key_name, request.context['timestamp'][0:8].encode(), want_truncated_response=False)
        k_region = self._sign(k_date, self._region_name)
        k_service = self._sign(k_region, self._service_name)
        k_signing = self._sign(k_service, "aws4_request")
        return self._sign(k_signing, string_to_sign, hex=True)

botocore.auth.SigV4Auth.signature = YKSigV4Auth.signature

print("Using YubiKey credential to perform AWS call")
print(boto3.client("sts").get_caller_identity())

Authors

  • Andrey Kislyuk

Bugs

Please report bugs, issues, feature requests, etc. on GitHub.

License

Licensed under the terms of the Apache License, Version 2.0.

https://img.shields.io/travis/com/pyauth/exile.svg https://codecov.io/github/pyauth/exile/coverage.svg?branch=master https://img.shields.io/pypi/v/exile.svg https://img.shields.io/pypi/l/exile.svg https://readthedocs.org/projects/exile/badge/?version=latest

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

exile-0.0.2-py3-none-any.whl (544.5 kB view details)

Uploaded Python 3

File details

Details for the file exile-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: exile-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 544.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.29.1 CPython/3.6.5

File hashes

Hashes for exile-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5b40d0c8ad75ef88c8d47535698abd893aea68cf8ae9038287f52354f52b4a26
MD5 d98ae036575482ad829c05144b59cab0
BLAKE2b-256 2f4527b6db6e24ad380d1f3b63f4690ff9d5f453b95e019d9cd247c4c4226264

See more details on using hashes here.

Supported by

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