Skip to main content

A CLI tool that allows you to log in and retrieve AWS temporary credentials using Red Hat SAML IDP

Project description

rh-aws-saml-login

Ruff PyPI PyPI platforms PyPI - License Checked with mypy

A CLI tool that allows you to log in and retrieve AWS temporary credentials using Red Hat SAML IDP.

demo

Pre-requisites

  • Python 3.11 or later
  • Connected to Red Hat VPN
  • A Red Hat managed computer (Kerberos must be installed and configured) and you are logged in with your Red Hat account

How it works

The rh-aws-saml-login CLI is a tool that simplifies the process of logging into an AWS account via Red Hat SSO. It retrieves a SAML token from the Red Hat SSO server, then fetches and parses the AWS SSO login page to present you with a list of all available accounts and their respective roles. You can then choose your desired account and role, and rh-aws-saml-login uses the SAML token to generate temporary AWS role credentials. Finally, it spawns a new shell with the necessary AWS_ environment variables already set up, so you can immediately use the aws CLI without any further configuration.

Installation

Prerequisites

rh-aws-saml-login needs the krb5 library to work. On most system, e.g., MacOS, this library is already installed. On CSB Fedora, you need to install the Kerberos development package:

sudo dnf install krb5-devel

Recommended Installation Method

The recommended way to install rh-aws-saml-login is to use the uv tool:

uv tool install -p python3.12 rh-aws-saml-login

and upgrade an existing installation with:

uv tool upgrade rh-aws-saml-login

Alternative Installation Methods

You can install this library from PyPI with pip:

python3 -m pip install rh-aws-saml-login

or install it with pipx:

pipx install rh-aws-saml-login

and upgrade an existing installation with:

pipx upgrade rh-aws-saml-login

Usage

Interactive mode

Just run rh-aws-saml-login to start the interactive mode. It will list all available AWS accounts and roles, and you can choose the one you want to log in to:

$ rh-aws-saml-login

         __                                                         __      __            _
   _____/ /_        ____ __      _______      _________ _____ ___  / /     / /___  ____ _(_)___
  / ___/ __ \______/ __ `/ | /| / / ___/_____/ ___/ __ `/ __ `__ \/ /_____/ / __ \/ __ `/ / __ \
 / /  / / / /_____/ /_/ /| |/ |/ (__  )_____(__  ) /_/ / / / / / / /_____/ / /_/ / /_/ / / / / /
/_/  /_/ /_/      \__,_/ |__/|__/____/     /____/\__,_/_/ /_/ /_/_/     /_/\____/\__, /_/_/ /_/
                                                                                /____/

✅ Test for a valid Kerberos ticket ...
✅ Getting SAML token ...
✅ Getting AWS accounts ...
✅ Getting temporary AWS credentials ...

Spawning a new shell. Use exit or CTRL+d to leave it!

🤓 app-sre
🚀 1234567890-app-sre
⌛ 59 minutes from now (2024-10-07 11:16:54+02:00)

$ aws s3 ls
...

This spawns a new shell with all required AWS environment variables set. See the Environment Variables section for more information.

Non-interactive mode

Instead of running the interactive mode, you can also use rh-aws-saml-login to run any arbitrary command with the AWS environment variables set:

rh-aws-saml-login <ACCOUNT_NAME> -- <COMMAND> [ARGUMENTS]

For example:

$ rh-aws-saml-login app-sre-stage -- aws s3 ls

         __                                                         __      __            _
   _____/ /_        ____ __      _______      _________ _____ ___  / /     / /___  ____ _(_)___
  / ___/ __ \______/ __ `/ | /| / / ___/_____/ ___/ __ `/ __ `__ \/ /_____/ / __ \/ __ `/ / __ \
 / /  / / / /_____/ /_/ /| |/ |/ (__  )_____(__  ) /_/ / / / / / / /_____/ / /_/ / /_/ / / / / /
/_/  /_/ /_/      \__,_/ |__/|__/____/     /____/\__,_/_/ /_/ /_/_/     /_/\____/\__, /_/_/ /_/
                                                                                /____/

✅ Test for a valid Kerberos ticket ...
✅ Getting SAML token ...
✅ Getting AWS accounts ...
✅ Getting temporary AWS credentials ...
2022-05-17 13:48:49 bucket-name-stage
2022-12-13 13:21:02 bucket-name-tfstate-stage
Thank you for using rh-aws-saml-login. 🙇‍♂️ Have a great day ahead! ❤️

Environment Variables

rh-aws-saml-login sets the following environment variables:

  • AWS_ACCOUNT_NAME: The name/alias of the AWS account
  • AWS_ROLE_NAME: The name of the role
  • AWS_ROLE_ARN: The ARN of the role
  • AWS_ACCESS_KEY_ID: The access key used by the AWS CLI
  • AWS_SECRET_ACCESS_KEY: The secret access key used by the AWS CLI
  • AWS_SESSION_TOKEN: The session token used by the AWS CLI
  • AWS_REGION: The default region used by the AWS CLI

Features

rh-aws-saml-login currently provides the following features (get help with -h or --help):

  • No configuration needed

  • Uses Kerberos authentication

  • Open the AWS web console for an account with the --console option

  • Shell auto-completion (bash, zsh, and fish) including AWS account names

  • Integrates nicely with the starship

     [env_var.AWS_ACCOUNT_NAME]
     format = "$symbol$style [$env_value]($style) "
     style = "cyan"
     symbol = "🚀"
    

Development

  • Update CHANGELOG.md with the new version number and date
  • Bump the version number in pyproject.toml

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

rh_aws_saml_login-0.6.0.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

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

rh_aws_saml_login-0.6.0-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file rh_aws_saml_login-0.6.0.tar.gz.

File metadata

  • Download URL: rh_aws_saml_login-0.6.0.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.18

File hashes

Hashes for rh_aws_saml_login-0.6.0.tar.gz
Algorithm Hash digest
SHA256 de4e642077f19799952b62b78b74a10906b3da1aaa688e9b8488cbf908ce0792
MD5 7d3b6596a1b9e0e9ff92a06d15812ecf
BLAKE2b-256 9c3f13273397ec4374642a6c5c5cec6c0c82631015f8a3075234ade85aca71e4

See more details on using hashes here.

File details

Details for the file rh_aws_saml_login-0.6.0-py3-none-any.whl.

File metadata

File hashes

Hashes for rh_aws_saml_login-0.6.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b88d0c6c57be7d61f878a3180c53ad240c3c40836a4caa2b6d0478ffd8e75d4e
MD5 d64ba17c34ba5500002e797be77c8e53
BLAKE2b-256 cedc878eee38f1cbc5d48837eb1ce89074c9d2a572ca34c1b6af1f9664cf15c3

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