Policy Sentry

0.15.1 · active · verified Fri Apr 10

Policy Sentry is an AWS IAM Least Privilege Policy Generator, auditor, and analysis database, currently at version 0.15.1. It compiles database tables based on the AWS IAM Documentation on Actions, Resources, and Condition Keys and leverages that data to create least-privilege IAM policies. It helps organizations limit the blast radius in the event of a breach and scale the creation of secure IAM policies. The project maintains an active release cadence with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically define policy requirements using a dictionary structure similar to the CLI's YAML templates, and then generate a least-privilege AWS IAM policy in JSON format. It creates a policy allowing read and list access to a specific S3 bucket and its objects.

from policy_sentry.writing.policy import write_policy
import json

# Define the policy requirements using a dictionary that mirrors the YAML template structure
policy_definition = {
    "mode": "crud",
    "name": "MyS3ReadPolicy",
    "read": [
        "arn:aws:s3:::my-unique-bucket",
        "arn:aws:s3:::my-unique-bucket/*"
    ],
    "write": [],
    "list": [
        "arn:aws:s3:::my-unique-bucket"
    ],
    "tagging": [],
    "permissions-management": [],
    "wildcard-only": {
        "single-actions": [],
        "service-read": [],
        "service-write": [],
        "service-list": [],
        "service-tagging": [],
        "service-permissions-management": []
    },
    "skip-resource-constraints": [],
    "exclude-actions": []
}

# Generate the IAM policy
output_policy = write_policy(policy_definition)

print(json.dumps(output_policy, indent=4))

view raw JSON →