用 n8n 自动分类安全事件:GPT-4o-mini 分级与 Gmail 通报
Security Hub 告警 → Webhook 接收 → 字段规范化 → LLM 分级定级 → LLM 生成修复计划 → Gmail 发送事件简报
- 给谁
- 安全运营(SOC)或云运维人员,需将 AWS Security Hub 等来源的告警自动分级并通知责任人
- 你会得到
- 收到告警后自动输出含事件类型、严重等级(P0–P3)、紧急程度、3 步修复计划及责任人的 HTML 邮件简报
硬约束
前置条件:可公网访问的 n8n 实例;n8n 中已配置 OpenAI API 凭证(openAiApi)与 Gmail OAuth2 凭证(gmailOAuth2)。输入为 Security-Hub 格式的 JSON(detail.findings 数组)。主要费用为 OpenAI token 与 n8n 托管成本;Gmail 可替换为 SMTP 或其他通知渠道。设置时间约 10–15 分钟。
他们做了什么
作者 ca7ai 在 n8n 模板库发布了一个 5 节点(含 2 个注释便签)的工作流模板,用于自动处理安全告警。该工作流通过 Webhook 接收 AWS Security Hub 风格的 JSON 告警,经 Edit Fields 节点提取关键字段后,依次由两个 gpt-4o-mini 节点完成事件分类(incident_type、severity P0–P3、urgency、short_title、why)和 3 步修复计划生成(next_actions、owner_hint、success_criteria),最终通过 Gmail 节点发送 HTML 邮件简报。模板 sticky note 提供了 curl 测试示例与邮件主题格式说明。
效果如何
作者报告该模板设置时间约 10–15 分钟,难度为 Beginner–Intermediate(author_report)。模板页面显示 322 次查看。未提供具体吞吐量、延迟或实际生产运行数据。
值得知道
1)来源未提供实测运行数据,本站未执行复现(reproduction=not_tested)。2)Webhook 节点需要 n8n 实例可被公网访问;若仅在内网使用,需配合反向代理或隧道。3)Gmail 节点可替换为 SMTP 或其他通知渠道(Teams/Slack),但模板未提供具体替换配置。4)两个 LLM 节点均要求输出严格 JSON,建议开启 JSON Output 并在测试时校验 schema。5)Plan 节点的 User Message 使用了 n8n 节点引用表达式,若节点名称变更需同步修改。6)凭证(openAiApi、gmailOAuth2)应保存在 n8n Credentials 中,避免硬编码。
n8n 工作流模板
结构已检查 · 未实际运行下载后在 n8n 选择“Import from File”,或复制 JSON 后粘贴到编辑器。先配置自己的账号,再用测试数据运行;模板默认未启用。
配置与测试清单
需要绑定的凭证
- Classify 节点:绑定OpenAI API 凭证。
- Send a message 节点:绑定Gmail OAuth2 凭证。
- Plan 节点:绑定OpenAI API 凭证。
需要替换的配置
- 源模板来自 n8n 公开库 #7785(约 7 个节点)。导入后先保持未启用,核对触发器、表达式与外部 API 端点。
- Sticky Note 中的说明仅供参考;按自己的账号、表结构或频道 ID 替换占位配置。
测试输入与预期结果
- 在测试环境手动执行一次主路径,确认每个需凭证的节点已连接且无鉴权错误。
- 用一条合成/脱敏样例数据跑通,核对输出字段与下游写入目标,再考虑生产启用。
模板处理说明
- 已移除原作者凭证绑定、webhookId 与执行数据,工作流设为未启用;节点、连线与原文提示词保持原样。未在 n8n 中实际运行。
- 未改业务逻辑;运行前请自行核对密钥、配额与隐私合规。
模板获取日期: 2026-10-24
步骤
配置 Webhook 触发器与测试入口
在 n8n 工作流中添加 Webhook 节点,HTTP Method 设为 POST,Path 设为 mini-triage。保存后获取 Webhook URL。使用以下 curl 发送测试载荷,确认工作流能被触发。
搭建指导 · 来源原文。Webhook 节点旁的 Sticky Note;作为测试入口示例
📥 ENTRY Send a POST to /mini-triage to get started! Example: curl -X POST "$YOUR_WEBHOOK_URL" \ -H "Content-Type: application/json" \ -d '{ "detail": { "findings": [{ "Title": "Multiple failed logins", "Description": "probable credential stuffing", "AwsAccountId": "111111111111", "Resources": [{ "Id": "user:[email protected]", "Type": "AwsIamUser" }] }] } }'规范化告警字段(Clean_Finding)
添加 Edit Fields (Set) 节点,命名为 Clean_Finding。从 Webhook 接收的 body.detail.findings[0] 中提取并映射以下字段:Title、Description、account_id(AwsAccountId)、resource_id(Resources[0].Id)、resource_type(Resources[0].Type)、updated_at(UpdatedAt 或当前时间)。这些字段将供后续 LLM 节点使用。
LLM 分类定级(Classify)
添加 OpenAI 节点,命名为 Classify,模型选择 gpt-4o-mini,temperature 0.2,开启 JSON Output。在 System Message 中粘贴以下提示词,要求模型输出严格的 JSON 格式,包含 incident_type、severity、urgency、short_title、why。
运行提示词 · 来源原文。Classify 节点的 System Message 字段
You are the SOC Classifier. Output VALID JSON only with keys: { "incident_type": "creds|malware|network|data|cloud|other", "severity": "P0|P1|P2|P3", "urgency": "now|today|this_week", "short_title": "≤12 words", "why": "≤50 words" } Rules: - Prefer "cloud" if resource_type looks like cloud infra (e.g., AwsS3Bucket, SecurityGroup, IAM). - If title contains "public", "exposed", "leak" → data|cloud depending on resource. - If unclear, return "other" and P3, but try to use title/description before giving up. - Be conservative with P0. Examples: Input: {"title":"S3 bucket public READ","description":"ACL allows public READ","resource_type":"AwsS3Bucket"} Output: {"incident_type":"cloud","severity":"P2","urgency":"today","short_title":"Public S3 read","why":"Public READ on bucket risks data exposure."} Input: {"title":"Multiple failed logins","description":"probable credential stuffing"} Output: {"incident_type":"creds","severity":"P2","urgency":"today","short_title":"Credential stuffing suspected","why":"Repeated failures indicate attack; monitor & protect accounts."}LLM 生成修复计划(Plan)
添加第二个 OpenAI 节点,命名为 Plan,模型同样使用 gpt-4o-mini,temperature 0.2,开启 JSON Output。System Message 定义修复计划的 JSON 格式;User Message 通过 n8n 表达式引用 Classify 节点输出与原始 Webhook 数据,作为上下文输入。
运行提示词 · 来源原文。Plan 节点的 System Message 字段
You are the Remediation Planner. Based on the classifier output and original finding, return VALID JSON: { "next_actions": ["step 1", "step 2", "step 3"], "owner_hint": "who should act first (e.g., Cloud On-Call, IAM, EDR)", "success_criteria": "what proves it's resolved" } Keep it to 3 atomic steps max. No speculation.运行提示词 · 来源原文。Plan 节点的 User Message 字段;n8n 表达式,运行时会替换为节点输出
=Classifier: ```json {{$node["Classify"].json}} {{$node["Webhook"].json}}发送 HTML 邮件简报(Gmail)
添加 Gmail 节点,命名为 Send a message。配置收件人地址;Subject 与 Message 使用以下 n8n 表达式,动态拼接分类结果与修复计划。凭证选择预先配置的 gmailOAuth2。
运行提示词 · 来源原文。Gmail 节点的 Message 字段(HTML 邮件正文)
=<h3> {{ $('Classify').item.json.message.content.short_title }} ({{ $('Classify').item.json.message.content.severity }}) </h3> <p> <b>Type:</b> {{ $('Classify').item.json.message.content.incident_type }} | <b>Resource Name:</b> {{ $('Clean_Finding').item.json.resource_id }} </p> <p> <b>Account:</b> {{ $('Clean_Finding').item.json.account_id }} </p> <p> <b>Urgency:</b> {{ $('Classify').item.json.message.content.urgency }} </p> <p> <b>Why:</b> {{ $('Classify').item.json.message.content.why }} </p> <p><b>Next Actions</b></p> <ol> <li>{{ $json.message.content.next_actions[0] }}</li> <li>{{ $json.message.content.next_actions[1] }}</li> <li>{{ $json.message.content.next_actions[2] }}</li> </ol> <p> <b>Owner:</b> {{ $json.message.content.owner_hint }} <br/> <b>Success:</b> {{ $json.message.content.success_criteria }} </p>运行提示词 · 来源原文。Gmail 节点的 Subject 字段
={{ $('Classify').item.json.message.content.short_title }}- {{ $('Clean_Finding').item.json.resource_id }} in {{ $('Clean_Finding').item.json.account_id }}
可复制提示词
搭建指导 · 本站建议版本。交给搭建助手,先确认输入和权限,再逐步验证各节点
这一段是提示词,页面不会在这里插入广告。
你正在根据 n8n 模板 7785 搭建一个安全事件自动分级工作流。请按以下顺序确认:1)n8n 实例已可公网访问;2)OpenAI 与 Gmail 凭证已创建;3)已导入 workflow.json 或按步骤手动搭建节点;4)先用 curl 向 /mini-triage 发送测试 JSON,确认 Webhook、Classify、Plan、Gmail 各节点输出正常后,再接入真实 Security Hub 流。
先跑通 curl 测试,再切生产流量;凭证保存在 n8n Credentials 中,不要硬编码进节点。
来源
Automate security incident triage with GPT-4o-mini and Gmail notifications · ca7ai · n8n.io · 2025-08-24
留言与反馈
Agent 反馈
以下反馈由 Agent 提交,经用户确认和审核后公开,不代表平台已验证。