Feature: hide user-bound devices from MCP
设备绑定到 Web 用户后,MCP 端点(静态 token,等同管理员凭证)仍能按 ID 操作,与"私人设备只归 owner"的模型冲突。按产品决定采用最严格策略:MCP 只面向公共设备,绑定设备对 MCP 一律不可见、不可达,即使知道 ID 也一样。 - list_hosts / get_host_detail / get_server_status 先过滤绑定设备再计数与 分页;离线列表用完整在线集合作差,避免在线私人设备以离线条目复现。 - 所有单主机工具在 callTool 统一拒绝(get_screenshot / list_files / read_file / terminal_exec / terminal_close 及将来新增工具),批量 ids 由 逐台执行处拒绝;后续新工具不会再漏。 - 拒绝返回与离线主机相同的 -32002 "Host not found or offline",不泄露设备 是否存在。 - get_audit_log 过滤 device_id / device / devices 中任意一个指向绑定设备的 记录;owner 快照一次取用,不逐条加锁。 - cmd 把 Web 的 DeviceACL 注入 MCP;未启用 ACL 时行为完全不变。 验证:go build/test/vet 全绿;新增 MCP 侧列表隐藏、按 ID 拒绝、批量拒绝、 状态计数、审计过滤(三种字段写法)测试。 Model: deepseek-flash Co-Authored-By: Claude Code <noreply@anthropic.com>
This commit is contained in:
1 parent
46434b46d0
commit
b704258ba4
6 files changed
+286
-12
No files matched your search
@@ -106,12 +106,17 @@ func (s *Server) callListHosts(_ context.Context, raw json.RawMessage) (any, *rp
|
||||
}
|
||||
includeOffline := args.IncludeOffline != nil && *args.IncludeOffline
|
||||
|
||||
onlineDevices := s.cfg.Hub.ListDevices()
|
||||
onlineSet := make(map[string]struct{}, len(onlineDevices))
|
||||
for _, d := range onlineDevices {
|
||||
// The offline history must be computed from the FULL online set, not the
|
||||
// ACL-filtered one: otherwise a private device that is currently online
|
||||
// would reappear as an "offline" entry until the outer filter drops it.
|
||||
// Filter once, at the end.
|
||||
onlineAll := s.cfg.Hub.ListDevices()
|
||||
onlineSet := make(map[string]struct{}, len(onlineAll))
|
||||
for _, d := range onlineAll {
|
||||
onlineSet[d.ID] = struct{}{}
|
||||
}
|
||||
offlineDevices := s.offlineDevices(onlineSet)
|
||||
onlineDevices := s.publicDevices(onlineAll)
|
||||
offlineDevices := s.publicDevices(s.offlineDevices(onlineSet))
|
||||
|
||||
var pool []hub.DeviceInfo
|
||||
switch {
|
||||
@@ -347,14 +352,19 @@ func (s *Server) hostDetailBatch(ids []string) (any, *rpcError) {
|
||||
// hostMaps indexes the online devices and offline history by ID. Building both
|
||||
// once per call keeps a 50-id batch at one hub snapshot instead of 50.
|
||||
func (s *Server) hostMaps() (online, offline map[string]hub.DeviceInfo) {
|
||||
onlineDevices := s.cfg.Hub.ListDevices()
|
||||
onlineAll := s.cfg.Hub.ListDevices()
|
||||
onlineSet := make(map[string]struct{}, len(onlineAll))
|
||||
onlineDevices := s.publicDevices(onlineAll)
|
||||
online = make(map[string]hub.DeviceInfo, len(onlineDevices))
|
||||
onlineSet := make(map[string]struct{}, len(onlineDevices))
|
||||
for _, d := range onlineDevices {
|
||||
online[d.ID] = d
|
||||
}
|
||||
// Derive offline entries from the full online set (see callListHosts):
|
||||
// a private online device must not be mistaken for an offline one.
|
||||
for _, d := range onlineAll {
|
||||
onlineSet[d.ID] = struct{}{}
|
||||
}
|
||||
offlineDevices := s.offlineDevices(onlineSet)
|
||||
offlineDevices := s.publicDevices(s.offlineDevices(onlineSet))
|
||||
offline = make(map[string]hub.DeviceInfo, len(offlineDevices))
|
||||
for _, d := range offlineDevices {
|
||||
offline[d.ID] = d
|
||||
@@ -483,12 +493,13 @@ func (s *Server) callGetServerStatus(_ context.Context, _ json.RawMessage) (any,
|
||||
text = fmt.Sprintf("YAMA Go 服务端 %s 已运行 %d 秒", s.cfg.Version, uptime)
|
||||
}
|
||||
if s.cfg.Hub != nil {
|
||||
onlineDevices := s.cfg.Hub.ListDevices()
|
||||
onlineSet := make(map[string]struct{}, len(onlineDevices))
|
||||
for _, d := range onlineDevices {
|
||||
onlineAll := s.cfg.Hub.ListDevices()
|
||||
onlineSet := make(map[string]struct{}, len(onlineAll))
|
||||
for _, d := range onlineAll {
|
||||
onlineSet[d.ID] = struct{}{}
|
||||
}
|
||||
offline := len(s.offlineDevices(onlineSet))
|
||||
onlineDevices := s.publicDevices(onlineAll)
|
||||
offline := len(s.publicDevices(s.offlineDevices(onlineSet)))
|
||||
status["hosts"] = map[string]any{"online": len(onlineDevices), "offline": offline}
|
||||
text += fmt.Sprintf(";在线 %d 台,离线 %d 台", len(onlineDevices), offline)
|
||||
}
|
||||
@@ -530,6 +541,9 @@ func (s *Server) callGetAuditLog(_ context.Context, raw json.RawMessage) (any, *
|
||||
// event name; the web UI's exact/prefix Event filter does not fit.
|
||||
EventContains: args.Type,
|
||||
}
|
||||
// Audit records name their target device. A device bound to a web user is
|
||||
// invisible to MCP, so its activity must not leak through the log either.
|
||||
q.DeviceAllowed = s.ownerChecker()
|
||||
q.Limit = auditquery.ClampLimit(args.Limit, auditquery.MaxLimit)
|
||||
q.Offset = auditquery.ClampOffset(args.Offset)
|
||||
|
||||
|
||||
Reference in new issue
Block a user