Feature: add per-device owner bindings to the web console
Web 控制台此前所有 admin 角色用户共享全部设备。新增设备级归属:内置 admin 把设备绑定给一个用户名后,该设备对其他 admin/viewer 不可见不可控,只有 owner 与内置 admin 可见可控。 - 新增 device_acl.json(与 users.json 同目录,YAMA_DEVICE_ACL_FILE 可覆盖), 原子写、启动加载;文件损坏拒绝启动,避免私人设备变成公共。 - 可见性:内置 admin 全部;未绑定设备仅 admin 角色;绑定设备仅 owner。 覆盖 get_devices、/api/devices、屏幕墙,以及 connect/term_open/mouse/key/ clipboard/keyframe/rdp_reset 全部控制通道;device_update 也只推给可见者。 - 只有内置 admin(用户名 admin + role admin)能 bind/unbind;admin 角色保留 建用户、删设备、审计等既有功能。删设备清绑定。 - 审计日志也按归属过滤:非内置 admin 只能看到公共设备和自己绑定设备的记录 (device_id / device / devices 三种写法都识别);auditquery 增 DeviceAllowed 钩子,ACL 提供 Owner 快照,避免扫描时逐条加锁。 - 删用户会解绑其设备;但账号名下有绑定设备时只有内置 admin 能删,其他 admin 删除会把设备释放到公共池,属于越权。解绑在删除前完成,解绑失败中止删除; 删除失败时回滚绑定。 - 绑定/解绑后立即重新校验在线会话:失去权限的屏幕/终端会话被断开。 - 本地用户名禁止 '@'(保留给 SSO 邮箱);本地密码登录拒绝 '@' 用户名, SSO 拒绝名为 admin 的身份,避免绕过超级管理员判定。 - 前端:superadmin 卡片显示 owner、绑定按钮和弹窗(本地用户 datalist + SSO 邮箱自由输入);deviceAcl 能力位由服务端挑战下发,C++ 端无此位不显示; 设备 ID 经 jsAttr 转义后再进 onclick,修掉存储型 XSS。 验证:go build/test/vet 全绿;新增 ACL 持久化、可见性矩阵、控制通道拒绝、 绑定/解绑会话重校验、device_update 不泄露、分组过滤、删用户解绑与越权拒绝、 审计按归属过滤等测试;本地起 Go 服务 + WebSocket 探针验证 challenge、绑定、 非 superadmin 拒绝、解绑。 Model: deepseek-flash Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
db148c4a69
commit
46434b46d0
16 files changed
+1716
-30
No files matched your search
@@ -100,6 +100,75 @@ func TestQueryAuditHandlerReturnsEvents(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// An admin-role user may read public-device audit records and their own, but
|
||||
// not records naming another user's bound device. The superadmin sees all.
|
||||
func TestQueryAuditHandlerFiltersBoundDevices(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
lg := logger.New(logger.Config{
|
||||
Level: logger.LevelInfo,
|
||||
Console: false,
|
||||
File: filepath.Join(dir, "server.log"),
|
||||
AuditFile: filepath.Join(dir, "audit.log"),
|
||||
})
|
||||
t.Cleanup(func() { _ = lg.Close() })
|
||||
|
||||
acl := NewDeviceACL(filepath.Join(dir, "device_acl.json"))
|
||||
if err := acl.Bind([]string{"1001"}, "alice@corp.com", "admin"); err != nil {
|
||||
t.Fatalf("bind 1001: %v", err)
|
||||
}
|
||||
if err := acl.Bind([]string{"1002"}, "bob@corp.com", "admin"); err != nil {
|
||||
t.Fatalf("bind 1002: %v", err)
|
||||
}
|
||||
wh := newWSHub(wsauth.New(), hub.New(), nil, lg).withDeviceACL(acl)
|
||||
t.Cleanup(wh.stop)
|
||||
|
||||
wh.log.Audit("remote.screen.start", map[string]any{"device_id": "1001"})
|
||||
wh.log.Audit("remote.screen.start", map[string]any{"device_id": "1002"})
|
||||
wh.log.Audit("remote.screen.start", map[string]any{"device_id": "1003"}) // public
|
||||
wh.log.Audit("mcp.tool.call", map[string]any{"device": "1001"})
|
||||
wh.log.Audit("admin.device.bind", map[string]any{"devices": []string{"1001"}, "owner": "alice@corp.com"})
|
||||
|
||||
query := func(user string) string {
|
||||
t.Helper()
|
||||
c, tok := aclTestClient(t, wh, user, "admin")
|
||||
raw, _ := json.Marshal(map[string]any{"token": tok, "limit": 50})
|
||||
wh.handleQueryAudit(c, raw)
|
||||
msg := readUntilCmd(t, c, "audit_result")
|
||||
if msg["ok"] != true {
|
||||
t.Fatalf("%s: reply = %+v", user, msg)
|
||||
}
|
||||
events, _ := json.Marshal(msg["events"])
|
||||
return string(events)
|
||||
}
|
||||
|
||||
alice := query("alice@corp.com")
|
||||
for _, want := range []string{`"device_id":"1001"`, `"device_id":"1003"`, `"device":"1001"`, `"devices":["1001"]`} {
|
||||
if !strings.Contains(alice, want) {
|
||||
t.Fatalf("alice events missing %s: %s", want, alice)
|
||||
}
|
||||
}
|
||||
if strings.Contains(alice, `"device_id":"1002"`) {
|
||||
t.Fatalf("alice saw bob's bound device: %s", alice)
|
||||
}
|
||||
|
||||
bob := query("bob@corp.com")
|
||||
if !strings.Contains(bob, `"device_id":"1002"`) {
|
||||
t.Fatalf("bob events missing his own device: %s", bob)
|
||||
}
|
||||
for _, leak := range []string{`"device_id":"1001"`, `"device":"1001"`, `"devices":["1001"]`} {
|
||||
if strings.Contains(bob, leak) {
|
||||
t.Fatalf("bob saw alice's bound device record %s: %s", leak, bob)
|
||||
}
|
||||
}
|
||||
|
||||
super := query("admin")
|
||||
for _, want := range []string{`"device_id":"1001"`, `"device_id":"1002"`, `"device":"1001"`, `"devices":["1001"]`} {
|
||||
if !strings.Contains(super, want) {
|
||||
t.Fatalf("superadmin events missing %s: %s", want, super)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestQueryAuditHandlerDisabledFile(t *testing.T) {
|
||||
dir := t.TempDir()
|
||||
wh, _ := newAuditTestHubWithoutAuditFile(t, dir)
|
||||
|
||||
Reference in new issue
Block a user