Skip to main content

asp: Agent Scoped Permissions

ci PyPI Python License: MIT

Record the AWS calls your Python code, or your AI agent, actually makes, and get the least-privilege IAM policy for it.

from asp import record

with record() as rec:
    run_my_script()            # or: agent.run("archive last month's reports")

print(rec.policy_json())
{
  "Version": "2012-10-17",
  "Statement": [
    {"Effect": "Allow", "Action": ["s3:GetObject"], "Resource": "arn:aws:s3:::reports/*"},
    {"Effect": "Allow", "Action": ["s3:PutObject"], "Resource": "arn:aws:s3:::archive/*"}
  ]
}

It only reads from reports and only writes to archive, because that's all the code did.

Why

AI agents and scripts are often given broad AWS permissions because nobody knows what they really need. asp watches what they actually do and writes the smallest policy that allows it. It works offline with moto, so it fits in your tests.

Install

pip install asp-iam

Use

from asp import record

# as a block
with record() as rec:
    ...
rec.actions()       # ['dynamodb:PutItem', 's3:GetObject']
rec.policy()        # dict
rec.save("policy.json")
rec.terraform()     # the same policy as a Terraform resource

# as a decorator
@record(save_to="policy.json")
def nightly_job():
    ...

Correct permission names

Python call names aren't always permission names: list_objects_v2 needs s3:ListBucket, copy_object needs s3:GetObject + s3:PutObject, CloudWatch calls need cloudwatch:*, Bedrock's Converse needs bedrock:InvokeModel. These exceptions live in one readable table, mappings.py. Found a missing one? Add a row and a test.

AI agents: give them only what they use

examples/ai_agent.py gives an agent three AWS tools (list, read, write files) and the task "summarise the October report and save it to the archive". Recorded with asp:

The agent needed only this:
- read files in bucket 'reports'
- list files in bucket 'reports'
- write files in bucket 'archive'

Instead of broad S3 access "to be safe", the agent gets exactly this. If it is ever misled (for example by instructions hidden in a file it reads), it cannot delete data or touch other buckets.

python examples/ai_agent.py            # scripted stand-in, no API key, fake AWS
python examples/ai_agent.py --claude   # real Claude drives the agent (pip install anthropic)

rec.explain() produces the plain-English summary with ordinary code, not an LLM, so it is always exactly what the policy says.

From your test suite (pytest plugin)

pytest --asp                    # writes asp-policy.json: the permissions your tests needed
pytest --asp-check role.json    # fails the run if the code needs actions role.json doesn't allow

Put --asp-check in CI and a change that suddenly needs a new AWS permission is caught before it fails in production. Only calls made inside test bodies are recorded: put setup (like creating fake buckets with moto) in fixtures so it stays out of the policy.

Check an existing policy

result = rec.check("role_policy.json")   # dict, JSON text or a file path
print(result.summary())
missing (code would fail): 0
unused (can be removed): 2
  - dynamodb:Scan
  - iam:CreateUser
too broad (wildcards): 1
  - s3:*

result.ok is False when the code needs something the policy doesn't allow, which is handy in CI. This first version compares actions, not resources.

Status

Early (v0.x). Policies name the exact actions and, for the services above, the exact resources. Other services keep "Resource": "*". rec.policy(scope_resources=False) gives the old all-* form.

Roadmap:

  • Terraform output (rec.terraform())
  • exact IAM names where API and IAM names differ (src/asp/mappings.py, contributions welcome)
  • restrict Resource to the exact S3 buckets, DynamoDB tables (and indexes), SQS queues, SNS topics, Lambda functions used
  • check mode: compare an existing policy with what the code really needs (actions)
  • AI-agent example and plain-English explain()
  • pytest plugin: pytest --asp / pytest --asp-check role.json

Contributing

Found an AWS call that gets the wrong permission name? Add one row to mappings.py plus a test, and open a PR. Issues labelled good first issue are a good place to start.

License

MIT

Metadata

Release files for asp-iam 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 asp-iam 0.1.0
File Size Uploaded Provenance Actions
asp_iam-0.1.0.tar.gz 113.8 kB With provenance Details for asp_iam-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 126.6 kB

Release files / asp_iam-0.1.0.tar.gz

Download URL asp_iam-0.1.0.tar.gz
Size 113.8 kB
Tags Source
SHA-256 checksum
How to use checksums
e4dedbf3eae0f149c1e6eac20599b161fb5fc5fe027922df963acfbff09b2b25
BLAKE2b-256 checksum
How to use checksums
0d76850ed415f94d2cd664c8a63fdd5c0a8ddac6b550b4539a4ddb933e1f12e4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

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

Download URL asp_iam-0.1.0-py3-none-any.whl
Size 12.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
054da5250c8e988c44da98d824cc6e0ea27ba4248cd9bb2ec9e72dad03f0e477
BLAKE2b-256 checksum
How to use checksums
e87ec605c02f9d3e87e5709d0bc2da829068b2584f3576bd5b486c565724b1bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

Security for asp-iam 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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for asp_iam-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 13, 2026.

Transparency log

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 Full 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