Skip to main content

AWS-AR (AWS Assume Role CLI Utility) 🚀

PyPI - Version PyPI - Python Version License

aws-ar is a production-grade, lightweight command-line utility that streamlines assuming AWS IAM roles, chaining multiple roles recursively, and automatically configuring your local AWS CLI environments.

Instead of manually running aws sts assume-role, copying the temporary credentials, and pasting them into your ~/.aws/credentials file, aws-ar handles the entire workflow in a single command. It creates or updates an AWS CLI profile with the newly assumed role's temporary security credentials.

Additionally, aws-ar features powerful endpoint scraping tools. You can fetch credentials via basic HTTP, pass complex curl commands directly, or even pipe (|) raw JSON/XML/HTML directly into the CLI to easily siphon AWS credentials into your local environment.

✨ Features

  • Automated Workflow: Fetch temporary credentials via STS AssumeRole and configure your local profile automatically.
  • Role Chaining: Cleanly string together multiple roles (RoleA -> RoleB -> RoleC) safely via memory and write the final credentials directly locally.
  • Endpoint Extraction: Scrape embedded AWS credentials directly from HTTP endpoints / metadata URLs.
  • Advanced Scraping: Supports fetching via raw curl commands (headers, body, etc.) or standard Unix pipelines (e.g., wget ... | aws-ar --new-profile x).
  • Profile Management: Safely update existing profiles or create entirely new ones so your default credentials remain isolated.
  • Cross-Account Support: Easily assume roles across different AWS accounts.
  • Simplicity: Built cleanly around the existing AWS CLI ecosystem.

📋 Prerequisites

  • AWS CLI: The AWS Command Line Interface must be installed and properly configured.
  • Python 3.x: Ensure you have Python installed in your environment.

📦 Installation

You can install aws-ar safely and easily from PyPI:

pip install aws-ar

🚀 Usage

The basic syntax for aws-ar requires either a --role-arn, --endpoint, --curl, or piped inputs, along with the name of the new profile (--new-profile) to store the temporary credentials in.

# Assume a single role
aws-ar --role-arn <ROLE_ARN> --new-profile <NEW_PROFILE_NAME> [--profile <SOURCE_PROFILE>]

# Assume a role chain RoleA -> RoleB -> RoleC
aws-ar --role-arn <ROLE_ARN_A> <ROLE_ARN_B> <ROLE_ARN_C> --new-profile <NEW_PROFILE_NAME> [--profile <SOURCE_PROFILE>]

# Extract credentials from an endpoint
aws-ar --endpoint <HTTP_URL> --new-profile <NEW_PROFILE_NAME>

# Extract with complex curl commands
aws-ar --curl "curl -X POST -H 'Authorization: xyz' http://target.com" --new-profile <NEW_PROFILE_NAME>

# Pipe directly from bash!
curl -s http://target.com | aws-ar --new-profile <NEW_PROFILE_NAME>

Arguments

Argument Requirement Description
STDIN (Pipe) Conditionally Required Pass any output string containing credentials directly into aws-ar via Unix pipe |.
--role-arn Conditionally Required The exact ARN(s) of the IAM role you want to assume. Pass multiple ARNs space-separated to assume a chain of roles recursively.
--endpoint Conditionally Required An HTTP URL that returns AWS credentials via GET (e.g., metadata service, SSRF exploitation).
--curl Conditionally Required A raw shell curl command if you need custom headers, methods, or request bodies.
--new-profile Required The name of the AWS CLI profile to create/update with the configured temporary credentials.
--profile Optional The name of the existing AWS profile to use when making an assume-role call. Defaults to default.

💡 Examples

Example 1: Basic Role Assumption and Chaining (A -> B -> C) ⛓️

Assume a target role (prod-admin), or chain multiple targets cleanly stringing ARNs together.

aws-ar \
  --profile default \
  --role-arn \
      arn:aws:iam::111111111111:role/AuditRole \
      arn:aws:iam::222222222222:role/InvestigatorRole \
  --new-profile chained-session

Example 2: Extract credentials from an endpoint 🌐

Easily pull credentials directly from an EC2 metadata URL or an exposed web application SSRF endpoint. Let aws-ar cleanly parse dirty HTML/XML and set up the profile automatically.

aws-ar \
  --endpoint "http://169.254.169.254/latest/meta-data/iam/security-credentials/NewRoleTest" \
  --new-profile metadata-stolen-credentials

Example 3: Extracting via curl with Headers 🕵️

If an SSRF endpoint or metadata service requires a specific Token or HTTP verb (like IMDSv2 requires PUT and specific headers):

aws-ar \
  --curl "curl -s -X GET -H 'X-aws-ec2-metadata-token: AQAEA...' http://169.254.169.254/latest/meta-data/iam/security-credentials/EC2Role" \
  --new-profile imdsv2-credentials

Example 4: Extracting directly via Unix Pipeline | 🪄

Alternatively, you can just use your favorite tools and pass their final STDOUT completely into aws-ar!

wget -qO- http://my-stolen-creds.com/data.json | aws-ar --new-profile my-stolen-credentials

You can now use any of these profiles with any AWS CLI command natively:

aws s3 ls --profile <NEW_PROFILE_NAME>

🛠️ How it Works under the hood

Under the hood, aws-ar securely executes the following:

  1. Validates and iterates through your aws sts assume-role chain utilizing os.environ hooks, OR processes your --endpoint/--curl/Pipe streams organically.
  2. Extracts the AccessKeyId, SecretAccessKey, and SessionToken using a robust, battle-tested regex parser (bypassing XML/HTML clutter for --endpoint usage).
  3. Uses aws configure set to securely inject these short-lived credentials into your specified --new-profile inside ~/.aws/config and ~/.aws/credentials.

🤝 Contributing

Contributions, issues, and feature requests are highly welcome! Feel free to check the issues page or submit a Pull Request.

📄 License

This project is open-sourced and licensed under the MIT License.

Metadata

Release files for aws-ar 3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-ar 3.0
File Size Uploaded Provenance Actions
aws_ar-3.0.tar.gz 7.7 kB Without provenance Details for aws_ar-3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for aws-ar 3.0
File Interpreter ABI Platform Actions
aws_ar-3.0-py3-none-any.whl Python 3 none any Details for aws_ar-3.0-py3-none-any.whl

Total release size: 15.3 kB

Release files / aws_ar-3.0.tar.gz

Download URL aws_ar-3.0.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
0cda593a54145f8c9bf7da7946b6363bcc3c462af89dcd6ff8e7af8a37e8c8fa
BLAKE2b-256 checksum
How to use checksums
1ff7188c670695452e3ff3e4c75dea000b15c21855b4d37166ba39ecd415e35c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / aws_ar-3.0-py3-none-any.whl

Download URL aws_ar-3.0-py3-none-any.whl
Size 7.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f377b1e711beac707d312ea6de998729dc3a0f3a0107fd3971b77895b6842e0
BLAKE2b-256 checksum
How to use checksums
6675ecc6b611f48105505128b145f01e4a1b5e54a1d7df3ec0597937edd85bdd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Security for aws-ar 3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

3.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page