A Gradio-based chatbot that generates Minimum Viable Permissions AWS IAM policies based on natural language descriptions of use cases. It emphasizes Principle of Least Privilege (POLP) during creation. This tool helps AWS cloud administrators quickly create least-privilege IAM policies without the need for extensive manual policy crafting.
- Interactive chat interface built with Gradio
- Powered by Amazon Bedrock's Claude 3.5 Sonnet model
- Generates IAM policies following the principle of least privilege
- Provides detailed explanations for each permission
- Includes security recommendations and best practices
- Python 3.12+
- AWS account with access to Amazon Bedrock
- AWS credentials with permissions to invoke Bedrock models
If your server has the uv package, you should use this:
# In case you do not have python 3.13 under UV:
uv python install 3.13
# Or to install a version that satisfies constraints:
uv python install '>=3.12,<=3.13'
# Then download uv dependencies
uv init
uv python pin 3.13
uv add -r requirements.txtUse the provided setup script to quickly get started:
# Clone the repository
git clone https://github.com/yourusername/iam-policy-generator-chatbot.git
cd iam-policy-generator-chatbot
# Make the setup script executable
chmod +x setup_and_run.sh
# Run the setup script
./setup_and_run.shThe setup script will:
- Check for Python and pip installation
- Install required dependencies
- Create a
.envfile if it doesn't exist - Test the connection to AWS Bedrock
- Provide options to run the web application, generate policies from the command line, or view saved policies
If you prefer to set up manually:
-
Clone this repository:
git clone https://github.com/yourusername/iam-policy-generator-chatbot.git cd iam-policy-generator-chatbot -
Install the required dependencies:
pip install -r requirements.txt -
Create a
.envfile based on the provided.env.example:cp .env.example .env -
Edit the
.envfile with your AWS credentials:AWS_ACCESS_KEY_ID=your_access_key_here AWS_SECRET_ACCESS_KEY=your_secret_key_here AWS_REGION=us-east-1 # Change to your preferred region where Bedrock is available -
Create the directory for saved policies:
mkdir -p saved_policies
-
Run the Gradio application:
uv run app.py -
Open the provided URL in your web browser (typically http://127.0.0.1:7860)
-
Enter a description of your AWS use case in the text box and click "Generate Policy"
-
Review the generated policy and explanations before implementation
-
Use the validation results to identify potential security issues
-
Save policies for future reference
Generate policies directly from the command line:
# Generate a policy
./generate_policy_cli.py "I need permissions for an EC2 instance to read from an S3 bucket"
# View saved policies
./view_policy.py list- Interactive chat interface for describing AWS use cases
- Detailed explanations of each permission included in the policy
- Follows the principle of least privilege
- Automatic validation against IAM best practices
- Identifies overly permissive permissions
- Flags missing resource constraints
- Provides recommendations for improvement
- Save generated policies with custom names
- View saved policies in the application
- Export policies as JSON files
For a detailed overview of the system architecture and how the components work together, see ARCHITECTURE.md.
View and analyze saved policies:
# List all saved policies
uv run view_policy.py list
# View a specific policy
uv run view_policy.py view policy_name.json
# Validate a policy against best practices
uv run view_policy.py validate policy_name.json
Generate policies directly from the command line without using the web interface:
# Generate a policy from a text description
uv run generate_policy_cli.py "I need permissions for an EC2 instance to read from an S3 bucket named 'data-bucket'"
# Generate a policy from a description in a file
uv run generate_policy_cli.py --file use_case.txt
# Generate, validate, and save a policy
uv run generate_policy_cli.py --validate --save my_policy "I need permissions for a Lambda to access DynamoDB"
# Output only the JSON policy
uv run generate_policy_cli.py --json-only "Provide this user athena read only access to a table named 'test_table' under database named 'dev'"
- "I need permissions for an EC2 instance to read from a specific S3 bucket named 'company-data' and write logs to CloudWatch."
- "Create a policy for a Lambda function that needs to access items from a DynamoDB table called 'user-profiles' and send emails via SES."
- "I need a policy for a developer role that can deploy CloudFormation stacks but only in the development account."
- "Generate permissions for a CI/CD pipeline that needs to deploy to ECS and update a CloudFront distribution."
The example_policies directory contains reference IAM policies that demonstrate best practices:
s3_read_only.json: Read-only access to a specific S3 bucket with condition constraintslambda_dynamodb_cloudwatch.json: Permissions for a Lambda function to read from DynamoDB and write logs to CloudWatch
- Always review generated policies before implementation
- Consider adding conditions to further restrict permissions
- Implement additional security controls like MFA where appropriate
- Regularly audit and rotate credentials
- Use resource-level permissions whenever possible
- Avoid wildcard permissions in production environments