SimeonDee/Enterprise-Security-Guardrail-Auditor

GitHub: SimeonDee/Enterprise-Security-Guardrail-Auditor

一个基于 FastAPI 和 React 构建的 IaC 安全扫描应用,用于审计 Terraform 配置中的高风险模式并提供可视化风险评分。

Stars: 0 | Forks: 0

# 企业安全护栏审计器

根据安全基线审计基础设施即代码文件。标记高风险模式。可视化风险。

Python 3.11+ React 19 FastAPI Coverage 95% MIT License

## 功能介绍 上传一个 Terraform (`.tf`) 文件,即可立即获得: - **安全审计结果** — 公开的 S3 存储桶、开放的 SSH 端口、通配符 IAM 策略、未加密的数据库等 - **风险评分** — 根据审计结果的严重程度计算出的 0–100 加权评分 - **可视化仪表板** — 严重程度分布图表、趋势数据、最近的扫描历史记录 - **修复指南** — 针对每项审计结果提供可操作的修复建议 ## 截图 ### 仪表板 ![Dashboard](https://static.pigsec.cn/wp-content/uploads/repos/cas/18/1869b366feb9cd27bc5d1b380c55822d3e2d63a0fea1f7c0b9b29700b037b094.png) ### 扫描历史 ![Scan History](https://static.pigsec.cn/wp-content/uploads/repos/cas/44/448c983775f5b26308ba2ae3386a967f96eb9fa8f3803df6b16db278eb75e2f7.png) ### 新扫描 — 文件上传 ![New Scan File Upload](https://static.pigsec.cn/wp-content/uploads/repos/cas/36/363fd982a5bf3b0246ef910509a01e654715486282c20935e28f3442c8d4239a.png) ### 新扫描 — 直接输入 ![New Scan Direct Entry](https://static.pigsec.cn/wp-content/uploads/repos/cas/37/3763d7937e42b3a25d1bee9de912ce70557b543fbe121161170c2dc610426e57.png) ### 新扫描 — 直接输入 (S3/RDS/EBS) ![Scan Direct Input](https://static.pigsec.cn/wp-content/uploads/repos/cas/17/1775e283188560faa9f949aa0b9baee5c6043615a4075aea2eeea62c4856f368.png) ### 扫描结果 — 直接输入 (S3/SG/IAM) ![Scan Results Direct Entry](https://static.pigsec.cn/wp-content/uploads/repos/cas/82/82b0ee3b175a7851f7e89c1e673b5bee5d071f53544a8974f3f51ec6495233e1.png) ### 扫描结果 — 直接输入 (S3/RDS/EBS) ![Scan Results Direct Input](https://static.pigsec.cn/wp-content/uploads/repos/cas/fe/fef3b77e30462bcc216ccb07d5996e66b8b2edf473d4225ba4f88c5807490702.png) ### 扫描结果 — 上传的文件(多服务) ![Scan Results Uploaded](https://static.pigsec.cn/wp-content/uploads/repos/cas/b9/b907e35cb5bebe8755d0ddd6d4e98ac27f81d627588e4994e2d0b2b2a5bc7d36.png) ## 架构 ``` ┌────────────────────────┐ ┌──────────────────────────────┐ │ React Frontend │ HTTP │ FastAPI Backend │ │ TypeScript + Vite │ ──────▶ │ │ │ Tailwind + Recharts │ │ Routes → Services → Models │ └────────────────────────┘ │ │ │ ┌────────────────────────┐ │ │ │ Scanner Engine │ │ │ │ Parser → Rules → │ │ │ │ Scoring → Results │ │ │ └────────────────────────┘ │ │ │ │ SQLAlchemy + SQLite │ └──────────────────────────────┘ ``` ## 技术栈 | 层级 | 技术 | |-------|-----------| | Frontend | React 19, Vite 6, TypeScript, Tailwind CSS 3, Recharts, React Query | | Backend | Python 3.11, FastAPI, SQLAlchemy 2.x (async), Pydantic v2 | | Database | 通过 aiosqlite 实现 SQLite | | Testing | pytest (97 个测试,95% 覆盖率) / Vitest + RTL (24 个测试) | | DevOps | Docker, GitHub Actions CI, pre-commit hooks | | Linting | ruff, black, mypy, tsc | ## 快速开始 ### Docker(推荐) ``` git clone https://github.com/SimeonDee/Enterprise-Security-Guardrail-Auditor.git cd Enterprise-Security-Guardrail-Auditor cp .env.example .env cp backend/.env.example backend/.env.docker docker compose up --build -d ``` - Frontend: http://localhost:3000 - API: http://localhost:8000/docs ### 本地开发 ``` # Backend cd backend python -m venv venv && source venv/bin/activate pip install -e ".[dev]" uvicorn app.main:app --reload --port 8000 # Frontend (新终端) cd frontend npm ci npm run dev ``` ## 安全规则 五条内置规则可检测关键的 AWS 配置错误: | 规则 | 严重程度 | 检测内容 | |------|----------|---------| | S3 公开访问 | Critical | S3 存储桶上的公开 ACL | | 开放 SSH | Critical | 对 0.0.0.0/0 开放的端口 22 | | 公开数据库 | Critical | 可公开访问的 RDS | | 禁用加密 | High | 显式禁用加密 | | 通配符 IAM | Critical | IAM 策略中的 `"Action": "*"` | 规则是可扩展的 — 通过继承 `BaseRule` 添加新规则。请参阅 [docs/security-rules.md](docs/security-rules.md)。 ## 风险评分 审计结果根据严重程度进行加权,并标准化为 0–100 分制: | 严重程度 | 权重 | 示例 | |----------|--------|---------| | Critical | 10 | 3 个 critical 审计结果 → 评分 100 | | High | 7 | 3 个 high 审计结果 → 评分 70 | | Medium | 4 | 3 个 medium 审计结果 → 评分 40 | | Low | 1 | 3 个 low 审计结果 → 评分 10 | ## API RESTful JSON API 位于 `/api/v1/`。完整参考:[docs/api-reference.md](docs/api-reference.md) | Endpoint | 方法 | 描述 | |----------|--------|-------------| | `/scans` | GET | 列出扫描记录(支持分页、过滤) | | `/scans` | POST | 从 JSON 创建扫描 | | `/scans/upload` | POST | 上传 `.tf` 文件 | | `/scans/{id}` | GET | 扫描详情 + 违规项 | | `/scans/{id}` | DELETE | 删除扫描 | | `/guardrails` | GET/POST | 列出 / 创建规则 | | `/guardrails/{id}` | GET/PATCH/DELETE | 读取 / 更新 / 删除规则 | | `/dashboard/summary` | GET | 聚合统计信息 | ## 测试 ``` # Backend — 97 个测试,94.65% 覆盖率 cd backend && source venv/bin/activate pytest # Frontend — 24 个测试 cd frontend && npm test ``` ## 项目结构 ``` ├── .github/workflows/ci.yml # GitHub Actions CI (5 jobs) ├── .pre-commit-config.yaml # Pre-commit hooks ├── Makefile # Developer shortcuts ├── docker-compose.yml # Docker orchestration ├── prompts.md # AI prompt audit log ├── to-do.md # Task tracking ├── backend/ │ ├── app/ │ │ ├── api/v1/endpoints/ # Route handlers │ │ ├── core/ # Middleware, logging, errors │ │ ├── models/ # SQLAlchemy ORM models │ │ ├── scanner/ # Security engine │ │ │ ├── parser.py # Terraform HCL parser │ │ │ ├── rules/ # Pluggable rule system │ │ │ ├── scoring.py # Risk score calculator │ │ │ └── engine.py # Orchestrator │ │ ├── schemas/ # Pydantic request/response │ │ └── services/ # Business logic │ ├── alembic/ # Database migrations │ └── tests/ # 97 pytest tests ├── frontend/ │ ├── src/ │ │ ├── components/ # Reusable UI components │ │ ├── pages/ # Route pages │ │ ├── services/api.ts # Axios API client │ │ └── types/api.ts # TypeScript interfaces │ └── src/test/ # Vitest tests ├── docs/ # Project documentation (12 files) ├── samples/ # Vulnerable Terraform test files ├── scripts/ # Utility scripts (PPTX generator) └── submission_assets/ # Submission deliverables ├── aI-generated_presentation_deck/ # Presentation (.md + .pptx + script) ├── tagle_ai_tag_output_summary_files/ # Tagle AI Tag outputs ├── prompts.md # Prompt audit log copy ├── project_github_repo_link.md └── submission_checklist.md ``` ## 文档 | 文档 | 描述 | |----------|-------------| | [架构](docs/architecture.md) | 系统设计、数据流、设计决策 | | [API 参考](docs/api-reference.md) | 完整的 endpoint 文档 | | [安全规则](docs/security-rules.md) | 规则详情 + 自定义规则指南 | | [部署](docs/deployment.md) | Docker 设置、环境变量、数据持久化 | | [开发工作流](docs/dev-workflow.md) | 设置、测试、CI、pre-commit | | [Frontend](docs/frontend.md) | React 架构、组件、测试 | | [安全审计](docs/security-audit.md) | 26 项审计结果的安全审查 | | [QA 报告](docs/qa-report.md) | 质量评估报告 | | [演示文稿](docs/presentation.md) | 项目概述幻灯片 | | [演示文档](docs/presentation.pptx) | PowerPoint 演示文稿(16 张幻灯片) | | [最终总结](docs/final-summary.md) | 项目回顾 | ## 示例测试文件 `samples/` 目录包含用于测试的、故意包含漏洞的 Terraform 配置: | 文件 | 漏洞数量 | 目的 | |------|----------------|---------| | [vulnerable-infra.tf](samples/vulnerable-infra.tf) | 11 项审计结果 | 核心规则覆盖(S3, SSH, DB, 加密, IAM) | | [multi-service-vulnerable.tf](samples/multi-service-vulnerable.tf) | 9 项审计结果 | 边界情况(宽端口范围、组策略、authenticated-read) | 通过仪表板或 API 上传这些文件,以对扫描器进行端到端验证。 ## AI 辅助开发 本项目使用 **AI 辅助开发**,基于 **GitHub Copilot (Claude Opus 4.6)** 构建。每个提示和操作都记录在 [prompts.md](prompts.md) 中。从脚手架搭建到可用于生产环境的 MVP,整个开发过程在 12 轮结构化交互中完成。 ## 作者 **Adedoyin Simeon Adeyemi** - GitHub: [@SimeonDee](https://github.com/SimeonDee) ## 许可证 MIT
标签:AV绕过, ECS, FastAPI, IaC配置扫描, React, Syscalls, Terraform, 安全合规审计, 请求拦截, 逆向工具