Skip to main content

Easy AWS MFA authentication and role assuming

Project description

AWS Auth

Version License Supported Python Versions

pip install aws-auth-utils

aws configure --profile mfa-source

aws_auth mfa

The commands use click for argument parsing and if required arguments are missing it will prompt you.

To authenticate using your MFA token you will need to have a profile configured using regular an AWS Access Key.

We will use that and your MFA token to generate an authorized session profile. By default we will try to use the mfa-source and create the default profile.

If you only have a single MFA device set up, it will use that automatically. If you have multiple, it will the first one.

MFA

$ aws_auth mfa --help
Usage: aws_auth mfa [OPTIONS]

Options:
  -a, --mfa-arn TEXT          The identification number of the MFA device that
                              is associated with the IAM user. i.e.:
                              "arn:aws:iam::123456789012:mfa/tony.stark". You
                              can find this on the IAM page.
  -c, --code TEXT             The code generated by your MFA device.
  -d, --duration INTEGER      The duration, in seconds, of the session.
  -sp, --source-profile TEXT  What AWS profile to get the session token with.
  -tp, --target-profile TEXT  What AWS profile to store the credentials under.
  -v, --verbose BOOLEAN
  --help                      Show this message and exit.

Assume Role

The assume role is useful for multi-org environments where you want to impersonate a role in a child organization. If you access multiple organizations I recommend you set up aliases.

aws_auth assume \
  --role-arn arn:aws:iam::123456789012:role/OrganizationAccountAccessRole \
  --session-name child_org \
  --target-profile child_session
$ aws_auth assume --help
Usage: aws_auth assume [OPTIONS]

  Get MFA authenticated and assumed role session credentials and save them to
  the aws credentials file

  If you have multiple accounts you'd like to switch between, I recommend
  setting up aliases that call this script with predefined arguments.

Options:
  -r, --role-arn TEXT         The Arn of the Role to assume.
  -n, --session-name TEXT     The identifier for the assumed role session.
  -a, --mfa-arn TEXT          The identification number of the MFA device that
                              is associated with the IAM user. i.e.:
                              "arn:aws:iam::123456789012:mfa/tony.stark". You
                              can find this on the IAM page.
  -c, --code TEXT             The code generated by your MFA device.
  -d, --duration INTEGER      The duration, in seconds, of the session.
                              (defaults to 4 hours)
  -sp, --source-profile TEXT  What AWS profile to get the session token with.
  -tp, --target-profile TEXT  What AWS profile to store the credentials under.
  -v, --verbose BOOLEAN
  --help                      Show this message and exit.

Export Token

Simple export tokens and store them as standard credentials. Useful when dealing with SSO sessions but tools don't handle it.

aws_auth export \
  --source-profile default
  --target-profile exported-token

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

aws_auth_utils-1.2.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

aws_auth_utils-1.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

Details for the file aws_auth_utils-1.2.0.tar.gz.

File metadata

  • Download URL: aws_auth_utils-1.2.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.0 HTTPX/0.28.1

File hashes

Hashes for aws_auth_utils-1.2.0.tar.gz
Algorithm Hash digest
SHA256 601af7f4e4015db7f595629e523cfb605c9c6ea197d2ebbf09a6cd1b49223e34
MD5 1f1ea22dce2d11e82090644de42911a7
BLAKE2b-256 0923bac9d476037641a3e4662b4ee753dd119e7f2772bdb677a2f91ad5e5ccf7

See more details on using hashes here.

File details

Details for the file aws_auth_utils-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: aws_auth_utils-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.16.3 cpython/3.13.0 HTTPX/0.28.1

File hashes

Hashes for aws_auth_utils-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7387ebe93aa318adb5207ae7cb9e7c26a71a67ad10fee9a780b110f2d4e0d4ba
MD5 986154c4a72e796215f6d56b7dfa5591
BLAKE2b-256 0a1a89debbcf296ce12018c1c8a4f7993836ea1825d9139eee8dd214e2c46206

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