PolicyUniverse
PolicyUniverse, currently at version 1.5.1.20231109, is a Python library for parsing and processing AWS IAM Policies, Statements, ARNs, and wildcards. It provides classes to parse AWS IAM and Resource Policies, expand wildcards using AWS permission data, and minify policies to help users stay under AWS policy size limits. The project, open-sourced by Netflix-Skunkworks, sees releases as needed, with its latest update in November 2023.
Warnings
- gotcha Minification of policies does not currently work on 'Deny' statements. Attempting to minify a policy with 'Deny' effects will raise an exception.
- gotcha While PolicyUniverse can minify policies to meet size limits, the resulting minified policies can be significantly less readable. It is recommended to avoid minification if possible, prioritizing human readability and maintainability.
Install
-
pip install policyuniverse
Imports
- ARN
from policyuniverse.arn import ARN
- Policy
from policyuniverse.policy import Policy
- Statement
from policyuniverse.statement import Statement
Quickstart
from policyuniverse.policy import Policy
policy_document = {
'Version': '2012-10-17',
'Statement': [
{
'Effect': 'Allow',
'Principal': 'arn:aws:iam::012345678910:root',
'Action': ['s3:*'],
'Resource': '*',
'Condition': {
'IpAddress': {
'AWS:SourceIP': ['0.0.0.0/0']
}
}
},
{
'Effect': 'Allow',
'Principal': 'arn:aws:iam::*:role/Hello',
'Action': ['ec2:*'],
'Resource': '*',
'Condition': {
'StringLike': {
'AWS:SourceOwner': '012345678910'
}
}
}
]
}
policy = Policy(policy_document)
print(f"Policy principals: {policy.principals}")
print(f"Is internet accessible: {policy.is_internet_accessible()}")
print(f"Actions summary: {policy.action_summary()}")