fix(reconciliation): 平台 Key 自动带工作空间访问租户资源 (CYWL-37)
build / build (push) Successful in 1m58s

WeKnora v0.9.1 的 /system/admin/runtime/* 由 apiKeyPlatform 声明为
PlatformOnly,租户 Key 即使在 capabilities 里带 system_runtime_read 也会
在网关被 403;要让运行时读与对账共用一把 Key,绑定页必须保存平台 Key,
而平台 Key 访问租户资源要求 X-Tenant-ID。

客户端在首次收到 409 TENANT_REQUIRED 时用同一把 Key 查
/api/v1/tenants/all,按工作空间逐个重试原请求;成功后缓存并在后续请求
带上 X-Tenant-ID。租户 Key 不触发该路径,普通 409(上传冲突)不受影响。
This commit is contained in:
Zhero & 助理
2026-12-02 16:20:10 +08:00
committed by Hermes Assistant
parent 7567159dc0
commit 5798183392
4 changed files with 241 additions and 7 deletions
+5 -2
View File
@@ -118,12 +118,15 @@ WeKnora v0.9.1 新增了系统管理员「任务队列」(CHANGELOG #4732、#5
**列表的盲区**:不传 `parse_status` 时上游隐藏 `deleting` 行(`repository/knowledge.go:176`),所以“列表里没有”不等于“已删除”,R1 必须单条 GET 复核。
**运行时读 Key 的配置契约(Q7,2026-12-02 改判)**
**运行时读 Key 的配置契约(Q7,2026-12-02 改判,同日修正)**
- 不再单独维护平台级只读 Key:「导入对账」的 `runtime/queues` 与 `runtime/documents/{id}`(以及页面上的「WeKnora 处理详情」)直接使用「系统设置 → 知识库绑定」测试环境保存的地址与 Key,与对账扫描共用同一个 resolver。
- **绑定里的 Key 必须是平台 Key**:WeKnora v0.9.1 的 `/api/v1/system/admin/runtime/*` 由 `apiKeyPlatform` 声明为 `PlatformOnly`,`internal/middleware/api_key_gate.go` 在能力判定之前就先拒绝非 platform scope 的 Key,所以租户 Key 即使授予 `system_runtime_read` 也会得到 403。改动前实测:租户 Key 打 queues 403、打 `knowledge-bases` 200;平台 Key 反之。
- **平台 Key 访问租户资源要带工作空间**:缺少 `X-Tenant-ID` 时上游返回 `409 TENANT_REQUIRED`。平台在首次遇到该响应时用同一把 Key 请求 `/api/v1/tenants/all`,按返回的工作空间逐个重试原请求,成功后缓存该 ID 并在后续请求带上 `X-Tenant-ID`;租户 Key 不会触发这条路径,行为与之前一致。
- 绑定 Key 建议按最小权限配置(`system_runtime_read` + `retrieve`,需要列库时再加 `manage_kbs`),不要保存带租户管理/写能力的全权限 Key。
- 每次请求解析绑定;管理员换 Key 保存后,下一次请求即生效,不需要重启 API。不再读取任何 Key 文件。
- 绑定未配置或无法解密 → 503 `runtime_read_unavailable`,页面指向绑定页;上游 401/403 → 502 `runtime_key_forbidden`,页面提示去 WeKnora 授权 `system_runtime_read`;连接或运行时读失败 → 502 `runtime_unreachable`,页面提示连不上 WeKnora。
- `/monitor/overview` 的 `weknora_queues` 不可用时为 `null`,并用 `weknora_queue_error` 携带上述原因码;三种情况都不影响对账批次本身(对账只用租户 Key 列库与读单条)。
- `/monitor/overview` 的 `weknora_queues` 不可用时为 `null`,并用 `weknora_queue_error` 携带上述原因码;三种情况都不影响对账批次本身。
## 6. 运行方式