AWS安全MCP
 
模型上下文协议(MCP)服务器,使AI助手能够通过自然语言查询执行全面的AWS安全分析。
概述
AWS Security MCP将Claude等AI助手与AWS安全服务连接起来,通过会话查询实现实时基础设施分析。该系统自动发现和分析多个AWS帐户中的资源,提供安全见解,而不需要深入的AWS CLI知识。
关键能力
- 跨帐户发现:自动检测和访问AWS组织帐户
- 自然语言接口:使用简明英语查询AWS资源
- 证券分析:GuardDuty、SecurityHub和Access Analyzer的综合调查结果
- 基础设施测绘:网络拓扑、威胁建模、安全审查和爆炸半径分析
- 日志分析:Athena支持对CloudTrail、VPC流日志和安全事件的分析
先决条件
- python:3.11或更高
- 程序包管理器: 紫外线
- AWS帐户:具有适当的IAM权限
- MCP客户端:Claude Desktop、Cline或兼容客户端
AWS要求
MCP服务器的AWS凭据必须具有以下权限:
核心MCP权限
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "CrossAccountAccess",
"Effect": "Allow",
"Action": [
"sts:AssumeRole"
],
"Resource": "arn:aws:iam::*:role/aws-security-mcp-cross-account-access"
},
{
"Sid": "OrganizationDiscovery",
"Effect": "Allow",
"Action": [
"organizations:ListAccounts"
],
"Resource": "*"
}
]
}Athena集成权限
对于高级日志分析功能,需要额外的权限:
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AthenaQueryExecution",
"Effect": "Allow",
"Action": [
"athena:BatchGetQueryExecution",
"athena:GetQueryExecution",
"athena:GetQueryResults",
"athena:GetWorkGroup",
"athena:GetTableMetadata",
"athena:ListQueryExecutions",
"athena:StartQueryExecution",
"athena:GetQueryResultsStream",
"athena:GetDataCatalog",
"athena:ListDataCatalogs",
"athena:ListDatabases",
"athena:ListTableMetadata"
],
"Resource": "*"
},
{
"Sid": "GlueCatalogAccess",
"Effect": "Allow",
"Action": [
"glue:GetDatabase",
"glue:GetDatabases",
"glue:GetTable",
"glue:GetTables",
"glue:GetPartition",
"glue:GetPartitions",
"glue:BatchGetPartition"
],
"Resource": "*"
},
{
"Sid": "S3LogDataAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket"
],
"Resource": [
"arn:aws:s3:::your-cloudtrail-bucket/*",
"arn:aws:s3:::your-cloudtrail-bucket",
"arn:aws:s3:::your-vpc-flow-logs-bucket/*",
"arn:aws:s3:::your-vpc-flow-logs-bucket",
"arn:aws:s3:::your-security-logs-bucket/*",
"arn:aws:s3:::your-security-logs-bucket"
]
},
{
"Sid": "AthenaResultsAccess",
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:ListBucket",
"s3:PutObject"
],
"Resource": [
"arn:aws:s3:::your-athena-results-bucket/*",
"arn:aws:s3:::your-athena-results-bucket"
]
}
]
}所需的AWS管理策略
安全审计策略(必填)
将AWS管理的SecurityAudit策略附加到MCP服务器的IAM用户或IAM角色:
Policy ARN: arn:aws:iam::aws:policy/SecurityAudit此策略提供对AWS安全服务的全面只读访问 必要的 AWS安全MCP功能。它包括以下权限:
- 国际机械师协会:用户、角色、策略、访问分析
- EC2:安全组、实例、VPC配置
- 第3页:存储桶策略、ACL、公共访问设置
- GuardDuty 的:调查结果、探测器、威胁情报
- SecurityHub:安全标准、合规性调查结果
- 访问分析器:IAM访问分析和结果
- 拉姆达:功能配置和权限
- CloudFront:分发安全设置
- 路线53:DNS配置和健康检查
- 空军:Web ACL规则和配置
- 所有其他与安全相关的AWS服务
可选管理策略
- Athena完全访问:
arn:aws:iam::aws:policy/AmazonAthenaFullAccess(用于简化Athena日志分析)
重要提示
- 最好将此MCP服务器与Claude Desktop Pro/Max Plan或任何其他允许您处理大于100000的令牌大小的平台一起使用
- 将S3权限中的bucket名称替换为实际的CloudTrail、VPC流日志和Athena结果bucket名称
- SecurityAudit策略是 强制性的 用于基本的AWS安全MCP功能
- Athena集成权限是可选的,仅对高级日志分析功能是必需的
- 所有权限都遵循最小权限原则,并在可能的情况下进行只读访问
快速入门~本地设置
- 更新config.yml
aws:
region: "us-east-1"
profile: {profileName}
.
.
.- 通过~local设置配置您的AWS凭据
- aws sso
$ aws configure sso
SSO Session Name - email@example.com
URL - https://yourDomain.awsapps.com/start/#
Region - us-east-1- 环境变量
export AWS_ACCESS_KEY_ID=
export export AWS_SECRET_ACCESS_KEY=
export export AWS_SESSION_TOKEN=- 运行以下命令
git clone https://github.com/groovyBugify/aws-security-mcp.git
uv venv
source .venv/bin/activate
uv pip install -r requirements.txt- 配置MCP客户端
# Install mcp-proxy
uv tool install mcp-proxy
# Check location of mcp-proxy
which mcp-proxy
# Add to Claude Desktop config
{
"mcpServers": {
"aws-security": {
"command": "/path/to/mcp-proxy",
"args": ["http://localhost:8000/sse"]
}
}
}快速入门~作为AWS ECS服务
- 登录AWS ECR
$ aws ecr get-login-password --region {region} | docker login --username AWS --password-stdin {accountID}.dkr.ecr.{region}.amazonaws.com- 创建ECR代表
$ aws ecr create-repository --repository-name aws-security-mcp --region {region}- 构建Docker镜像
$ cd aws-security-mcp/
$ docker buildx build --platform linux/amd64 -t aws-security-mcp .
$ docker tag aws-security-mcp:latest {accountID}.dkr.ecr.{region}.amazonaws.com/aws-security-mcp:latest
$ docker push {accountID}.dkr.ecr.{region}.amazonaws.com/aws-security-mcp:latest- 部署为AWS ECS服务
- 使用“2048”CPU和“4096”内存创建任务定义,这是可选的,您可以选择任何值 - 配置任务定义以对端口8000进行端口映射 - 创建具有以下权限的ECS任务角色 - 安全审计IAM政策 - Athena访问(上述政策) - STS假定角色权限以假定跨帐户角色 - 创建具有基本权限的ECS任务执行角色 - 任务定义完成后。 - 使用任务定义创建AWS ECS服务 - 您也可以配置负载均衡器 - 确保关闭负载平衡器上的粘滞会话 - 注册ALB的taget组和端口80/443的侦听器->ECS服务(8000) - 注册Route53域的ALB。
- 配置MCP客户端
# Install mcp-proxy
uv tool install mcp-proxy
# Check location of mcp-proxy
which mcp-proxy
# Add to Claude Desktop config
{
"mcpServers": {
"aws-security": {
"command": "/path/to/mcp-proxy",
"args": ["http://{alb}/sse"]
}
}
}配置
YAML配置
编辑 config.yaml 根据您的需求,在项目根目录中:
aws:
region: "us-east-1"
profile: null
server:
log_level: "info"
startup_quiet: false
tool_quiet: false
cross_account:
role_name: "aws-security-mcp-cross-account-access"
auto_setup_on_startup: true
max_concurrent_assumptions: 5环境变量覆盖
环境变量优先于YAML配置:
export MCP_LOG_LEVEL=debug
export MCP_STARTUP_QUIET=false
export AWS_DEFAULT_REGION=eu-west-1使用示例
基础架构查询
Query: "Can you share a list of running ec2 instances?"
Query: "Share all the secrets stored on env variables of Lambda functions, and share a list of functions for remediating this issue."
Query: "Check my 'prod-ecs-cluster' and share more details about the 'user-login' service, is it deployed?"证券分析
Query: "Show all GuardDuty findings from the last 7 days, and priortise based on the risk of exposure."
Query: "Analyze IAM roles with administrative privileges"
Query: "Generate blast radius analysis for IP 172.16.1.10"
Query: "Fetch more details about the ip - 172.22.141.11, and share a network map for this resource.跨账户操作
Query: "List all connected AWS accounts"
Query: "Refresh my AWS session"
Query: "Find resources tagged Team:Security across all accounts"
Query: "Show compliance status across organization"建筑
跨帐户访问
AWS Security MCP实现了多帐户访问的中心辐射模型:
- 发现:用途
organizations:ListAccounts识别目标客户 - 角色假设:假设
aws-security-mcp-cross-account-access每个帐户中的角色 - 会话管理:通过自动刷新维护临时凭据
- 后备方案:对非组织帐户使用默认凭据链
所需IAM角色设置
在每个目标AWS帐户中创建此角色:
角色名称: aws-security-mcp-cross-account-access
信任政策:
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::YOUR-MASTER-ACCOUNT-ID:root"
},
"Action": "sts:AssumeRole"
}
]
}权限:附加AWS托管策略 arn:aws:iam::aws:policy/SecurityAudit
雅典娜集成
概述
AWS Security MCP与Amazon Athena集成,提供高级日志分析功能。此功能需要预先存在的包含安全相关日志的Athena表。
支持的日志类型
虽然MCP服务器可以通过Athena分析任何日志源,但建议使用以下源为MCP客户端提供全面的安全元数据。为了获得最佳的安全覆盖,我们建议至少实施CloudTrail和VPC流日志:
推荐日志源:
- AWS CloudTrail:API调用审核和用户活动跟踪
- VPC流日志:网络流量模式分析
- CloudFront日志:CDN请求和响应分析
- ALB访问日志:应用程序负载平衡器流量洞察
- WAF日志:Web应用程序防火墙事件和阻止(Cloudflare/AWS WAF/Akamai)
- AWS屏蔽日志:DDoS保护和缓解事件
自定义日志源的灵活性
MCP服务器支持查询存储在S3中的任何日志类型,使您能够完全灵活地分析自定义或其他日志源。要启用对任何日志源的分析,请确保:
- S3存储:您的日志存储在S3存储桶中
- 雅典娜桌:日志格式存在正确配置的Athena表
- IAM权限:MCP服务器具有
s3:GetObject和s3:ListBucket目标存储桶的权限
此架构允许您将安全分析扩展到标准AWS日志之外,以包括应用程序日志、自定义安全事件或第三方安全工具输出。
查询功能
配置表后,您可以执行高级查询:
Query: "Show all failed login attempts from external IPs in the last 24 hours"
Query: "Can you share what did 'saransh.rana@company.com' did in past 24 hours on my aws account? and share a timeline report?"
Query: "Can you check for all the 'Access Denied/Error/Forbidden' on my PCI(123456789012) aws account and share the username and userIP of the principal, and do a reverse IP checkup if this IP is coming from my own AWS Org or external party."
Query: "Correlate GuardDuty findings with CloudTrail and VPC Flow logs events"设置先决条件
- S3铲斗:CloudTrail和VPC流日志必须存储在S3中
- 雅典娜工作组:使用结果位置配置适当的工作组
- 分区:启用分区投影以提高性能
- IAM权限:向MCP执行角色授予Athena查询权限
支持的AWS服务
当前可用
| 服务 | 能力 |
|---|---|
| 国际机械师协会 | 用户、角色、策略、访问密钥、权限分析 |
| EC2 | 实例、安全组、VPC、子网、网络接口 |
| 第3页 | Bucket、权限、公共访问分析 |
| GuardDuty 的 | 调查结果、探测器、威胁情报 |
| SecurityHub | 调查结果、合规标准、安全评分 |
| 拉姆达 | 功能、权限、配置、触发器 |
| CloudFront | 分布、起源、行为、安全策略 |
| ELB/ALB/NLB | 负载平衡器、目标群体、侦听器、健康检查 |
| 路线53 | 托管区域、DNS记录、健康检查 |
| 空军 | Web ACL、规则、速率限制 |
| 盾 | DDoS保护状态和指标 |
| 访问分析器 | IAM访问分析和结果 |
| ECS/ECR | 容器服务、存储库、图像扫描 |
| 组织 | 账户结构、SCP、组织单位 |
| 雅典娜 | 日志分析、安全事件关联 |
计划添加
- Oauth身份验证
- AWS配置合规性分析
- AWS安全中心CSPM集成
- 外部CSPM集成
高级配置
生产部署
对于生产环境,请使用以下配置:
server:
host: "0.0.0.0"
log_level: "error"
startup_quiet: true
tool_quiet: true
minimal_logging: true
cross_account:
max_concurrent_assumptions: 10
session_duration_seconds: 7200Docker部署
FROM python:3.11-slim
WORKDIR /app
COPY . .
RUN pip install -r requirements.txt
EXPOSE 8000
CMD ["python", "aws_security_mcp/main.py", "sse"]docker build -t aws-security-mcp .
docker run -p 8000:8000 \
-e AWS_ACCESS_KEY_ID=your_key \
-e AWS_SECRET_ACCESS_KEY=your_secret \
aws-security-mcp负载平衡器配置
- 健康检查:
GET /health - SSE端点:
/sse - 超时:至少60秒
- 粘性会话:不需要
故障排除
常见问题
工具发现失败
# Check AWS credentials
aws sts get-caller-identity
# Verify cross-account role exists
aws iam get-role --role-name aws-security-mcp-cross-account-access跨帐户访问被拒绝
# Test role assumption manually
aws sts assume-role \
--role-arn arn:aws:iam::TARGET-ACCOUNT:role/aws-security-mcp-cross-account-access \
--role-session-name test-session性能问题
# Reduce concurrent operations
cross_account:
max_concurrent_assumptions: 3
# Enable minimal logging
server:
minimal_logging: true调试模式
启用详细日志记录以进行故障排除:
export MCP_LOG_LEVEL=debug
export MCP_STARTUP_QUIET=false
python3 aws_security_mcp/main.py sse许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
支持
- 问题:
- 文档: 维基工程
- 安全问题:请私下向维护人员报告

