Citadel-Cloud-Management/terraform-aws-guardduty-ai

GitHub: Citadel-Cloud-Management/terraform-aws-guardduty-ai

该项目是一个 Terraform 模块,用于部署集成 Amazon Bedrock AI 分析能力的 AWS GuardDuty 威胁检测系统,提供自动化分诊、多账户管理及安全中心集成功能。

Stars: 0 | Forks: 0

# terraform-aws-guardduty-ai 用于部署 **AWS GuardDuty 以及 AI 增强威胁检测** 的 Terraform 模块。该模块配置了一个具备所有保护计划的 GuardDuty 检测器,一个利用 Amazon Bedrock 分析发现的 AI 分诊管道,EventBridge 路由,SNS 告警,Security Hub 集成,以及基于 S3 的发现归档。 ## Architecture(架构) ``` 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 ``` ## Documentation(文档) - [什么是 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) ## Prerequisites(前置条件) 1. **Terraform** >= 1.5.0 2. **AWS Provider** >= 5.40.0 3. **AWS CLI** 已配置,且凭证拥有 GuardDuty、Security Hub、EventBridge、Lambda、S3、SNS、IAM 和 CloudWatch 的权限。 4. **Amazon Bedrock 模型访问权限**已为所选的 `bedrock_model_id` 启用(仅在 `enable_ai_triage = true` 时需要)。 5. GuardDuty 尚未在目标账户和区域中启用(每个账户每个区域仅允许一个检测器)。 6. 如果使用 Security Hub,则不得已在目标账户/区域中启用。 ## Usage Example(使用示例) ``` 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" } } ``` ## Deployment Guide(部署指南) ### Step 1 -- Prepare the Environment(准备环境) ``` git clone https://github.com/kogunlowo123/terraform-aws-guardduty-ai.git cd terraform-aws-guardduty-ai aws sts get-caller-identity ``` ### Step 2 -- Enable Bedrock Model Access (if using AI triage)(启用 Bedrock 模型访问权限,如使用 AI 分诊) 打开 [Amazon Bedrock 控制台](https://console.aws.amazon.com/bedrock/) 并为 `bedrock_model_id` 中指定的基础模型申请访问权限。 ### Step 3 -- Create a Terraform Configuration(创建 Terraform 配置) 在工作目录中创建一个 `main.tf` 来调用此模块(参见上面的使用示例)。 ### Step 4 -- Initialize and Plan(初始化与计划) ``` terraform init terraform plan -out=tfplan ``` 仔细检查计划。确认 GuardDuty 尚未在目标账户/区域中启用。 ### Step 5 -- Apply(应用) ``` terraform apply tfplan ``` ### Step 6 -- Subscribe to SNS Notifications(订阅 SNS 通知) 应用完成后,将您的告警端点订阅到 SNS 主题: ``` aws sns subscribe \ --topic-arn \ --protocol email \ --notification-endpoint security-team@example.com ``` ### Step 7 -- Verify the Detector(验证检测器) ``` aws guardduty list-detectors aws guardduty get-detector --detector-id ``` ### Step 8 -- Generate a Test Finding(生成测试发现) ``` aws guardduty create-sample-findings \ --detector-id \ --finding-types "Recon:EC2/PortProbeUnprotectedPort" ``` 检查您的 SNS 订阅和 CloudWatch Logs 中的 AI 丰富分析内容。 ## Inputs(输入参数) | Name | Description | Type | Default | Required | |------|-------------|------|---------|----------| | `detector_name` | 用于命名相关资源的逻辑名称 | `string` | n/a | yes | | `enable_s3_protection` | 启用 S3 保护 | `bool` | `true` | no | | `enable_eks_protection` | 启用 EKS 审计日志监控 | `bool` | `true` | no | | `enable_malware_protection` | 为 EBS 启用恶意软件保护 | `bool` | `true` | no | | `enable_rds_protection` | 启用 RDS 登录活动监控 | `bool` | `true` | no | | `enable_lambda_protection` | 启用 Lambda 网络活动监控 | `bool` | `true` | no | | `enable_runtime_monitoring` | 启用运行时监控 | `bool` | `true` | no | | `publishing_destination_bucket` | 用于导出发现的 S3 存储桶名称(如果为空则自动创建) | `string` | `""` | no | | `finding_publishing_frequency` | 发布频率 (FIFTEEN_MINUTES, ONE_HOUR, SIX_HOURS) | `string` | `"FIFTEEN_MINUTES"` | no | | `filter_criteria` | 自定义 GuardDuty 过滤器配置列表 | `list(object)` | `[]` | no | | `enable_ai_triage` | 通过 Lambda 和 Bedrock 启用 AI 驱动的分诊 | `bool` | `true` | no | | `bedrock_model_id` | 用于 AI 分诊的 Bedrock 模型 ID | `string` | `"anthropic.claude-3-sonnet-20240229-v1:0"` | no | | `sns_topic_name` | 用于告警的 SNS 主题名称(如果为空则自动生成) | `string` | `""` | no | | `enable_security_hub` | 启用带有 GuardDuty 订阅的 Security Hub | `bool` | `true` | no | | `member_accounts` | 成员账户配置列表 | `list(object)` | `[]` | no | | `lambda_log_retention_days` | CloudWatch 日志保留天数 | `number` | `30` | no | | `lambda_timeout` | Lambda 函数超时时间(秒) | `number` | `120` | no | | `lambda_memory_size` | Lambda 函数内存(MB) | `number` | `512` | no | | `findings_archive_lifecycle_days` | 转换到 Glacier 之前的天数 | `number` | `90` | no | | `tags` | 所有资源的标签映射 | `map(string)` | `{}` | no | ## Outputs(输出值) | Name | Description | |------|-------------| | `detector_id` | GuardDuty 检测器的 ID | | `detector_arn` | GuardDuty 检测器的 ARN | | `security_hub_arn` | Security Hub 账户的 ARN(如果启用) | | `eventbridge_rule_arn` | EventBridge 规则的 ARN | | `lambda_function_arn` | AI 分诊 Lambda 的 ARN(如果启用) | | `sns_topic_arn` | SNS 主题的 ARN | | `s3_bucket_arn` | 发现归档 S3 存储桶的 ARN | | `s3_bucket_name` | 发现归档 S3 存储桶的名称 | | `lambda_role_arn` | Lambda 执行角色的 ARN(如果启用) | | `cloudwatch_log_group_name` | CloudWatch 日志组名称(如果启用) | ## License(许可证) MIT License。详见 [LICENSE](LICENSE)。
标签:AI安全, Amazon Bedrock, AMSI绕过, AWS, Chat Copilot, CISA项目, DevSecOps, DPI, ECS, EKS保护, EventBridge, GuardDuty, IP 地址批量处理, Lambda, RDS保护, S3, Security Hub, SNS, Terraform, 上游代理, 勒索软件检测, 多账户管理, 威胁情报, 威胁检测, 开发者工具, 日志归档, 漏洞探索, 自动化分诊, 运行时监控, 速率限制