Skip to main content

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

Installation

git clone https://github.com/mrlikl/cfn2iam.git
cd cfn2iam
uv sync

Usage

python source/app.py <template_file> [options]
# or using shorthand options
python source/app.py -t <template_file> [options]

Arguments

  • template_file or -t, --template-file: Path to the CloudFormation template file (JSON or YAML)

Options

  • -d, --allow-delete: Allow delete permissions instead of denying them
  • -c, --create-role: Create an IAM role with the generated permissions (default: True)
  • -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:

python source/app.py path/to/template.yaml
# or
python source/app.py -t path/to/template.yaml

Create an IAM role with delete permissions denied (default behavior):

python source/app.py path/to/template.yaml

Create an IAM role with delete permissions allowed:

python source/app.py path/to/template.yaml -d

Create an IAM role with a custom name:

python source/app.py path/to/template.yaml -r MyCustomRole

Create an IAM role with a permissions boundary:

python source/app.py path/to/template.yaml -p arn:aws:iam::123456789012:policy/boundary

How It Works

  1. The tool parses the CloudFormation template to extract all resource types
  2. For each resource type, it queries the CloudFormation registry to get the required permissions
  3. It categorizes permissions into "update" (create/update/read) and "delete-specific" permissions
  4. It generates a policy document with appropriate Allow and Deny statements
  5. It saves the policy document to a file with a unique name
  6. 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

cfn2iam-0.1.1.tar.gz (16.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cfn2iam-0.1.1-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file cfn2iam-0.1.1.tar.gz.

File metadata

  • Download URL: cfn2iam-0.1.1.tar.gz
  • Upload date:
  • Size: 16.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.10

File hashes

Hashes for cfn2iam-0.1.1.tar.gz
Algorithm Hash digest
SHA256 80d875b02309323994f7b79962669ca36c2b0a26c1eaaf27f1d02b7082884d18
MD5 cd7fc2ff13e7072a6bbf643c8a12c47a
BLAKE2b-256 8ad877cea9e5a81b0607f1876f401abfcccb3800af138d57a5322a6a30d87597

See more details on using hashes here.

File details

Details for the file cfn2iam-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: cfn2iam-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.10

File hashes

Hashes for cfn2iam-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7c2861706629cb030520741d2b80030cf2978f12dc2f404f22da1b63d5b45d65
MD5 180586d28c09904f2010f1089f959e57
BLAKE2b-256 a665cb7746502b71a31c2c959050bf76b30c68cd1cec4bff3eb17f2929458ce5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page