Automated Policy-as-Code & Cloud Security Posture Management Engine
Shift security left. Break the pipeline before breaches break production.
GuardianPy is a local-first, zero-cost DevSecOps compliance engine that acts as a security gatekeeper across both your infrastructure files (SAST) and simulated live AWS environments (CSPM)βwith no cloud credentials, no external SDKs, and no hardcoded secrets.
- Core Value Proposition
- System Architecture
- Compliance Rules Catalogue
- Quickstart & Installation
- Configuration Reference
- Pipeline Integration
- Live Output Example
- Generated Security Artifact
- ChatOps Alerting
- Project Structure
- Design Philosophy
- Roadmap
| Pillar | Description |
|---|---|
| π Shift-Left Enforcement | Intercepts threats at the local development or pre-commit phaseβbefore they reach staging or production environments. |
| πΈ Zero-Cost Cloud Auditing | Uses moto dependency injection to spin up a fully isolated, in-memory AWS environment. No cloud credentials. No accidental resource provisioning. No bill. |
| π¦ Automated Gatekeeping | Strictly compliant with POSIX standardsβemits exit 1 on policy failures and exit 0 on clean scans, enabling seamless integration with any CI/CD pipeline. |
| π£ ChatOps Integrated | Dispatches real-time security summaries to Slack and Discord via native urllib HTTPβzero heavyweight SDK dependencies. |
| π Modular Rule Engine | Every scanner and reporter is a fully decoupled module. Adding new compliance rules requires no changes to the core orchestrator. |
guardianpy/
β
βββ targets/ # π§ͺ Intentionally vulnerable test suite laboratory
β βββ Dockerfile.vuln # Anti-patterns: :latest, hardcoded secrets, root user
β βββ main.tf.vuln # Anti-patterns: public S3 ACL misconfiguration
β
βββ guardianpy/ # βοΈ Core engine
βββ main.py # CLI Orchestrator, Moto environment seeder & Gatekeeper
βββ config.py # 12-Factor App compliant environment variable manager
β
βββ scanners/ # π Rule-engine analysis modules
β βββ static.py # SAST: Regex-driven Dockerfile & Terraform scanner
β βββ aws_mock.py # CSPM: Mocked AWS S3 perimeter & IAM hardening auditor
β
βββ reporters/ # π Output delivery interfaces
βββ markdown.py # Generates immutable Markdown build artifacts
βββ notifier.py # Dispatches real-time Slack/Discord ChatOps alerts
| Component | Technology | Security Goal |
|---|---|---|
| Static Engine (SAST) | Python re (Regex) / Stream I/O |
Identifies configuration drift, unpinned image versions, and leaked secrets in IaC files |
| Cloud Simulation (CSPM) | boto3 / moto (In-Memory Sandbox) |
Validates IAM hardening and data perimeter controls without any live AWS risk |
| Orchestration | Python Standard Library (sys, os) |
Enforces pipeline automation blocking behavior via POSIX exit codes |
| Reporting Suite | urllib Native HTTP / Markdown |
Generates immutable build artifacts and powers real-time Slack/Discord ChatOps alerts |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β python3 -m guardianpy.main β
βββββββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β Phase 1: SAST Scan β
β Dockerfile.vuln + main.tf β
β (Regex Rule Engine) β
βββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β Phase 2: CSPM Audit β
β Moto In-Memory AWS Sandbox β
β (S3 Perimeter + IAM MFA) β
βββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β Phase 3: Results & Reports β
β Markdown Artifact + ChatOps β
βββββββββββββββββ¬ββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
β Phase 4: Gatekeeper β
β exit 1 (FAIL) / exit 0 (OK) β
βββββββββββββββββββββββββββββββββ
Analyzes local IaC files before any deployment occurs.
| ID | Severity | Rule | Rationale |
|---|---|---|---|
DOCK-001 |
π‘ MEDIUM | Blocks :latest base image tags |
Non-deterministic builds violate immutability principles and reproducibility. |
DOCK-002 |
π΄ CRITICAL | Detects hardcoded credentials in ENV statements |
Plaintext secrets in image layers are permanently exposed via docker history. |
DOCK-003 |
π HIGH | Flags missing USER directive |
Containers without an explicit user run as root by defaultβa critical container escape vector. |
| ID | Severity | Rule | Rationale |
|---|---|---|---|
TF-001 |
π΄ CRITICAL | Flags acl = "public-read" on S3 resources |
Public ACLs expose sensitive data to the open internetβa leading cause of cloud data breaches. |
Provisions a fully isolated, in-memory AWS environment via
motoand runs live-equivalent compliance checks.
| ID | Service | Severity | Rule | Standard Alignment |
|---|---|---|---|---|
AWS-S3-001 |
S3 | π΄ CRITICAL | Detects buckets with AllUsers public ACL grants |
CIS AWS Benchmark 2.1.2 |
AWS-IAM-001 |
IAM | π HIGH | Audits IAM users without MFA devices enrolled | CIS AWS Benchmark 1.10 / AWS Well-Architected |
- Python
3.9or higher pippackage manager
git clone https://github.com/aadieng100/guardianpy.git
cd guardianpy# Create and activate a private virtual environment
python3 -m venv .venv
source .venv/bin/activate # macOS / Linux
# .venv\Scripts\activate # Windows
# Upgrade pip and install locked, production-ready dependencies
pip install --upgrade pip
pip install -r requirements.txtpython3 -m guardianpy.mainThat's it. No AWS credentials. No external accounts. No cloud costs.
GuardianPy is fully configured through environment variables, following the 12-Factor App methodology. Every setting has a safe default so it works out of the box.
| Variable | Default | Description |
|---|---|---|
GUARDIAN_DOCKERFILE_PATH |
targets/Dockerfile.vuln |
Path to the Dockerfile to be scanned by the SAST engine. |
GUARDIAN_TERRAFORM_PATH |
targets/main.tf.vuln |
Path to the Terraform .tf file to be scanned. |
GUARDIAN_FAIL_ON_SEVERITY |
HIGH |
Minimum severity level that triggers a pipeline failure (CRITICAL, HIGH, MEDIUM). |
GUARDIAN_SLACK_WEBHOOK |
(empty) | Optional. Full Slack Incoming Webhook URL for ChatOps alerts. |
GUARDIAN_DISCORD_WEBHOOK |
(empty) | Optional. Full Discord Webhook URL for ChatOps alerts. |
export GUARDIAN_DOCKERFILE_PATH="infra/production/Dockerfile"
export GUARDIAN_TERRAFORM_PATH="infra/terraform/s3.tf"
export GUARDIAN_FAIL_ON_SEVERITY="CRITICAL"
python3 -m guardianpy.mainGuardianPy emits a standard POSIX exit code, making it compatible with any CI/CD platform.
| Exit Code | Meaning | Trigger Condition |
|---|---|---|
0 |
β PASSED | No findings at or above the configured severity threshold. |
1 |
β BLOCKED | One or more findings meet or exceed the configured severity threshold. |
# .github/workflows/security.yml
name: GuardianPy Security Gate
on: [push, pull_request]
jobs:
security-scan:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Install Dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run GuardianPy Compliance Scan
env:
GUARDIAN_FAIL_ON_SEVERITY: HIGH
GUARDIAN_DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
run: python3 -m guardianpy.main
- name: Upload Security Report Artifact
if: always()
uses: actions/upload-artifact@v4
with:
name: guardianpy-security-report
path: guardianpy_report.md# .gitlab-ci.yml
security:guardianpy:
stage: test
image: python:3.11-slim
script:
- pip install -r requirements.txt
- python3 -m guardianpy.main
artifacts:
when: always
paths:
- guardianpy_report.md
variables:
GUARDIAN_FAIL_ON_SEVERITY: "HIGH"Running against the bundled vulnerable test suite produces the following output:
============================================================
π‘οΈ GUARDIANPY: DevSecOps Static & Cloud Compliance Scanner π‘οΈ
============================================================
[+] Running Static Code Analysis (Shift-Left SAST)...
-> Scanning Dockerfile: targets/Dockerfile.vuln
-> Scanning Terraform: targets/main.tf.vuln
[+] Initializing Mock Cloud Environment & Running CSPM Audit...
============================================================
π SCAN RESULTS: Found 5 issues.
============================================================
[MEDIUM] File: targets/Dockerfile.vuln (Line 2)
Issue: Usage of ':latest' tag detected. Prefer pinned versions or content hashes for immutability.
[CRITICAL] File: targets/Dockerfile.vuln (Line 5)
Issue: Potential hardcoded secret or API key detected in environment variable.
[HIGH] File: targets/Dockerfile.vuln (Line Global)
Issue: No 'USER' instruction detected. The container will run as root by default.
[CRITICAL] File: targets/main.tf.vuln (Line 17)
Issue: S3 bucket configured with a public ACL ('public-read'). Major data leakage risk.
[CRITICAL] Resource: arn:aws:s3:::guardianpy-public-exposure-bucket (S3_Bucket)
Issue: S3 Bucket 'guardianpy-public-exposure-bucket' has a public ACL configuration.
[HIGH] Resource: arn:aws:iam:::user/vulnerable-ci-user (IAM_User)
Issue: IAM User 'vulnerable-ci-user' does not have Multi-Factor Authentication (MFA) enabled.
[+] Generating local security report...
-> Markdown report successfully written to: /path/to/guardianpy_report.md
============================================================
β [GATEKEEPER BLOCKED] Critical/High vulnerabilities detected.
Stopping process execution with Exit Code 1.
============================================================
Every scan automatically writes an immutable, structured Markdown report to guardianpy_report.md.
This artifact is designed to be:
- Committed to version control as a security audit trail.
- Uploaded as a CI/CD pipeline artifact for permanent build records.
- Parsed by downstream tooling for ticket creation or SIEM ingestion.
GuardianPy can stream real-time security summaries to your team's communication channels with zero external SDK dependencies (uses Python's built-in urllib only).
export GUARDIAN_SLACK_WEBHOOK="https://hooks.slack.com/services/YOUR/WEBHOOK/URL"
python3 -m guardianpy.mainexport GUARDIAN_DISCORD_WEBHOOK="https://discord.com/api/webhooks/YOUR_ID/YOUR_TOKEN"
python3 -m guardianpy.mainBoth can be active simultaneously. The alert payload looks like:
π¨ GuardianPy Security Alert π¨
Scan completed with blocking issues found.
β’ Total Issues: 5
β’ π₯ Critical: 3
β’ β οΈ High: 1
Please check the generated Markdown artifact for full details.
Security Note: Always pass webhook URLs via environment variables or CI/CD secrets managementβnever hardcode them in source files.
guardianpy/
βββ .gitignore
βββ README.md
βββ requirements.txt # Pinned production dependencies
β
βββ targets/ # Intentionally vulnerable IaC test suite
β βββ Dockerfile.vuln # Anti-patterns: :latest, root exec, hardcoded secrets
β βββ main.tf.vuln # Anti-patterns: public-read S3 ACL
β
βββ guardianpy/ # Core engine package
βββ __init__.py
βββ main.py # CLI orchestrator + Moto environment seeder
βββ config.py # 12-Factor environment variable management
β
βββ scanners/
β βββ __init__.py
β βββ static.py # SAST: Dockerfile & Terraform regex rule engine
β βββ aws_mock.py # CSPM: Mocked AWS S3 & IAM compliance auditor
β
βββ reporters/
βββ __init__.py
βββ markdown.py # Generates structured Markdown security reports
βββ notifier.py # ChatOps: native Slack & Discord webhook dispatcher
GuardianPy was engineered around three core principles:
1. Zero External Friction
The entire tool runs on a single pip install -r requirements.txt. No AWS credentials are needed. No external accounts. No paid tiers. The CSPM engine uses moto to provision a fully isolated, in-memory AWS runtime that is completely destroyed after each scan.
2. Strict Separation of Concerns
Each module has a single, clearly defined responsibility. The scanners/ layer performs detection only. The reporters/ layer handles presentation only. The config.py layer manages environment state only. The main.py orchestrator wires them together without embedding business logic. This architecture makes adding new compliance rules a matter of editing one file.
3. Production-Grade Security by Default
GuardianPy is designed to follow the same security standards it enforces. Secrets are loaded from the environment, never from source. The HTTP client uses Python's built-in urllib to avoid supply-chain risk from third-party HTTP libraries. Pipeline exits are deterministic and testable.
- JSON / SARIF Report Output β Structured machine-readable reports for SIEM ingestion and GitHub Code Scanning integration.
- Pre-Commit Hook β Native
pre-commitframework integration for zero-friction developer adoption. - Extended SAST Rules β Support for
docker-compose.yml, Kubernetes manifests, and Helm charts. - Extended CSPM Rules β AWS Security Groups, CloudTrail logging compliance, and S3 public access block validation.
- Configurable Rule Sets β YAML-driven rule definitions to allow teams to author and share custom policies.
- Multi-Cloud Support β Azure and GCP CSPM modules using equivalent mock libraries.
| Package | Version | Purpose |
|---|---|---|
boto3 |
1.34.131 |
AWS SDK β client interface for CSPM module |
moto[s3,iam] |
5.0.10 |
In-memory AWS mock framework for zero-cost cloud simulation |
All other functionality relies exclusively on the Python Standard Library (re, os, sys, json, urllib, datetime).
This project is licensed under the MIT License. See LICENSE for details.
Built as a demonstration of advanced DevSecOps engineering principles. Shifting security to the earliest layers of developmentβefficiently, securely, and at zero cost.