安全数据协议服务器

Tetragon MCP Server 是一个将Tetragon内核级安全观测数据通过Model Context Protocol(MCP)暴露给任何支持MCP规范的LLM提供商或AI应用的服务器。

  • by calghar
  • Go
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 calghar/tetragon-mcp

使用说明

四边形MCP服务器(WIP)


A. 模型上下文协议(MCP)服务器 这暴露了 Tetragon's 将内核级安全可观察性数据发送给支持MCP规范的任何LLM提供者或AI应用程序。

🚀 快速开始

先决条件

单集群开发设置

# Clone the repository
git clone https://github.com/calghar/tetragon-mcp.git
cd tetragon-mcp

# Start development environment (includes Tetragon + MCP server + test workloads)
make dev-setup

# Test the server
make dev-test

多集群设置

# Build the binary
make build

# Create multi-cluster configuration
cp examples/multi-cluster-config.yaml ~/.tetragon-mcp.yaml

# Edit configuration with your cluster details
vim ~/.tetragon-mcp.yaml

# Run with multi-cluster configuration
./tetragon-mcp --config ~/.tetragon-mcp.yaml

多集群配置示例:

clusters:
  - name: "production"
    address: "prod-tetragon.example.com:54321"
    auth:
      type: "tls"
      tls:
        cert_file: "/path/to/prod-client.crt"
        key_file: "/path/to/prod-client.key"
    labels:
      environment: "production"
      region: "us-west-2"
  
  - name: "staging"
    address: "staging-tetragon.example.com:54321"
    auth:
      type: "none"
    labels:
      environment: "staging"

mcp:
  address: ":8080"
events:
  buffer_size: 50000
  retention_seconds: 7200

生产部署

本地部署

# Build and deploy locally
make image IMAGE_TAG=production
./scripts/deploy-docker.sh --type production --config /path/to/production-config.yaml

Docker容器部署

# Using Docker Compose (recommended for production)
cd deploy/docker
docker-compose -f docker-compose-production.yml up -d

# Using standalone Docker
docker run -d \
  --name tetragon-mcp \
  -p 8080:8080 \
  -v /opt/tetragon-mcp/config.yaml:/etc/tetragon-mcp/config.yaml:ro \
  -v /opt/tetragon-mcp/certs:/etc/certs:ro \
  --restart unless-stopped \
  tetragon-mcp:latest

Kubernetes部署

# Deploy to Kubernetes cluster
kubectl apply -f deploy/kubernetes/multi-cluster-deployment.yaml

# Using Helm (for single cluster)
make deploy NAMESPACE=your-namespace

云部署

待定

📖 什么是Tetragon MCP服务器?

此服务器桥接 四边形 (运行时安全可观察性) AI/LLM应用 使用 模型上下文协议.

主要特点

  • 实时安全数据:从Tetragon流式传输内核级事件
  • 通用LLM集成:兼容任何支持MCP的LLM提供商(Claude、OpenAI、自定义应用程序)
  • 双重运输模式:用于LLM集成的Stdio模式,用于测试和API的HTTP模式
  • 高级过滤:基于时间、基于流程、基于命名空间和 基于集群的 过滤
  • 多种事件类型:进程执行、网络活动、文件访问、内核探测
  • 多集群支持:连接到不同集群中的多个Tetragon实例
  • 灵活的身份验证:支持TLS、mTLS和基于令牌的身份验证
  • 灵活部署:在本地部署,如Docker容器、Kubernetes或云中
  • 生产就绪:Kubernetes原生,带有Helm图表、监控和安全策略
  • 易于开发:一个带有种类集群的命令设置

用例

  • 跨集群安全分析:“显示过去一小时内所有生产集群中可疑的流程执行情况”
  • 多环境事件响应:“这个受损的吊舱在测试和生产过程中建立了哪些网络连接?”
  • 集中合规监控:“列出开发、暂存和生产过程中的所有文件访问事件以供审核”
  • 高级威胁狩猎:“在所有受监控的集群中查找具有异常权限升级模式的流程”
  • 环境相关性:“比较临时集群和生产集群之间的安全事件,以识别部署风险”

🏗️ 建筑

单集群部署

MCP服务器将LLM应用程序连接到单个Tetragon实例:

LLM/AI工具 ↔ Tetragon MCP服务器 ↔ 四边形(DaemonSet) ↔ eBPF内核事件

  • LLM应用程序通过MCP协议(基于stdio或HTTP的JSON-RPC)进行通信
  • MCP服务器通过gRPC(端口54321)连接到Tetragon
  • Tetragon通过eBPF收集内核事件

多集群部署

  • 每个集群都运行自己的Tetragon实例
  • MCP服务器同时连接到多个Tetragon端点
  • 事件丰富了集群元数据(名称、标签、区域)
  • LLM应用程序可以跨所有集群进行查询,也可以按特定集群进行筛选

🔧 发展

从源代码构建

# Build binary
make build

# Run tests
make test-all

# Run with hot reload
make dev

可用命令

make help                 # Show all available commands

# Development
make dev-setup           # Setup complete dev environment  
make dev-clean           # Clean up dev environment
make dev-logs            # View server logs

# Testing  
make test                # Unit tests
make test-integration    # Integration tests
make test-e2e           # End-to-end tests
make test-all           # All tests

# Production
make deploy             # Deploy with Helm
make image              # Build production image

🤖 MCP集成

Tetragon MCP服务器支持这两种功能 标准 和 超文本传输协议 传输模式,使其与实现模型上下文协议规范的任何LLM提供程序兼容。

标准模式(建议用于LLM集成)

大多数LLM应用程序(Claude Desktop、OpenAI工具、自定义应用程序)使用stdio模式,在该模式下,它们将MCP服务器作为子进程启动:

克劳德桌面

添加到您的Claude桌面配置(~/.config/claude-desktop/config.json):

{
  "mcpServers": {
    "tetragon": {
      "command": "/path/to/tetragon-mcp",
      "args": ["--stdio", "--config", "/path/to/config.yaml"],
      "env": {
        "TETRAGON_MCP_LOG_LEVEL": "info"
      }
    }
  }
}

其他与MCP兼容的LLM提供商

对于支持MCP stdio传输的其他LLM应用程序:

# Generic stdio usage
/path/to/tetragon-mcp --stdio --config /path/to/config.yaml

# With inline configuration
/path/to/tetragon-mcp --stdio --tetragon-address localhost:54321 --log-level info

HTTP模式(用于自定义应用程序和测试)

HTTP模式对于测试、调试和喜欢REST API的自定义应用程序非常有用:

# Start in HTTP mode (default)
./tetragon-mcp --config /path/to/config.yaml

# Access via HTTP on port 8080
curl -X POST http://localhost:8080/mcp/v1/resources/list -d '{}'

集成示例

Python集成:

import requests

# List available resources
response = requests.post("http://your-server:8080/mcp/v1/resources/list", json={})
resources = response.json()["resources"]

# Read security events
response = requests.post("http://your-server:8080/mcp/v1/resources/read", json={
    "uri": "tetragon://events/process-exec",
    "filters": {"limit": 10, "start_time": "2025-01-20T10:00:00Z"}
})
events = response.json()["contents"]

卷曲测试

运行后 make dev-setup,您可以直接测试MCP API:

# Health check
curl -X POST http://localhost:30080/health

# Initialize MCP connection
curl -X POST http://localhost:30080/mcp/v1/initialize \
  -H "Content-Type: application/json" -d '{}'

# List available resources
curl -X POST http://localhost:30080/mcp/v1/resources/list \
  -H "Content-Type: application/json" -d '{}'

# Read process execution events
curl -X POST http://localhost:30080/mcp/v1/resources/read \
  -H "Content-Type: application/json" \
  -d '{"uri": "tetragon://events/process-exec", "filters": {"limit": 5}}' | jq .

# Read all events with time filter
curl -X POST http://localhost:30080/mcp/v1/resources/read \
  -H "Content-Type: application/json" \
  -d '{"uri": "tetragon://events", "filters": {"limit": 10}}' | jq .

# Browse events by time buckets (NEW!)
curl -X POST http://localhost:30080/mcp/v1/resources/read \
  -H "Content-Type: application/json" \
  -d '{"uri": "tetragon://events/buckets/daily"}' | jq .

# Access events for a specific date
curl -X POST http://localhost:30080/mcp/v1/resources/read \
  -H "Content-Type: application/json" \
  -d '{"uri": "tetragon://events/2025-09-27"}' | jq .

# Access filtered events for a specific hour
curl -X POST http://localhost:30080/mcp/v1/resources/read \
  -H "Content-Type: application/json" \
  -d '{"uri": "tetragon://events/2025-09-27/14/process-exec"}' | jq .

🪣 时间段导航

服务器支持分层时间段导航,便于数据探索:

导航资源

  • tetragon://events/buckets/daily -浏览有活动的可用日期
  • tetragon://events/buckets/hourly -浏览活动可用时间
  • tetragon://events/by-type -先按类型浏览事件,然后按时间浏览
  • tetragon://events/recent -过去24小时内的最新事件

直接时间访问

  • tetragon://events/2025-09-27 -特定日期的所有事件
  • tetragon://events/2025-09-27/14 -特定小时的活动(14:00-15:00)
  • tetragon://events/2025-09-27/process-exec -日期的特定事件类型
  • tetragon://events/2025-09-27/14/kprobe -一小时的特定事件类型

优点:

  • 数据驱动的:仅显示实际包含事件的时间段
  • 可浏览:像文件系统层次结构一样导航
  • 高效:使用索引查找进行快速桶发现
  • 向后兼容:所有现有URI继续工作
  • 灵活的:多种导航模式(时间优先与类型优先)

📖 文档

🤝 贡献

请查看 贡献指南 和 开发者指南 开始吧。

快速开发工作流程

# 1. Fork and clone
git clone https://github.com/YOUR_USERNAME/tetragon-mcp.git

# 2. Create feature branch
git checkout -b feature/your-feature

# 3. Setup development environment
make dev-setup

# 4. Make changes and test
make test-all

# 5. Submit PR
git push origin feature/your-feature

🙏 致谢