TrailScraper is a command-line tool that extracts and analyzes AWS CloudTrail data to generate IAM policies and assist with identity and access management.
A command-line tool to get valuable information out of AWS CloudTrail
This tool is designed for AWS administrators and security professionals who need to audit, analyze, and generate IAM policies based on CloudTrail logs. It helps users filter CloudTrail events, download logs, and automate policy creation to improve cloud security posture and compliance.
Requires AWS credentials configured locally to access CloudTrail API or S3 buckets. Including the us-east-1 region is important to capture global service events. Logs from organizational trails require specifying the organization ID. The tool can help automate least privilege policy creation but may need manual review for completeness.
For OSX, run: brew install trailscraper
Ensure Python version 3.5 or higher is installed
Install via pip: pip install trailscraper
Run directly using Docker with AWS environment variables and mounting ~/.aws directory
Use GitHub Container Registry for current Docker images (version 0.7.0 and later)
Older Docker versions available on DockerHub
trailscraper select --use-cloudtrail-api --filter-assumed-role-arn some-arn --from 'one hour ago' --to 'now'
Fetches CloudTrail events matching a filter directly from the CloudTrail API
trailscraper download --bucket some-bucket --account-id some-account-id --region us-east-1 --from 'two days ago' --to 'now'
Downloads CloudTrail logs from a specified S3 bucket and region, including global service logs
trailscraper download --bucket some-bucket --account-id some-account-id --region us-east-1 --org-id o-someorgid --from 'two days ago' --to 'now'
Downloads CloudTrail logs from organizational trails for centralized AWS accounts
trailscraper select --filter-assumed-role-arn some-arn --from 'one hour ago' --to 'now'
Filters and finds CloudTrail events matching criteria in previously downloaded logs
gzcat some-records.json.gz | trailscraper generate
Generates an IAM policy based on provided CloudTrail event records
cat minimal-policy.json | trailscraper guess
Extends an existing IAM policy by guessing additional relevant actions not present in logs