A tool to automatically generate minimal IAM policy to deploy a CloudFormation stack from its template.
Project description
CloudFormation to IAM (cfn2iam)
A tool to automatically generate minimal IAM policy to deploy a CloudFormation stack from its template.
Overview
This tool analyzes CloudFormation templates to identify all resource types used, then queries the CloudFormation registry to determine the required IAM permissions for each resource type. It can generate IAM policy documents or create IAM roles with the appropriate permissions.
Features
- Parse CloudFormation templates in JSON or YAML format
- Extract resource types and determine required permissions
- Generate IAM policy documents with appropriate permissions
- Create IAM roles with the generated permissions
- Option to allow or deny delete permissions
- Support for permissions boundaries
Prerequisites
- Python 3.9+
- AWS CLI configured with CloudFormation DescribeType permission
- uv package manager
Installation
pip install cfn2iam
Usage
cfn2iam <template_path> [options]
Options
-d, --allow-delete: Allow delete permissions instead of denying them (default: False)-c, --create-role: Create an IAM role with the generated permissions (default: False)-r, --role-name: Name for the IAM role (if not specified, uses 'cfn2iam-<random_hash>')-p, --permissions-boundary: ARN of the permissions boundary to attach to the role
Examples
Generate a policy document from a template:
cfn2iam path/to/template.yaml
Create an IAM role with delete permissions allowed:
cfn2iam path/to/template.yaml -d
Create an IAM role with a custom name:
cfn2iam path/to/template.yaml -r MyCustomRole
Create an IAM role with a permissions boundary:
cfn2iam path/to/template.yaml -p arn:aws:iam::123456789012:policy/boundary
How It Works
- The tool parses the CloudFormation template to extract all resource types
- For each resource type, it queries the CloudFormation registry to get the required permissions
- It categorizes permissions into "update" (create/update/read) and "delete-specific" permissions
- It generates a policy document with appropriate Allow and Deny statements
- It saves the policy document to a file with a unique name
- If requested (default), it creates an IAM role with the generated policy
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cfn2iam-0.1.2.tar.gz.
File metadata
- Download URL: cfn2iam-0.1.2.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dca117e999a1f368c79b4e72f6f32f248fb17a2909f0b5d2756ebe9a6b1eb0fd
|
|
| MD5 |
5c8f13201fab0e3db91354d0f512a359
|
|
| BLAKE2b-256 |
58875c76727431baae833ce4380e13c28502cfc642a609a285f9b489802cb95e
|
File details
Details for the file cfn2iam-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cfn2iam-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
863721560d450acb313a529826d7d76ad06d4b9adb4b4f7b477626e0f6cbe068
|
|
| MD5 |
b246ee24ba40c19a70c36a8af0b69878
|
|
| BLAKE2b-256 |
7e86be76fc0a86e314456a7f22e391d73158655397710ac513d39fe9b9c73995
|