feat(auth,gateway): 接线 viewer 只读门 — 12 条监控 GET 对 viewer 开放,敏感档保持 owner/admin
背景:auth.go 注释写着 RoleViewer 是只读监控档,但实现从未接线 —— 管理侧 24 个 GET 全是 owner/admin,viewer 全 403。本批把它接上(手机端「全功能管理」的前置之一)。
- routes.go:新增第四道门 viewerAuth = Authorize(owner, admin, viewer);registerAdminRoutes 传入。**只**把 12 条只读监控 GET 从 writeAuth 换过来:personas / sessions / plugins / plugins-installed / channels / iot / automations / rag / observability{metrics,trace,logs} / notifications;其余 12 条读与 32 条写**一行不动**
- 保持 owner/admin(viewer 403):memories / llm / users / backthink / audit / sessions-export / channels-messages ×2;owner-only(35 条)含凭据获取(login-qr/login-status)、channels view/friends、全部写操作
- 三处「编码旧策略」的既有测试按**新权限矩阵**改写(不是放宽):gateway_test 的 /admin/plugins viewer 403→200 且补一条 memories 403;observability_logs 的 ViewerForbidden→ViewerReadsTail;notifications 的 viewer 403→200
- 新增 rbac_viewer_test.go:5 个顶层 / 185 个子测试(12 条×3 角色 200、9+35 条 viewer 403、admin 在读档非 401/403 且在 owner-only 403、56 条匿名 401、写路由 viewer 403);含 3 次变异验证(含**反向变异**:把 memories 误放开为 viewerAuth 会 FAIL)
- auth.go 的 RoleViewer 注释改为**实际**可见面;Docs/api-client 新增 §2.0 管理侧权限矩阵 + 变更记录 v0.40;顺带修 §0 一处不实陈述(原写「管理端另支持 X-API-Key」→ 标注尚未接线)
- 验收:**隔离 worktree(HEAD + 本片)** go build/vet/test 全绿 + linux/amd64 与 darwin/arm64 交叉编译 + gofmt 干净(主工作树此时被另一代理的在途改动占用,见下条提交)
- 已知遗留(未改前端,按范围只记录):管理面板未按角色隐藏分区 → viewer 打开 memories/users/llm/审计等页会吃 403(应做能力降级)
This commit is contained in:
1 parent
2c100fe3d9
commit
3f79159fbd
7 files changed
+341
-40
No files matched your search
@@ -257,8 +257,8 @@ func TestAdminListNotifications_NoSourcesNoFabrication(t *testing.T) {
|
||||
}
|
||||
|
||||
// TestAdminListNotifications_Errors proves the endpoint fails loudly: an unknown
|
||||
// family is a 400, a failing source is a 500 (never a silently shortened feed),
|
||||
// and a viewer is rejected by RBAC.
|
||||
// family is a 400 and a failing source is a 500 (never a silently shortened
|
||||
// feed). A viewer reads the feed (read-only monitoring tier).
|
||||
func TestAdminListNotifications_Errors(t *testing.T) {
|
||||
t.Parallel()
|
||||
audit, bt := notificationFeedFixture()
|
||||
@@ -278,8 +278,8 @@ func TestAdminListNotifications_Errors(t *testing.T) {
|
||||
}
|
||||
|
||||
viewer := signAny(t, jwt, "acct", auth.RoleViewer)
|
||||
if status, _, _ := listNotifications(t, ts, viewer, ""); status != http.StatusForbidden {
|
||||
t.Fatalf("viewer status = %d, want 403", status)
|
||||
if status, _, _ := listNotifications(t, ts, viewer, ""); status != http.StatusOK {
|
||||
t.Fatalf("viewer status = %d, want 200", status)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user