feat: v2.0.0 邮件接收架构改造 —— 移除 Node,Email Worker 直连 Console(docs/11)
- 两阶段接收:POST /internal/email/authorize(accept/reject/temporary_error)+ POST /internal/email/ingest(raw MIME 直传) - Worker-Console 协议:Authorization: WmailHub-Worker + timestamp/nonce/body-hash/HMAC,nonce 防重放,凭据撤销即时生效 - 数据模型:nodes/node_credentials -> cloudflare_accounts/worker_credentials(迁移 0003),emails/domains 归属 account_id - 接入流程 Connect Cloudflare Account:OAuth 自动同步域名 + 部署账号级 Email Worker + 签发 Worker 凭据;rotate 自动重部署 - 动态邮箱:创建/删除/禁用下一封邮件立即生效;拒绝码 DOMAIN_*/MAILBOX_*;超时/5xx 不伪装成邮箱不存在 - 删除 node/ 目录、旧 /api/internal/nodes 协议、ingress/enrollment 概念;dev.ts 简化为 console + email worker 双进程 - 前端:账号页 Email Worker/凭据管理,设置窗口移除默认 Ingress,仪表盘/文案同步;版本 2.0.0 - 测试 62 项全过(新增 authorize 决策矩阵 + Worker 两阶段临时错误语义);本机虚拟 E2E 12 场景全通 - docs 00-10 同步改写;README 更新
This commit is contained in:
+25
-32
@@ -1,30 +1,12 @@
|
||||
# Node 与 Console 通信协议
|
||||
# Email Worker <-> Console 内部协议(docs/11 §8,协议版本 1)
|
||||
|
||||
Node -> Console 必须使用 HTTPS + HMAC 请求签名 + timestamp + nonce + body hash。
|
||||
`/internal/email/authorize` 与 `/internal/email/ingest` 都是内部 API,不能匿名访问。
|
||||
每个请求必须满足:HTTPS + Worker ID + timestamp + nonce + body SHA256 + HMAC-SHA256。
|
||||
|
||||
## Credential
|
||||
## 请求头
|
||||
|
||||
```text
|
||||
node_id
|
||||
credential_id
|
||||
credential_secret
|
||||
cloudflare_account_id
|
||||
```
|
||||
|
||||
Console 保存 secret 的安全摘要;Node 保存实际 secret。
|
||||
|
||||
## 签名
|
||||
|
||||
```text
|
||||
body_hash = SHA256(raw_body)
|
||||
canonical = METHOD + "\n" + PATH + "\n" + TIMESTAMP + "\n" + NONCE + "\n" + body_hash
|
||||
signature = HMAC-SHA256(secret, canonical)
|
||||
```
|
||||
|
||||
请求头:
|
||||
|
||||
```text
|
||||
Authorization: WmailHub-Node <node_id>
|
||||
Authorization: WmailHub-Worker <worker_id>
|
||||
X-WmailHub-Timestamp: <unix_seconds>
|
||||
X-WmailHub-Nonce: <random>
|
||||
X-WmailHub-Body-SHA256: <hex>
|
||||
@@ -32,18 +14,29 @@ X-WmailHub-Signature: <hex>
|
||||
X-WmailHub-Protocol: 1
|
||||
```
|
||||
|
||||
Console 拒绝 timestamp 超窗、重复 nonce、错误 signature、错误 body hash、已撤销 credential。默认 timestamp window 建议 5 分钟。
|
||||
## 签名
|
||||
|
||||
```text
|
||||
body_hash = SHA256(raw_body)
|
||||
canonical = METHOD + "\n" + PATH + "\n" + TIMESTAMP + "\n" + NONCE + "\n" + body_hash
|
||||
signature = HMAC-SHA256(worker_credential_secret, canonical)
|
||||
```
|
||||
|
||||
## Console 必须校验
|
||||
|
||||
1. Worker ID(存在且 credential active);
|
||||
2. timestamp(默认窗口 5 分钟);
|
||||
3. nonce 不重复(唯一索引入库,主键冲突即 replay);
|
||||
4. body hash;
|
||||
5. HMAC;
|
||||
6. credential 状态(撤销立即生效);
|
||||
7. Worker 所属 Cloudflare 账号与收件域名一致。
|
||||
|
||||
## API
|
||||
|
||||
```text
|
||||
POST /api/internal/nodes/{node_id}/emails
|
||||
POST /api/internal/nodes/{node_id}/heartbeat
|
||||
GET /api/internal/nodes/{node_id}/config
|
||||
POST /internal/email/authorize { "recipient": "...", "sender": "...", "message_id": "..." }
|
||||
POST /internal/email/ingest raw MIME(message/rfc822),收件人经 X-WmailHub-Recipient/Sender 头传递
|
||||
```
|
||||
|
||||
邮件请求推荐 `Content-Type: message/rfc822`,body 直接使用 raw MIME。
|
||||
|
||||
Console 可以立即撤销 credential。Node 收到 401/403 后不得无限重试。
|
||||
|
||||
协议必须版本化。
|
||||
Console 收到 401/403 的 Worker 应视为凭据失效,不得无限重试。协议必须版本化。
|
||||
|
||||
Reference in New Issue
Block a user