Skip to content

zoph-io/MAMIP

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Š MAMIP - Monitor AWS Managed IAM Policies

[Prod] MAMIP - GitHub Actions

MAMIP is a comprehensive monitoring tool that tracks changes in AWS Managed IAM Policies and provides automated notifications through multiple channels. Built with a serverless architecture using ECS Fargate and Terraform, it ensures continuous monitoring of AWS policy updates with real-time validation using AWS Access Analyzer.

πŸ“‹ Table of Contents

πŸ” Features

Core Functionality

  • Automated Policy Monitoring: Continuously tracks all AWS Managed IAM Policies
  • Change Detection: Identifies new, updated, and deprecated policies
  • Policy Validation: Validates policies using AWS Access Analyzer with detailed findings
  • Multi-Channel Notifications: Sends alerts via social media, SNS, and GitHub
  • Deprecation Tracking: Maintains historical records of deprecated policies
  • Individual Commit History: Each policy change gets its own commit with version tracking

Technical Features

  • Serverless Architecture: ECS Fargate with Spot instances for cost optimization
  • Infrastructure as Code: Complete Terraform configuration for reproducible deployments
  • Container-Based: Docker containerization for consistent execution environments
  • GitHub Integration: Secure token-based authentication via AWS Secrets Manager
  • Automated CI/CD: GitHub Actions for continuous integration and deployment

πŸ— Architecture

Schema ECS Fargate

System Components

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   GitHub Actions │────│   ECS Fargate    │────│   AWS Services  β”‚
β”‚   - Scheduled    β”‚    β”‚   - Container    β”‚    β”‚   - IAM APIs    β”‚
β”‚   - Manual       β”‚    β”‚   - Python App   β”‚    β”‚   - Access Analyzer β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚   - Secrets Mgr β”‚
                                               β”‚   - SNS/SQS     β”‚
                                               β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚                       β”‚                       β”‚
            β–Ό                       β–Ό                       β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   Data Storage  β”‚    β”‚   Notifications  β”‚    β”‚   Monitoring    β”‚
β”‚   - policies/   β”‚    β”‚   - Social Media β”‚    β”‚   - CloudWatch  β”‚
β”‚   - findings/   β”‚    β”‚   - Email/SNS    β”‚    β”‚   - Logs        β”‚
β”‚   - DEPRECATED  β”‚    β”‚   - GitHub       β”‚    β”‚   - Metrics     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data Flow

  1. Policy Fetching: Script retrieves current AWS Managed Policies
  2. Change Detection: Compares with local repository to identify changes
  3. Validation: New/updated policies validated using AWS Access Analyzer
  4. Storage: Policy documents stored in policies/, findings in findings/
  5. Versioning: Individual commits created for each policy change
  6. Notification: Alerts sent through configured channels
  7. Cleanup: Deprecated policies moved to tracking list

πŸ– Usage

Notification Channels

Choose from multiple ways to receive policy change notifications:

1. Social Media

2. GitHub Notifications

  • Enable "Releases Only" notifications on this repository
  • Subscribe to commit RSS feed: GitHub RSS Feed

3. AWS SNS Topic

aws sns subscribe \
  --topic-arn arn:aws:sns:eu-west-1:567589703415:mamip-sns-topic \
  --protocol email \
  --notification-endpoint [email protected]

4. Direct Repository Monitoring

  • Watch this repository for commit notifications
  • Monitor the policies/ directory for changes

Manual Execution

For manual policy checks:

# Local execution
cd automation
python validate-batch.py

# Container execution
docker run -e AWS_REGION=eu-west-1 your-ecr/mamip:latest

βœ… Policy Validation

Each AWS Managed Policy undergoes comprehensive validation using AWS Access Analyzer Policy Validation.

Validation Process

  1. Syntax Validation: Ensures proper JSON structure
  2. Security Analysis: Identifies potential security issues
  3. Best Practice Checks: Validates against AWS recommendations
  4. Resource Analysis: Checks resource ARN patterns

Validation Findings

  • Location: All findings stored in findings/ directory
  • Format: JSON files containing detailed validation results
  • Naming: Corresponds to policy names for easy reference
  • Types: Warnings, suggestions, and security findings

Example Finding Structure

{
  "findings": [
    {
      "findingType": "WARNING",
      "issueCode": "REDUNDANT_STATEMENT",
      "findingDetails": "...",
      "locations": [...]
    }
  ],
  "validatePolicyResponse": {...}
}

πŸ’Ύ Data Storage

Repository Structure

MAMIP/
β”œβ”€β”€ automation/           # Core application code
β”‚   β”œβ”€β”€ validate-batch.py # Main validation script
β”‚   β”œβ”€β”€ tf-fargate/      # Terraform infrastructure
β”‚   └── runbook-*.sh     # Execution scripts
β”œβ”€β”€ policies/            # Current AWS Managed Policies
β”œβ”€β”€ findings/           # Policy validation results
β”œβ”€β”€ DEPRECATED.json     # List of deprecated policies
└── assets/            # Documentation assets

Policy Storage

  • Current Policies: Stored in policies/ directory
  • File Naming: Direct policy name mapping
  • Format: AWS IAM policy JSON documents
  • Versioning: Git history tracks all changes

Deprecated Policies

Policies no longer maintained by AWS are tracked in DEPRECATED.json:

{
  "deprecated_policies": [
    {
      "policy_name": "ExampleDeprecatedPolicy",
      "deprecated_date": "2024-01-15",
      "reason": "Replaced by newer policy"
    }
  ]
}

πŸ”’ Security

Authentication

  • GitHub Integration: Uses AWS Secrets Manager for secure token storage
  • AWS Permissions: Least-privilege IAM roles for ECS tasks
  • Container Security: Regular base image updates

Secrets Management

  • GitHub tokens stored in AWS Secrets Manager
  • No hardcoded credentials in code
  • Environment-specific configuration

Permissions Required

The ECS task requires the following AWS permissions:

  • iam:ListPolicies - Fetch policy list
  • iam:GetPolicyVersion - Retrieve policy documents
  • access-analyzer:ValidatePolicy - Validate policies
  • secretsmanager:GetSecretValue - Retrieve GitHub token
  • sns:Publish - Send notifications
  • sqs:SendMessage - Queue social media posts
  • s3:GetObject, s3:PutObject - Access artifacts

πŸ“Š Monitoring

CloudWatch Integration

  • Container logs automatically sent to CloudWatch
  • Metrics tracking for execution success/failure
  • Alerting on validation errors

Execution Tracking

  • Detailed logging throughout execution
  • Error handling with automatic retries
  • Performance metrics collection

πŸŽ–οΈ Credits

Special thanks to Scott Piper for the original concept. This project extends his idea by:

  • Automating the complete monitoring process
  • Adding comprehensive policy validation
  • Implementing multiple notification channels
  • Providing infrastructure as code
  • Tracking policy deprecation lifecycle

πŸ“„ License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.


Maintained by: @z0ph
Latest Update: Automatically updated every 6 hours
Status: Build Status

About

[MAMIP] Monitor AWS Managed IAM Policies Changes

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project

 

Languages

  • Python 42.9%
  • HCL 25.1%
  • Shell 21.1%
  • Makefile 7.6%
  • Dockerfile 1.8%
  • Smarty 1.5%