Metadata-Version: 2.4
Name: pipelineguard-ai
Version: 1.0.2
Summary: PipelineGuard AI — Production-Ready, Real-Time GitHub Security and DevSecOps Platform
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.109.0
Requires-Dist: uvicorn>=0.27.0
Requires-Dist: pydantic>=2.0.0
Requires-Dist: pyyaml>=6.0.1
Requires-Dist: requests>=2.31.0
Requires-Dist: sqlalchemy>=2.0.0
Requires-Dist: watchdog>=3.0.0
Dynamic: requires-python

# 🛡️ PipelineGuard AI
### Production-Ready, Real-Time GitHub Security and DevSecOps Platform

> **"Secure Every Commit. Protect Every Pipeline."**  
> Detect and eliminate security vulnerabilities before developers commit, push, or merge dangerous code into GitHub.

---

## 🌟 Overview

PipelineGuard AI is a full-stack, enterprise-grade DevSecOps platform built to protect engineering teams against the six most dangerous supply chain and source code threats:

1. **Accidental Secret & Key Leakage** (AWS, GitHub PATs, Private SSH Keys, Database URLs, .env files)
2. **Malicious Pull Requests & Backdoors** (Obfuscated eval, reverse shells, command injection, exfiltration)
3. **Vulnerable Third-Party Dependencies** (Live integration with Google OSV vulnerability database & typosquat detection)
4. **CI/CD Pipeline Attacks** (GitHub Actions write-all permissions, unpinned commit SHAs, expression injection)
5. **Security Alert Overload & Fatigue** (Deduplication, CVSS-weighted risk scoring, audited suppressions)
6. **Breaking Changes & Dependency Failures** (Major SemVer upgrade analysis, import reference tracking)

---

## 🏗️ Architecture

```
Developer IDE (VS Code / PyCharm / IntelliJ)
    │
Windows PowerShell / CMD / Linux Bash / macOS Zsh
    │
PipelineGuard CLI (`pipelineguard`)
    │
Native Git Pre-Commit Hook (`.git/hooks/pre-commit`)
    │
Six Core Security Engines (Secrets, Malicious Code, OSV, CI/CD, Alerts, Breaking Changes)
    │
Risk Scoring (0-100) & AI Security Explanations
    │
├── [BLOCK COMMIT] -> If Critical/High findings exist (Exit code 1)
└── [ALLOW COMMIT] -> If clean policy pass (Exit code 0)
    │
GitHub Repository & Pull Request Checks
    │
FastAPI Cloud Backend & React TypeScript Cybersecurity Dashboard
```

---

## ⚡ Quickstart: Local Terminal Protection

PipelineGuard works out of the box on **Windows PowerShell**, **Windows CMD**, **Linux**, and **macOS**.

### 1. Installation

Install the package directly:
```bash
pip install -e .
```

Verify installation:
```bash
pipelineguard --help
```

### 2. Initialize in Your Git Repository

Navigate to any Git repository and run:
```bash
pipelineguard init
```

This automatically:
- Creates `.pipelineguard.yml` with configurable severity thresholds and allowlists.
- Installs the native `.git/hooks/pre-commit` hook (safely preserving and chaining any legacy hooks).

### 3. Automatic Pre-Commit Security Gate

Whenever a developer runs:
```bash
git add .
git commit -m "Add payment processor"
```

The Git pre-commit hook automatically invokes the real PipelineGuard scanner on staged changes before the commit takes place:

```text
🛡️  PIPELINEGUARD AI — SECURITY SCAN
   Secure Every Commit. Protect Every Pipeline.

📁 Target: C:\projects\payments-api (staged mode)
⏱️  Duration: 142ms | Files scanned: 2
📊 Risk Score: 70.0/100 | Grade: D

DETECTION MODULE FINDINGS:
────────────────────────────────────────────────────────────

🔴 [CRITICAL] Secret detected: AWS Access Key ID
   Category : Cloud Credential (SEC-001)
   Location : config.py:12
   Match    : AKIA************MPLE
   Fix      : Revoke and rotate this AWS access key immediately in AWS IAM. Use IAM Roles or AWS Secrets Manager.

────────────────────────────────────────────────────────────
SUMMARY:
   Critical : 1
   High     : 0
   Medium   : 0
   Low      : 0

⛔ SECURITY SCAN FAILED — COMMIT BLOCKED
Commit was blocked because blocking findings (1) were detected.
Fix the security issues listed above and run `git add` before committing again.
```

---

## 💻 CLI Commands Reference

| Command | Description |
|---|---|
| `pipelineguard init` | Initialize repository configuration & install pre-commit hook |
| `pipelineguard scan` | Scan Git staged changes (default) |
| `pipelineguard scan --all` | Audit entire repository workspace |
| `pipelineguard scan --secrets` | Run secret leakage detection engine only |
| `pipelineguard scan --dependencies` | Run OSV third-party dependency scanner only |
| `pipelineguard scan --workflows` | Run GitHub Actions CI/CD workflow scanner only |
| `pipelineguard scan --pr main` | Scan pull request changes against `main` base branch |
| `pipelineguard scan-url <url>` | Audit any public remote GitHub repository URL directly |
| `pipelineguard report` | View last scan report summary or export as `--json` or `--sarif` |
| `pipelineguard install-hook` | Reinstall or repair Git pre-commit hook |
| `pipelineguard uninstall-hook` | Safely remove Git pre-commit hook & restore legacy hooks |
| `pipelineguard status` | View active protection status, hook state, and posture grade |
| `pipelineguard watch` | Real-time file watcher that auto-scans upon file modifications |
| `pipelineguard serve` | Launch the SaaS Dashboard and FastAPI server on port 8765 |

---

## 🔍 The Six Security Detection Modules

### Module 1: Secret Leakage Detection
- **Shannon Entropy Analysis**: Detects high-randomness API keys, tokens, and credentials.
- **Pattern Matching**: AWS Access & Secret Keys, GitHub PATs & fine-grained tokens, SSH Private Keys, Google Cloud service accounts, Slack webhooks, Stripe live secret keys, OpenAI/Anthropic API keys, Database URLs (`postgres://`, `mongodb://`), and `.env` files.
- **Strict Masking**: Secrets are masked (`AKIA************`) across terminal outputs, JSON reports, and AI explanations. Raw secrets are never saved or transmitted.

### Module 2: Malicious Pull Request & Code Detection
- Detects dynamic execution (`eval(base64.b64decode(...))`, `bytes.fromhex`).
- Command injection patterns (`subprocess.Popen(f"...{user_input}", shell=True)`).
- Reverse shells & backdoors (`/dev/tcp/`, `mkfifo`, `nc -e`, `pty.spawn`).
- Credential exfiltration payloads over HTTP/DNS.

### Module 3: Third-Party Dependency Security
- Parses `requirements.txt`, `pyproject.toml`, `package.json`, `package-lock.json`, `go.mod`, and `Cargo.toml`.
- **Live Google OSV Integration**: Queries the official Google OSV REST API (`https://api.osv.dev/v1/querybatch`) for actual published CVEs, GHSA advisories, affected version ranges, and fixed versions.
- **Typosquatting & Package Confusion**: Detects malicious typosquat packages (e.g. `colourama`, `requesets`, `djang0`).
- **Offline Fallback**: Bundled local database of verified CVEs ensures zero-network environments continue operating securely.

### Module 4: CI/CD Pipeline Security
- Deep inspection of `.github/workflows/*.yml` and `*.yaml`.
- Flags excessive `permissions: write-all`.
- Alerts on actions not pinned to immutable 40-character commit SHAs.
- Detects dangerous `pull_request_target` usage when checking out untrusted PR branches.
- Expression injection: flags `${{ github.event.* }}` directly interpolated into `run:` scripts.

### Module 5: Intelligent Alert Management
- Deduplication via sha256 fingerprinting.
- Asset context awareness (test files & mocks are contextualized and adjusted).
- CVSS-weighted Risk Score (0-100) and Security Grade (A+, A, B, C, D, F).
- Audited risk suppressions with justification and author tracking.

### Module 6: Breaking Change Detection
- Detects major SemVer version bumps (e.g. `2.31.0` -> `3.0.0`).
- Import reference graph: scans repository code to identify which source files import the upgraded/removed library.
- Warns on wildcard version dependencies (`*`).

---

## 🌐 SaaS Web Dashboard & Landing Page

PipelineGuard AI includes a dark navy (`#080B20`) cybersecurity web dashboard built with React 18, TypeScript, and Tailwind CSS.

### Starting the Web Platform:
```bash
pipelineguard serve --port 8765
```
Open **http://localhost:8765/** in your browser:
- **Interactive 3D Hero Visual**: Glowing 3D infinity security loop canvas with circuit board traces and particles.
- **Online GitHub URL Scanner**: Paste any repository URL (e.g. `https://github.com/pallets/flask`) for an instant sandbox audit.
- **Full DevSecOps Dashboard**:
  - Security Overview (Risk score gauge, severity breakdown, blocked commits count).
  - Vulnerability Explorer with filterable findings, line indicators, and copyable remediation snippets.
  - Dependency Analysis (OSV CVEs and fixed versions).
  - CI/CD Workflow Analysis.
  - Audited Risk Acceptance Manager.

---

## 🧪 Automated Test Suite

Run the complete test suite covering all 6 modules, Git hook lifecycle, and API endpoints:
```bash
pytest tests/
```

Results:
```text
======================== 25 passed in 4.87s ========================
```

---

---

## 📊 Comprehensive Security Report Generation

PipelineGuard AI supports 5 production report formats designed for developers, DevSecOps leads, and executive auditors (SOC 2 Type II, ISO 27001):

| Format | Purpose | CLI Option | Web Export |
|---|---|---|:---:|
| **HTML Audit** | Self-contained, styled executive security audit report with metrics & remediation | `--html <file>` | ✅ |
| **CSV Spreadsheet** | RFC 4180 audit spreadsheet ready for compliance spreadsheets & Jira import | `--csv-file <file>` | ✅ |
| **SARIF v2.1.0** | OASIS Standard format directly ingestible by GitHub Code Scanning & GitLab CI | `--sarif-file <file>` | ✅ |
| **Markdown (GFM)** | Clean Markdown ready to paste into GitHub PR comments, issues, or release notes | `--markdown <file>` | ✅ |
| **Raw JSON** | Machine-readable structured feed for automated CI/CD pipeline gating | `--json-file <file>` | ✅ |

### Example CLI Report Commands:
```bash
# Scan repository and export interactive HTML and CSV reports
pipelineguard scan --all --html reports/audit.html --csv-file reports/compliance.csv

# Export the latest scan report in Markdown for a GitHub PR summary
pipelineguard report --markdown reports/pr_summary.md

# Output SARIF format to stdout for CI/CD runners
pipelineguard scan --format sarif

# Export last scan as compliance CSV
pipelineguard report --format csv > security_audit.csv
```

### Web UI Report Exports:
When running `pipelineguard serve`, the Web Dashboard and Online GitHub URL Scanner display 1-click download pills (`📄 HTML Audit`, `📊 CSV (SOC2)`, `🛡️ SARIF v2.1`, `📝 Markdown`, `📦 JSON`) for every scan.

---

## 🌍 How to Make It Public and Run on Another System

If another team member tries running `pipelineguard init` on her machine and gets:
> `'pipelineguard' is not recognized as an internal or external command`

This happens because the package was only installed in **your** local Python environment. Here are the **3 ways to make it public and let her use it immediately**:

### Method 1: One-Line Installer Script (Recommended for Windows / Mac / Linux)

#### On Windows (PowerShell):
If she has cloned or downloaded the project:
```powershell
powershell -ExecutionPolicy Bypass -File .\install.ps1
```
This automatically verifies Python, adds the Scripts directory to her User PATH, installs the package, and verifies `pipelineguard`. She can then open any Git repo and run:
```powershell
pipelineguard init
```

#### On Linux / macOS (Terminal):
```bash
chmod +x ./install.sh && ./install.sh
```

---

### Method 2: Distribute the Pre-Built Wheel or Install via Git

We pre-compiled the standalone distribution wheel in the `dist/` folder:
- `dist/pipelineguard-1.0.0-py3-none-any.whl`

#### Install the wheel directly on her machine:
```bash
pip install dist/pipelineguard-1.0.0-py3-none-any.whl
```

#### Or install directly from your GitHub repository (Public):
Once you push this repo to GitHub (`https://github.com/your-username/pipelineguard`):
```bash
pip install git+https://github.com/your-username/pipelineguard.git
```
Anyone worldwide can now type `pipelineguard init` in any terminal!

---

### Method 3: Share the Public Web Dashboard (Zero Installation Required!)

If she does not want to install Python or CLI tools, she can scan any repository directly in her web browser via your server:

1. **Start the PipelineGuard server**:
   ```bash
   pipelineguard serve --port 8765
   ```

2. **Expose it publicly using Cloudflare Tunnel (100% Free, No Port Forwarding)**:
   ```bash
   # In another terminal window:
   cloudflared tunnel --url http://localhost:8765
   ```
   Cloudflare gives you an instant, secure public HTTPS link, such as:
   `https://random-word-abc.trycloudflare.com`

   Send her this link! She can open it on her laptop or phone, paste any GitHub URL or run scans, download full HTML/CSV/SARIF reports, and inspect findings with zero installation.

3. **Or share on the same Wi-Fi / Local Network**:
   ```bash
   pipelineguard serve --host 0.0.0.0 --port 8765
   ```
   She can access it from her browser at `http://<your-ip-address>:8765`.

---

## 🐳 Docker Deployment

Run with PostgreSQL in production:
```bash
docker compose up -d
```
The platform will be live at `http://localhost:8765`.
