Code Monkey home page Code Monkey logo

iam-roles-anywhere-session's Introduction

IAM Roles Anywhere Session

License PyPI version Status

Code style: black pre-commit

This package provides an easy way to create a refreshable boto3 Session with AWS Roles Anywhere.

This package implements the algorithm described here: https://docs.aws.amazon.com/rolesanywhere/latest/userguide/authentication-sign-process.html.

Requirements

  • Python 3.8 or later
  • Creation and configuration of a trust anchor. See documentation
  • Valid X.509 certificate, private key, and optionally a certificate chain file associated with your trust anchor

Install

  • From PyPi
pip install iam-rolesanywhere-session
  • From source
git clone https://github.com/awslabs/iam-roles-anywhere-session.git
cd iam-roles-anywhere-session
python3 -m pip install ./

Configuration

For this package to work you will need to have at your disposal your certificate and private_key file in a PEM format.

IAMRoleAnywhereSession will take multiple arguments:

Name Description Type Default value
profile_arn The Amazon Resource Name (ARN) of the profile. string None
role_arn The Amazon Resource Name (ARN) of the role to assume. string None
trust_anchor_arn The Amazon Resource Name (ARN) of the trust anchor. string None
certificate The x509 certificate file, in PEM format. path or bytes None
private_key The certificate private key file, in PEM Format. path or bytes None
passphrase The passphrase use to decrypt private key file. string None
region The name of the region where you configured IAM Roles Anywhere. string us-east-1
session_duration The duration, in seconds, of the role session. The value specified can range from 900 seconds (15 minutes) up to 3600 seconds (1 hour). int 3600
service_name An identifier for the service, used to build the botosession. string rolesanywhere
endpoint Roles Anywhere API endpoint to use string '{service_name}.{region_name}.amazonaws.com'
proxies Proxy endpoint(s) for use behind private networks with a proxy. dict {}
proxies_config A dictionary of additional proxy configurations. dict {}
from iam_rolesanywhere_session import IAMRolesAnywhereSession
roles_anywhere_session = IAMRolesAnywhereSession(
    profile_arn="arn:aws:rolesanywhere:eu-central-1:************:profile/a6294488-77cf-4d4a-8c5c-40b96690bbf0",
    role_arn="arn:aws:iam::************:role/IAMRolesAnywhere-01",
    trust_anchor_arn="arn:aws:rolesanywhere:eu-central-1::************::trust-anchor/4579702c-9abb-47c2-88b2-c734e0b29539",
    certificate='certificate.pem',
    private_key='privkey.pem',
    region="eu-central-1"
).get_session()
s3 = roles_anywhere_session.client("s3")
print(s3.list_buckets())

Documentation

You can find here the complete documentation with additional usage and module reference.

Contributing

Contributions are very welcome. To learn more, see the Contributor Guide.

License

Distributed under the terms of the Apache 2

iam-roles-anywhere-session's People

Contributors

tbuatois avatar tylersmith34 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

Watchers

 avatar  avatar  avatar

iam-roles-anywhere-session's Issues

Possible file descriptor leak

Hi,

I notice that your code use open without context manager:

key_pem_file = open(private_key, 'rb')
_ = crypto.load_privatekey(crypto.FILETYPE_PEM, key_pem_file.read(), passphrase=self.private_key_passphrase)
key_pem_file.close()

Is there any reason for that? It creates risk of file description leak when parsing of file crashing. I suggest rewrite it to something like:

with open(private_key, 'rb') as key_pem_file:
   return crypto.load_privatekey(crypto.FILETYPE_PEM, key_pem_file.read(), passphrase=self.private_key_passphrase)

CC: @tbuatois based on git blame

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.