Skip to main content

This is a Python package to expand and deobfuscate IAM policies.

Project description

py-iam-expand logo

py-iam-expand

py-iam-expand is a Python tool to expand and deobfuscate AWS IAM actions.

This can help you to understand and analyze AWS IAM policies more effectively.

Features

  • Expand IAM actions with wildcards (*, ?).
  • Invert IAM action sets to find actions not matching specified patterns.
  • Process IAM policies in JSON format.
  • Command-line interface for easy use.
  • Removes whitespaces or other characters used to obfuscate policies.
  • Decide how to handle non valid actions: Raise an error, keep them or remove them.

Installation

Install py-iam-expand using pip:

pip install py-iam-expand

Usage

Command-Line Interface (CLI)

The py-iam-expand tool can be used via the command line to expand IAM actions.

Basic Expansion

Expand IAM actions from the command line:

py-iam-expand "s3:Get*"

This will output the expanded actions to the console:

s3:GetAccelerateConfiguration
s3:GetAccessGrant
s3:GetAccessGrantsInstance
s3:GetAccessGrantsInstanceForPrefix
s3:GetAccessGrantsInstanceResourcePolicy
...

Using Standard Input (stdin)

You can pipe IAM action patterns to py-iam-expand via stdin:

echo "s3:Get*Tagging" | py-iam-expand

Expanding IAM Policies

Expand actions within a JSON IAM policy document:

py-iam-expand < example_policy.json > expanded_policy.json

Inverting Actions

Invert a set of actions to find all actions not matching the provided patterns:

py-iam-expand -i s3:Get* ec2:Describe*

Command-Line Options

usage: py-iam-expand [-h] [--version] [-i] [--invalid-action {raise,remove,keep}]
                     [--invalid-notaction {raise,remove,keep}]
                     [ACTION_PATTERN ...]

Expand AWS IAM action patterns provided as arguments/stdin lines OR expand actions within an IAM Policy JSON provided
via stdin.

positional arguments:
  ACTION_PATTERN        IAM action pattern(s) to expand/invert (e.g., 's3:Get*' 'ec2:*'). If omitted, reads from
                        stdin. Cannot be used if stdin is a JSON policy.

optional arguments:
  -h, --help            show this help message and exit
  --version             Show the package version and exit
  -i, --invert          Invert pattern expansion result. Cannot be used if stdin is a JSON policy.
  --invalid-action {raise,remove,keep}
                        How to handle invalid patterns in Action elements: raise - raise an error (default), remove -
                        silently remove invalid patterns, keep - keep invalid patterns in the result
  --invalid-notaction {raise,remove,keep}
                        How to handle invalid patterns in NotAction elements: raise - raise an error, remove -
                        silently remove invalid patterns, keep - keep invalid patterns in the result (default)

Library

This package can be used as library, check examples in examples folder.

Running Tests

To run the tests:

poetry run pytest tests

Data

This project leverages the iam-data package for up-to-date AWS IAM data.

Contributing

Contributions are welcome! Please submit pull requests or open issues on GitHub.

Acknowledgment

This project was inspired by previous projects like cloud-copilot/iam-expand and ecdavis/iampoliciesgonewild

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

py_iam_expand-0.3.0.tar.gz (10.2 kB view details)

Uploaded Source

Built Distribution

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

py_iam_expand-0.3.0-py3-none-any.whl (12.5 kB view details)

Uploaded Python 3

File details

Details for the file py_iam_expand-0.3.0.tar.gz.

File metadata

  • Download URL: py_iam_expand-0.3.0.tar.gz
  • Upload date:
  • Size: 10.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for py_iam_expand-0.3.0.tar.gz
Algorithm Hash digest
SHA256 4ccfe25f40ba0633a152c4f86b49cde8972ee3d4b6009b017a4310cc4b9e64c7
MD5 7b80a885953bdc83fe586777fe4a2265
BLAKE2b-256 a308f6e11a029b81f0bec4b7b1f18704aadf509a882cc386c90ef1ac043c18cc

See more details on using hashes here.

File details

Details for the file py_iam_expand-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: py_iam_expand-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 12.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.1 CPython/3.12.3 Linux/6.11.0-1018-azure

File hashes

Hashes for py_iam_expand-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 94c0a1e9dd60316ce60ddc0cdc9a046119bde335b5bb9593ee29224857860d5a
MD5 73366db2745d86a11a518a720c01970a
BLAKE2b-256 5add4056d0bc3d6317039d2dd2ee7cd6a5389575603e270399a8f9f20e11e721

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