masridigital/md-compliance
GitHub: masridigital/md-compliance
面向MSP的AI驱动多租户合规管理平台,自动将安全数据映射到监管框架并生成证据与报告。
Stars: 0 | Forks: 0
# MD 合规
**面向 MSP 的多租户合规管理平台** — 由 [Masri Digital](https://masridigital.com) 构建。
自动从集成(Telivy、Microsoft 365)拉取安全数据,通过 AI 将发现映射到合规框架控制项,填充风险登记册,生成证据,计算用户/设备风险配置,并提供 AI 驱动的修复建议。
## 主要功能
| 功能 | 描述 |
|---------|-------------|
| **AI 驱动的合规** | 3 阶段 LLM 分析:按集成分析 + 跨来源关联。自动将发现映射到控制项,创建风险,生成证据。解耦的运行模式(仅 Telivy、仅 Microsoft 或全量)。 |
| **多提供商 LLM** | 4 层路由(提取 → 映射 → 分析 → 高级)。Together AI、Anthropic、OpenAI、Azure。Prompt 适配层自动针对各模型系列调整 prompts(Claude、Llama、DeepSeek、Qwen、Gemma、Kimi)。每周 AI 模型推荐引擎。 |
| **Telivy 集成** | 外部漏洞扫描、风险评估、泄露数据。具有历史记录的应用内 PDF 报告查看器。按需独立重新运行分析。 |
| **Microsoft 365 集成** | 安全评分、Defender 警报、Intune 设备合规、MFA 注册、身份保护、登录活动、SharePoint。缓存优先(无节流)。独立的重新拉取和分析按钮。 |
| **用户与设备风险配置** | 每用户评分(MFA、风险检测、管理员状态)+ 每设备评分(合规、加密、同步)。针对高风险项目生成 AI 风险叙述。 |
| **自动证据生成** | 创建带有物证引用(完成/部分/草稿层级)的证据条目。绝不伪造 —— 仅记录扫描发现的内容。 |
| **19 种合规框架** | FTC Safeguards (Core/Mortgage/Tax)、SOC 2、NIST CSF、NIST 800-53、HIPAA、PCI DSS v4.0、CMMC、ISO 27001、NY DFS、MA 201 CMR 等。 |
| **WISP 向导** | 书面信息安全程序(Written Information Security Programs)引导向导,支持 AI 辅助及 PDF/DOCX 导出。 |
| **后台处理** | 所有繁重的 LLM 工作在守护线程中运行,带有实时阶段跟踪(收集 → 分析 → 生成证据 → 完成)。15 分钟轮询窗口。即使用户导航离开或注销,处理仍继续。 |
| **PDF 报告** | 通过 WeasyPrint 生成 PDF 合规报告。包含封面页、项目指标、控制状态、审查摘要、风险登记册和证据清单。 |
| **存储路由** | 跨 Local、S3、Azure Blob、SharePoint、Egnyte 的基于角色的存储(证据/报告/备份)。自动回退到本地。 |
| **MCP Server** | 位于 `/mcp` 的 OAuth 2.0 Model Context Protocol,用于 Claude/ChatGPT 与 11 个合规工具的集成。 |
| **实时日志查看器** | 跨所有 Gunicorn worker 的 Redis 支持的日志聚合。级别过滤、自动刷新、敏感数据脱敏。重启后持久化。 |
| **多租户** | 完全租户隔离,包含每个租户的数据、项目、控制项、证据和风险登记册。 |
| **SSO / 2FA** | Google + Microsoft OAuth,支持 TOTP 2FA 的本地认证。 |
## 快速开始
### 前置条件
- 安装了 Docker 和 Docker Compose 的 Linux 服务器
- 指向您服务器的域名(例如 `compliance.yourdomain.com`)
- 开放端口 80 和 443
### 部署
```
git clone https://github.com/masridigital/md-compliance.git
cd md-compliance
chmod +x setup.sh
./setup.sh
```
设置向导会配置 SSL、生成 `.env`、设置数据库并启动应用。
### 首次登录
| 字段 | 值 |
|-------|-------|
| URL | `https://your-domain.com` |
| Email | 来自设置的管理员邮箱 |
| Password | 来自设置的密码 |
有关完整的部署详情,请参阅 [`SETUP.md`](SETUP.md)。
## 架构
```
md-compliance/
├── app/
│ ├── __init__.py # App factory, startup, error handlers
│ ├── models.py # Core models (5000+ lines)
│ ├── masri/
│ │ ├── llm_routes.py # LLM endpoints + 3-phase auto-process
│ │ ├── llm_service.py # Multi-provider LLM + 4-tier routing
│ │ ├── prompt_adapters.py # Per-model-family prompt adaptation layer
│ │ ├── entra_integration.py # Microsoft 365 (Defender, Intune, Entra)
│ │ ├── telivy_integration.py # Telivy external vulnerability scanning
│ │ ├── ninjaone_integration.py # NinjaOne RMM (endpoint management)
│ │ ├── defensx_integration.py # DefensX (browser security)
│ │ ├── risk_profiles.py # User & device risk scoring engine
│ │ ├── model_recommender.py # Weekly AI model recommendation engine
│ │ ├── storage_router.py # Role-based storage routing + fallback
│ │ ├── storage_providers.py # S3, Azure Blob, SharePoint, Egnyte, Local
│ │ ├── mcp_server.py # MCP OAuth server for AI assistants
│ │ ├── scheduler.py # Background jobs (daily refresh, weekly recs)
│ │ ├── log_buffer.py # In-app log viewer with redaction
│ │ ├── settings_routes.py # All settings API endpoints
│ │ ├── settings_service.py # Encryption + settings business logic
│ │ ├── notification_engine.py # Teams, Slack, Email, SMS dispatcher
│ │ └── wisp_routes.py # WISP wizard + PDF/DOCX export
│ ├── templates/
│ │ ├── integrations.html # Unified integrations page
│ │ ├── view_project.html # Project detail (controls, risks, evidence)
│ │ ├── workspace.html # Client/tenant management
│ │ └── system_info.html # System page + log viewer
│ └── auth/ # OAuth, local auth, TOTP 2FA
├── docker-compose.yml # App + Postgres + Redis + Nginx + Certbot
├── Dockerfile # Multi-stage Python 3.12 build
├── CLAUDE.md # AI development reference
├── MEMORY.md # Roadmap, technical debt, completed work
├── INTEGRATIONS.md # Integration methodology + specs
├── SETUP.md # Full deployment guide
├── pyproject.toml # Ruff linter configuration
└── run.sh # Gunicorn entrypoint with DB migrations
```
## 集成流水线
```
1. Map scan to client (Telivy) or configure Entra ID (Microsoft)
2. Auto-process pulls data from configured integrations
- run_mode: telivy_only | microsoft_only | full
- Real-time stage tracking via polling API
3. 3-phase LLM analysis (prompts auto-tuned per model family):
Phase 1: Telivy-only (external vulnerabilities)
Phase 2: Microsoft-only (internal security posture)
Phase 3: Cross-source correlation (both sources)
4. Controls mapped with status + evidence auto-generated
5. Risks created in Risk Register with dedup
6. User & device risk profiles computed
7. Progress bar updates automatically
8. Daily scheduler refreshes all data every 24 hours
```
### 支持的集成
| 集成 | 类型 | 状态 |
|-------------|------|--------|
| **Telivy** | 外部漏洞扫描 | Active |
| **Microsoft 365** | Entra ID + Defender + Intune | Active |
| **NinjaOne RMM** | 终端管理 | Active |
| **DefensX** | 浏览器安全 | Active |
| **Blackpoint Cyber** | MDR/SOC | 即将推出 |
| **Keeper Security** | 密码管理 | 即将推出 |
| **SentinelOne** | EDR | 即将推出 |
## API 端点
### LLM / 自动处理
```
POST /api/v1/llm/auto-process Background integration processing
GET /api/v1/llm/auto-process-status/:id Poll for results
POST /api/v1/llm/assist-gaps AI gap analysis (background)
GET /api/v1/llm/assist-gaps-status/:id Poll for recommendations
POST /api/v1/llm/control-assist Control assessment
POST /api/v1/llm/gap-narrative Gap analysis narrative
POST /api/v1/llm/risk-score Risk scoring
POST /api/v1/llm/refresh-microsoft/:id Manual Microsoft data refresh
GET /api/v1/llm/integration-data/:id Cached integration data for project
```
### Telivy
```
POST /api/v1/telivy/test Test connection
GET /api/v1/telivy/external-scans List external scans
POST /api/v1/telivy/external-scans Create new scan
GET /api/v1/telivy/external-scans/:id Scan details
GET /api/v1/telivy/external-scans/:id/findings Scan findings
GET /api/v1/telivy/external-scans/:id/breach-data Breach data
GET /api/v1/telivy/external-scans/:id/report PDF/DOCX report
GET /api/v1/telivy/risk-assessments List assessments
POST /api/v1/telivy/risk-assessments Create assessment
GET /api/v1/telivy/risk-assessments/:id Assessment details
GET /api/v1/telivy/risk-assessments/:id/devices Device inventory
GET /api/v1/telivy/risk-assessments/:id/scan-status Scan completion status
GET /api/v1/telivy/risk-assessments/:id/report Assessment report
```
### Entra ID / Microsoft 365
```
POST /api/v1/entra/test Test Graph API connection
GET /api/v1/entra/users Directory users
GET /api/v1/entra/mfa-status MFA enrollment report
POST /api/v1/entra/assess Compliance posture assessment
GET /api/v1/entra/csp-clients CSP/partner managed tenants
```
### NinjaOne RMM
```
POST /api/v1/ninjaone/test Test connection
GET /api/v1/ninjaone/organizations List organizations
GET /api/v1/ninjaone/devices Devices by organization
GET /api/v1/ninjaone/alerts Active alerts
```
### DefensX
```
POST /api/v1/defensx/test Test connection
GET /api/v1/defensx/customers List customers
GET /api/v1/defensx/agents/:id Agent status by customer
GET /api/v1/defensx/policies/:id Web policies by customer
```
### 设置
```
GET/PUT /api/v1/settings/llm LLM provider config
GET/PUT /api/v1/settings/llm/features Tier-based model routing
GET /api/v1/settings/llm/providers All configured providers
PUT /api/v1/settings/llm/providers/:key Add/update provider
POST /api/v1/settings/llm/recommendations/refresh AI model research
GET/PUT /api/v1/settings/storage/roles Storage role assignments
GET /api/v1/settings/system-logs Real-time application logs
```
### MCP Server
```
GET /mcp/.well-known/oauth-authorization-server OAuth discovery
POST /mcp/token Client credentials token
POST /mcp/tools/:name Execute compliance tool
```
## 部署命令
```
# 构建并启动
docker-compose up -d --build
# 使用 Celery (持久任务调度)
docker-compose --profile celery up -d --build
# 重启 (重置速率限制)
docker-compose restart app
# 查看日志
docker-compose logs --tail 50 app
# 实时错误监控
docker-compose logs -f app 2>&1 | grep -A 5 "ERROR\|Traceback"
# 从 git 更新
cd /opt/NinjaRMMAgent/programfiles/md-compliance
git pull origin main
docker-compose up -d --build
```
## 技术栈
- **Backend**: Flask 2.3.3, SQLAlchemy 2.x, PostgreSQL 16, Gunicorn
- **Frontend**: DaisyUI/Tailwind CSS, Alpine.js(无需构建步骤)
- **AI**: OpenAI, Anthropic, Together AI, Azure OpenAI(多提供商)
- **Auth**: OAuth2 (Google + Microsoft), TOTP 2FA
- **Encryption**: Fernet (PBKDF2-HMAC-SHA256, 260K 迭代)
- **Deployment**: Docker Compose (app + postgres + redis + nginx + certbot)
## 安全
- 所有凭据静态加密(Fernet)
- 所有端点上的租户级授权
- 速率限制(2000/天,500/小时)
- 应用内日志中的敏感数据脱敏
- 通过 Let's Encrypt 强制 HTTPS
- 带有启动标记和非活动超时的会话管理
将漏洞报告至 **security@masridigital.com**
## 许可证
版权所有 (c) 2026 Masri Digital LLC。保留所有权利。
根据 Commons Clause + GNU AGPL v3 许可。请参阅 [LICENSE](LICENSE)。
*由 [Masri Digital](https://masridigital.com) 构建并维护 — inquiry@masridigital.com*
标签:AI辅助, Anthropic, API限流, Apple风格UI, Azure, CIS基准, CMMC, DevSecOps, DLL 劫持, Entra ID, FTC Safeguards, HIPAA, Intune, ISO 27001, LLM, MCP服务器, Microsoft 365, MSP工具, NIST 800-53, NIST CSF, OpenAI, PCI DSS, PDF生成, SaaS, Secure Score, SharePoint, SOC 2, Together AI, UI设计, Unmanaged PE, Webhook, WISP向导, Written Information Security Program, 上游代理, 修复建议, 内存规避, 力导向图, 合规框架映射, 合规管理, 合规自动化, 后端开发, 多模型路由, 多租户平台, 大语言模型, 安全合规, 安全建议, 安全评分, 审计, 微软安全集成, 提示词工程, 提示词模板, 搜索引擎查询, 数据隐私, 治理风险与合规, 测试用例, 策略决策点, 缓存策略, 网络代理, 网络安全, 自动报告, 设备合规性, 证据生成, 请求拦截, 身份保护, 逆向工具, 隐私保护