Skip to main content

iamwhy

Explains AWS IAM access denials from the command line. Given an IAM principal and an action that's being denied, iamwhy traces exactly why: which policy, which statement, which condition is blocking it.

Quick start

python3.11 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"

iamwhy alice s3:GetObject
iamwhy arn:aws:iam::123456789012:role/MyRole ec2:TerminateInstances \
    --resource "arn:aws:ec2:us-east-1:123456789012:instance/i-abc123"

Usage

iamwhy PRINCIPAL ACTION [OPTIONS]

Arguments:
  PRINCIPAL   IAM user ARN, role ARN, STS assumed-role session ARN,
              bare username, or bare role name
  ACTION      AWS action string, e.g. s3:GetObject

Options:
  --resource TEXT       Resource ARN (default: *)
  --context KEY=VALUE   Context entry (repeatable)
  --output [text|json]  Output format (default: text)
  --profile TEXT        AWS credentials profile ($AWS_PROFILE)
  --region TEXT         AWS region ($AWS_DEFAULT_REGION)

Example output

Principal: arn:aws:iam::123456789012:user/alice
Action:    s3:GetObject
Resource:  arn:aws:s3:::my-bucket/data.csv

Verdict: DENIED (explicit deny)

Reason: An explicit Deny statement in "DenyPublicS3" overrides any Allow.

╭─ arn:aws:iam::123456789012:policy/DenyPublicS3 (IAMPolicy) ─╮
│ Statement: Sid=DenyS3Public                                  │
│   Effect:  Deny                                              │
│   Action:  s3:*                                              │
│   Resource: *                                                │
╰──────────────────────────────────────────────────────────────╯

Decision breakdown:
  DenyPublicS3         explicitDeny
  AmazonS3FullAccess   allowed

Missing context: (none)

JSON output

iamwhy alice s3:GetObject --output json | jq .cause
# "explicit_deny"

The JSON schema:

{
  "principal": "arn:...",
  "principal_type": "user",
  "action": "s3:GetObject",
  "resource": "*",
  "decision": "explicitDeny",
  "cause": "explicit_deny",
  "summary": "...",
  "orgs_blocked": false,
  "boundary_blocked": false,
  "missing_context": [],
  "blocking_policies": [{"policy_id": "...", "decision": "...", "statement": {...}}],
  "all_breakdown": [{"policy_id": "...", "decision": "..."}]
}

Cause values

Cause Description
explicit_deny A Deny statement in a policy explicitly blocks the action
implicit_deny No Allow was found; the default deny applies
scp_block An AWS Organizations SCP denies the action
permissions_boundary The principal's permissions boundary does not allow the action
missing_context A condition could not be evaluated due to absent context keys
combined Multiple of the above apply simultaneously

Exit codes

Code Meaning
0 Access allowed
1 Access denied
2 Usage error or AWS API error

Required permissions

iamwhy needs the following IAM permissions for the credentials you run it with:

{
  "Effect": "Allow",
  "Action": [
    "iam:SimulatePrincipalPolicy",
    "iam:GetUser",
    "iam:GetRole",
    "iam:GetPolicy",
    "iam:GetPolicyVersion",
    "iam:GetUserPolicy",
    "iam:GetRolePolicy",
    "iam:ListAttachedUserPolicies",
    "iam:ListUserPolicies",
    "iam:ListGroupsForUser",
    "iam:ListAttachedGroupPolicies",
    "iam:ListGroupPolicies",
    "iam:ListAttachedRolePolicies",
    "iam:ListRolePolicies"
  ],
  "Resource": "*"
}

iam:GetPolicy* and iam:List* are optional — iamwhy degrades gracefully if they are absent, showing the policy ID without the statement text.

Development

python3.11 -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest
coverage run -m pytest && coverage report

Metadata

Release files for iamwhy 0.1.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 iamwhy 0.1.0
File Size Uploaded Provenance Actions
iamwhy-0.1.0.tar.gz 19.9 kB Without provenance Details for iamwhy-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for iamwhy 0.1.0
File Interpreter ABI Platform Actions
iamwhy-0.1.0-py3-none-any.whl Python 3 none any Details for iamwhy-0.1.0-py3-none-any.whl

Total release size: 34.2 kB

Release files / iamwhy-0.1.0.tar.gz

Download URL iamwhy-0.1.0.tar.gz
Size 19.9 kB
Tags Source
SHA-256 checksum
How to use checksums
4730caf1da0213c4e6db4a0e5d0bee7d8f552099949b3d9cd9371dc867ebfc51
BLAKE2b-256 checksum
How to use checksums
141ca4342461d9c809627f7d217af3738e1463ffd425a2b0671415e0eb8c4b6f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Release files / iamwhy-0.1.0-py3-none-any.whl

Download URL iamwhy-0.1.0-py3-none-any.whl
Size 14.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b34c4b971d482fcf4e6443d4de5432c24405d5d28bab8c43c67d6f56d923d36
BLAKE2b-256 checksum
How to use checksums
943a210839b1fb97cbac881e61b63c63bac7092c9eb706994f3fa98f2c0ceac8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.0

Security for iamwhy 0.1.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

0.1.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