kogunlowo123/terraform-aws-guardduty-ai
GitHub: kogunlowo123/terraform-aws-guardduty-ai
一个将 AWS GuardDuty 与 Amazon Bedrock AI 分析深度集成的 Terraform 模块,实现从威胁检测、智能分类到告警通知和合规归档的全自动化安全运营流水线。
Stars: 0 | Forks: 0
# terraform-aws-guardduty-ai
用于部署 **AWS GuardDuty 与 AI 增强威胁检测** 的 Terraform 模块。该模块配置了一个包含所有保护计划的 GuardDuty detector,一个使用 Amazon Bedrock 分析调查结果的 AI 驱动分类管道,EventBridge 路由,SNS 告警,Security Hub 集成,以及基于 S3 的调查结果归档。
## 架构
```
graph TB
subgraph Detection["GuardDuty Detection"]
style Detection fill:#232F3E,color:#FF9900,stroke:#FF9900
GD["GuardDuty Detector"]
S3P["S3 Protection"]
EKSP["EKS Protection"]
MALP["Malware Protection"]
RDSP["RDS Protection"]
LAMP["Lambda Protection"]
RUNM["Runtime Monitoring"]
end
subgraph EventRouting["Event Routing"]
style EventRouting fill:#1A3A5C,color:#48C9B0,stroke:#48C9B0
EB["EventBridge Rule"]
end
subgraph AiTriage["AI Triage Pipeline"]
style AiTriage fill:#3C1361,color:#AF7AC5,stroke:#AF7AC5
LF["Lambda Function\n(AI Triage)"]
BR["Amazon Bedrock\n(Foundation Model)"]
end
subgraph Alerting["Alerting & Notification"]
style Alerting fill:#7B241C,color:#F1948A,stroke:#F1948A
SNS["SNS Topic"]
EMAIL["Email / PagerDuty / Slack"]
end
subgraph Archival["Findings Archival"]
style Archival fill:#1B4332,color:#82E0AA,stroke:#82E0AA
S3["S3 Bucket"]
GLACIER["Glacier\n(Lifecycle)"]
end
subgraph SecurityHub["Security Hub"]
style SecurityHub fill:#0D3B66,color:#5DADE2,stroke:#5DADE2
SH["Security Hub"]
SHP["GuardDuty\nProduct Subscription"]
end
subgraph MultiAccount["Multi-Account"]
style MultiAccount fill:#4A235A,color:#D2B4DE,stroke:#D2B4DE
MA1["Member Account 1"]
MA2["Member Account N"]
end
GD --> S3P
GD --> EKSP
GD --> MALP
GD --> RDSP
GD --> LAMP
GD --> RUNM
GD -->|"Finding Event"| EB
EB -->|"Route"| LF
EB -->|"Route"| SNS
LF -->|"Invoke Model"| BR
LF -->|"Enriched Alert"| SNS
SNS --> EMAIL
GD -->|"Export"| S3
S3 -->|"Lifecycle"| GLACIER
GD --> SH
SH --> SHP
MA1 -->|"Member"| GD
MA2 -->|"Member"| GD
```
## 文档
- [什么是 Amazon GuardDuty?](https://docs.aws.amazon.com/guardduty/latest/ug/what-is-guardduty.html)
- [修复 GuardDuty 调查结果](https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_remediate.html)
- [Terraform aws_guardduty_detector 资源](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/guardduty_detector)
## 前置条件
1. **Terraform** >= 1.5.0
2. **AWS Provider** >= 5.40.0
3. **AWS CLI** 已配置具有 GuardDuty、Security Hub、EventBridge、Lambda、S3、SNS、IAM 和 CloudWatch 权限的凭证。
4. 已为选定的 `bedrock_model_id` 启用 **Amazon Bedrock 模型访问**(仅在 `enable_ai_triage = true` 时需要)。
5. GuardDuty 不得已在目标账户和区域中启用(每个账户每个区域只允许一个 detector)。
6. 如果使用 Security Hub,它不得已在目标账户/区域中启用。
## 使用示例
```
module "guardduty_ai" {
source = "github.com/kogunlowo123/terraform-aws-guardduty-ai"
detector_name = "prod-security"
# Protection plans
enable_s3_protection = true
enable_eks_protection = true
enable_malware_protection = true
enable_rds_protection = true
enable_lambda_protection = true
enable_runtime_monitoring = true
# Findings configuration
finding_publishing_frequency = "FIFTEEN_MINUTES"
# AI triage
enable_ai_triage = true
bedrock_model_id = "anthropic.claude-3-sonnet-20240229-v1:0"
# Security Hub
enable_security_hub = true
# Filters - auto-archive known benign patterns
filter_criteria = [
{
name = "archive-dns-benign"
description = "Archive low-severity DNS findings from known services"
action = "ARCHIVE"
rank = 1
criterion = [
{
field = "severity"
less_than = "4"
},
{
field = "type"
equals = ["Recon:EC2/Portscan"]
}
]
}
]
# Multi-account (optional)
member_accounts = [
{
account_id = "111111111111"
email = "security-dev@example.com"
},
{
account_id = "222222222222"
email = "security-staging@example.com"
}
]
tags = {
Environment = "production"
Team = "security"
ManagedBy = "terraform"
}
}
```
## 部署指南
### 步骤 1 -- 准备环境
```
git clone https://github.com/kogunlowo123/terraform-aws-guardduty-ai.git
cd terraform-aws-guardduty-ai
aws sts get-caller-identity
```
### 步骤 2 -- 启用 Bedrock 模型访问(如果使用 AI 分类)
打开 [Amazon Bedrock 控制台](https://console.aws.amazon.com/bedrock/) 并为 `bedrock_model_id` 中指定的 foundation model 请求访问权限。
### 步骤 3 -- 创建 Terraform 配置
在工作目录中创建一个调用此模块的 `main.tf`(请参阅上面的使用示例)。
### 步骤 4 -- 初始化并规划
```
terraform init
terraform plan -out=tfplan
```
仔细审查计划。确认 GuardDuty 尚未在目标账户/区域中启用。
### 步骤 5 -- 应用
```
terraform apply tfplan
```
### 步骤 6 -- 订阅 SNS 通知
应用完成后,将您的告警端点订阅到 SNS topic:
```
aws sns subscribe \
--topic-arn \
--protocol email \
--notification-endpoint security-team@example.com
```
### 步骤 7 -- 验证 Detector
```
aws guardduty list-detectors
aws guardduty get-detector --detector-id
```
### 步骤 8 -- 生成测试调查结果
```
aws guardduty create-sample-findings \
--detector-id \
--finding-types "Recon:EC2/PortProbeUnprotectedPort"
```
检查您的 SNS 订阅和 CloudWatch Logs 以获取 AI 增强的分析。
## 输入
| 名称 | 描述 | 类型 | 默认值 | 必需 |
|------|-------------|------|---------|----------|
| `detector_name` | 用于命名相关资源的逻辑名称 | `string` | n/a | 是 |
| `enable_s3_protection` | 启用 S3 保护 | `bool` | `true` | 否 |
| `enable_eks_protection` | 启用 EKS 审计日志监控 | `bool` | `true` | 否 |
| `enable_malware_protection` | 启用 EBS 恶意软件保护 | `bool` | `true` | 否 |
| `enable_rds_protection` | 启用 RDS 登录活动监控 | `bool` | `true` | 否 |
| `enable_lambda_protection` | 启用 Lambda 网络活动监控 | `bool` | `true` | 否 |
| `enable_runtime_monitoring` | 启用运行时监控 | `bool` | `true` | 否 |
| `publishing_destination_bucket` | 用于导出调查结果的 S3 bucket 名称(如果为空则自动创建) | `string` | `""` | 否 |
| `finding_publishing_frequency` | 发布频率 (FIFTEEN_MINUTES, ONE_HOUR, SIX_HOURS) | `string` | `"FIFTEEN_MINUTES"` | 否 |
| `filter_criteria` | 自定义 GuardDuty 过滤器配置列表 | `list(object)` | `[]` | 否 |
| `enable_ai_triage` | 通过 Lambda 和 Bedrock 启用 AI 驱动的分类 | `bool` | `true` | 否 |
| `bedrock_model_id` | 用于 AI 分类的 Bedrock 模型 ID | `string` | `"anthropic.claude-3-sonnet-20240229-v1:0"` | 否 |
| `sns_topic_name` | 用于告警的 SNS topic 名称(如果为空则自动生成) | `string` | `""` | 否 |
| `enable_security_hub` | 启用 Security Hub 并订阅 GuardDuty | `bool` | `true` | 否 |
| `member_accounts` | 成员账户配置列表 | `list(object)` | `[]` | 否 |
| `lambda_log_retention_days` | CloudWatch 日志保留天数 | `number` | `30` | 否 |
| `lambda_timeout` | Lambda 函数超时时间(秒) | `number` | `120` | 否 |
| `lambda_memory_size` | Lambda 函数内存 (MB) | `number` | `512` | 否 |
| `findings_archive_lifecycle_days` | 转换到 Glacier 前的天数 | `number` | `90` | 否 |
| `tags` | 所有资源的标签映射 | `map(string)` | `{}` | 否 |
## 输出
| 名称 | 描述 |
|------|-------------|
| `detector_id` | GuardDuty detector 的 ID |
| `detector_arn` | GuardDuty detector 的 ARN |
| `security_hub_arn` | Security Hub 账户的 ARN(如果已启用) |
| `eventbridge_rule_arn` | EventBridge 规则的 ARN |
| `lambda_function_arn` | AI 分类 Lambda 的 ARN(如果已启用) |
| `sns_topic_arn` | SNS topic 的 ARN |
| `s3_bucket_arn` | 调查结果归档 S3 bucket 的 ARN |
| `s3_bucket_name` | 调查结果归档 S3 bucket 的名称 |
| `lambda_role_arn` | Lambda 执行角色的 ARN(如果已启用) |
| `cloudwatch_log_group_name` | CloudWatch 日志组名称(如果已启用) |
## 许可证
MIT 许可证。详见 [LICENSE](LICENSE)。
标签:AI 安全, Amazon Bedrock, AMSI绕过, AWS, CISA项目, DevSecOps, DLL 劫持, DPI, EC2, ECS, EKS 安全, EventBridge, GuardDuty, IaC, JSONLines, Lambda, RDS 保护, S3 归档, Security Hub, SNS 通知, SOAR, Terraform, 上游代理, 云端安全, 人工智能安全, 合规性, 多账户管理, 大语言模型, 威胁检测, 安全警报, 开源模块, 恶意软件防护, 漏斗分析, 漏洞探索, 生成式 AI, 运行时监控, 速率限制, 零信任