Skip to content

tasnimmizaoui/InfraGuard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

31 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ InfraGuard

Shift-Left AWS Security Monitoring with Automated CI/CD Pipeline

Python 3.11+ Docker Terraform AWS License: MIT

InfraGuard is a comprehensive AWS security monitoring solution that combines runtime infrastructure scanning with shift-left security to detect and prevent security misconfigurations before deployment.

🐳 Now available on Docker Hub! Just docker pull tasnimmizaoui/infraguard:latest and start scanning.

InfraGuard Architecture

Key Features

  • Dual-Mode Security Scanning

    • Runtime Scanning: Monitor existing AWS infrastructure for security risks
    • Plan-Time Scanning: Analyze Terraform plans before deployment (shift-left)
  • Automated CI/CD Pipeline

    • GitHub Actions integration with security gates
    • Blocks deployments with critical security findings
    • Automatic infrastructure deployment on push to main
  • Full Terraform Infrastructure

    • CloudTrail for audit logging
    • VPC Flow Logs for network monitoring
    • S3 buckets with encryption and versioning
    • Lambda-based automated scanning
    • IAM roles following least privilege
  • Comprehensive Security Checks

    • S3: Public access, encryption, versioning
    • Security Groups: SSH/RDP exposure, overly permissive rules
    • IAM: Overpermissive policies, unused credentials
    • CloudTrail: Audit logging configuration
    • VPC: Flow logs enablement

Documentation

Quick Start

Prerequisites

  • Docker (for easiest setup) OR Python 3.11+
  • AWS Account with configured credentials
  • Terraform 1.6+ (optional, for infrastructure deployment)
  • GitHub Account (optional, for CI/CD)

Option 1: Docker Hub (Fastest - No Build Required) ⚑

# Pull the pre-built image from Docker Hub
docker pull yourusername/infraguard:latest

# Run security scan (mount your AWS credentials)
docker run --rm \
  -v ~/.aws:/home/infraguard/.aws:ro \
  -e AWS_REGION=eu-north-1 \
  yourusername/infraguard:latest check-all

# Run specific scans
docker run --rm -v ~/.aws:/home/infraguard/.aws:ro -e AWS_REGION=eu-north-1 \
  yourusername/infraguard:latest check-iam

docker run --rm -v ~/.aws:/home/infraguard/.aws:ro -e AWS_REGION=eu-north-1 \
  yourusername/infraguard:latest check-network

Windows PowerShell:

docker pull yourusername/infraguard:latest

docker run --rm `
  -v C:\Users\$env:USERNAME\.aws:/home/infraguard/.aws:ro `
  -e AWS_REGION=eu-north-1 `
  yourusername/infraguard:latest check-all

Option 2: Docker Compose (For Development)

# Clone repository
git clone https://github.com/tasnimmizaoui/InfraGuard.git
cd InfraGuard

# Build and run
docker-compose build
docker-compose run --rm infraguard check-all

Option 3: Local Python Installation

# Clone and install
git clone https://github.com/tasnimmizaoui/InfraGuard.git
cd InfraGuard
pip install -r requirements.txt

# Configure AWS
aws configure
export AWS_REGION=eu-north-1

# Run security scan
python main.py check-all

# Scan Terraform plan before deployment
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
python main.py scan-plan --plan-file tfplan.json

4. Deploy Infrastructure

# Bootstrap Terraform backend
cd terraform/bootstrap
terraform init
terraform apply

# Deploy main infrastructure
cd ..
terraform init
terraform apply

See Quick Start Guide for detailed instructions.

Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚       GitHub Actions Pipeline        β”‚
β”‚  (Push to main triggers deployment)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚
     β”Œβ”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
     β”‚                      β”‚
β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”          β”Œβ”€β”€β”€β”€β”΄β”€β”€β”€β”€β”
β”‚ Runtime   β”‚          β”‚Plan-Timeβ”‚
β”‚ Scanning  β”‚          β”‚ Scanningβ”‚
β”‚ (Existing)β”‚          β”‚ (Shift- β”‚
β”‚   Infra)  β”‚          β”‚   Left) β”‚
β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”˜          β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜
     β”‚                      β”‚
     β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
    β”‚ Security Gate β”‚
    β”‚ (Block on     β”‚
    β”‚  Critical)    β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”
    β”‚   Terraform   β”‚
    β”‚     Apply     β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
            β”‚
    β”Œβ”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
    β”‚  AWS Infrastructure  β”‚
    β”‚ β€’ CloudTrail         β”‚
    β”‚ β€’ VPC Flow Logs      β”‚
    β”‚ β€’ Lambda Scanner     β”‚
    β”‚ β€’ S3 Buckets         β”‚
    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

See Architecture Documentation for details.

Usage Examples

Runtime Scanning

# Scan all AWS resources
python main.py check-all --output-file findings.json

# Scan specific services
python main.py check-iam
python main.py check-s3
python main.py check-network

Plan-Time Scanning (Shift-Left)

# Create and scan Terraform plan
cd terraform
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
python ../main.py scan-plan --plan-file tfplan.json

CI/CD Pipeline

The pipeline automatically runs on every push to main:

  1. Security Scan - Scans existing AWS infrastructure
  2. Security Gate - Blocks on critical findings
  3. Terraform Plan - Creates deployment plan
  4. Plan Scan - Analyzes planned changes (shift-left)
  5. Deploy - Applies infrastructure if all checks pass

Development

Project Structure

InfraGuard/
β”œβ”€β”€ infra_guard/          # Core Python package
β”‚   β”œβ”€β”€ policy_engine.py  # Reusable security policies
β”‚   β”œβ”€β”€ plan_analyzer.py  # Terraform plan scanner
β”‚   β”œβ”€β”€ detection_rules.py # Runtime scanner
β”‚   └── ...
β”œβ”€β”€ terraform/            # Infrastructure as Code
β”‚   β”œβ”€β”€ modules/          # Reusable Terraform modules
β”‚   β”œβ”€β”€ bootstrap/        # Backend initialization
β”‚   └── main.tf           # Main configuration
β”œβ”€β”€ .github/workflows/    # CI/CD pipeline
β”‚   └── security-scan.yml
β”œβ”€β”€ docs/                 # Documentation
β”œβ”€β”€ tests/                # Test suites
└── main.py               # CLI entry point

Running Tests

# Run test pipeline locally
bash test_pipeline.sh

# Test with insecure configuration
cd test_plan/insecure_test
terraform plan -out=tfplan
terraform show -json tfplan > tfplan.json
python ../../main.py scan-plan --plan-file tfplan.json

πŸ“ Severity Levels

  • πŸ”΄ CRITICAL: Immediate security risk (e.g., S3 bucket public, default security group open)
  • 🟠 HIGH: Significant security concern (e.g., SSH open to internet, no CloudTrail)
  • 🟑 MEDIUM: Moderate security issue (e.g., no VPC Flow Logs)
  • 🟒 LOW: Best practice recommendation (e.g., S3 versioning disabled)

🀝 Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Built By HungryHeidi for AWS Security

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages