asp: Agent Scoped Permissions
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.
Permissions AWS checks behind the scenes
Some permissions never appear as calls of their own. asp adds them:
- KMS: uploading or downloading an S3 object encrypted with a KMS key also needs the key
(
kms:GenerateDataKey/kms:Decrypt), including buckets with default encryption - iam:PassRole: handing a role to a service (a Lambda's role, an ECS task role, ...)
- presigned URLs: a download link needs
s3:GetObject, an upload forms3:PutObject, because whoever uses the link acts with your permissions
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
Resourceto the exact S3 buckets, DynamoDB tables (and indexes), SQS queues, SNS topics, Lambda functions used -
checkmode: 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.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| asp_iam-0.1.1.tar.gz | 116.5 kB | With provenance | Details for asp_iam-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| asp_iam-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for asp_iam-0.1.1-py3-none-any.whl |
Total release size: 131.3 kB
Release files / asp_iam-0.1.1.tar.gz
| Download URL | asp_iam-0.1.1.tar.gz |
|---|---|
| Size | 116.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2ca172bda9b3fd3509d61183fa590c5882c85bd45b1bc70e2a8e80fcd711965c
|
|
BLAKE2b-256 checksum How to use checksums |
009ef3721bb6315002d00cb207751dad2a86ae2456e3bc971825e349d7e982b7
|
| 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 logRelease files / asp_iam-0.1.1-py3-none-any.whl
| Download URL | asp_iam-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f36086012f6d4978f71a7769cec6160050bd7edb757e9b0f159c8bffafd9f3a1
|
|
BLAKE2b-256 checksum How to use checksums |
b9e53bca76e626f9a6cc46bee665ef008d88c97779174cc238c94130768bfca8
|
| 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 logSecurity for asp-iam 0.1.1
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.
Attestation for asp_iam-0.1.1.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 logA 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.