kratosvil/aws-sovereign-ops

GitHub: kratosvil/aws-sovereign-ops

零出口 AI 运维平台,利用 AWS 托管服务在私有 VPC 内实现事件自动检测、分析与人工审批后修复。

Stars: 0 | Forks: 0

# aws-sovereign-ops 零出口 AI 运维平台(AWS)。一个自主代理检测基础设施故障、提出修复方案并执行——仅在人工批准后生效。所有运行均在私有 VPC 内完成。AI 流量绝不会离开互联网。 ![AWS Sovereign Ops — Zero-Egress AI Operations Platform](https://raw.githubusercontent.com/kratosvil/aws-sovereign-ops/main/images/banner.png) ## 架构 ``` ┌─────────────────────────────────────────────────────────────────┐ │ PRIVATE VPC (zero-egress — no route to 0.0.0.0/0) │ │ │ │ CloudWatch Alarm │ │ OOMKilled / latency / error rate │ │ │ │ │ ▼ EventBridge │ │ ┌──────────────────┐ PrivateLink ┌───────────────┐ │ │ │ MCP Server │ ◄──────────────────── ►│ Bedrock │ │ │ │ (ECS Fargate) │ (VPC Interface │ Claude / Nova │ │ │ │ │ Endpoint) └───────────────┘ │ │ │ analyze_incident│ │ │ │ propose_fix │ │ │ │ execute_approved│◄── Human APPROVE token │ │ │ rollback │ │ │ └────────┬─────────┘ │ │ │ AWS Cloud Control API │ │ ▼ │ │ EKS / ECS / RDS ──► CloudTrail (S3 WORM + KMS) │ │ immutable audit log │ └───────────────────────┬─────────────────────────────────────────┘ │ Lambda + SNS ▼ OPERATOR receives: • What happened (plain language) • Root cause identified • Proposed fix (Terraform diff) • Expected state after fix • Change risk level Decides: APPROVE / REJECT ``` ## 工作原理 — 演示场景(Pod OOMKilled) ``` 1. EKS pod hits memory limit → OOMKilled ↓ 2. CloudWatch alarm → EventBridge → MCP Server triggered ↓ 3. MCP Server calls Bedrock via PrivateLink (no internet) Bedrock analyzes: pod logs + metrics + crash history ↓ 4. Fix proposal generated: - Root cause: memory leak at /api/infer endpoint - Fix: memory limit 512MB → 1GB + HPA minReplicas 2 → 3 - Risk: low — configuration change only, no destructive ops - Expected: pod stable, p99 latency < 200ms ↓ 5. Operator receives Slack/email notification with APPROVE / REJECT ↓ 6. Operator approves → MCP Server executes: kubectl patch + terraform apply (HPA update) Every action recorded in CloudTrail: task_id, approved_by, timestamp ↓ 7. Agent validates metrics post-apply → incident documented Total time: < 5 minutes vs 45 minutes manual ``` ## 技术栈 | 层 | 技术 | |----|------| | IaC | Terraform >= 1.5 — 模块化,复用 tf-modules-forge | | 代理计算 | ECS Fargate — 无需管理节点 | | AI 大脑 | Amazon Bedrock(Claude 3 Haiku 演示版 / Sonnet 生产版) | | AI 传输 | VPC 接口端点 — Bedrock 完全不接触互联网 | | 代理框架 | MCP(模型上下文协议)— Python | | 事件触发 | CloudWatch 告警 + EventBridge | | 人工介入通知器 | AWS Lambda + SNS | | 审计 | CloudTrail — S3 WORM 存储桶 + KMS 加密 | | IAM | 最小权限 — 无写入、无计费、无根访问权限 | | 网络 | VPC 零出口 — Bedrock、CloudWatch、STS 使用 PrivateLink | ## 仓库结构 ``` aws-sovereign-ops/ ├── modules/ │ ├── bedrock-privatelink/ # VPC Interface Endpoints for Bedrock + CW + STS │ ├── cloudtrail-audit/ # CloudTrail + S3 WORM bucket + KMS │ └── cloudwatch-alarms/ # OOMKilled, latency, error rate alarms ├── examples/ │ └── sovereign-aiops/ # Full stack demo — assembles all modules ├── mcp-server/ │ ├── server.py # MCP Server entrypoint │ ├── tools/ │ │ ├── analyze_incident.py # Read-only — pulls logs + metrics from CloudWatch │ │ ├── propose_fix.py # Generates Terraform diff + risk assessment │ │ ├── execute_approved.py # Applies fix after validating HITL token │ │ └── rollback.py # Reverts last apply after HITL approval │ └── requirements.txt ├── lambda/ │ └── hitl-notifier/ # Sends APPROVE/REJECT notification to operator ├── scripts/ │ └── demo.sh # Simulates OOMKilled and runs full remediation loop └── docs/ └── architecture.md ``` ## 模块 ### `modules/bedrock-privatelink` 为 Amazon Bedrock、CloudWatch 和 STS 创建 VPC 接口端点,使 MCP 服务器可通过 PrivateLink 调用 Bedrock 而不离开 VPC。 | 资源 | 用途 | |------|------| | `aws_vpc_endpoint` — Bedrock Runtime | 通过 PrivateLink 进行 LLM 推理 | | `aws_vpc_endpoint` — CloudWatch | 从 VPC 内获取指标与日志 | | `aws_vpc_endpoint` — STS | 无需互联网即可假设 IAM 角色 | | 安全组 | 仅限制对 MCP 服务器安全组的端点访问 | ### `modules/cloudtrail-audit` 为每个代理操作提供不可变的审计追踪。代理无法删除或修改自己的审计日志。 | 资源 | 用途 | |------|------| | CloudTrail(多区域) | 捕获每个 API 调用并标记 task_id | | S3 存储桶 — WORM 策略 | 对象锁定防止删除或覆盖 | | KMS 密钥 | 对所有 CloudTrail 事件进行静态加密 | | S3 存储桶策略 | 拒绝代理角色执行 `s3:DeleteObject` | ### `modules/cloudwatch-alarms` 预置告警,触发自主修复循环。 | 告警 | 指标 | 阈值 | |------|------|------| | `oomkilled` | `kube_pod_container_status_last_terminated_reason` | >= 1 | | `high-latency` | ALB `TargetResponseTime` p99 | > 2 秒(持续 5 分钟) | | `error-rate` | ALB `HTTPCode_Target_5XX_Count` | > 5%(持续 5 分钟) | | `cpu-overload` | ECS `CPUUtilization` | > 85%(持续 10 分钟) | ## MCP 服务器工具 | 工具 | 访问权限 | 是否需要 HITL 令牌 | |------|----------|-------------------| | `analyze_incident` | 只读 — CloudWatch 日志与指标 | 否 | | `propose_fix` | 生成 TF 差异与风险评分 | 否 | | `execute_approved` | 应用修复到 AWS 资源 | 是 — 验证令牌 | | `rollback` | 回滚最近一次 Terraform 应用 | 是 — 验证令牌 | 只读工具可自由运行。任何写入操作均需在 HITL Lambda 批准后颁发的一次性令牌。令牌有效期为 15 分钟。 ## 安全层级 ``` Layer 1 — Network: Zero-egress VPC, PrivateLink only — no NAT, no IGW for agent traffic Layer 2 — IAM: Least privilege — no IAM write, no billing, no root access Layer 3 — MCP: Read-only by default — write requires HITL session token Layer 4 — Terraform: Blast radius control — max resources per apply enforced Layer 5 — Audit: CloudTrail WORM — immutable, tied to task_id + approver identity Layer 6 — Circuit: 2 consecutive failures → agent suspends + escalates to human ``` ## 目标应用场景 | 行业 | 合规要求 | 使用场景 | |------|----------|----------| | 金融科技 | SOC2 / PCI-DSS | 在受监管边界内实现无需数据外传的自主事件响应 | | 健康科技 | HIPAA | AI 辅助运维,PHI 工作负载不接触公共 AI 端点 | | SaaS B2B | SOC2 | 平台可靠性团队在不增加人工值班负担的情况下降低 MTTR | ## 预估演示成本(48 小时) | 资源 | 预估成本 | |------|----------| | VPC 接口端点 x3(48 小时) | ~$1.75 | | ECS Fargate — MCP 服务器(48 小时) | ~$0.50 | | Bedrock Claude 3 Haiku — 演示令牌 | ~$0.50 | | CloudWatch + S3 + CloudTrail | ~$0.30 | | Lambda HITL 通知器 | ~$0.00(免费额度) | | **总计** | **< $5 USD** | ## 先决条件 在克隆仓库前安装以下工具。 | 工具 | 版本 | 安装方式 | |------|------|----------| | `make` | 任意 | **macOS:** `xcode-select --install` · **Ubuntu/Debian:** `sudo apt install make` · **Windows:** [GnuWin32](https://gnuwin32.sourceforge.net/packages/make.htm) | | `python3` | >= 3.11 | **macOS:** `brew install python@3.11` · **Ubuntu:** `sudo apt install python3.11` · **Windows:** [python.org](https://www.python.org/downloads/) | | `pip` | 任意 | 随 Python 3.11+ 附带 | | `terraform` | >= 1.5 | [developer.hashicorp.com/terraform/install](https://developer.hashicorp.com/terraform/install) | | `aws cli` | v2 | [docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) | **AWS 要求:** - 已配置 AWS CLI:`aws configure` - 已启用 Amazon Bedrock 模型访问:在账户与区域中启用 `anthropic.claude-3-haiku-20240307-v1:0` ## 快速开始 所有命令均在**克隆仓库的根目录**下执行。 ``` # 克隆 git clone https://github.com/kratosvil/aws-sovereign-ops.git cd aws-sovereign-ops # 安装 MCP Server 依赖(仅运行一次) make mcp-install # 设置所需环境变量 export AWS_REGION=us-east-1 export BEDROCK_MODEL_ID=anthropic.claude-3-haiku-20240307-v1:0 export HITL_SNS_TOPIC=arn:aws:sns:us-east-1:YOUR_ACCOUNT_ID:sovereign-aiops-alarms export HITL_TOKEN_SECRET=your-secret-key export API_BASE_URL=https://YOUR_API_GW_ID.execute-api.us-east-1.amazonaws.com/prod export PROJECT_NAME=sovereign-aiops # 启动 MCP Server(终端 1) make mcp-run # 运行演示(终端 2 — 仓库根目录) bash scripts/demo.sh ``` **部署完整 AWS 基础设施:** ``` # 部署(仓库根目录) make init-example make apply-example # 演示后销毁 — VPC 端点按小时计费 make destroy-example ``` ## 架构决策 - **通过 PrivateLink 使用 Bedrock** — LLM 推理绝不离开 VPC。满足 SOC2/HIPAA 要求,确保数据不流经公共互联网。 - **MCP 作为执行层** — 模型上下文协议为 LLM 提供结构化、可审计的工具调用,替代自由形式的 Shell 执行。每个工具调用均被记录。 - **人工介入作为商业差异化** — 企业采用此方案是因为代理无法单方面修改生产环境。人类始终是最终决策点。 - **ECS Fargate 作为代理** — 无需管理 EC2 节点,无 SSH 暴露,空闲时自动缩容至零。 - **复用 tf-modules-forge** — 网络、IAM、S3、ECR、ECS Fargate、EKS 模块均来自 [kratosvil/tf-modules-forge](https://github.com/kratosvil/tf-modules-forge)。仅在此构建三个新模块(bedrock-privatelink、cloudtrail-audit、cloudwatch-alarms)。 - **CloudTrail WORM** — S3 对象锁定防止代理删除审计日志。对监管环境中的取证完整性至关重要。 ## 许可证 MIT
标签:AI运维, AWS, Bedrock, Claude, CloudWatch, CVE检测, DPI, ECS Fargate, EventBridge, HITL, MCP Server, OOMKilled, PrivateLink, SEO, 主权云, 事件驱动, 云端自动化, 人工审批, 关键词优化, 安全运营, 延迟监控, 扫描框架, 无外联, 模块化设计, 漏洞探索, 私有VPC, 自动化修复, 自动回滚, 自治响应, 错误率, 零外联