Skip to main content

IAM Policies minifier

Optimize long AWS IAM policies by strategically using wildcards, reducing the number of characters, and maintaining the intended scope of permissions.

Background

When crafting long and complex AWS IAM customer-managed policies, the 6,144 character limit imposed by AWS can become a problem. While one approach to address this limitation is to split a long policy into multiple customer-managed policies, this may not always be the ideal solution. In such scenarios, it's possible to reduce the length of a policy by strategically using wildcards where possible.

The iam-minify-er traverses through a list of IAM actions defined in a policy, identifies optimal locations for wildcards, and effectively reduces the character count while maintaining the intended permission scope.

Instalation

python -m pip install iam-minify

Usage & features

  • iam-minify example-policy.json

The script will traverse though all policy statemends defined in the policy document, and optimise IAM actions within the same statement. It processes different policy statements in isolation in order to not grant unintended access to resources.

Limitations

  • Actions in the supplied IAM policy documents can contain wildcards only at the end of the string. Wildcards anywhere else than at the end of the string are currently not supported. E.g., s3:Get* will work while s3:*Object will throw an error.

Example

Consider the following IAM policy:

// ./example-policy.json

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAccessPoints",
        "s3:ListAccessPointsForObjectLambda",
        "s3:ListAllMyBuckets",
        "s3:ListBucket",
        "s3:ListBucketMultipartUploads",
        "s3:ListBucketVersions",
        "s3:ListJobs",
        "s3:ListMultipartUploadParts",
        "s3:ListMultiRegionAccessPoints"
        "s3:ListStorageLensConfigurations",
      ],
      "Resource": "*"
    }
  ]
}

Executing iam-minify example-policy.json will output the following result:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "s3:ListAccessP*",
        "s3:ListAl*",
        "s3:ListB*",
        "s3:ListJ*",
        "s3:ListM*",
        "s3:ListStorageLensC*"
      ],
      "Resource": "*"
    }
  ]
}

Metadata

Release files for iam-minify 0.0.4

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

Source distribution (sdist)

Source distribution for iam-minify 0.0.4
File Size Uploaded
iam-minify-0.0.4.tar.gz 7.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for iam-minify 0.0.4
File Interpreter ABI Platform
iam_minify-0.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 15.2 kB

Release files / iam-minify-0.0.4.tar.gz

Download URL iam-minify-0.0.4.tar.gz
Size 7.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d383fc98fa6274575f8f52dec8647bb5a9ed4183c53c72898136edb1d51cc457
BLAKE2b-256 checksum
How to use checksums
29ebd9feecc3f5528ba34312e8ba9fde3afb60e49379d0ff0626554f499099cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release files / iam_minify-0.0.4-py3-none-any.whl

Download URL iam_minify-0.0.4-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c5e320735394b249ae22e7ed71c454336031b484aab53f1b28a8b8b0909a9cf
BLAKE2b-256 checksum
How to use checksums
b90f7fc2c9d13e7f3d145cc165a7f33bcac8cc02b19dfc4b2e1f4b02a1663045
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.0.0 CPython/3.12.2

Release history Release notifications | RSS feed

This release

0.0.4 This release

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

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