fix(reconciliation): 平台 Key 自动带工作空间访问租户资源 (CYWL-37) #53
Reference in New Issue
Block a user
Delete Branch "hifox-agent/assistant/CYWL-37-workspace"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
CYWL-37 续:让「运行时读」和「对账」真的能共用一把 Key。
为什么还要改
上一轮把运行时读改成复用「知识库绑定」的 Key,但 WeKnora v0.9.1 的
/api/v1/system/admin/runtime/*在internal/router/routes_auth_tenant.go里由apiKeyPlatform(...)声明成PlatformOnly,而internal/middleware/api_key_gate.go的
authorize()在能力判定之前就拒绝非 platform scope 的 Key:所以租户 Key(绑定页里原来那把)即使授予
system_runtime_read也是 403。实测(测试实例 v0.9.1):租户 Key 打
runtime/queues→ 403、打knowledge-bases→ 200;平台 Key 反之。结论:绑定里必须是平台 Key。
平台 Key 访问租户资源要求
X-Tenant-ID,否则409 TENANT_REQUIRED(实测确认,带上
X-Tenant-ID: 10000后列库、取单个知识库、列文档全部 200)。改了什么
internal/platform/weknora/client.go:首次收到409 TENANT_REQUIRED时,用同一把 Key请求
/api/v1/tenants/all,按工作空间逐个重放原请求;成功后缓存 ID,后续请求自动带X-Tenant-ID。JSON 请求体缓冲上限 1 MiB 以支持重放;上传流式接口不走这条路径。X-Tenant-ID,也不会去查工作空间清单。ErrConflict)不会被误判成TENANT_REQUIRED。docs/IMPORT_RECONCILIATION_REQUIREMENTS.md§5/Q7 写清平台 Key 约束、工作空间自动识别与建议的最小能力集(
system_runtime_read+retrieve,列库再加manage_kbs);CHANGELOG 记一条。验证
go build ./...退出 0;TMPDIR=/tmp go test ./...全绿(含新增 3 个用例:平台 Key 拒绝后重放成功、租户 Key 从不发
X-Tenant-ID、普通 409 不误判)。make verify:17/17 success(local 档案,identity=skipped 属预期)。