@sparkelf/dsh-dataops-managed 0.3.36 → 0.3.38

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -4365,6 +4365,11 @@ async function apply(ctx, config) {
4365
4365
  if (request.method === "GET") {
4366
4366
  const url = new URL(request.url ?? "/", "http://localhost");
4367
4367
  const section = url.searchParams.get("section") ?? "matrix";
4368
+ if (section === "visible-roles") {
4369
+ const result = await api.request("/api/system/permission-center/roles/visible");
4370
+ writeJson(response, result.status, result.body);
4371
+ return;
4372
+ }
4368
4373
  const suffix = section === "members" ? "?q=" + encodeURIComponent(url.searchParams.get("q") ?? "") + "&departmentCode=" + encodeURIComponent(url.searchParams.get("departmentCode") ?? "") : section === "resources" ? "?kind=" + encodeURIComponent(url.searchParams.get("kind") ?? "") : "";
4369
4374
  const target = section === "members" ? "/api/system/permission-center/members" + suffix : section === "departments" ? "/api/system/permission-center/departments" : section === "resources" ? "/api/system/permission-center/resources" + suffix : "/api/system/permission-center/matrix" + (url.searchParams.get("scope") === "dsh" ? "?scope=dsh" : "");
4370
4375
  const result = await api.request(target);
@@ -4398,6 +4403,22 @@ async function apply(ctx, config) {
4398
4403
  writeJson(response, result.status, result.body);
4399
4404
  return;
4400
4405
  }
4406
+ if (section === "member-grant" && typeof value.userId === "string" && typeof value.roleCode === "string") {
4407
+ const result = await api.request("/api/system/permission-center/members/" + encodeURIComponent(value.userId) + "/role-grants", {
4408
+ method: "PUT",
4409
+ body: JSON.stringify({
4410
+ roleCode: value.roleCode,
4411
+ departmentCode: typeof value.departmentCode === "string" ? value.departmentCode : null
4412
+ })
4413
+ });
4414
+ writeJson(response, result.status, result.body);
4415
+ return;
4416
+ }
4417
+ if (section === "member-revoke" && typeof value.userId === "string" && typeof value.roleCode === "string") {
4418
+ const result = await api.request("/api/system/permission-center/members/" + encodeURIComponent(value.userId) + "/role-grants/" + encodeURIComponent(value.roleCode), { method: "DELETE" });
4419
+ writeJson(response, result.status, result.body);
4420
+ return;
4421
+ }
4401
4422
  if (section === "departments" && typeof value.code === "string") {
4402
4423
  const result = await api.request("/api/system/permission-center/departments/" + encodeURIComponent(value.code) + "/admin", {
4403
4424
  method: "PUT",
@@ -79,6 +79,17 @@ export declare const en: {
79
79
  readonly reviewSettingsWaiting: "Review settings API is waiting for the backend (task-39).";
80
80
  readonly permNav: "Permissions";
81
81
  readonly permTitle: "Permission centre";
82
+ readonly permRefresh: "Refresh";
83
+ readonly permGroupRoles: "Roles";
84
+ readonly permGroupOrg: "Organisation";
85
+ readonly permGroupResources: "Resources";
86
+ readonly permRoleSearch: "Search roles";
87
+ readonly permGrant: "Grant";
88
+ readonly permRevoke: "Revoke role";
89
+ readonly permGrantSelect: "Select a role…";
90
+ readonly permTranspose: "Transpose matrix";
91
+ readonly permRoleColumn: "Role";
92
+ readonly permRoleEmpty: "No matching roles";
82
93
  readonly permTabRoles: "Role permissions";
83
94
  readonly permTabMembers: "Member roles";
84
95
  readonly permTabDepartments: "Departments";
@@ -155,3 +155,24 @@ export declare function updateDepartment(input: {
155
155
  }): Promise<RbacSaveResult>;
156
156
  /** Delete one department after the confirmation dialog. */
157
157
  export declare function deleteDepartment(code: string): Promise<RbacSaveResult>;
158
+ /** One role the caller may delegate, as `roles/visible` returns it. */
159
+ export interface VisibleRoleRow {
160
+ code: string;
161
+ name: string;
162
+ systemKey?: string | null;
163
+ departmentScoped: boolean;
164
+ displayOrder: number;
165
+ level: number;
166
+ }
167
+ /** The caller's delegation scope and the roles inside it. */
168
+ export interface VisibleRolesView {
169
+ actorLevel: number;
170
+ departmentCodes: readonly string[];
171
+ roles: readonly VisibleRoleRow[];
172
+ }
173
+ /** Roles the caller may grant or revoke. */
174
+ export declare function fetchVisibleRoles(): Promise<VisibleRolesView | null>;
175
+ /** Grant one role to a member (level/department rules are enforced by the backend). */
176
+ export declare function grantMemberRole(userId: string, roleCode: string, departmentCode?: string | null): Promise<RbacSaveResult>;
177
+ /** Revoke one role from a member. */
178
+ export declare function revokeMemberRole(userId: string, roleCode: string): Promise<RbacSaveResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sparkelf/dsh-dataops-managed",
3
- "version": "0.3.36",
3
+ "version": "0.3.38",
4
4
  "description": "DataOps JWT intake and credential-backed MCP tools for managed DeepSeek Harness workspaces.",
5
5
  "type": "module",
6
6
  "main": "./lib/index.js",
@@ -42,6 +42,7 @@
42
42
  "skills/dataops-query/SKILL.md",
43
43
  "skills/dataops-query/i18n/zh.json",
44
44
  "skills/dataops-collect/SKILL.md",
45
+ "skills/admin-workspace-rescue/SKILL.md",
45
46
  "README.md",
46
47
  "LICENSE"
47
48
  ],
@@ -0,0 +1,95 @@
1
+ ---
2
+ name: admin-workspace-rescue
3
+ description: 超管代维另一个用户的 DSH 工作区时使用。包含临时 SSH 隧道的开通与撤销、常见故障的定位与修复顺序(workspace 记录、会话迁移、备份恢复)、安全红线与 24 小时到期规则。仅超级管理员可见。
4
+ ---
5
+
6
+ # 超管代维工作区(临时 SSH 隧道)
7
+
8
+ 你是以**自己的超管身份**去救另一个用户的工作区,不是拿到对方的凭据。隧道是限时的、可撤销的、全程留痕的;它不改变「这是别人的工作区」这件事。
9
+
10
+ ## 一、什么时候用
11
+
12
+ - 用户报「工作区起不来 / 一直准备中 / 会话列表空了 / 打不开」而你在门户里看不到根因;
13
+ - 需要看容器内的真实文件、进程、日志(`workspace.json`、`sessions/`、`profile`、`web.log`);
14
+ - 需要执行一次修复脚本(修 workspace 记录、迁移会话目录、清 stale lock、备份会话)。
15
+
16
+ 不适用:对方只是不会用(那是产品引导);需要改对方数据内容(那是业务操作,走正常入口)。
17
+
18
+ ## 二、开通与撤销
19
+
20
+ 两个工具:
21
+
22
+ - `admin_workspace_tunnel_open(userId)` → 返回一次性连接信息(`privateKey` / `targetHost` / `port` / `expiresAt`)。**私钥只出现这一次**,不落库、不进日志。
23
+ - `admin_workspace_tunnel_revoke(userId)` → 立即撤销(删除对应的 `authorized_keys` 标记行并结束转发)。
24
+
25
+ 规则:
26
+
27
+ 1. 开通前先在门户里确认目标工作区 id 和 owner,**不要凭用户名猜 userId**;
28
+ 2. 私钥只在当轮使用,用完即 `revoke`;不要把私钥写进文件、贴进聊天、存进工作区;
29
+ 3. 隧道默认 **24 小时**到期,服务端每 5 分钟清理过期标记;到期后连接立即失效,**不要依赖自己记时间**;
30
+ 4. 同一目标不要并行开多条;用完就撤销,撤销后要复验「再连失败」再结束。
31
+
32
+ ## 三、连上之后先做什么
33
+
34
+ 按「只读 → 备份 → 修复 → 复验」的顺序,不要一上来就改:
35
+
36
+ 1. **只读定位**:
37
+ - `dataops-dsh-service status`(容器内)看服务状态;
38
+ - `tail -n 200 /workspace/.dataops/dsh/logs/web.log` 看启动错误;
39
+ - `ls /workspace/.dataops/dsh/storages/workspace.json`、`ls /workspace/.dataops/dsh/sessions/` 看存储是否还在;
40
+ - `ps aux | grep -E "dsh|sidecar"` 看进程是否卡死。
41
+ 2. **动手前备份**:任何写操作前,先把要改的文件/目录打成 tar 放到 `/workspace/.dataops/backups/`(带时间戳);没有备份不做破坏性动作。
42
+ 3. **修复**:优先用容器里已有的脚本函数,而不是手写 sed:
43
+ - workspace 记录异常(`workspace.json` 指向 `/root`、时间戳缺失、重复键)→ `dataops-dsh-service` 的 `repair_workspace_record()`;
44
+ - stale profile lock → `clear_stale_profile_lock()`;
45
+ - 会话目录迁移 → 按 `persisted_sessions.cwd` 只改 cwd 前缀,目录键跟着 workspace 键走。
46
+ 4. **复验**:`dataops-dsh-service status` 回到 `running/ready`,让用户在门户里打开一次会话,确认能进、历史在。
47
+
48
+ ## 四、安全红线(违反即事故)
49
+
50
+ - **不导出、不读取、不复制用户的 JWT / cookie / 凭据**;
51
+ - **不删除用户数据**:`sessions/`、`workspace.json`、附件目录只做备份与修复,不做 `rm -rf`;确需删除先问用户;
52
+ - **不代替用户发言**、不往用户的会话里写内容;
53
+ - **不在容器里安装新东西、不改镜像**;只做修复动作;
54
+ - 操作范围仅限**这一次故障**;与故障无关的文件一律不动;
55
+ - 全程按「一次隧道一次任务」使用,任务结束立即 `revoke`。
56
+
57
+ ## 五、到期与清理
58
+
59
+ - 到期时间由服务端签发(默认 24h),写在 `authorized_keys` 的注释里(`dataops-admin-tunnel:<actor>:<expiresAt>`);
60
+ - 清理任务每 5 分钟扫一次过期标记,删行并关闭转发;**手动撤销与到期清理效果一致**;
61
+ - 如果发现「已过期但还能连」,立刻 `revoke` 并上报——这是安全缺陷,不是正常现象。
62
+
63
+ ## 六、DataOps MCP 未挂载 / 401:internal-token 缺失
64
+
65
+ 会话里看不到 `mcp__dataops__*` 工具,或每次调用都 401——先怀疑内部 token,而不是模型或网络。
66
+
67
+ **根因**:MCP server 配置在 `/workspace/.dataops/pi/runtimes/<id>/mcp.json`,里面的 token 是占位符
68
+ `${DATAOPS_AI_WORKSPACE_INTERNAL_TOKEN}`;真实凭证来自容器内 `/run/dataops-workspace/internal-token`,
69
+ 由后端工作区生命周期写入(`ensureWorkspacePlatformServices()`,token 由 `buildWorkspaceInternalToken(userId)` 生成)。
70
+ 容器重建/重启走非标准路径时该文件会缺失,进程 env 里也没有这个变量,MCP server 拿不到 token → 每次 401。
71
+
72
+ **诊断三步**(只用只读命令):
73
+
74
+ 1. `docker exec <容器> ls -l /run/dataops-workspace/internal-token`
75
+ —— 文件不存在即命中;存在则看权限和属主是否被改;
76
+ 2. `docker exec <容器> env | grep DATAOPS_AI_WORKSPACE`
77
+ —— 正常情况下这里应为空(token 走文件,不走 env);如果有值但 MCP 仍 401,说明 env 与文件不一致;
78
+ 3. `docker exec <容器> tail -n 50 /workspace/.dataops/dsh/logs/web.log | grep -i "mcp\|401"`
79
+ —— 确认是 MCP 401,而不是模型侧没挂上工具。
80
+
81
+ **修复**:走工作区生命周期重新注入——让后端重新执行平台服务注入(`ensureWorkspacePlatformServices`)或按标准路径重建容器,
82
+ token 由后端重新生成;**注入完成后还要再重启一次 DSH(或重启整个工作区),让 MCP server 带着新 token 重新拉起**——
83
+ 只注入不重启,进程里仍是旧值,现象不会消失。**不要手工把 token 写进 `mcp.json`,也不要把 token 打印出来或贴给用户**——
84
+ 手写进去的 token 在下次重建时又会失配,而且等于把凭据落到了用户可读的文件里。
85
+
86
+ 现在重启路径已经内置了注入(`restartWorkspace` → `injectWorkspaceInternalToken`),所以超管直接执行
87
+ `admin_workspace_restart(userId)` 一次即可同时完成「重启容器 + 重新注入」;若走了别的手工路径,按上一段补一次重启。
88
+
89
+ **验证**:
90
+ - 新开会话,工具列表里应出现 `mcp__dataops__*`;
91
+ - 或用一个需要鉴权的 `/api/ai/...` 调用确认返回 200(不要回显 token 本身)。
92
+
93
+ ## 七、汇报
94
+
95
+ 结束时给用户三句话:**做了什么**(动作与文件)、**结果**(服务状态/会话是否恢复)、**遗留**(还需要用户自己确认什么)。不要贴私钥、不要贴用户的敏感路径内容。