Skip to content

feat: add m01 (网哨M01) mail gateway threat-intelligence service#154

Open
K6gg wants to merge 1 commit into
chaitin:mainfrom
K6gg:feat/add-m01-intelligence-service
Open

feat: add m01 (网哨M01) mail gateway threat-intelligence service#154
K6gg wants to merge 1 commit into
chaitin:mainfrom
K6gg:feat/add-m01-intelligence-service

Conversation

@K6gg

@K6gg K6gg commented Jun 24, 2026

Copy link
Copy Markdown

Closes #137

接入设备

网哨 M01 邮件安全网关 — 本地威胁情报(情报漏洞资产)。服务包 services/m01__intelligence,proto 包 M01_Intelligence

设备版本

产品「全量 API 文档」(OpenAPI 3.0.1),/m01/intelligence/* 路由。

认证方式

  • x-api-key(ApiKeyAuth,主)secret.apiKey,以 x-api-key: <key> 头发送。
  • Bearer JWT(备)secret.apiToken,无 apiKey 时以 Authorization: Bearer <token> 发送。

实现方法

方式:RPC(gRPC,6 个方法)

方法 类型 端点 说明
DetectIntelligence POST /m01/intelligence/detection IOC 批量查询(核心);queries[] 各含 pattern/type/request_id
ListIntelligence POST /m01/intelligence/list 分页 + 多条件/时间范围过滤
AddIntelligence POST /m01/intelligence/add 批量添加;必填 tlp/urgency/attribute/pattern;返回成功/失败明细
UpdateIntelligence POST /m01/intelligence/update 按 id 批量改
DeleteIntelligence POST /m01/intelligence/delete 批量删除
GetIntelligenceStats GET /m01/intelligence/stats total / active / revoked
  • 上游 {code,msg,data} 信封统一解封;枚举(tlp/urgency/attribute/status/type)在 handler 侧校验。
  • 错误映射:参数/枚举错误→INVALID_ARGUMENT,401/403 或信封 code 401/403→PERMISSION_DENIED,4xx 或信封 code 400→FAILED_PRECONDITION,5xx/网络→UNAVAILABLE,非 JSON→UNKNOWN
  • 写操作声明默认参数(add status 默认 active)、幂等语义(add 按 pattern 去重 / update 按 id / delete 缺失幂等)、回滚方式(Add⇄Delete)和审计字段(x-request-id / x-engine-instance)。

测试命令

cd services
npm run validate -- --service-dir m01__intelligence   # service package naming checks passed
npm test -- --service-dir m01__intelligence            # 31/31 pass(行 100% / 分支 90%)
npm run pack:check                                     # ok

已知限制

  1. 仅覆盖本地威胁情报域;邮件深度检测 / 沙箱 / SMTP 过滤等其它域未纳入本包。
  2. 枚举以 string 透传 + handler 校验(未用 proto enum)。
  3. info / records 等多态结构以 google.protobuf.Struct 原样透传。
  4. 列表未做自动翻页(由调用方传 page/page_size 控制)。

真实设备验证

待补:在测试网关用 disposable indicator 执行以下闭环并附截图。

# 1) 统计(只读,确认连通与鉴权)
curl "https://<host>/m01/intelligence/stats" -H "x-api-key: <key>"
# -> {"code":200,"msg":"ok","data":{"total":N,"active_count":..,"revoked_count":..}}

# 2) 添加一条测试情报(写入测试对象)
curl -X POST "https://<host>/m01/intelligence/add" -H "x-api-key: <key>" -H "Content-Type: application/json" \
  -d '[{"pattern":"evil.example.test","tlp":"RED","urgency":"high","attribute":"url-domain"}]'

# 3) 检测命中
curl -X POST "https://<host>/m01/intelligence/detection" -H "x-api-key: <key>" -H "Content-Type: application/json" \
  -d '[{"pattern":"evil.example.test","type":"url-domain","request_id":"verify-1"}]'

# 4) 删除(清理测试对象)
curl -X POST "https://<host>/m01/intelligence/delete" -H "x-api-key: <key>" -H "Content-Type: application/json" \
  -d '[{"intelligence_id":"<id>","intelligence_type":"url-domain","pattern":"evil.example.test","pattern_type":"exact"}]'
方法 结果
GetIntelligenceStats ✅ 返回统计
AddIntelligence ✅ success_count=1
DetectIntelligence ✅ hit=true
DeleteIntelligence ✅ 清理完成,统计回基线

(截图:网哨 M01 控制台本地情报列表中可见该 indicator 的新增与删除)

Add services/m01__intelligence exposing the m01 mail security gateway local
threat-intelligence APIs as gRPC methods: DetectIntelligence, ListIntelligence,
AddIntelligence, UpdateIntelligence, DeleteIntelligence, GetIntelligenceStats.

- x-api-key auth with Bearer JWT fallback
- { code, msg, data } envelope unwrap; handler-side enum validation
- Idempotent add (dedup by pattern), update by id, delete on absence
- Standard gRPC error mapping; x-request-id/x-engine-instance audit headers
- Mock-based unit tests (100% line, >90% branch) and a mock upstream
- Wire into root dispatcher and package.json bin/files

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@K6gg K6gg changed the title Add m01 mail gateway threat-intelligence service package feat: add m01 (网哨M01) mail gateway threat-intelligence service Jun 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

网哨M01

1 participant