返回市场
接入层-MCP

接入层-MCP

作者:kebabmane2 星标更新:2025-06-25

项目介绍

技术文档摘要

Amazon Security Lake MCP 服务器

这是一个使用 AWS Athena 查询 Amazon Security Lake 数据的 MCP(模型上下文协议)服务器。该服务器提供了对存储在 Security Lake 中的 OCSF 标准化安全数据的结构化访问,使 AI 助手和应用程序能够搜索 IP 地址、GuardDuty 发现,并探索可用的数据源。

特性

  • IP 地址搜索:跨 Security Lake 数据源(源和目标)搜索 IP 地址
  • GuardDuty 发现:按 ID、严重性和类型过滤查询 GuardDuty 安全发现
  • 数据源发现:列出并分析可用的 Security Lake 数据源和表
  • OCSF 合规性:内置 OCSF(开放网络安全架构框架)模式验证
  • AWS 集成:与 AWS Athena、S3 和 IAM 的无缝集成
  • 安全第一:输入验证、查询净化和最小权限访问

要求

  • Python 3.10 或更高版本
  • 已配置 Amazon Security Lake 的 AWS 账户
  • 配置的 AWS 凭据(IAM 角色、配置文件或环境变量)
  • 对 AWS Athena 和 Security Lake 数据库的访问权限

安装

方案 1:使用 pip(推荐)

pip install amazon-security-lake-mcp

方案 2:从源代码安装

git clone <repository-url>
cd amazon-security-lake-mcp
pip install -e .

方案 3:使用 Docker

docker build -t amazon-security-lake-mcp .
docker run -it amazon-security-lake-mcp

配置

自动资源发现(推荐)

MCP 服务器可以自动发现您的 Security Lake 资源!只需配置您的 AWS 凭据,服务器将找到:

  • 用于 Athena 查询结果的 Security Lake S3 存储桶
  • Security Lake Glue 数据库名称
  • 适当的 IAM 权限和配置

最小配置:

# 只需提供 AWS 区域以启用自动发现
export ASL_MCP_AWS_REGION="us-east-1"
export ASL_MCP_AWS_PROFILE="your-aws-profile"  # 如果使用默认凭据则可选

测试发现:

# 安装后测试资源发现
python -c "
from asl_mcp_server.aws.discovery import AWSResourceDiscovery
discovery = AWSResourceDiscovery('us-east-1')
print(discovery.get_discovery_summary())
"

手动配置

如果您偏好手动配置或自动发现失败:

# 必需
export ASL_MCP_ATHENA_OUTPUT_LOCATION="s3://your-athena-results-bucket/path/"

# 可选(有默认值)
export ASL_MCP_AWS_REGION="us-east-1"
export ASL_MCP_AWS_PROFILE="your-aws-profile"
export ASL_MCP_SECURITY_LAKE_DATABASE="amazon_security_lake_glue_db"
export ASL_MCP_ATHENA_WORKGROUP="primary"
export ASL_MCP_AUTO_DISCOVER_RESOURCES="false"  # 禁用自动发现
export ASL_MCP_LOG_LEVEL="INFO"
export ASL_MCP_MAX_QUERY_RESULTS="1000"
export ASL_MCP_QUERY_TIMEOUT_SECONDS="300"

配置文件

在项目目录中创建一个 .env 文件:

# 最小配置(启用自动发现)
ASL_MCP_AWS_REGION=us-east-1
ASL_MCP_AWS_PROFILE=security-lake-user

# 或完整的手动配置
ASL_MCP_ATHENA_OUTPUT_LOCATION=s3://my-athena-results/
ASL_MCP_AWS_REGION=us-east-1
ASL_MCP_SECURITY_LAKE_DATABASE=amazon_security_lake_glue_db
ASL_MCP_AUTO_DISCOVER_RESOURCES=false
ASL_MCP_LOG_LEVEL=INFO

AWS 权限

MCP 服务器需要以下 AWS 权限:

{
  "Version": "2012-10-17",
  "Statement": [
    {
      "Effect": "Allow",
      "Action": [
        "athena:StartQueryExecution",
        "athena:GetQueryExecution",
        "athena:GetQueryResults",
        "athena:ListDataCatalogs",
        "athena:ListDatabases",
        "athena:ListTableMetadata"
      ],
      "Resource": "*"
    },
    {
      "Effect": "Allow",
      "Action": [
        "s3:GetObject",
        "s3:ListBucket",
        "s3:PutObject"
      ],
      "Resource": [
        "arn:aws:s3:::aws-security-data-lake-*",
        "arn:aws:s3:::aws-security-data-lake-*/*",
        "arn:aws:s3:::your-athena-results-bucket",
        "arn:aws:s3:::your-athena-results-bucket/*"
      ]
    },
    {
      "Effect": "Allow",
      "Action": [
        "glue:GetDatabase",
        "glue:GetTable",
        "glue:GetPartitions"
      ],
      "Resource": "*"
    }
  ]
}

使用

与 Claude Desktop 集成

要将此 MCP 服务器与 Claude Desktop 结合使用,您需要在 Claude Desktop 的设置中进行配置。

步骤 1:安装 MCP 服务器

选项 A:使用 pipx(推荐用于 Claude Desktop)

# 如果没有 pipx,请安装它
brew install pipx  # macOS
# 或:pip install --user pipx  # 其他系统

# 全局安装 MCP 服务器
pipx install amazon-security-lcp

# 或从源代码安装
git clone <repository-url>
cd amazon-security-lake-mcp
pipx install -e .

选项 B:使用 pip 和虚拟环境

# 创建虚拟环境
python3 -m venv asl-mcp-env
source asl-mcp-env/bin/activate  # Linux/macOS
# 或:asl-mcp-env\Scripts\activate  # Windows

# 安装包
pip install amazon-security-lake-mcp

查找已安装命令路径:

# 对于 pipx 安装
which asl-mcp-server
# 典型输出:/Users/username/.local/bin/asl-mcp-server

# 对于 pip 安装在 venv 中
which asl-mcp-server  # (激活 venv 后)

步骤 2:配置 Claude Desktop

将 MCP 服务器添加到您的 Claude Desktop 配置中。配置文件的位置取决于您的操作系统:

  • macOS~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows%APPDATA%\Claude\claude_desktop_config.json
  • Linux~/.config/Claude/claude_desktop_config.json

选项 A:使用命令的完整路径(推荐)

{
  "mcpServers": {
    "amazon-security-lake": {
      "command": "/Users/username/.local/bin/asl-mcp-server",
      "env": {
        "ASL_MCP_AWS_REGION": "us-east-1",
        "ASL_MCP_AWS_PROFILE": "your-aws-profile",
        "ASL_MCP_LOG_LEVEL": "INFO"
      }
    }
  }
}

替换 /Users/username/.local/bin/asl-mcp-server 为实际路径 which asl-mcp-server 输出

选项 B:使用 Python 模块(最可靠)

{
  "mcpServers": {
    "amazon-security-lake": {
      "command": "/opt/homebrew/bin/python3",
      "args": ["-m", "asl_mcp_server.server"],
      "cwd": "/path/to/amazon-security-lake-mcp",
      "env": {
        "ASL_MCP_AWS_REGION": "us-east-1",
        "ASL_MCP_AWS_PROFILE": "your-aws-profile",
        "PYTHONPATH": "/path/to/amazon-security-lake-mcp/src",
        "ASL_MCP_LOG_LEVEL": "INFO"
      }
    }
  }
}

选项 C:使用 Python 路径(如果未全局安装)

{
  "mcpServers": {
    "amazon-security-lake": {
      "command": "python",
      "args": ["-m", "asl_mcp_server.server"],
      "cwd": "/path/to/amazon-security-lake-mcp",
      "env": {
        "ASL_MCP_AWS_REGION": "us-east-1",
        "ASL_MCP_AWS_PROFILE": "your-aws-profile"
      }
    }
  }
}

步骤 3:重启 Claude Desktop

保存配置文件后,完全重启 Claude Desktop(退出并重新启动应用程序)。

步骤 4:验证连接

在 Claude Desktop 中,您可以现在询问如下问题:

  • “你能发现我的 Security Lake 资源吗?”
  • “在我的安全数据中搜索 IP 地址 192.168.1.100”
  • “显示我最近的高严重性 GuardDuty 发现”
  • “我的 Security Lake 中有哪些数据源?”

示例 Claude Desktop 对话

用户:你能帮我调查我在 AWS 环境中的安全事件吗?

Claude:我可以使用您的 Amazon Security Lake 数据来帮助您调查安全事件!让我先发现您的 Security Lake 资源,然后我们可以搜索特定的指标。

[Claude 使用 discover_aws_resources 工具]

我发现您的 Security Lake 设置如下:
- 数据库:amazon_security_lake_glue_db_us_east_1
- 区域:us-east-1
- Athena 结果:s3://aws-athena-query-results-123456789012-us-east-1/

您想调查什么?我可以:
1. 搜索特定的 IP 地址
2. 查找 GuardDuty 发现
3. 显示可用的数据源
4. 按时间段或严重级别搜索

用户:搜索与 IP 地址 203.0.113.45 相关的任何活动

Claude:[使用 search_ip_addresses 工具查询 Security Lake 数据]

我找到了涉及 IP 203.0.113.45 的 3 个安全事件:
...

生产使用的高级 Claude Desktop 配置

考虑这些额外配置:

环境特定配置:

{
  "mcpServers": {
    "security-lake-prod": {
      "command": "asl-mcp-server",
      "env": {
        "ASL_MCP_AWS_REGION": "us-east-1",
        "ASL_MCP_AWS_PROFILE": "prod-security-readonly",
        "ASL_MCP_MAX_QUERY_RESULTS": "500",
        "ASL_MCP_QUERY_TIMEOUT_SECONDS": "180"
      }
    },
    "security-lake-dev": {
      "command": "asl-mcp-server",
      "env": {
        "ASL_MCP_AWS_REGION": "us-west-2",
        "ASL_MCP_AWS_PROFILE": "dev-security",
        "ASL_MCP_LOG_LEVEL": "DEBUG"
      }
    }
  }
}

单独运行 MCP 服务器

您也可以单独运行服务器进行测试:

# 使用已安装的命令
asl-mcp-server

# 或使用 Python 模块
python -m asl_mcp_server.server

可用工具

1. 搜索 IP 地址

在 Security Lake 数据中搜索 IP 地址:

{
  "tool": "search_ip_addresses",
  "arguments": {
    "ip_address": "192.168.1.100",
    "start_time": "2024-01-15T00:00:00Z",
    "end_time": "2024-01-15T23:59:59Z",
    "sources": ["guardduty", "cloudtrail"],
    "limit": 100
  }
}

参数:

  • ip_address(必需):要搜索的 IP 地址(IPv4 或 IPv6)
  • start_time(可选):ISO 格式的开始时间(默认:7 天前)
  • end_time(可选):ISO 格式的结束时间(默认:现在)
  • sources(可选):要搜索的数据源(guardduty、cloudtrail、vpcflow 等)
  • limit(可选):返回的最大结果数(默认:100,最大:1000)

2. 搜索 GuardDuty 发现

查询 GuardDuty 安全发现:

{
  "tool": "search_guardduty_findings",
  "arguments": {
    "finding_id": "12345abc-def0-1234-5678-90abcdef1234",
    "severity": "High",
    "finding_type": "Trojan:EC2/MaliciousIP",
    "start_time": "2024-01-15T00:00:00Z",
    "end_time": "2024-01-15T23:59:59Z",
    "limit": 50
  }
}

参数:

  • finding_id(可选):特定的 GuardDuty 发现 ID
  • severity(可选):严重性级别(Critical、High、Medium、Low、Informational)
  • finding_type(可选):要搜索的发现类型
  • start_time(可选):ISO 格式的开始时间(默认:7 天前)
  • end_time(可选):ISO 格式的结束时间(默认:现在)
  • limit(可选):返回的最大结果数(默认:100,最大:1000)

3. 列出数据源

发现可用的 Security Lake 数据源:

{
  "tool": "list_data_sources",
  "arguments": {
    "include_schema": true
  }
}

参数:

  • include_schema(可选):是否包含详细的表模式信息(默认:false)

4. 发现 AWS 资源

自动发现您 AWS 账户中的 Security Lake 资源:

{
  "tool": "discover_aws_resources",
  "arguments": {}
}

此工具扫描您的 AWS 账户以找到:

  • Security Lake S3 存储桶和数据库
  • Athena 输出位置
  • 配置建议
  • 设置验证

5. 统一安全搜索

智能搜索所有可用的 Security Lake 数据源:

{
  "tool": "universal_security_search",
  "arguments": {
    "query_type": "findings",
    "filters": {
      "severity": "High",
      "start_time": "2024-01-15T00:00:00Z",
      "end_time": "2024-01-15T23:59:59Z"
    },
    "limit": 50
  }
}

查询类型:

  • findings:搜索安全发现(GuardDuty、Security Hub)
  • network:搜索网络活动(VPC 流、DNS、Route53)
  • api_calls:搜索 API 活动(CloudTrail)
  • ip_search:跨所有来源搜索 IP 地址

关键特性:

  • 自动适应可用的数据源
  • 支持 OCSF 1.0 和 2.0 模式
  • 智能回退(例如,对于 GuardDuty 数据使用 Security Hub)
  • 不同来源的统一结果格式

6. 测试连接

验证与 AWS 服务的连接:

{
  "tool": "test_connection",
  "arguments": {}
}

响应格式

所有工具均返回一致的响应格式:

{
  "success": true,
  "error": null,
  "results": [...],
  "metadata": {
    "query_info": {...},
    "summary": {...}
  },
  "count": 10
}

示例响应 - IP 搜索

{
  "success": true,
  "results": [
    {
      "timestamp": "2024-01-15T10:30:00Z",
      "event_type": "网络活动",
      "severity": "中等",
      "ip_context": {
        "角色": "源",
        "方向": "出站"
      },
      "network_info": {
        "源 IP": "192.168.1.100",
        "目标 IP": "203.0.113.45",
        "源端口": 3456,
        "目标端口": 443
      },
      "aws_context": {
        "账户 ID": "123456789012",
        "区域": "us-east-1"
      },
      "product_info": {
        "名称": "VPC 流日志",
        "供应商": "AWS"
      }
    }
  ],
  "metadata": {
    "summary": {
      "总事件数": 1,
      "最常见的事件类型": "网络活动",
      "最高严重性": "中等"
    }
  },
  "count": 1
}

开发

设置开发环境

# 克隆仓库
git clone <repository-url>
cd amazon-security-lake-mcp

# 安装开发依赖
pip install -e ".[dev]"

# 安装 pre-commit 钩子
pre-commit install

运行测试

# 运行所有测试
pytest

# 运行带有覆盖率的测试
pytest --cov=asl_mcp_server --cov-report=html

# 运行特定测试类别
pytest -m unit        # 仅单元测试