@coda-console/friends 0.9.2 → 0.10.1
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/README.md +87 -3
- package/lib/rpc-caller.mjs +10 -3
- package/lib/rpc-format.mjs +25 -5
- package/lib/rpc-holder.mjs +102 -10
- package/lib/rpc-store.mjs +44 -23
- package/main.mjs +7 -5
- package/package.json +1 -1
- package/view/app.mjs +212 -28
- package/view/style.css +26 -0
package/README.md
CHANGED
|
@@ -21,14 +21,98 @@
|
|
|
21
21
|
|
|
22
22
|
## 把远程执行授给好友
|
|
23
23
|
|
|
24
|
-
好友之间可以把一台机器上的 `remote-exec`(协议 `remote-exec/machine@1`)授给对方:对方的 Agent 经本机的代理记录,在你的机器上执行命令。授出的可以是加好友的这台自己,也可以是同一空间里别的机器(这台作网关)。`remote-exec`
|
|
24
|
+
好友之间可以把一台机器上的 `remote-exec`(协议 `remote-exec/machine@1`)授给对方:对方的 Agent 经本机的代理记录,在你的机器上执行命令。授出的可以是加好友的这台自己,也可以是同一空间里别的机器(这台作网关)。`remote-exec` 本身不感知好友,签名、验签与转发都在本插件里(「仅限目录」的授权只是每次调用时带上 `remote-exec` 自己的 `restrict` 参数,见「授权的范围」);没装 `remote-exec` 的机器照常使用好友功能(清单里是可选实现与可选依赖)。
|
|
25
25
|
|
|
26
26
|
### 用法
|
|
27
27
|
|
|
28
|
-
- **授予**:在好友详情的「共享」一节,「我授给 TA
|
|
28
|
+
- **授予**:在好友详情的「共享」一节,「我授给 TA」点「授予…」,选一台机器:列表里先是这台自己,再是同一空间里打开了远程执行的别的机器,都按机器名列出,一次授一台。选定后出范围表单,见下面的「在页面上选范围、看范围、改范围」。前提是已互认(已绑定好友通道),并且被授出的那台在 `remote-exec` 里打开了「允许本空间的机器在这台上执行」。
|
|
29
|
+
- **范围**:授予时选「整台机器」(默认)或「仅限目录」,授出后可以改,页面上的用法见下面的「在页面上选范围、看范围、改范围」,范围本身的含义见「授权的范围」。
|
|
29
30
|
- **撤销**:授权那一行的菜单选「撤销」。撤销以本机为准,立即生效:还没启动的调用不再启动,已经在跑的发取消,授权先显示「撤销中」,取消在后面跟上,不弹确认。
|
|
30
31
|
- **用好友授给我的**:「TA 授给我」里的每一条是一条代理记录,名字见下面的「代理记录的名字」,同步在你的空间里。会话里像用本机的远程执行一样,对这条记录调用 `exec`;你空间里的别的机器也能用,签名和收回答由持有这条记录的那台机器做。
|
|
31
|
-
-
|
|
32
|
+
- **看别人做了什么**:持有方在「共享」里能看到最近的操作记录(谁、哪条授权、命令摘要与结局,仅限目录的授权还有当时的范围)。
|
|
33
|
+
|
|
34
|
+
### 在页面上选范围、看范围、改范围
|
|
35
|
+
|
|
36
|
+
**授予时选范围**:「授予…」里点一台机器,出现范围表单(上面是这台机器的名字、系统和用户):
|
|
37
|
+
|
|
38
|
+
- **整台机器**(默认选中):等同于登录这台机器上的这个账号。点「授予」,与以前一样先在列表里出现「授予中」的一行。
|
|
39
|
+
- **仅限目录**:下面出目录列表。每行一个目标机上的绝对路径加「读写」或「只读」;「添加目录」加一行、「删除」去掉一行,路径手输(页面不浏览目标机的文件系统)。至少一行、至少一行「读写」、至多 50 行,路径要以 `/` 开头。不合规时「授予」按钮不可用,列表下面写明缺什么(哪一行没填、不是绝对路径、没有读写行、超过 50 行),不会发出请求。
|
|
40
|
+
- **只有 macOS 的机器能选「仅限目录」**:目标机系统不是 macOS 时这个选项是灰的,旁边写明「第一期只支持 macOS 的机器」。这只是按机器记录里的系统给的提示,授予时持有方到目标机探测的结果才算数(见「授权的范围」)。
|
|
41
|
+
- 点「换一台机器」回到列表重选,范围与填过的目录都重置。
|
|
42
|
+
|
|
43
|
+
**授「仅限目录」要等探测**:点「授予」后,持有方先到目标机上探测一次,要几秒,最长约 30 秒。这期间按钮是「正在探测…」,表单上的内容都不能动、也不能关,只会发出一次请求。成功了表单关掉、授权出现在「我授给 TA」里;失败了表单不关、填的内容都留着,改一下可以直接再点「授予」。提示由错误码决定,持有方的原话作补充放在提示下面,目录类的错误会指出是哪一行(并把那一行的输入框标红):
|
|
44
|
+
|
|
45
|
+
| 提示 | 意思与怎么办 |
|
|
46
|
+
| --- | --- |
|
|
47
|
+
| 这台机器不能用「仅限目录」 | `sandbox_unsupported`:目标机不是 macOS,或没有 `/usr/bin/sandbox-exec`。这台只能授整台机器 |
|
|
48
|
+
| 这台机器上的「远程执行」版本太旧 | `restrict_unsupported`:到那台机器上把 `remote-exec` 升到 0.2.0 及以上 |
|
|
49
|
+
| 第 N 行……不存在/不是目录 | `restrict_dir_not_found`、`restrict_dir_not_a_directory`:那一行的路径在目标机上没有、或不是目录,改路径 |
|
|
50
|
+
| 第 N 行与第 M 行……重叠 | `restrict_overlap`:允许目录之间不能互相包含或重复,请去掉其中一条(表单提交前就地检查字面部分,经符号链接、大小写的以目标机为准) |
|
|
51
|
+
| 第 N 行……受保护的位置 | `restrict_protected`:目录不能包含、也不能落在 Coda 的状态目录或 `~/.ssh` 里面(整个家目录因为包含 `~/.ssh` 也不行),请选与它们不重叠的目录 |
|
|
52
|
+
| 目标机上的沙箱起不来 | `sandbox_failed`:目标机上沙箱没跑通,原话在提示下面 |
|
|
53
|
+
| 目标机现在离线/读不到目标机/记录不在了/已经不是…… | `target_offline`、`target_unreachable`、`target_missing`、`target_changed`:目标机的状态不对,等它回来、让它重新打开远程执行,或关掉表单重选 |
|
|
54
|
+
| 目标机 30 秒内没有回应 | `timeout`:确认目标机在线、远程执行已打开,再试一次 |
|
|
55
|
+
| 范围太大 | `restrict_too_large`:目录太多或路径太长,签不出授权记录,减少或缩短 |
|
|
56
|
+
| 已经授给 TA 一条范围不同的授权 | `already_granted`:同一位好友对同一台机器只有一条有效授权,到那一行的菜单选「修改范围…」 |
|
|
57
|
+
| 目标机上的远程执行没打开 | `disabled`:让那台机器在 `remote-exec` 里打开开关 |
|
|
58
|
+
| 没有收到目标机的回应 | 页面等了 45 秒还没有回复(不是目标机的错误码):表单关掉,那一行显示「待确认」(授予是新出现的一行,改范围是原授权行上),页面每隔几秒读一遍列表核对;之后才到的回复照常处理(成功就并入,明确失败写在那一行)。核对读到想要的结果就落定;连续几遍都没有,授予的一行变成「未授予」可重试,改范围的一行写明「没有确认范围改成功」、仍是原来的范围,可以再改 |
|
|
59
|
+
|
|
60
|
+
这些失败都没有建或改任何东西(没有回应那一条除外,以后面的核对为准)。授「整台机器」不探测,也不会出现这些提示。
|
|
61
|
+
|
|
62
|
+
**看范围**:
|
|
63
|
+
|
|
64
|
+
- 「我授给 TA」的每一行,名字下面是范围:「整台机器」,或「仅限目录 · 第一条目录(读写/只读)等 N 个」(只有一条时不写「等 N 个」)。点开能看到全部目录和各自的「读写」「只读」,长路径折行显示、不会撑破一行。
|
|
65
|
+
- 「TA 授给我」的每一条同样写「整台机器」或目录摘要,点开看全部目录。这只是展示:放行与限制只在对方的网关与目标机上。
|
|
66
|
+
- 「最近的操作」里,仅限目录的调用有「仅限目录 · N 个」的标记,点开是那次调用当时的范围;整台机器的调用没有标记。
|
|
67
|
+
|
|
68
|
+
**改范围**:「我授给 TA」里仍可用的授权,行尾菜单选「修改范围…」,打开同一张表单,机器固定不能换,范围预填现在的。可以改目录,也可以在两种范围之间切(切到「整台机器」不探测)。点「保存范围」,同样要等探测,失败的提示同上。已撤销、已失效(目标不在了、本机或好友的身份变了)、正在撤销的授权,菜单里没有这一项。改完对之后的调用生效,已经在跑的不动。
|
|
69
|
+
|
|
70
|
+
### 授权的范围
|
|
71
|
+
|
|
72
|
+
一条授权有一个范围,是这条授权自己的属性(同一位好友对同一台机器仍只有一条有效授权):
|
|
73
|
+
|
|
74
|
+
- **整台机器**:好友的命令不受限,与以前一样,也是没有范围字段的旧授权的含义,不需要迁移。
|
|
75
|
+
- **仅限目录**:`restrict: { dirs: [{ path, access }] }`,`path` 是目标机上的绝对路径(至多 1024 字节),`access` 是 `rw`(可读写)或 `ro`(只读);1 到 50 行,至少一行 `rw`(与 `remote-exec` 一致)。好友的每条命令都在目标机的 macOS 沙箱里执行,只能读写这些目录(外加系统运行所需的只读路径和本次调用专用的临时目录,例外见 `remote-exec` README「受限执行」)。
|
|
76
|
+
|
|
77
|
+
**怎么授、怎么改**(页面上的用法见上一节;在会话或脚本里也可以经 `coda self` 调同名的操作,页面用的是同名的消息):
|
|
78
|
+
|
|
79
|
+
```
|
|
80
|
+
coda self grants.grant '{"friend":"ed25519:…","target":{"kind":"remote-exec/machine@1","id":"…"},"restrict":{"dirs":[{"path":"/Users/me/work","access":"rw"}]}}'
|
|
81
|
+
coda self grants.restrict '{"grant":"<授权号>","restrict":{"dirs":[…]}}' # restrict 不给(或 null)是改回整台机器
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
- **授予时先到目标机探测**:授「仅限目录」之前,网关向目标机发一次带这份 `restrict` 的 `exec`(命令 `true`,不给 `cwd`,没有副作用,目标机的操作记录里会有一行),目标机认了才建授权;不通过就当场失败、什么也不建、不签发,错误码与原因如下。授「整台机器」不探测。改成「仅限目录」同样先探测,不通过就不改。
|
|
85
|
+
|
|
86
|
+
| 错误码 | 原因 |
|
|
87
|
+
| --- | --- |
|
|
88
|
+
| `sandbox_unsupported` | 目标机不是 macOS,或没有可执行的 `/usr/bin/sandbox-exec` |
|
|
89
|
+
| `restrict_unsupported` | 目标机上的远程执行版本太旧(0.2.0 之前),按 schema 拒绝了 `restrict` 字段 |
|
|
90
|
+
| `restrict_dir_not_found`、`restrict_dir_not_a_directory` | 某个目录在目标机上不存在、不是目录(消息里有路径) |
|
|
91
|
+
| `restrict_protected` | 某个目录包含或落在目标机受保护的位置里(Coda 状态根、`~/.ssh`) |
|
|
92
|
+
| `restrict_overlap` | 允许目录互相重叠(相同、一条在另一条里面,字面或真实路径上);目标机为了不让受限命令经可写目录里的链接改道、也不让「只读」子目录实际可写而拒绝,消息里有冲突的两条 |
|
|
93
|
+
| `sandbox_failed` | 沙箱起不来,或探测命令没跑成 |
|
|
94
|
+
| `target_offline` | 目标机离线(已记成离线的不发探测;探测时连不上也是它) |
|
|
95
|
+
| `timeout` 及目标机的其他码 | 30 秒内目标机没有回应,或它的远程执行没打开(`disabled`)等,原样带回 |
|
|
96
|
+
| `restrict_too_large` | 范围写进授权记录后超过签发的 64 KiB 上限(路径里的引号、反斜杠、控制字符转义后更长),签不出去;在落盘与探测之前就拒绝,请减少目录或缩短路径 |
|
|
97
|
+
| `invalid_input` | `restrict` 形状不合格,没发探测 |
|
|
98
|
+
|
|
99
|
+
探测是权威:授予页上目标记录的 `os` 以 `Darwin` 开头只是「可能支持」的提示(`grants.targets` 每行的 `restrictHint`)。
|
|
100
|
+
- **已有授权**:授予先看有没有已有的有效授权,再决定要不要探测:范围相同原样给回那一条,范围不同报 `already_granted`(消息里带授权号),改范围走 `grants.restrict`;这两种都不探测,目标离线、探测会失败时也一样。只有确实要新建时才探测。
|
|
101
|
+
- **改范围**:落盘就对之后的调用生效:准入时与提交给目标机之前读的都是新范围,提交那一刻的范围记进在途项,重启后接手的也按它;已经在跑的调用不动。改完用同一个授权号重新签发授权记录(版本递增),好友看到新范围;目标暂时读不到(别台被移出空间)期间改的,待重新签发的状态保留,目标带着相同的 spec 回来后签出新范围。
|
|
102
|
+
- **每次调用带什么**:「仅限目录」的授权,网关每次都把授权行里的 `restrict` 写进交给目标机的 `exec` 输入(直接授出本机、与经网关转给空间里别的机器两条路径一样);「整台机器」的不写。好友请求里的 `restrict` 与任何未知字段在重建输入时丢掉,不透传,也去不掉授权行里的。好友没给 `cwd` 就不填,目标机用第一条 `rw` 目录;给了就须在允许的目录里(否则目标机以 `cwd_not_allowed` 拒绝)。目标机返回的沙箱类错误码与效果原样带回好友。
|
|
103
|
+
- **页面消息**:`grants.grant`、`grants.restrict` 经视图消息失败时,回复是 `{ type: 'reply', rid, ok: false, error, effects, code }`,`code` 是上表的稳定错误码(还有 `already_granted`、`not_found`、`invalid_state` 等),页面不必解析中文消息;成功的回复没有 `code`。
|
|
104
|
+
- **好友这一侧**:「TA 授给我」的每一条(`proxies.list`)带 `restrict`(仅限目录的才有,没有是整台机器),只用来展示,放行与限制只在网关与目标机。代理记录 `spec` 的形状不变(它登记在 `remote-exec/machine@1` 下,加字段旧节点会丢掉整条记录),仅限目录的授权,`spec.cwd`(默认目录)是第一条 `rw` 目录。代理记录的 `exec` 不收 `restrict`,当场以 `invalid_input` 拒绝,免得调用方以为自己收紧了、实际没有。
|
|
105
|
+
|
|
106
|
+
**能挡什么、挡不住什么**:用的就是 `remote-exec` 的受限执行,挡得住与挡不住的、macOS 沙箱的例外、错误码与已知限制见它的 README「受限执行」:这些目录之外的文件内容、`~/.ssh`、Coda 的整个状态根读写不到(系统运行所需的 `/usr`、`/bin`、`/sbin`、`/private/etc` 等只读路径,以及本次调用专用的临时目录,命令仍可使用),包括本插件的 `rpc/grants.json`(已有测试里真跑沙箱确认);不禁网、不限 CPU 与内存,目录是否存在与元信息不保证不可见。同一系统用户下,不受限的调用(含「整台机器」的授权)仍够得着这些,所以「仅限目录」只约束带限制的那条命令。
|
|
107
|
+
|
|
108
|
+
**目标机要求**:macOS,有 `/usr/bin/sandbox-exec`,远程执行 0.2.0 及以上。要不要升目标机的远程执行,授予时的探测会说。
|
|
109
|
+
|
|
110
|
+
**新旧版本互通**(授权的范围随好友插件 0.10.0):
|
|
111
|
+
|
|
112
|
+
- 「整台机器」的授权签出的记录与以前逐字节一样(`v: 1`),旧版好友照常能用。
|
|
113
|
+
- 「仅限目录」的授权记录是 `v: 2`,多一项 `restrict`。旧版好友的校验严格要求 `v` 是 1、不许多出字段,**收下前就拒掉**:新授予的在旧版好友那边不出现代理记录;已登记的授权被改成仅限目录后,旧版那边的代理记录留着但标为不可用(「好友的授权记录不在了,或和这位好友的通道已断开……」,调用当场失败、没发出任何请求),不会显示成一条可用的整台机器授权。要让旧版好友用上,请他升级。
|
|
114
|
+
- 旧版网关(持有方)读到新版写的 `grants.json`:只要表里有一行带范围,文件的 `v` 就是 2,旧版把它当损坏、停止准入(`grants.list` 的 `corrupt` 是 `grants.json`),绝不会把仅限目录的授权当整台机器放行;表里没有带范围的行时文件还是 `v: 1`,旧版照常读。降级后要用,先把仅限目录的授权改回整台机器(表里没有带范围的行了,文件回到 `v: 1`)。操作记录里带 `restrict` 的行,旧版读不了(该月的记录显示损坏,记不下新的),只影响记录。
|
|
115
|
+
- 范围在好友那边只是展示:好友篡改或伪造它没有用,放行与限制只在网关与目标机。
|
|
32
116
|
|
|
33
117
|
### 代理记录的名字
|
|
34
118
|
|
package/lib/rpc-caller.mjs
CHANGED
|
@@ -20,6 +20,10 @@
|
|
|
20
20
|
// - 请求拿到结局就撤回,拿不到的过期后撤回,都按发出时的作者署名:签不了或本机作者不是它,就推迟到能签、作者切回来,或过了保留期。
|
|
21
21
|
// 处理函数还没了结(重启后等 resume 收尾)的发出项不动。撤回请求与删掉发出项是两件事:发出项是重启后按原调用号找回、核对回答的索引,
|
|
22
22
|
// 留到恢复期结束才删:本进程的处理函数把结局交回宿主之后;上一代进程留下的,启动后 resume 的 30 秒窗口过了之后。
|
|
23
|
+
// - 授权的范围:授权记录(v2)里的 `restrict` 是仅限目录的范围,记在 `known` 里,`proxies.list` 的每一行带上它(没有是整台机器),只用来展示,
|
|
24
|
+
// 放行与限制都在持有方与目标机。代理记录的 `spec` 形状不变(登记在 remote-exec/machine@1 下,加字段旧节点会丢掉整条记录):仅限目录的授权,
|
|
25
|
+
// `spec.cwd` 是授权记录里写的第一条 rw 目录。旧版收不下 v2 的授权记录(见 rpc-format),所以仅限目录的授权旧版好友看不到、已登记的会标成不可用。
|
|
26
|
+
// 代理记录的 exec 不收 `restrict`:范围由授权定,当场拒绝,免得调用方以为自己收紧了、实际没有。
|
|
23
27
|
// - 本机作者变了:旧作者下的代理记录停用,正在等的请求不再处理,要等重新授予。
|
|
24
28
|
// - 签名只经网关的内部入口(signRpc、retractRpc)。
|
|
25
29
|
import { isDeepStrictEqual } from 'node:util';
|
|
@@ -110,7 +114,7 @@ export function createCaller(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
110
114
|
known.set(key, { holder, grant, grantee: null, spec: entry.spec, stem: entry.spec.name.slice(0, entry.spec.name.lastIndexOf('#')), tail, offered: false, present: false });
|
|
111
115
|
}
|
|
112
116
|
for (const [key, { friend, body }] of found) {
|
|
113
|
-
known.set(key, { holder: body.holder, grant: body.grant, grantee: body.grantee, spec: body.spec, ...stemOf(body.spec.name, friend), offered: body.available, present: true });
|
|
117
|
+
known.set(key, { holder: body.holder, grant: body.grant, grantee: body.grantee, spec: body.spec, restrict: body.restrict, ...stemOf(body.spec.name, friend), offered: body.available, present: true });
|
|
114
118
|
}
|
|
115
119
|
const contests = new Map();
|
|
116
120
|
for (const [key, grant] of known) {
|
|
@@ -187,6 +191,7 @@ export function createCaller(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
187
191
|
await ready;
|
|
188
192
|
const me = await identity(), grant = known.get(ctx.record?.key), problem = problemOf(grant, me);
|
|
189
193
|
if (problem) throw fail(...PROBLEMS[problem]);
|
|
194
|
+
if (input?.restrict !== undefined) throw fail('invalid_input', 'restrict 不能由调用方给:好友的授权已定了范围(整台机器,或授权里列的目录),要收得更紧就在命令里自己做');
|
|
190
195
|
const rebuilt = rebuildExecInput(input);
|
|
191
196
|
if (!rebuilt.ok) throw fail('invalid_input', rebuilt.message);
|
|
192
197
|
const request = requestId(ctx.id), createdAt = now();
|
|
@@ -369,13 +374,15 @@ export function createCaller(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
369
374
|
|
|
370
375
|
// 好友授给本机的代理记录(给好友页读,只读):给了 `friend`(好友的公钥)就只列这位好友的,按他通道背后的机器钥匙筛。
|
|
371
376
|
// 名字取空间里登记着这一授权的那条代理记录的(去重让给别的机器的,取那台的;哪儿都没登记是 null)。
|
|
372
|
-
// 状态:available 可用,或 PROBLEMS 里的原因(off、channel、author、sign
|
|
377
|
+
// 状态:available 可用,或 PROBLEMS 里的原因(off、channel、author、sign)。`restrict` 是授权的范围(仅限目录的才有,没有是整台机器),只用来展示;
|
|
378
|
+
// 重启后授权记录还没重新读到的行(status 是 channel)没有它。
|
|
373
379
|
async function list({ friend } = {}) {
|
|
374
380
|
if (friend !== undefined && !isAuthor(friend)) throw fail('invalid_input', 'friend 须是好友的公钥(ed25519:…)');
|
|
375
381
|
await ready;
|
|
376
382
|
const me = await identity(), holders = new Set(me.friends.filter(one => friend === undefined || one.author === friend).map(one => one.machine));
|
|
377
383
|
return [...known].filter(([, grant]) => friend === undefined || holders.has(grant.holder))
|
|
378
|
-
.map(([key, grant]) => ({ key, grant: grant.grant, holder: grant.holder, name: grant.title, os: grant.spec.os, user: grant.spec.user, status: problemOf(grant, me) ?? 'available'
|
|
384
|
+
.map(([key, grant]) => ({ key, grant: grant.grant, holder: grant.holder, name: grant.title, os: grant.spec.os, user: grant.spec.user, status: problemOf(grant, me) ?? 'available',
|
|
385
|
+
...(grant.restrict ? { restrict: grant.restrict } : {}) }));
|
|
379
386
|
}
|
|
380
387
|
|
|
381
388
|
// ---- 请求的撤回 ----
|
package/lib/rpc-format.mjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// 好友签名网关的记录格式:三种签名记录(授权 friends/rpc-grant、调用请求 friends/rpc-call、回答 friends/rpc-answer)的正文构造与校验、
|
|
2
2
|
// 请求号与回答 id 与内核幂等键的派生、请求摘要、重放窗口、exec 输入的重建、按字节算的大小上限与回答截短。纯函数,不碰盘、不碰 Coda。
|
|
3
3
|
// 校验的结果一律是 `{ ok: true, ... }` 或 `{ ok: false, code }`:码是稳定的,持有方与调用方会把它记进操作记录。
|
|
4
|
+
// 授权的范围(整台机器,或仅限目录的 `restrict`):整台机器的授权正文是 v1,与加范围之前逐字节一样;仅限目录的授权正文是 v2,多一项 `restrict`。
|
|
5
|
+
// v1 校验严格拒绝未知字段与 v2,所以旧版好友看不到仅限目录的授权(见 README「新旧版本互通」);范围只在网关与目标机强制,好友一侧的只用来展示。
|
|
4
6
|
import { createHash } from 'node:crypto';
|
|
5
7
|
|
|
6
8
|
export const KIND_GRANT = 'friends/rpc-grant', KIND_CALL = 'friends/rpc-call', KIND_ANSWER = 'friends/rpc-answer';
|
|
@@ -31,6 +33,22 @@ const isText = value => typeof value === 'string';
|
|
|
31
33
|
|
|
32
34
|
export const isAuthor = value => isText(value) && AUTHOR.test(value);
|
|
33
35
|
|
|
36
|
+
// ---- 授权的范围 ----
|
|
37
|
+
|
|
38
|
+
// 范围就是 remote-exec 的 `exec` 输入里的 `restrict`:`{ dirs: [{ path, access: 'rw' | 'ro' }] }`,行数上限与 remote-exec 一致(50),至少一行 `rw`。
|
|
39
|
+
// 路径另有字节数上限(macOS 的 PATH_MAX),好让 50 行写进授权记录也不超 Accord 记录的 64 KiB。
|
|
40
|
+
export const MAX_RESTRICT_DIRS = 50, MAX_RESTRICT_PATH_BYTES = 1024;
|
|
41
|
+
const dirOk = one => isPlain(one) && Object.keys(one).length === 2 && isText(one.path) && one.path.startsWith('/') && !one.path.includes('\0')
|
|
42
|
+
&& Buffer.byteLength(one.path) <= MAX_RESTRICT_PATH_BYTES && (one.access === 'rw' || one.access === 'ro');
|
|
43
|
+
export const restrictOk = restrict => isPlain(restrict) && Object.keys(restrict).length === 1 && Array.isArray(restrict.dirs)
|
|
44
|
+
&& restrict.dirs.length >= 1 && restrict.dirs.length <= MAX_RESTRICT_DIRS && restrict.dirs.every(dirOk) && restrict.dirs.some(one => one.access === 'rw');
|
|
45
|
+
/** 合格的范围按固定的键序抄一份(授权行、授权记录与探测都用它,同一范围的写法唯一);不合格给 null。 */
|
|
46
|
+
export const cleanRestrict = restrict => restrictOk(restrict) ? { dirs: restrict.dirs.map(({ path, access }) => ({ path, access })) } : null;
|
|
47
|
+
/** 不给 `cwd` 时目标机用的目录:第一条 `rw`。 */
|
|
48
|
+
export const firstRw = restrict => restrict.dirs.find(one => one.access === 'rw').path;
|
|
49
|
+
/** 记录的系统以 `Darwin` 开头才可能支持受限执行(只是提示,权威是授予时的探测)。 */
|
|
50
|
+
export const sandboxHint = os => isText(os) && os.startsWith('Darwin');
|
|
51
|
+
|
|
34
52
|
/**
|
|
35
53
|
* 本机此刻替调用请求(friends/rpc-call)署名的作者(`coda/accord@1` 的 local 记录):`{ author, person, canSign }`。
|
|
36
54
|
* `status.certificate` 为 null 是没绑个人身份的后端,作者是机器钥匙,没有有效期,能签;是对象是个人作者(根),证书 `active` 才能签;
|
|
@@ -129,9 +147,9 @@ const errorOk = error => isPlain(error) && Object.keys(error).length === 3 && is
|
|
|
129
147
|
// 每种正文:必有的字段与可有的字段,各配一个类型检查;多出来的字段、缺的必有字段、类型不对都拒。
|
|
130
148
|
const SHAPES = {
|
|
131
149
|
[KIND_GRANT]: {
|
|
132
|
-
required: { v: v => v === 1, holder: isAuthor, grantee: isAuthor, grant: v => isText(v) && UUID.test(v), protocol: v => v === PROTOCOL,
|
|
150
|
+
required: { v: v => v === 1 || v === 2, holder: isAuthor, grantee: isAuthor, grant: v => isText(v) && UUID.test(v), protocol: v => v === PROTOCOL,
|
|
133
151
|
ops: v => Array.isArray(v) && v.length === 1 && v[0] === 'exec', spec: specOk, available: v => typeof v === 'boolean', grantedAt: isTime },
|
|
134
|
-
optional: {},
|
|
152
|
+
optional: { restrict: restrictOk },
|
|
135
153
|
},
|
|
136
154
|
[KIND_CALL]: {
|
|
137
155
|
required: { v: v => v === 1, caller: isAuthor, holder: isAuthor, grant: v => isText(v) && UUID.test(v), request: v => isText(v) && REQUEST.test(v),
|
|
@@ -170,6 +188,8 @@ function shapeProblem(kind, body) {
|
|
|
170
188
|
}
|
|
171
189
|
for (const [key, check] of Object.entries(optional)) if (Object.hasOwn(body, key) && !check(body[key])) return 'bad_body';
|
|
172
190
|
if (kind === KIND_CALL && Object.hasOwn(body, 'cancel') !== Object.hasOwn(body, 'canceledAt')) return 'bad_body';
|
|
191
|
+
// 授权:v1 是整台机器、没有 restrict;v2 是仅限目录、必有 restrict。
|
|
192
|
+
if (kind === KIND_GRANT && (body.v === 2) !== Object.hasOwn(body, 'restrict')) return 'bad_body';
|
|
173
193
|
return null;
|
|
174
194
|
}
|
|
175
195
|
|
|
@@ -226,9 +246,9 @@ function build(kind, body) {
|
|
|
226
246
|
return { kind, id: rule.id(body), body, audience: [body[rule.receiver]] };
|
|
227
247
|
}
|
|
228
248
|
|
|
229
|
-
/** 授权:id 是授权号,受众是被授权者。`spec`、`available`
|
|
230
|
-
export const grantRecord = ({ holder, grantee, grant, spec, available, grantedAt }) =>
|
|
231
|
-
build(KIND_GRANT, { v: 1, holder, grantee, grant, protocol: PROTOCOL, ops: ['exec'], spec, available, grantedAt });
|
|
249
|
+
/** 授权:id 是授权号,受众是被授权者。`spec`、`available`、`restrict` 只用于展示。给了 `restrict` 是 v2 的仅限目录授权,不给是与以前逐字节一样的 v1。 */
|
|
250
|
+
export const grantRecord = ({ holder, grantee, grant, spec, available, grantedAt, restrict }) =>
|
|
251
|
+
build(KIND_GRANT, { v: restrict ? 2 : 1, holder, grantee, grant, protocol: PROTOCOL, ops: ['exec'], spec, available, grantedAt, ...(restrict ? { restrict } : {}) });
|
|
232
252
|
|
|
233
253
|
/** 调用请求:id 是请求号(`requestId` 派生),受众是持有方。 */
|
|
234
254
|
export const callRecord = ({ caller, holder, grant, request, input, createdAt, expiresAt }) =>
|
package/lib/rpc-holder.mjs
CHANGED
|
@@ -12,6 +12,9 @@
|
|
|
12
12
|
// - 授权表(rpc-store 的 grants.json)是权威:撤权与失效先落盘、不可逆,之后尚未提交的不再启动,已提交的走「对方发来取消」同一条路径取消;授权记录(friends/rpc-grant)的发与撤
|
|
13
13
|
// 按授权号排成一条队,发不出去等能发了再补,撤回要等原来那把机器钥匙能签时补发。启动后查一次目录,本机机器钥匙签出、授权表里却没有对应有效授权的
|
|
14
14
|
// (清过状态目录后留下的)也排进这条队撤回;授权表损坏时不查。
|
|
15
|
+
// - 授权的范围(授权行的 `restrict`):没有是整台机器,有是仅限目录。范围只在这里强制:好友请求里的 `restrict` 与任何未知字段在重建输入时丢掉,
|
|
16
|
+
// 不透传;仅限目录的授权,每次调用都带授权行里的 `restrict`(提交那一刻读最新的授权行记进在途项,改范围对之后的调用立即生效、已提交的不动),
|
|
17
|
+
// 没给 cwd 就让目标机用第一条 `rw` 目录。授「仅限目录」与改成仅限目录之前,先向目标机发一次带这份 `restrict` 的探测,目标机拒绝就不授、不改。
|
|
15
18
|
// - 持有方始终以机器出现:授权记录与回答用本机机器钥匙签(rpc-format 的 machineOf,网关带 `signer: "machine"`),与有没有绑个人身份、
|
|
16
19
|
// 证书是否有效无关;证书过期照常准入、执行、签回答、撤回答。授权记下授予时的机器钥匙,机器钥匙变了授权就此失效;
|
|
17
20
|
// 本机绑定、解绑个人身份或换根都不影响它授出的授权。
|
|
@@ -26,8 +29,9 @@
|
|
|
26
29
|
import { performance } from 'node:perf_hooks';
|
|
27
30
|
import { isDeepStrictEqual } from 'node:util';
|
|
28
31
|
import { certStateOf, statusOf } from './friends.mjs';
|
|
29
|
-
import { KIND_ANSWER, KIND_CALL, KIND_GRANT, PROTOCOL, answerId, answerRecord, clockWentBack, grantRecord, idempotencyKey, isAuthor, rebuildExecInput,
|
|
32
|
+
import { KIND_ANSWER, KIND_CALL, KIND_GRANT, PROTOCOL, answerId, answerRecord, cleanRestrict, clockWentBack, firstRw, grantRecord, idempotencyKey, isAuthor, rebuildExecInput,
|
|
30
33
|
machineNameOk, machineOf, replayWindow, requestDigest, verifyCall } from './rpc-format.mjs';
|
|
34
|
+
import { MAX_BODY_BYTES } from './outbox.mjs';
|
|
31
35
|
import { answerDueAt, commandInfo, inflightKey, isCorrupt } from './rpc-store.mjs';
|
|
32
36
|
export { ANSWER_KEEP_MS } from './rpc-store.mjs';
|
|
33
37
|
|
|
@@ -37,6 +41,8 @@ export const POLL_MS = 15_000;
|
|
|
37
41
|
// exec 不给 timeout 时 remote-exec 的默认时限(秒);remote-exec 的操作时限比命令时限多 30 秒(630 对 600),收尾用。
|
|
38
42
|
// 跨机调用的总时限是命令时限加 CALL_GRACE_MS(remote-exec 的 30 秒余量,再留 30 秒给结局送回):到点由内核放弃,排着没送出的不会再执行。
|
|
39
43
|
const DEFAULT_TIMEOUT_S = 120, CALL_GRACE_MS = 60_000;
|
|
44
|
+
// 授「仅限目录」前探测目标机的时限:够目标机起一次沙箱、跑一条 `true`;目标机没有及时回应就按没通过。
|
|
45
|
+
const PROBE_TIMEOUT_MS = 30_000;
|
|
40
46
|
// 见过的最大时刻至多每分钟落一次盘。
|
|
41
47
|
const CLOCK_STEP_MS = 60_000;
|
|
42
48
|
// 失效落盘失败后重试的退避:从 1 秒起翻倍,至多 1 分钟。
|
|
@@ -260,7 +266,11 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
260
266
|
const check = await targetCheck(row, me);
|
|
261
267
|
if (ENDING[check.problem]) row = await endGrant(id, ENDING[check.problem]);
|
|
262
268
|
// 别台的目标此刻读不到:已发出的授权记录原样留着(只拒不失效),那台回来后照常。
|
|
263
|
-
|
|
269
|
+
// 但授权的范围改过、新正文还没签出的,待发布要留着(返回 false,由后面的节拍再来),目标回来后签出新范围。
|
|
270
|
+
else if (check.problem) {
|
|
271
|
+
const [mine] = (await coda.query(ACCORD, 'records', { kind: KIND_GRANT, author: me.machine, id, limit: 1 }))?.records ?? [];
|
|
272
|
+
return isDeepStrictEqual(mine?.body?.restrict ?? null, row.restrict ?? null);
|
|
273
|
+
}
|
|
264
274
|
target = check.entry;
|
|
265
275
|
}
|
|
266
276
|
}
|
|
@@ -272,7 +282,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
272
282
|
return true;
|
|
273
283
|
}
|
|
274
284
|
if (stopped || !isAuthor(me.machine)) return false;
|
|
275
|
-
const record =
|
|
285
|
+
const record = grantRecordOf(row, target);
|
|
276
286
|
const [mine] = (await coda.query(ACCORD, 'records', { kind: KIND_GRANT, author: me.machine, id, limit: 1 }))?.records ?? [];
|
|
277
287
|
// 签之前再读一次:撤了,或这时落进了待落盘的失效,都不发(失效落盘后再来撤)。
|
|
278
288
|
const latest = await store.getGrant(id);
|
|
@@ -281,6 +291,19 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
281
291
|
return true;
|
|
282
292
|
}
|
|
283
293
|
const pickSpec = spec => ({ name: spec?.name, os: spec?.os, user: spec?.user, cwd: spec?.cwd });
|
|
294
|
+
// 一条授权发给好友的授权记录。仅限目录的授权,记录里的默认目录是第一条 rw 目录(目标机上不给 cwd 时用的也是它)。
|
|
295
|
+
function grantRecordOf(row, target) {
|
|
296
|
+
const spec = pickSpec(target.spec);
|
|
297
|
+
return grantRecord({ holder: row.holder.machine, grantee: row.grantee, grant: row.id, spec: row.restrict ? { ...spec, cwd: firstRw(row.restrict) } : spec,
|
|
298
|
+
available: target.status?.available === true, grantedAt: row.createdAt, restrict: row.restrict });
|
|
299
|
+
}
|
|
300
|
+
// 落盘之前先量实际要签的授权记录:网关签发的字节上限是 MAX_BODY_BYTES,含 JSON 转义;超了落盘也永远签不出去,当场拒绝。
|
|
301
|
+
// 记录的大小只取决于范围、机器的 spec 与固定长度的各项,所以用占位的授权号量(UUID 长度固定)。
|
|
302
|
+
function checkFits(machine, grantee, target, restrict) {
|
|
303
|
+
const row = { id: '00000000-0000-4000-8000-000000000000', holder: { machine }, grantee, createdAt: now(), restrict };
|
|
304
|
+
if (Buffer.byteLength(JSON.stringify(grantRecordOf(row, target).body)) > MAX_BODY_BYTES)
|
|
305
|
+
throw fail('restrict_too_large', `仅限目录的范围写进授权记录超过 ${MAX_BODY_BYTES} 字节的上限(路径里的引号、反斜杠、控制字符转义后更长),签不出去:请减少目录或缩短路径`);
|
|
306
|
+
}
|
|
284
307
|
|
|
285
308
|
// 跟上一条授权:开始前先取走它的待补标记,没成再标回去;同步进行中新来的标记留着,由随后的节拍再补一次。
|
|
286
309
|
async function settle(id) {
|
|
@@ -519,7 +542,8 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
519
542
|
try {
|
|
520
543
|
// 先登记中止的手柄、再读一次:取消落在这之前的,这里看得到;落在之后的,会经手柄中止。
|
|
521
544
|
if ((await store.get(entry.caller, entry.request))?.canceled) controller.abort();
|
|
522
|
-
|
|
545
|
+
// 范围取自提交那一刻记下的(见 store.markSubmitted),不取好友的请求;重启后接手的也是同一份。
|
|
546
|
+
const { target, input: given, restrict } = entry.call, input = restrict ? { ...given, restrict } : given;
|
|
523
547
|
const limit = (input.timeout ?? DEFAULT_TIMEOUT_S) * 1000 + CALL_GRACE_MS;
|
|
524
548
|
let outcome = outcomes.get(key);
|
|
525
549
|
if (outcome === undefined && controller.signal.aborted) {
|
|
@@ -585,9 +609,11 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
585
609
|
const finishedAt = now(), key = inflightKey(entry.caller, entry.request), { target, input } = entry.call;
|
|
586
610
|
let name = target.id;
|
|
587
611
|
try { name = (await targetOf(target))?.spec?.name || target.id; } catch { /* 名字只是展示 */ }
|
|
612
|
+
// 当时的授权范围:提交过的是提交那一刻记下的,没提交过的(拒绝、取消)取授权行此刻的。
|
|
613
|
+
const restrict = entry.call.restrict !== undefined ? entry.call.restrict : (await store.getGrant(entry.grant))?.restrict;
|
|
588
614
|
const row = { v: 1, at: finishedAt, request: entry.request, friend: entry.caller, grant: entry.grant, target: { kind: target.kind, id: target.id, name }, op: 'exec',
|
|
589
615
|
command: commandInfo(input.command), outcome: state, ...(error ? { code: error.code } : {}), ...(result && 'exitCode' in result ? { exitCode: result.exitCode } : {}),
|
|
590
|
-
ms: Math.round(monotonic() - (since.get(key) ?? monotonic())) };
|
|
616
|
+
...(restrict ? { restrict } : {}), ms: Math.round(monotonic() - (since.get(key) ?? monotonic())) };
|
|
591
617
|
return { state, ending: { finishedAt, ...(result === undefined ? {} : { result }), ...(error === undefined ? {} : { error }) }, row };
|
|
592
618
|
}
|
|
593
619
|
|
|
@@ -706,8 +732,39 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
706
732
|
|
|
707
733
|
// ---- 授予、撤销与列出 ----
|
|
708
734
|
|
|
709
|
-
|
|
735
|
+
// 授权的范围:不给(或 null)是整台机器;给了须是合格的 `{ dirs: [{ path, access }] }`,按固定键序抄一份。
|
|
736
|
+
function scopeOf(restrict) {
|
|
737
|
+
if (restrict === undefined || restrict === null) return null;
|
|
738
|
+
const scope = cleanRestrict(restrict);
|
|
739
|
+
if (!scope) throw invalid('restrict 须是 { dirs: [{ path, access }] }:1 到 50 项,path 是绝对路径(至多 1024 字节),access 是 rw 或 ro,至少一项 rw');
|
|
740
|
+
return scope;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// 探测失败的原因(给调用的页面看):码是稳定的,目标机拒绝的码原样带回,旧版目标机按 schema 拒绝 restrict 这个字段(invalid_input)记为 restrict_unsupported。
|
|
744
|
+
const PROBE_CAUSES = {
|
|
745
|
+
sandbox_unsupported: '目标机不支持受限执行(只有 macOS 且有 /usr/bin/sandbox-exec 的机器可以)',
|
|
746
|
+
restrict_unsupported: '目标机上的远程执行版本太旧,不认识 restrict',
|
|
747
|
+
restrict_dir_not_found: '目标机上有目录不存在',
|
|
748
|
+
restrict_dir_not_a_directory: '目标机上有路径不是目录',
|
|
749
|
+
restrict_protected: '有目录与目标机上受保护的位置(Coda 状态根、~/.ssh)重叠',
|
|
750
|
+
restrict_overlap: '有允许目录互相重叠(重复,或一条在另一条里面)',
|
|
751
|
+
sandbox_failed: '目标机上的沙箱起不来',
|
|
752
|
+
target_offline: REASONS.target_offline,
|
|
753
|
+
};
|
|
754
|
+
// 授「仅限目录」之前向目标机发一次带这份 restrict 的 exec(`true`,不给 cwd,没有副作用):目标机认、目录都能用才算数。
|
|
755
|
+
// 目标机拒绝、版本太旧、连不上、或沙箱起不来,都当场失败:什么也不授。
|
|
756
|
+
async function probe(target, restrict) {
|
|
757
|
+
let result;
|
|
758
|
+
try { result = await coda.call({ kind: target.kind, id: target.id }, 'exec', { command: 'true', restrict }, { timeout: PROBE_TIMEOUT_MS }); } catch (e) {
|
|
759
|
+
const code = e?.code === 'invalid_input' ? 'restrict_unsupported' : e?.code === 'peer_offline' ? 'target_offline' : String(e?.code ?? 'probe_failed');
|
|
760
|
+
throw fail(code, `没有授出仅限目录的范围,目标机探测没通过${PROBE_CAUSES[code] ? `(${PROBE_CAUSES[code]})` : ''}:${message(e)}`);
|
|
761
|
+
}
|
|
762
|
+
if (result?.exitCode !== 0) throw fail('sandbox_failed', `没有授出仅限目录的范围,目标机探测没通过(${PROBE_CAUSES.sandbox_failed}):true 退出码 ${result?.exitCode},${String(result?.stderr ?? '').trim()}`);
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
async function grant({ friend, target, restrict } = {}) {
|
|
710
766
|
if (stopped) throw fail('interrupted', '好友网关已停止');
|
|
767
|
+
const scope = scopeOf(restrict);
|
|
711
768
|
if (!isAuthor(friend)) throw invalid('friend 须是好友的公钥(ed25519:…)');
|
|
712
769
|
if (!target || typeof target !== 'object' || target.kind !== PROTOCOL || typeof target.id !== 'string' || !target.id) throw invalid(`target 须是一条 ${PROTOCOL} 记录的 { kind, id }`);
|
|
713
770
|
const entry = await targetOf(target);
|
|
@@ -719,9 +776,23 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
719
776
|
const me = await identity();
|
|
720
777
|
if (!me.bound.has(friend)) throw invalid('这位不是已绑定好友通道的好友');
|
|
721
778
|
if (!isAuthor(me.machine)) throw fail('invalid_state', '读不出本机的机器钥匙,不能授权');
|
|
722
|
-
|
|
779
|
+
const at = { owner: entry.owner, provider: entry.plugin, kind: target.kind, id: target.id };
|
|
780
|
+
// 先看有没有已有的有效授权(同一好友、同一目标):范围相同原样给回(页面重试授予拿到的还是它),不同报已存在,改范围走 grants.restrict;都不探测,目标离线也一样。
|
|
781
|
+
const live = await store.findLiveGrant({ holder: { machine: me.machine }, grantee: friend, target: at }, pendingEnd);
|
|
782
|
+
if (live) {
|
|
783
|
+
if (!isDeepStrictEqual(live.restrict ?? null, scope)) throw fail('already_granted', `已经授给这位好友一条(授权号 ${live.id}),范围不同:改范围请用 grants.restrict,不要再授一条`);
|
|
784
|
+
// 状态与 grants.list 一样按目标此刻的实况(离线就是 target_offline),只是不做 exec 探测。
|
|
785
|
+
return describe(live, me, await targetCheck(live, me, { live: true }).catch(() => ({ entry: null, problem: 'target_unreachable' })));
|
|
786
|
+
}
|
|
787
|
+
if (scope) {
|
|
788
|
+
checkFits(me.machine, friend, entry, scope);
|
|
789
|
+
if (entry.local !== true && await machineOffline(entry.owner)) throw fail('target_offline', `没有授出仅限目录的范围,目标机探测没通过(${REASONS.target_offline})`);
|
|
790
|
+
await probe(target, scope);
|
|
791
|
+
}
|
|
792
|
+
// 探测期间别处又授出了同一条:store 的写入里仍原子去重,给回那一条,范围不同照样报已存在。
|
|
723
793
|
const added = await store.addGrant({ holder: { machine: me.machine }, grantee: friend, granteePerson: me.bound.get(friend),
|
|
724
|
-
target:
|
|
794
|
+
target: at, createdAt: now(), ...(scope ? { restrict: scope } : {}) }, pendingEnd), row = added.entry;
|
|
795
|
+
if (!added.created && !isDeepStrictEqual(row.restrict ?? null, scope)) throw fail('already_granted', `已经授给这位好友一条(授权号 ${row.id}),范围不同:改范围请用 grants.restrict,不要再授一条`);
|
|
725
796
|
// 新授出的:不归此前的失效管,并发出授权记录。
|
|
726
797
|
if (added.created) {
|
|
727
798
|
for (const one of pendingEnds.values()) one.after.add(row.id);
|
|
@@ -730,6 +801,27 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
730
801
|
return describe(row, me, { entry, problem: null });
|
|
731
802
|
}
|
|
732
803
|
|
|
804
|
+
// 改一条有效授权的范围:整台机器 ↔ 仅限目录,或换目录(`restrict` 不给是整台机器)。改成仅限目录先探测,目标机拒绝就不改。
|
|
805
|
+
// 落盘之后立即对之后的准入与提交生效,已经提交的调用不动;随后重新签发授权记录(同一授权号、更高版本),好友那边看到新范围。
|
|
806
|
+
async function restrictGrant({ grant: id, restrict } = {}) {
|
|
807
|
+
if (stopped) throw fail('interrupted', '好友网关已停止');
|
|
808
|
+
if (typeof id !== 'string' || !id) throw invalid('grant 须是授权号');
|
|
809
|
+
const scope = scopeOf(restrict), row = await store.getGrant(id);
|
|
810
|
+
if (!row) throw fail('not_found', `没有授权 ${id}`);
|
|
811
|
+
const gone = () => fail('invalid_state', '这条授权已撤销或已失效,不能改范围');
|
|
812
|
+
if (row.revokedAt !== undefined || pendingEnd(row)) throw gone();
|
|
813
|
+
const me = await identity(), check = await targetCheck(row, me, { live: true });
|
|
814
|
+
if (scope) {
|
|
815
|
+
if (check.problem) throw fail(check.problem, `没有改范围,目标机探测没通过(${REASONS[check.problem]})`);
|
|
816
|
+
checkFits(row.holder.machine, row.grantee, check.entry, scope);
|
|
817
|
+
await probe(row.target, scope);
|
|
818
|
+
}
|
|
819
|
+
const set = await store.setRestrict(id, scope, pendingEnd);
|
|
820
|
+
if (!set.ok) throw set.code === 'not_found' ? fail('not_found', `没有授权 ${id}`) : gone();
|
|
821
|
+
await settle(id);
|
|
822
|
+
return describe(set.entry, me, check);
|
|
823
|
+
}
|
|
824
|
+
|
|
733
825
|
async function revoke({ grant: id } = {}) {
|
|
734
826
|
if (typeof id !== 'string' || !id) throw invalid('grant 须是授权号');
|
|
735
827
|
// 撤权先落盘:之后排队中、恢复中尚未提交的都不再启动(提交前在同一个串行操作里再读授权行)。
|
|
@@ -759,7 +851,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
759
851
|
: ['target_unreachable', 'target_offline'].includes(problem) ? problem : problem ? 'target_missing' : !isAuthor(me.machine) ? 'no_identity'
|
|
760
852
|
: target.status?.available === true ? 'available' : 'target_off');
|
|
761
853
|
return { grant: row.id, friend: row.grantee, target: { kind: row.target.kind, id: row.target.id, name: target?.spec?.name ?? null },
|
|
762
|
-
createdAt: row.createdAt, ...(row.revokedAt === undefined ? {} : { revokedAt: row.revokedAt }), status };
|
|
854
|
+
createdAt: row.createdAt, ...(row.restrict ? { restrict: row.restrict } : {}), ...(row.revokedAt === undefined ? {} : { revokedAt: row.revokedAt }), status };
|
|
763
855
|
}
|
|
764
856
|
|
|
765
857
|
async function list() {
|
|
@@ -787,7 +879,7 @@ export function createHolder(coda, { store, signRpc, retractRpc, onAccord, pages
|
|
|
787
879
|
|
|
788
880
|
return {
|
|
789
881
|
// `coda self` 的处理函数。
|
|
790
|
-
self: { 'grants.list': list, 'grants.grant': grant, 'grants.revoke': revoke, 'ledger.list': ledger },
|
|
882
|
+
self: { 'grants.list': list, 'grants.grant': grant, 'grants.restrict': restrictGrant, 'grants.revoke': revoke, 'ledger.list': ledger },
|
|
791
883
|
tick: () => tick(),
|
|
792
884
|
// 测试与诊断用:此刻还在推进的在途项数。
|
|
793
885
|
busy: () => drives.size,
|
package/lib/rpc-store.mjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
// 好友签名网关的本机状态:插件状态目录下 `rpc/` 里的四样东西。
|
|
2
|
-
// grants.json
|
|
2
|
+
// grants.json 授权表(持有方):本机授权行是权威,撤权先落盘。授权行的 `restrict` 是授权的范围(仅限目录),没有就是整台机器。
|
|
3
|
+
// 表里有任何一行带 `restrict` 时文件的 `v` 是 2,否则是 1:旧版读到 v2 的表按「损坏」停止准入,不会把仅限目录的授权当整台机器放行。
|
|
3
4
|
// inflight.json 在途与去重表(持有方):键是 (调用方作者, 请求号),状态只进不退,终态先落盘。
|
|
4
5
|
// outgoing.json 发出表(调用方):本人查账用;也存着请求正文与核对回答要的各项(发出时的作者、持有方、授权号、摘要),重启后收尾、补发取消、撤回都照它。
|
|
5
6
|
// ledger-YYYY-MM.jsonl 操作记录(持有方):每个请求一行,拒绝按「作者、原因、分钟」合并成一行,留 90 天。
|
|
@@ -10,7 +11,7 @@ import { createHash, randomUUID } from 'node:crypto';
|
|
|
10
11
|
import { chmod, mkdir, open, readFile, readdir, rename, rm, unlink } from 'node:fs/promises';
|
|
11
12
|
import { join } from 'node:path';
|
|
12
13
|
import { isDeepStrictEqual } from 'node:util';
|
|
13
|
-
import { isAuthor, rebuildExecInput, requestDigest } from './rpc-format.mjs';
|
|
14
|
+
import { isAuthor, rebuildExecInput, requestDigest, restrictOk } from './rpc-format.mjs';
|
|
14
15
|
|
|
15
16
|
const MINUTE = 60_000, DAY = 24 * 60 * MINUTE;
|
|
16
17
|
export const LIMITS = Object.freeze({
|
|
@@ -42,13 +43,13 @@ export const isCorrupt = error => error?.code === 'corrupt';
|
|
|
42
43
|
|
|
43
44
|
// ---- 条目的形状 ----
|
|
44
45
|
|
|
45
|
-
// 授权行:`holder.machine` 是授予时本机的机器钥匙(持有方始终以机器出现);`target.owner` 是目标记录所在的后端:本机的,或同一空间里本机作网关授出的别的机器;`granteePerson` 是被授权的好友当时是不是个人作者
|
|
46
|
+
// 授权行:`restrict`(可省)是授权的范围:`{ dirs }`,没有是整台机器,旧行就是这样;`holder.machine` 是授予时本机的机器钥匙(持有方始终以机器出现);`target.owner` 是目标记录所在的后端:本机的,或同一空间里本机作网关授出的别的机器;`granteePerson` 是被授权的好友当时是不是个人作者
|
|
46
47
|
// (好友表的 `certified`,宿主还不写时是 null)。
|
|
47
48
|
const isFlag = value => typeof value === 'boolean';
|
|
48
49
|
// 授权号以外的各项:新授权在 store 里查重没命中才生成授权号,先按这些校验。
|
|
49
50
|
const grantFieldsOk = entry => isPlain(entry) && isPlain(entry.holder) && isAuthor(entry.holder.machine)
|
|
50
51
|
&& isAuthor(entry.grantee) && (entry.granteePerson === null || isFlag(entry.granteePerson)) && isTarget(entry.target) && Array.isArray(entry.ops) && entry.ops.length === 1 && entry.ops[0] === 'exec'
|
|
51
|
-
&& isTime(entry.createdAt) && optional(entry.revokedAt, isTime) && optional(entry.endedBy, isText) && optional(entry.retractedAt, isTime);
|
|
52
|
+
&& isTime(entry.createdAt) && optional(entry.restrict, restrictOk) && optional(entry.revokedAt, isTime) && optional(entry.endedBy, isText) && optional(entry.retractedAt, isTime);
|
|
52
53
|
const grantOk = entry => grantFieldsOk(entry) && isText(entry.id);
|
|
53
54
|
|
|
54
55
|
// 在途项按状态校验:非终态要有完整的子调用参数(固定目标、重建后的输入;幂等键与最晚启动时刻每项都有),且不带结局与「已签出」;
|
|
@@ -57,7 +58,8 @@ const grantOk = entry => grantFieldsOk(entry) && isText(entry.id);
|
|
|
57
58
|
const inflightOk = entry => {
|
|
58
59
|
// 存的是重建后的 exec 输入:按 rpc-format 的重建规则能原样重建(结果与存的完全相同)才算。
|
|
59
60
|
const inputOk = input => { const rebuilt = rebuildExecInput(input); return rebuilt.ok && isDeepStrictEqual(rebuilt.input, input); };
|
|
60
|
-
|
|
61
|
+
// `restrict` 是提交那一刻读到的授权范围(null 是整台机器),执行时才带上;准入时没有它。
|
|
62
|
+
const callOk = call => isPlain(call) && isTarget(call.target) && inputOk(call.input) && optional(call.restrict, value => value === null || restrictOk(value));
|
|
61
63
|
if (!(isPlain(entry) && isAuthor(entry.caller) && isText(entry.request) && isText(entry.grant) && isText(entry.digest) && isText(entry.key)
|
|
62
64
|
&& isTime(entry.notAfter) && isTime(entry.admittedAt) && STATES.includes(entry.state)
|
|
63
65
|
&& optional(entry.call, callOk) && optional(entry.canceled, value => value === true) && optional(entry.canceledAt, isTime) && optional(entry.canceledBy, isText)
|
|
@@ -77,7 +79,7 @@ const outgoingOk = entry => isPlain(entry) && isText(entry.request) && isText(en
|
|
|
77
79
|
&& isAuthor(entry.author) && isAuthor(entry.holder) && isText(entry.grant) && isText(entry.digest) && isPlain(entry.body) && optional(entry.settled, value => value === true);
|
|
78
80
|
|
|
79
81
|
const TABLES = {
|
|
80
|
-
grants: { file: 'grants.json', field: 'grants', ok: grantOk, keyOf: entry => entry.id },
|
|
82
|
+
grants: { file: 'grants.json', field: 'grants', ok: grantOk, keyOf: entry => entry.id, version: entries => Object.values(entries).some(entry => entry?.restrict !== undefined) ? 2 : 1 },
|
|
81
83
|
inflight: { file: 'inflight.json', field: 'entries', ok: inflightOk, keyOf: entry => inflightKey(entry.caller, entry.request) },
|
|
82
84
|
outgoing: { file: 'outgoing.json', field: 'entries', ok: outgoingOk, keyOf: entry => entry.request },
|
|
83
85
|
};
|
|
@@ -100,8 +102,8 @@ async function writeAtomic(dir, name, text) {
|
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
// 整张表的毛病:形状不对、有项不合格、键与项对不上;没毛病给 null。读盘与每次写入都过它。
|
|
103
|
-
function tableProblem({ field, ok, keyOf }, parsed) {
|
|
104
|
-
if (!isPlain(parsed) || parsed.v !==
|
|
105
|
+
function tableProblem({ field, ok, keyOf, version }, parsed) {
|
|
106
|
+
if (!isPlain(parsed) || !isPlain(parsed[field]) || parsed.v !== (version?.(parsed[field]) ?? 1)) return '形状不对';
|
|
105
107
|
for (const [key, entry] of Object.entries(parsed[field])) if (!ok(entry) || keyOf(entry) !== key) return `项 ${key} 形状不对`;
|
|
106
108
|
return null;
|
|
107
109
|
}
|
|
@@ -121,7 +123,7 @@ async function readTable(dir, table) {
|
|
|
121
123
|
}
|
|
122
124
|
|
|
123
125
|
function writeTable(dir, table, entries) {
|
|
124
|
-
const value = { v: 1, [table.field]: entries }, problem = tableProblem(table, value);
|
|
126
|
+
const value = { v: table.version?.(entries) ?? 1, [table.field]: entries }, problem = tableProblem(table, value);
|
|
125
127
|
if (problem) throw invalid(`${table.file} 要写的内容不合格:${problem}`);
|
|
126
128
|
return writeAtomic(dir, table.file, `${JSON.stringify(value, null, 2)}\n`);
|
|
127
129
|
}
|
|
@@ -135,16 +137,16 @@ const SHA256 = /^[0-9a-f]{64}$/;
|
|
|
135
137
|
/** 命令的摘要:前 80 个字符与整条命令的 sha256;操作记录默认只存这个,不存命令全文。 */
|
|
136
138
|
export const commandInfo = text => ({ summary: [...text].slice(0, SUMMARY_CHARS).join(''), sha256: createHash('sha256').update(text).digest('hex') });
|
|
137
139
|
|
|
138
|
-
// 一行的形状:字段是固定的一组,多一项少一项都不行(命令全文、cwd、stdin
|
|
140
|
+
// 一行的形状:字段是固定的一组,多一项少一项都不行(命令全文、cwd、stdin 进不来)。`restrict` 是这次调用当时的授权范围,仅限目录的才有,没有是整台机器。写入前校验新行,读月份文件时校验每一行。
|
|
139
141
|
const hasKeys = (value, required, optionalKeys = []) => isPlain(value) && required.every(key => Object.hasOwn(value, key))
|
|
140
142
|
&& Object.keys(value).every(key => required.includes(key) || optionalKeys.includes(key));
|
|
141
143
|
const rejectionRowOk = row => hasKeys(row, ['v', 'at', 'friend', 'outcome', 'code', 'count']) && row.v === 1 && isTime(row.at) && isAuthor(row.friend)
|
|
142
144
|
&& isText(row.code) && Number.isSafeInteger(row.count) && row.count >= 1;
|
|
143
|
-
const completedRowOk = row => hasKeys(row, ['v', 'at', 'request', 'friend', 'grant', 'target', 'op', 'command', 'outcome', 'ms'], ['code', 'exitCode'])
|
|
145
|
+
const completedRowOk = row => hasKeys(row, ['v', 'at', 'request', 'friend', 'grant', 'target', 'op', 'command', 'outcome', 'ms'], ['code', 'exitCode', 'restrict'])
|
|
144
146
|
&& row.v === 1 && isTime(row.at) && isText(row.request) && isAuthor(row.friend) && isText(row.grant)
|
|
145
147
|
&& hasKeys(row.target, ['kind', 'id', 'name']) && ['kind', 'id', 'name'].every(key => isText(row.target[key])) && row.op === 'exec'
|
|
146
148
|
&& hasKeys(row.command, ['summary', 'sha256']) && typeof row.command.summary === 'string' && [...row.command.summary].length <= SUMMARY_CHARS && typeof row.command.sha256 === 'string' && SHA256.test(row.command.sha256)
|
|
147
|
-
&& isText(row.outcome) && optional(row.code, isText) && optional(row.exitCode, value => value === null || Number.isSafeInteger(value))
|
|
149
|
+
&& isText(row.outcome) && optional(row.code, isText) && optional(row.exitCode, value => value === null || Number.isSafeInteger(value)) && optional(row.restrict, restrictOk)
|
|
148
150
|
&& Number.isSafeInteger(row.ms) && row.ms >= 0;
|
|
149
151
|
// 合并后的拒绝行(outcome 是 rejected)与正常行各一套形状;两条写入路径与读取共用这一个判断。
|
|
150
152
|
const ledgerRowOk = row => isPlain(row) && (row.outcome === 'rejected' ? rejectionRowOk(row) : completedRowOk(row));
|
|
@@ -169,15 +171,19 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
169
171
|
|
|
170
172
|
// ---- 授权 ----
|
|
171
173
|
|
|
172
|
-
// 形状不对是调用方的错;`target` 是固定的 { owner, provider, kind, id }
|
|
174
|
+
// 形状不对是调用方的错;`target` 是固定的 { owner, provider, kind, id };`restrict` 是授权的范围,不给是整台机器。给 `{ created, entry }`。
|
|
173
175
|
// 同一把机器钥匙、同一位好友、同一个目标已有没撤的授权:原样给回那一条(`created: false`),不生成授权号、不写盘(重试授予不会多出一条撤不干净的)。
|
|
174
176
|
// 撤了的不算;`ended(grant)` 给原因的(调用方还没落盘的失效,同 markSubmitted)也不算。没命中才生成授权号、落盘(`created: true`);生成的授权号已存在就拒绝,旧行不动。
|
|
175
|
-
|
|
176
|
-
|
|
177
|
+
// 有效授权的匹配规则(一份):同一把机器钥匙、同一位好友、同一个目标、没撤、也不在 `ended(grant)` 给了原因的失效里。addGrant 的去重与授予前的查询(findLiveGrant)共用它。
|
|
178
|
+
const liveOf = (grants, { holder, grantee, target }, ended) => Object.values(grants).find(one => one.revokedAt === undefined && one.holder.machine === holder.machine
|
|
179
|
+
&& one.grantee === grantee && ['owner', 'provider', 'kind', 'id'].every(key => one.target[key] === target[key]) && !ended(one));
|
|
180
|
+
const findLiveGrant = (match, ended = () => null) => serial(async () => liveOf(await load('grants'), match, ended) ?? null);
|
|
181
|
+
|
|
182
|
+
const addGrant = ({ holder, grantee, granteePerson, target, createdAt, restrict }, ended = () => null) => serial(async () => {
|
|
183
|
+
const fields = { holder, grantee, granteePerson, target, ops: ['exec'], createdAt, ...(restrict ? { restrict } : {}) };
|
|
177
184
|
if (!grantFieldsOk(fields)) throw invalid('授权的各项不合格');
|
|
178
185
|
const grants = await load('grants');
|
|
179
|
-
const live =
|
|
180
|
-
&& ['owner', 'provider', 'kind', 'id'].every(key => one.target[key] === target[key]) && !ended(one));
|
|
186
|
+
const live = liveOf(grants, { holder, grantee, target }, ended);
|
|
181
187
|
if (live) return { created: false, entry: live };
|
|
182
188
|
const entry = { id: newId(), ...fields };
|
|
183
189
|
if (grants[entry.id]) throw invalid(`授权号 ${entry.id} 已存在`);
|
|
@@ -198,6 +204,19 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
198
204
|
return grants[id];
|
|
199
205
|
});
|
|
200
206
|
|
|
207
|
+
// 改一条有效授权的范围(`restrict` 不给是整台机器),先落盘再返回;之后的准入与提交(markSubmitted)读到的都是新范围,已经提交的调用不动。
|
|
208
|
+
// 给 `{ ok: true, entry }`;没有这条授权是 `not_found`,已撤、已失效或 `ended(grant)` 给了原因(调用方还没落盘的失效)是 `revoked`。范围没变不写盘。
|
|
209
|
+
const setRestrict = (id, restrict, ended = () => null) => serial(async () => {
|
|
210
|
+
const grants = await load('grants'), entry = grants[id];
|
|
211
|
+
if (!entry) return { ok: false, code: 'not_found' };
|
|
212
|
+
if (entry.revokedAt !== undefined || ended(entry)) return { ok: false, code: 'revoked', entry };
|
|
213
|
+
if (isDeepStrictEqual(entry.restrict, restrict ?? undefined)) return { ok: true, entry };
|
|
214
|
+
const { restrict: old, ...rest } = entry;
|
|
215
|
+
grants[id] = { ...rest, ...(restrict ? { restrict } : {}) };
|
|
216
|
+
await save('grants', grants);
|
|
217
|
+
return { ok: true, entry: grants[id] };
|
|
218
|
+
});
|
|
219
|
+
|
|
201
220
|
// 让 `match` 选中的、还有效的授权一并失效(同一个串行操作里落盘),`endedBy` 是原因;给回这次失效的那些。
|
|
202
221
|
const endGrants = (match, endedBy, at = now()) => serial(async () => {
|
|
203
222
|
const grants = await load('grants'), ended = Object.values(grants).filter(entry => entry.revokedAt === undefined && match(entry));
|
|
@@ -303,7 +322,9 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
303
322
|
/**
|
|
304
323
|
* admitted → submitted,提交给内核之前调用:已标了取消的不让提交(`canceled`);同一个串行操作里读最新的授权行、按此刻判最晚启动时刻,
|
|
305
324
|
* 授权没了、撤了或失效了给 `revoked`(`reason` 是失效的原因),过了最晚启动时刻给 `expired`;同时执行的配额也在这里判(`busy`)。
|
|
306
|
-
*
|
|
325
|
+
* 提交的同一个串行操作里把授权此刻的范围记进 `call.restrict`(整台机器是 null),执行带的就是它:改范围与提交排在一条队里,
|
|
326
|
+
* 要么提交读到新范围,要么这次调用就是在旧范围下提交的(已提交的不动),不会按旧范围准入、却不带限制地执行。
|
|
327
|
+
* 已经是 submitted 的原样给回(重启后再提交用同一个幂等键,范围也还是提交时那份);已是终态的给 `terminal`。
|
|
307
328
|
* `ended(grant)` 是调用方另外的失效判定(还没落盘的失效),也在同一个串行操作里、决定提交的那一刻调用,给原因就当失效(`revoked`)。
|
|
308
329
|
*/
|
|
309
330
|
const markSubmitted = (caller, request, ended = () => null) => serial(async () => {
|
|
@@ -317,7 +338,7 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
317
338
|
const reason = ended(grant);
|
|
318
339
|
if (reason) return { ok: false, code: 'revoked', reason, entry };
|
|
319
340
|
if (now() >= entry.notAfter) return { ok: false, code: 'expired', entry };
|
|
320
|
-
return tallyVerdict('executing', counts(entries, caller).executing) ?? { ...entry, state: 'submitted' };
|
|
341
|
+
return tallyVerdict('executing', counts(entries, caller).executing) ?? { ...entry, state: 'submitted', call: { ...entry.call, restrict: grant.restrict ?? null } };
|
|
321
342
|
});
|
|
322
343
|
});
|
|
323
344
|
|
|
@@ -480,12 +501,12 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
480
501
|
|
|
481
502
|
/**
|
|
482
503
|
* 记一个请求的结局。`command` 是命令全文,只存前 80 字与 sha256;`cwd`、`stdin` 不收。
|
|
483
|
-
* 行:`{ v:1, at, request, friend, grant, target:{kind,id,name}, op, command:{summary,sha256}, outcome, code?, exitCode?, ms }
|
|
504
|
+
* 行:`{ v:1, at, request, friend, grant, target:{kind,id,name}, op, command:{summary,sha256}, outcome, code?, exitCode?, restrict?, ms }`(`restrict` 是当时的授权范围,仅限目录的才有)。`at` 已超过 90 天的不落盘。
|
|
484
505
|
*/
|
|
485
|
-
const appendLedger = ({ at = now(), request, friend, grant, target, op = 'exec', command, outcome, code, exitCode, ms }) => serial(async () => {
|
|
506
|
+
const appendLedger = ({ at = now(), request, friend, grant, target, op = 'exec', command, outcome, code, exitCode, restrict, ms }) => serial(async () => {
|
|
486
507
|
if (typeof command !== 'string') throw invalid('command 须是命令全文,记录里只存摘要');
|
|
487
508
|
const row = { v: 1, at, request, friend, grant, target: { kind: target?.kind, id: target?.id, name: target?.name }, op, command: commandInfo(command), outcome,
|
|
488
|
-
...(code === undefined ? {} : { code }), ...(exitCode === undefined ? {} : { exitCode }), ms };
|
|
509
|
+
...(code === undefined ? {} : { code }), ...(exitCode === undefined ? {} : { exitCode }), ...(restrict ? { restrict } : {}), ms };
|
|
489
510
|
if (!ledgerRowOk(row) || outcome === 'rejected') throw invalid('操作记录的各项不合格');
|
|
490
511
|
if (pastKeep(at)) return row;
|
|
491
512
|
await ledgerPrepare();
|
|
@@ -548,7 +569,7 @@ export function createRpcStore(stateDir, { now = Date.now, newId = randomUUID, o
|
|
|
548
569
|
return {
|
|
549
570
|
listGrants: () => serial(async () => Object.values(await load('grants'))),
|
|
550
571
|
getGrant: id => serial(async () => (await load('grants'))[id] ?? null),
|
|
551
|
-
addGrant, revokeGrant, endGrants, markGrantRetracted,
|
|
572
|
+
addGrant, findLiveGrant, revokeGrant, setRestrict, endGrants, markGrantRetracted,
|
|
552
573
|
admit, get, cancel, markSubmitted, finish, markLogged, markSigned, markRetracted, purge, quota, readClock, writeClock,
|
|
553
574
|
listInflight: () => serial(async () => Object.values(await load('inflight'))),
|
|
554
575
|
listOutgoing: () => serial(async () => Object.values(await load('outgoing'))),
|
package/main.mjs
CHANGED
|
@@ -3,23 +3,24 @@
|
|
|
3
3
|
// - 业务无关的社交网关 friends/social@1(lib/gateway.mjs):别的插件经它读好友、发布与撤回记录,全部透传 coda/accord@1;
|
|
4
4
|
// 发布策略用 `coda self policy.get|policy.setKind` 读写;
|
|
5
5
|
// - 签名网关的持有方(lib/rpc-holder.mjs):把本机或同一空间里别的机器的 remote-exec 记录的 exec 授给好友、转发好友签名的调用,
|
|
6
|
-
// 授权与操作记录用 `coda self grants.list|grants.grant|grants.revoke|ledger.list` 读写。持有方出错不影响社交网关。
|
|
6
|
+
// 授权与操作记录用 `coda self grants.list|grants.grant|grants.restrict|grants.revoke|ledger.list` 读写。持有方出错不影响社交网关。
|
|
7
7
|
// - 签名网关的调用方(lib/rpc-caller.mjs):把好友授给本机的记录登记成代理记录,接住对它的 exec 转给好友签名执行。调用方出错不影响社交网关与持有方。
|
|
8
8
|
// 好友授给本机的代理记录用 `coda self proxies.list` 读;授予时可选的 remote-exec 记录(本机的与同空间别的机器的)用 `coda self grants.targets` 读。
|
|
9
9
|
// 持有方、调用方的这几样(shared)好友页也经视图消息调用。
|
|
10
10
|
import { createGateway } from './lib/gateway.mjs';
|
|
11
11
|
import { createCaller } from './lib/rpc-caller.mjs';
|
|
12
|
+
import { sandboxHint } from './lib/rpc-format.mjs';
|
|
12
13
|
import { createHolder } from './lib/rpc-holder.mjs';
|
|
13
14
|
import { createRpcStore } from './lib/rpc-store.mjs';
|
|
14
15
|
|
|
15
|
-
const HOLDER_ACTIONS = ['grants.list', 'grants.grant', 'grants.revoke', 'ledger.list'];
|
|
16
|
+
const HOLDER_ACTIONS = ['grants.list', 'grants.grant', 'grants.restrict', 'grants.revoke', 'ledger.list'];
|
|
16
17
|
const TARGET_KIND = 'remote-exec/machine@1';
|
|
17
18
|
let gateway = null, holder = null, caller = null, callerStart = null, callerDown = null;
|
|
18
19
|
const handles = [];
|
|
19
20
|
|
|
20
21
|
export async function activate(coda) {
|
|
21
22
|
const dir = coda.plugin.state;
|
|
22
|
-
//
|
|
23
|
+
// 好友页的「共享」一节用的:持有方的五个操作、调用方的代理记录、可授出的 remote-exec 记录。
|
|
23
24
|
const shared = {
|
|
24
25
|
...Object.fromEntries(HOLDER_ACTIONS.map(name => [name, input => {
|
|
25
26
|
if (!holder) throw new Error('这台机器没有插件状态目录,好友授权存不下');
|
|
@@ -33,7 +34,8 @@ export async function activate(coda) {
|
|
|
33
34
|
},
|
|
34
35
|
// 本机的在前,然后是同一空间里别的机器自己的;只列 remote-exec 提供的(好友分享来的代理记录 provider 是 friends,不列)。
|
|
35
36
|
'grants.targets': async () => (await coda.list(TARGET_KIND)).filter(entry => entry.plugin === 'remote-exec')
|
|
36
|
-
.map(entry => ({ id: entry.id, name: entry.spec?.name ?? entry.id, os: entry.spec?.os ?? '', user: entry.spec?.user ?? '', available: entry.status?.available === true, local: entry.local === true
|
|
37
|
+
.map(entry => ({ id: entry.id, name: entry.spec?.name ?? entry.id, os: entry.spec?.os ?? '', user: entry.spec?.user ?? '', available: entry.status?.available === true, local: entry.local === true,
|
|
38
|
+
restrictHint: sandboxHint(entry.spec?.os) })),
|
|
37
39
|
};
|
|
38
40
|
coda.views.register('friends', {
|
|
39
41
|
open(view) {
|
|
@@ -41,7 +43,7 @@ export async function activate(coda) {
|
|
|
41
43
|
const name = message?.type;
|
|
42
44
|
if (!Object.hasOwn(shared, name) || typeof message.rid !== 'string') return;
|
|
43
45
|
try { view.postMessage({ type: 'reply', rid: message.rid, ok: true, value: await shared[name](message) }); }
|
|
44
|
-
catch (e) { view.postMessage({ type: 'reply', rid: message.rid, ok: false, error: String(e?.message ?? e), effects: e?.effects }); }
|
|
46
|
+
catch (e) { view.postMessage({ type: 'reply', rid: message.rid, ok: false, error: String(e?.message ?? e), effects: e?.effects, ...(typeof e?.code === 'string' ? { code: e.code } : {}) }); }
|
|
45
47
|
});
|
|
46
48
|
},
|
|
47
49
|
});
|
package/package.json
CHANGED
package/view/app.mjs
CHANGED
|
@@ -21,6 +21,8 @@ const RECOVER_MS = 3000;
|
|
|
21
21
|
const REVOKE_RETRIES = 3;
|
|
22
22
|
// 结果不明的授予:连续读到这么多遍有效列表、里面都没有这条授权,就回滚这一行,允许重试(持有方对同一目标的授予幂等)。
|
|
23
23
|
const GRANT_CONFIRMS = 3;
|
|
24
|
+
// 仅限目录的授予、改范围要先到目标机探测(持有方最长等 30 秒):页面多等一会儿再算没有回应。
|
|
25
|
+
const PROBE_WAIT_MS = 45_000;
|
|
24
26
|
|
|
25
27
|
// 视图里的每台电脑(成员在页面生命周期内不变)各存一份数据;读不到的(unreachable)也在,只是不发请求。
|
|
26
28
|
// 节点的名字、忙碌、错误、已收回按(电脑, 控制服务器节点 ID)记在 m.fn 里,不与好友行的 state.busy / state.notice 混用(那两个按 Accord 的 node 记)。
|
|
@@ -37,24 +39,24 @@ function say(target, text, kind = 'hint') { target.className = kind; target.text
|
|
|
37
39
|
const pendingReplies = new Map();
|
|
38
40
|
let counter = 0;
|
|
39
41
|
// `late`:等不到回应时也不丢这条回复,晚到了就交给它(授予这类不能重发的写操作用)。
|
|
40
|
-
function ask(m, type, input = {}, late) {
|
|
42
|
+
function ask(m, type, input = {}, late, wait = 10_000) {
|
|
41
43
|
const rid = `n${++counter}`;
|
|
42
44
|
return new Promise((resolve, reject) => {
|
|
43
45
|
const settle = fn => v => { clearTimeout(timer); pendingReplies.delete(rid); fn(v); };
|
|
44
46
|
const timer = setTimeout(() => {
|
|
45
47
|
if (late) pendingReplies.get(rid).late = late; else pendingReplies.delete(rid);
|
|
46
48
|
reject(new Error('模块没有回应'));
|
|
47
|
-
},
|
|
49
|
+
}, wait);
|
|
48
50
|
pendingReplies.set(rid, { machine: m.id, resolve: settle(resolve), reject: settle(reject) });
|
|
49
51
|
Promise.resolve().then(() => coda.postMessage({ type, rid, ...input }, via(m))).catch(error => pendingReplies.get(rid)?.reject(Object.assign(new Error(`发送失败:${error?.message ?? error}`), { refused: true })));
|
|
50
52
|
});
|
|
51
53
|
}
|
|
52
54
|
addEventListener('message', event => {
|
|
53
|
-
const { type, rid, ok, value, error, effects } = event.data ?? {};
|
|
55
|
+
const { type, rid, ok, value, error, effects, code } = event.data ?? {};
|
|
54
56
|
const wait = type === 'reply' ? pendingReplies.get(rid) : null;
|
|
55
57
|
if (!wait || (event.machine?.id && event.machine.id !== wait.machine)) return;
|
|
56
58
|
// refused:确认什么也没写——模块明确回了错误且 effects 为 none,或消息根本没发出去(postMessage 抛错);别的错误、超时都是结果不明。
|
|
57
|
-
const failure = Object.assign(new Error(error), { refused: effects === 'none' });
|
|
59
|
+
const failure = Object.assign(new Error(error), { refused: effects === 'none', code });
|
|
58
60
|
if (wait.late) { pendingReplies.delete(rid); wait.late(ok ? { value } : { failure }); } else if (ok) wait.resolve(value); else wait.reject(failure);
|
|
59
61
|
});
|
|
60
62
|
|
|
@@ -110,7 +112,7 @@ function closeDialog() {
|
|
|
110
112
|
// Escape 一次收一层:授予选择框,再是行尾菜单,再是弹层。
|
|
111
113
|
addEventListener('keydown', e => {
|
|
112
114
|
if (e.key !== 'Escape') return;
|
|
113
|
-
if (picker.ctx)
|
|
115
|
+
if (picker.ctx) cancelPicker();
|
|
114
116
|
else if (state.menu) { state.menu = null; draw(); }
|
|
115
117
|
else if (openDialog) closeDialog();
|
|
116
118
|
});
|
|
@@ -397,16 +399,19 @@ const SHARE_STATUS = {
|
|
|
397
399
|
available: ['可用', 'bound'], target_off: ['目标已关闭', 'pending'], target_missing: ['目标不在了', 'pending'], target_offline: ['目标离线', 'pending'], target_unreachable: ['读不到目标', 'pending'], no_identity: ['读不出本机身份', 'pending'],
|
|
398
400
|
granting: ['授予中', 'busy'], revoking: ['撤销中', 'busy'], machine_changed: ['已停用', 'pending'], grantee_changed: ['已停用', 'pending'],
|
|
399
401
|
};
|
|
402
|
+
const PENDING = ['待确认', 'busy'];
|
|
400
403
|
const PROXY_STATUS = {
|
|
401
404
|
available: ['可用', 'bound'], off: ['TA 那边没开远程执行', 'pending'], channel: ['和 TA 的通道断了', 'pending'],
|
|
402
405
|
author: ['本机身份变了,请 TA 重新授予', 'pending'], sign: ['本机没有可用的签名证书', 'pending'],
|
|
403
406
|
};
|
|
404
407
|
// 授出的范围不让选,由对方的身份决定:个人身份授给他名下的机器,机器身份只授给那一台;基座还没给 certified 时不写。
|
|
405
408
|
const scopeNote = certified => (certified === true ? '授给这个人名下的机器' : certified === false ? '只授给对方那一台机器' : null);
|
|
406
|
-
const shareOf = m => (m.share ??= { grants: null, problem: null, corrupt: null, clock: 0, writes: 0, touched: 0, reread: false, pending: [], revoking: new Map(), theirs: new Map(), ops: new Map(), targets: null, targetsProblem: null, opsOpen: false, timer: null });
|
|
409
|
+
const shareOf = m => (m.share ??= { grants: null, problem: null, corrupt: null, clock: 0, writes: 0, touched: 0, reread: false, pending: [], revoking: new Map(), theirs: new Map(), ops: new Map(), targets: null, targetsProblem: null, opsOpen: false, scopeOpen: new Set(), rescoping: new Map(), timer: null });
|
|
407
410
|
const certifiedOf = (m, row) => m.friends.find(friend => friend.node === row.node)?.certified;
|
|
408
411
|
const mergeGrant = (sh, made) => { const all = sh.grants ?? []; sh.grants = all.some(g => g.grant === made.grant) ? all.map(g => (g.grant === made.grant ? made : g)) : [...all, made]; };
|
|
409
412
|
// 已撤的不显示;撤销中的(名下的调用还在取消)显示。
|
|
413
|
+
// 能改范围的:还在用的授权(已撤销、已失效、目标不在了的不行)。
|
|
414
|
+
const EDITABLE = new Set(['available', 'target_off', 'target_offline', 'target_unreachable']);
|
|
410
415
|
const visibleGrant = g => g.status === 'revoking' || (g.status !== 'revoked' && g.revokedAt === undefined);
|
|
411
416
|
|
|
412
417
|
function loadShare(m, row) {
|
|
@@ -445,6 +450,13 @@ async function readGrants(m, round = false) {
|
|
|
445
450
|
if (p.state !== 'granting' || !p.unknown || (p.misses = (p.misses ?? 0) + 1) < GRANT_CONFIRMS) continue;
|
|
446
451
|
Object.assign(p, { state: 'denied', reason: '没有确认授予成功,请重试', unknown: false, expired: true });
|
|
447
452
|
}
|
|
453
|
+
// 结果不明的改范围:列表里是想改成的范围(或授权已不在了)就是核对完了;连续读到上限遍都不是,就写明没确认,回到原范围可再改。
|
|
454
|
+
for (const [grant, one] of sh.rescoping) {
|
|
455
|
+
if (!one.unknown) continue;
|
|
456
|
+
const found = read.grants.find(g => g.grant === grant);
|
|
457
|
+
if (!found || found.revokedAt !== undefined || JSON.stringify(found.restrict ?? null) === JSON.stringify(one.restrict)) sh.rescoping.delete(grant);
|
|
458
|
+
else if ((one.misses = (one.misses ?? 0) + 1) >= GRANT_CONFIRMS) sh.rescoping.set(grant, { error: '没有确认范围改成功,仍是原来的范围,可以再改一次' });
|
|
459
|
+
}
|
|
448
460
|
// 结果不明的撤销:读到已撤或在撤销中就是核对完了,留下的是仍可用的,由恢复循环再发一次。
|
|
449
461
|
for (const [grant, one] of sh.revoking) if (one.unknown && !read.grants.some(g => g.grant === grant && visibleGrant(g) && g.status !== 'revoking')) sh.revoking.delete(grant);
|
|
450
462
|
}
|
|
@@ -468,7 +480,7 @@ async function readOps(m, row) {
|
|
|
468
480
|
// 对应的授权仍可用,才重发;读和重发都结束了才排下一轮(所以同一授权的撤销不会有两个在途重试)。
|
|
469
481
|
function recover(m) {
|
|
470
482
|
const sh = shareOf(m);
|
|
471
|
-
const need = sh.pending.some(p => p.unknown) || [...sh.revoking.values()].some(r => r.unknown) || (sh.grants ?? []).some(g => g.status === 'revoking');
|
|
483
|
+
const need = sh.pending.some(p => p.unknown) || [...sh.revoking.values()].some(r => r.unknown) || [...sh.rescoping.values()].some(r => r.unknown) || (sh.grants ?? []).some(g => g.status === 'revoking');
|
|
472
484
|
if (!need || sh.timer) return;
|
|
473
485
|
sh.timer = setTimeout(async () => {
|
|
474
486
|
if (await readGrants(m, true)) {
|
|
@@ -526,32 +538,44 @@ async function grantTo(m, row, target) {
|
|
|
526
538
|
const dots = () => svg('svg', { viewBox: '0 0 24 24', width: 18, height: 18, fill: 'currentColor', 'aria-hidden': 'true' },
|
|
527
539
|
svg('circle', { cx: 5, cy: 12, r: 2 }), svg('circle', { cx: 12, cy: 12, r: 2 }), svg('circle', { cx: 19, cy: 12, r: 2 }));
|
|
528
540
|
const emptyRow = text => h('li', { class: 'empty g-empty' }, text);
|
|
541
|
+
const ACCESS = { rw: '读写', ro: '只读' };
|
|
542
|
+
// 授权的范围:整台机器,或第一条目录加「等 N 个」,点开看全部目录与各自的读写;short 是操作记录里的简短标记(整台机器的不标)。展开与否按 key 记着,重画不丢。
|
|
543
|
+
function scopeView(sh, key, restrict, short) {
|
|
544
|
+
if (!restrict) return short ? null : h('span', { class: 'g-sub truncate' }, '整台机器');
|
|
545
|
+
const { dirs } = restrict, [first] = dirs;
|
|
546
|
+
return h('details', { class: 'scope', open: sh.scopeOpen.has(key), ontoggle: e => { if (e.target.open) sh.scopeOpen.add(key); else sh.scopeOpen.delete(key); } },
|
|
547
|
+
// 长路径在摘要里截断,读写标记与「等 N 个」留在后面不被截掉。
|
|
548
|
+
h('summary', { class: 'g-sub' }, short ? `仅限目录 · ${dirs.length} 个` : [h('span', { class: 'sum-main' }, `仅限目录 · ${first.path}`), h('span', { class: 'sum-tail' }, `(${ACCESS[first.access]})${dirs.length > 1 ? `等 ${dirs.length} 个` : ''}`)]),
|
|
549
|
+
h('ul', { class: 'dirs' }, dirs.map(dir => h('li', {}, h('span', { class: 'tag' }, ACCESS[dir.access]), h('span', { class: 'mono selectable' }, dir.path)))));
|
|
550
|
+
}
|
|
529
551
|
// 一行:名称与说明、状态、行尾只有一个菜单按钮(没有菜单的行也留着这个槽,列对得齐)。
|
|
530
|
-
function shareRow({ key, name, sub, subKind, badge, busy, menu }) {
|
|
552
|
+
function shareRow({ key, name, sub, subKind, scope, badge, busy, menu }) {
|
|
531
553
|
const open = state.menu === key;
|
|
532
554
|
return h('li', { class: 'g-row', 'aria-busy': busy ? 'true' : null },
|
|
533
|
-
h('div', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, name), sub ? h('span', { class: `g-sub truncate${subKind === 'error' ? ' error' : ''}` }, sub) : null),
|
|
555
|
+
h('div', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, name), sub ? h('span', { class: `g-sub truncate${subKind === 'error' ? ' error' : ''}` }, sub) : null, scope),
|
|
534
556
|
h('span', { class: `badge ${badge[1]}` }, badge[0]),
|
|
535
557
|
menu ? h('button', { class: 'kebab', type: 'button', 'aria-label': `更多操作:${name}`, 'aria-haspopup': 'menu', 'aria-expanded': String(open), disabled: busy,
|
|
536
558
|
onclick: e => { e.stopPropagation?.(); state.menu = open ? null : key; draw(); } }, dots()) : h('span', { class: 'kebab-slot', 'aria-hidden': 'true' }),
|
|
537
|
-
open && menu ? h('div', { class: 'menu', role: 'menu' }, h('button', { type: 'button', role: 'menuitem', class:
|
|
538
|
-
onclick: e => { e.stopPropagation?.();
|
|
559
|
+
open && menu ? h('div', { class: 'menu', role: 'menu' }, menu.map(item => h('button', { type: 'button', role: 'menuitem', class: item.danger ? 'danger' : '',
|
|
560
|
+
onclick: e => { e.stopPropagation?.(); item.run(); } }, item.label, item.note ? h('span', { class: 'menu-note' }, item.note) : null))) : null);
|
|
539
561
|
}
|
|
540
562
|
function drawShare(m, row) {
|
|
541
563
|
const sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
|
|
542
564
|
const mine = [
|
|
543
565
|
...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => {
|
|
544
|
-
const local = sh.revoking.get(g.grant),
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
566
|
+
const local = sh.revoking.get(g.grant), re = sh.rescoping.get(g.grant), waiting = re?.unknown, failed = local?.error ?? re?.error;
|
|
567
|
+
const busy = g.status === 'revoking' || (local && !local.error) || waiting;
|
|
568
|
+
return shareRow({ key: `g:${g.grant}`, name: g.target.name ?? g.target.id, sub: failed ?? (waiting ? '范围改动待确认:下面还是原来的范围' : scope), subKind: failed ? 'error' : null, scope: scopeView(sh, `g:${g.grant}`, g.restrict),
|
|
569
|
+
badge: waiting ? PENDING : busy ? SHARE_STATUS.revoking : SHARE_STATUS[g.status] ?? ['已失效', 'pending'], busy,
|
|
570
|
+
menu: [...(EDITABLE.has(g.status) ? [{ label: '修改范围…', run: () => openScope(m, row, g) }] : []),
|
|
571
|
+
{ label: '撤销', note: '同时取消对方正在跑的调用', danger: true, run: () => revokeGrant(m, g) }] });
|
|
548
572
|
}),
|
|
549
|
-
...sh.pending.filter(p => p.friend === row.author).map(p => shareRow({ key: `p:${p.target.id}`, name: p.target.name, sub: p.state === 'denied' ? p.reason : scope, subKind: p.state === 'denied' ? 'error' : null,
|
|
550
|
-
badge: p.state === 'denied' ? ['未授予', 'conflict'] : SHARE_STATUS.granting, busy: p.state === 'granting',
|
|
551
|
-
menu: { label: '移除', run: () => { sh.pending = sh.pending.filter(one => one !== p); state.menu = null; draw(); } } })),
|
|
573
|
+
...sh.pending.filter(p => p.friend === row.author).map(p => shareRow({ key: `p:${p.target.id}`, name: p.target.name, sub: p.state === 'denied' ? p.reason : p.restrict && p.unknown ? '授予待确认:正在核对列表' : scope, subKind: p.state === 'denied' ? 'error' : null, scope: scopeView(sh, `p:${p.target.id}`, p.restrict ?? null),
|
|
574
|
+
badge: p.state === 'denied' ? ['未授予', 'conflict'] : p.restrict && p.unknown ? PENDING : SHARE_STATUS.granting, busy: p.state === 'granting',
|
|
575
|
+
menu: [{ label: '移除', run: () => { sh.pending = sh.pending.filter(one => one !== p); state.menu = null; draw(); } }] })),
|
|
552
576
|
];
|
|
553
577
|
const their = sh.theirs.get(row.author);
|
|
554
|
-
const theirRows = (their?.rows ?? []).map(proxy => shareRow({ key: `t:${proxy.key}`, name: proxy.name, badge: PROXY_STATUS[proxy.status] ?? ['不可用', 'pending'] }));
|
|
578
|
+
const theirRows = (their?.rows ?? []).map(proxy => shareRow({ key: `t:${proxy.key}`, name: proxy.name, scope: scopeView(sh, `t:${proxy.key}`, proxy.restrict), badge: PROXY_STATUS[proxy.status] ?? ['不可用', 'pending'] }));
|
|
555
579
|
const ops = sh.ops.get(row.author);
|
|
556
580
|
const canGrant = row.status === 'bound' && Boolean(row.author) && sh.grants !== null && !sh.corrupt;
|
|
557
581
|
fill(detail.share,
|
|
@@ -568,7 +592,7 @@ function drawShare(m, row) {
|
|
|
568
592
|
if (sh.opsOpen && row.author) readOps(m, row);
|
|
569
593
|
} }, h('summary', {}, '最近的操作'),
|
|
570
594
|
h('div', { class: 'ops-list' }, ops?.problem ? h('p', { class: 'error' }, ops.problem) : !ops ? h('p', { class: 'empty' }, row.author ? '正在读取…' : '还没有操作记录')
|
|
571
|
-
: ops.rows.length ? [...ops.rows.map(opRow), h('p', { class: 'hint' }, '完整记录:coda self ledger.list')] : h('p', { class: 'empty' }, '还没有操作记录'))));
|
|
595
|
+
: ops.rows.length ? [...ops.rows.map(one => opRow(sh, one)), h('p', { class: 'hint' }, '完整记录:coda self ledger.list')] : h('p', { class: 'empty' }, '还没有操作记录'))));
|
|
572
596
|
}
|
|
573
597
|
// 操作记录的摘要:时间、操作、命令摘要、结局、耗时。
|
|
574
598
|
const duration = ms => (ms < 10_000 ? `${(ms / 1000).toFixed(1)} 秒` : ms < 60_000 ? `${Math.round(ms / 1000)} 秒` : `${Math.round(ms / 60_000)} 分钟`);
|
|
@@ -579,19 +603,23 @@ function outcomeOf(row) {
|
|
|
579
603
|
if (row.exitCode === undefined || row.exitCode === 0) return ['成功', 'bound'];
|
|
580
604
|
return [row.exitCode === null ? '失败' : `失败(退出码 ${row.exitCode})`, 'conflict'];
|
|
581
605
|
}
|
|
582
|
-
function opRow(row) {
|
|
606
|
+
function opRow(sh, row) {
|
|
583
607
|
const [label, kind] = outcomeOf(row), rejected = row.outcome === 'rejected';
|
|
584
608
|
return h('div', { class: 'op' },
|
|
585
609
|
h('div', { class: 'op-top' }, h('span', { class: 'op-time' }, formatTime(row.at)), h('span', { class: 'tag' }, rejected ? '请求' : '执行'), h('span', { class: 'spacer' }),
|
|
586
610
|
h('span', { class: `badge ${kind}` }, label), h('span', { class: 'dur' }, rejected ? '—' : duration(row.ms))),
|
|
587
|
-
h('div', { class: 'op-cmd truncate selectable' }, rejected ? `${row.code}${row.count > 1 ? ` × ${row.count}` : ''}` : row.command.summary)
|
|
611
|
+
h('div', { class: 'op-cmd truncate selectable' }, rejected ? `${row.code}${row.count > 1 ? ` × ${row.count}` : ''}` : row.command.summary),
|
|
612
|
+
scopeView(sh, `o:${row.request}`, row.restrict, true));
|
|
588
613
|
}
|
|
589
614
|
|
|
590
|
-
//
|
|
591
|
-
|
|
592
|
-
|
|
615
|
+
// 授予与修改范围用同一张表单,叠在好友详情上:授予先在列表里选机器、选定后出范围;修改范围直接是表单(机器固定)。
|
|
616
|
+
// 表单里的输入框不随页面的整体重画重建(否则打字时会丢焦点):只有结构变化(切范围、加删行、出错)才重画表单。
|
|
617
|
+
const MAX_DIRS = 50, MAX_PATH_BYTES = 1024;
|
|
618
|
+
const picker = { dialog: makeDialog({ title: '授予远程执行', close: '取消', cancel: () => cancelPicker() }), ctx: null, list: h('ul', { class: 'glist' }) };
|
|
593
619
|
function openPicker(m, row) {
|
|
594
|
-
picker.ctx = { m, row };
|
|
620
|
+
picker.ctx = { m, row, stage: 'list' };
|
|
621
|
+
picker.dialog.heading.textContent = '授予远程执行';
|
|
622
|
+
fill(picker.dialog.body, picker.list);
|
|
595
623
|
picker.dialog.scrim.hidden = false;
|
|
596
624
|
drawPicker();
|
|
597
625
|
const sh = shareOf(m);
|
|
@@ -601,18 +629,174 @@ function closePicker() {
|
|
|
601
629
|
picker.ctx = null;
|
|
602
630
|
picker.dialog.scrim.hidden = true;
|
|
603
631
|
}
|
|
632
|
+
// 探测在途时不能关:结果要落在这张表单上。
|
|
633
|
+
function cancelPicker() { if (!picker.ctx?.busy) closePicker(); }
|
|
604
634
|
function drawPicker() {
|
|
605
|
-
if (
|
|
635
|
+
if (picker.ctx?.stage !== 'list') return;
|
|
606
636
|
const { m, row } = picker.ctx, sh = shareOf(m), scope = scopeNote(certifiedOf(m, row));
|
|
607
637
|
const taken = new Set([...(sh.grants ?? []).filter(g => g.friend === row.author && visibleGrant(g)).map(g => g.target.id), ...sh.pending.filter(p => p.friend === row.author && p.state !== 'denied').map(p => p.target.id)]);
|
|
608
638
|
fill(picker.list, sh.targetsProblem ? h('li', { class: 'error g-empty' }, sh.targetsProblem) : sh.targets === null ? emptyRow('正在读取…')
|
|
609
639
|
: sh.targets.length ? sh.targets.map(target => {
|
|
610
640
|
const why = sh.corrupt ? '持有方出了故障' : !target.available ? '远程执行没打开' : taken.has(target.id) ? '已授给 TA' : '';
|
|
611
|
-
return h('li', {}, h('button', { class: 'pick', type: 'button', disabled: Boolean(why), onclick: () => { if (!why)
|
|
641
|
+
return h('li', {}, h('button', { class: 'pick', type: 'button', disabled: Boolean(why), onclick: () => { if (!why) chooseTarget(target); } },
|
|
612
642
|
h('span', { class: 'g-info' }, h('span', { class: 'g-name truncate' }, target.name), h('span', { class: 'g-sub truncate' }, `${target.os} · ${target.user}`), scope ? h('span', { class: 'g-sub truncate' }, scope) : null),
|
|
613
643
|
why ? h('span', { class: 'why' }, why) : null));
|
|
614
644
|
}) : emptyRow('没有可授出的远程执行记录'));
|
|
615
645
|
}
|
|
646
|
+
const blankDir = access => ({ path: '', access });
|
|
647
|
+
// 选定机器:范围回到「整台机器」,目录清空(换机器重选时也一样)。
|
|
648
|
+
function chooseTarget(target) {
|
|
649
|
+
if (!picker.ctx) return;
|
|
650
|
+
Object.assign(picker.ctx, { stage: 'form', target, mode: 'whole', dirs: [blankDir('rw')], problem: null, busy: false });
|
|
651
|
+
drawForm();
|
|
652
|
+
}
|
|
653
|
+
function openScope(m, row, g) {
|
|
654
|
+
state.menu = null;
|
|
655
|
+
const sh = shareOf(m), target = sh.targets?.find(t => t.id === g.target.id) ?? { id: g.target.id, name: g.target.name ?? g.target.id };
|
|
656
|
+
const ctx = picker.ctx = { m, row, stage: 'form', grant: g, target, mode: g.restrict ? 'dirs' : 'whole', dirs: g.restrict?.dirs.map(dir => ({ ...dir })) ?? [blankDir('rw')], problem: null, busy: false };
|
|
657
|
+
picker.dialog.scrim.hidden = false;
|
|
658
|
+
drawForm();
|
|
659
|
+
// 目标机的系统(能不能选仅限目录)取自可授出的记录;读到了与已有的不同才重画。
|
|
660
|
+
ask(m, 'grants.targets').then(targets => {
|
|
661
|
+
sh.targets = targets;
|
|
662
|
+
const found = targets.find(t => t.id === g.target.id);
|
|
663
|
+
if (found && picker.ctx === ctx && !ctx.busy && found.restrictHint !== ctx.target.restrictHint) { ctx.target = found; drawForm(); }
|
|
664
|
+
}, () => {});
|
|
665
|
+
}
|
|
666
|
+
// 允许目录互相重叠的字面部分,与目标机同一套规则:规范掉 `.`、`..`、多余斜杠与结尾斜杠,相同或一条在另一条里面就算。经链接、大小写的真实路径层面以目标机为准。
|
|
667
|
+
const OVERLAP = '允许目录之间不能互相包含或重复,请去掉其中一条';
|
|
668
|
+
const normalPath = path => {
|
|
669
|
+
const parts = [];
|
|
670
|
+
for (const part of path.split('/')) { if (part === '..') parts.pop(); else if (part && part !== '.') parts.push(part); }
|
|
671
|
+
return `/${parts.join('/')}`;
|
|
672
|
+
};
|
|
673
|
+
const within = (path, parent) => path === parent || path.startsWith(parent === '/' ? '/' : `${parent}/`);
|
|
674
|
+
// 表单上方的校验:不合规就给出缺什么(第一处),确认按钮不可用,不发请求。
|
|
675
|
+
function scopeProblem(dirs) {
|
|
676
|
+
if (!dirs.length) return '至少要有一个目录';
|
|
677
|
+
if (dirs.length > MAX_DIRS) return `最多 ${MAX_DIRS} 个目录,现在有 ${dirs.length} 个`;
|
|
678
|
+
for (const [i, { path }] of dirs.entries()) {
|
|
679
|
+
if (!path) return `第 ${i + 1} 行还没填路径`;
|
|
680
|
+
if (!path.startsWith('/')) return `第 ${i + 1} 行:要填目标机上的绝对路径,以 / 开头`;
|
|
681
|
+
if (new TextEncoder().encode(path).length > MAX_PATH_BYTES) return `第 ${i + 1} 行:路径太长(至多 ${MAX_PATH_BYTES} 字节)`;
|
|
682
|
+
}
|
|
683
|
+
const flat = dirs.map(dir => normalPath(dir.path));
|
|
684
|
+
for (const [i, one] of flat.entries()) {
|
|
685
|
+
const j = flat.findIndex((other, at) => at > i && (within(one, other) || within(other, one)));
|
|
686
|
+
if (j >= 0) return `第 ${i + 1} 行(${dirs[i].path})与第 ${j + 1} 行(${dirs[j].path})重叠:${OVERLAP}`;
|
|
687
|
+
}
|
|
688
|
+
if (!dirs.some(dir => dir.access === 'rw')) return '至少要有一个「读写」的目录';
|
|
689
|
+
return null;
|
|
690
|
+
}
|
|
691
|
+
// 失败按持有方给的稳定错误码说明;后端的原话作补充。目录类的错误尽量指到是哪一行(持有方的原话里带路径,取路径最长的那行)。
|
|
692
|
+
const FAIL_TEXT = {
|
|
693
|
+
sandbox_unsupported: '这台机器不能用「仅限目录」:目标机要是 macOS,并且有 /usr/bin/sandbox-exec',
|
|
694
|
+
restrict_unsupported: '这台机器上的「远程执行」版本太旧,不认识「仅限目录」:到那台机器上升到 0.2.0 及以上再试',
|
|
695
|
+
restrict_dir_not_found: ['目录在目标机上不存在', '有目录在目标机上不存在'],
|
|
696
|
+
restrict_dir_not_a_directory: ['这个路径在目标机上不是目录', '有路径在目标机上不是目录'],
|
|
697
|
+
restrict_protected: ['与目标机上受保护的位置重叠:目录不能包含、也不能落在 Coda 的状态目录或 ~/.ssh 里面(整个家目录因为包含 ~/.ssh 也不行):请选与它们不重叠的目录', '有目录与目标机上受保护的位置重叠:目录不能包含、也不能落在 Coda 的状态目录或 ~/.ssh 里面(整个家目录因为包含 ~/.ssh 也不行):请选与它们不重叠的目录'],
|
|
698
|
+
sandbox_failed: '目标机上的沙箱起不来,没有授出',
|
|
699
|
+
target_offline: '目标机现在离线,没法探测:等它回来再试',
|
|
700
|
+
target_unreachable: '读不到目标机(可能被移出了空间):等它回到空间再试',
|
|
701
|
+
target_missing: '目标机上的远程执行记录不在了:先让那台机器重新打开远程执行',
|
|
702
|
+
target_changed: '目标已经不是授权时的那台机器的记录了:关掉这张表单重新选',
|
|
703
|
+
timeout: '目标机 30 秒内没有回应,没有授出:确认它在线、远程执行已打开,再试一次',
|
|
704
|
+
restrict_overlap: OVERLAP,
|
|
705
|
+
restrict_too_large: '范围太大,签不出授权记录:减少目录,或缩短路径',
|
|
706
|
+
already_granted: '已经授给 TA 一条范围不同的授权:到「我授给 TA」里那一行的菜单选「修改范围…」',
|
|
707
|
+
disabled: '目标机上的远程执行没打开',
|
|
708
|
+
invalid_input: '范围的格式不对:检查每一行的路径和读写',
|
|
709
|
+
invalid_state: '这条授权已撤销或已失效,不能再改范围',
|
|
710
|
+
not_found: '这条授权或目标记录已经不在了:关掉这张表单刷新一下',
|
|
711
|
+
};
|
|
712
|
+
function problemOf(c, e) {
|
|
713
|
+
if (!e.code) return { text: e.refused ? `没有发出:${e.message}` : '没有收到目标机的回应,不能确定有没有成功:先看「我授给 TA」里有没有这一条,再决定要不要重试' };
|
|
714
|
+
if (e.code === 'restrict_overlap') {
|
|
715
|
+
// 目标机的消息里是「第 N 条(原写法)与第 M 条(原写法)」,序号就是表单的行号;两条的原写法都对得上才指到行,对不上就只给说明。
|
|
716
|
+
const [, a, p, b, q] = /第 (\d+) 条((.*))与第 (\d+) 条((.*?)),同一目录/s.exec(e.message) ?? [];
|
|
717
|
+
const rows = a && c.dirs[a - 1]?.path === p && c.dirs[b - 1]?.path === q ? [c.dirs[a - 1], c.dirs[b - 1]] : [];
|
|
718
|
+
return { text: rows.length ? `第 ${a} 行(${p})与第 ${b} 行(${q}):${OVERLAP}` : OVERLAP, detail: e.message, rows };
|
|
719
|
+
}
|
|
720
|
+
const text = FAIL_TEXT[e.code], [one, any] = Array.isArray(text) ? text : [text, text];
|
|
721
|
+
const hit = Array.isArray(text) ? c.dirs.filter(dir => dir.path && e.message.includes(dir.path)).sort((a, b) => b.path.length - a.path.length)[0] : null;
|
|
722
|
+
return { text: hit ? `第 ${c.dirs.indexOf(hit) + 1} 行(${hit.path}):${one}` : (any ?? `没有成功(${e.code})`), detail: e.message, rows: hit ? [hit] : [] };
|
|
723
|
+
}
|
|
724
|
+
async function confirmScope() {
|
|
725
|
+
const c = picker.ctx;
|
|
726
|
+
if (!c || c.busy || (c.mode === 'dirs' && scopeProblem(c.dirs))) return;
|
|
727
|
+
if (!c.grant && c.mode === 'whole') return grantTo(c.m, c.row, c.target);
|
|
728
|
+
const { m, grant, row, target } = c, sh = shareOf(m), restrict = c.mode === 'dirs' ? { dirs: c.dirs.map(({ path, access }) => ({ path, access })) } : null;
|
|
729
|
+
c.busy = true; c.problem = null;
|
|
730
|
+
drawForm();
|
|
731
|
+
// 记着这次写:回应超时了才登记(授予是一行待确认的授权,改范围是授权行上的待确认)。晚到的回应、列表核对都按它收尾。
|
|
732
|
+
const unknown = grant ? { restrict, unknown: true } : { friend: row.author, target: { id: target.id, name: target.name }, state: 'granting', restrict, unknown: true };
|
|
733
|
+
const kept = () => (grant ? sh.rescoping.get(grant.grant) === unknown : sh.pending.includes(unknown));
|
|
734
|
+
const lose = text => { if (grant) sh.rescoping.set(grant.grant, { error: text }); else Object.assign(unknown, { state: 'denied', reason: text, unknown: false }); };
|
|
735
|
+
const late = reply => {
|
|
736
|
+
if (!kept()) return;
|
|
737
|
+
beginWrite(sh);
|
|
738
|
+
if (reply.value) { mergeGrant(sh, reply.value); if (grant) sh.rescoping.delete(grant.grant); else sh.pending = sh.pending.filter(p => p !== unknown); } else lose(problemOf({ dirs: c.dirs }, reply.failure).text);
|
|
739
|
+
endWrite(m);
|
|
740
|
+
readGrants(m);
|
|
741
|
+
draw();
|
|
742
|
+
};
|
|
743
|
+
if (grant) sh.rescoping.delete(grant.grant);
|
|
744
|
+
beginWrite(sh);
|
|
745
|
+
let made, failure;
|
|
746
|
+
try { made = await ask(m, grant ? 'grants.restrict' : 'grants.grant', grant ? { grant: grant.grant, restrict } : { friend: row.author, target: { kind: MACHINE_KIND, id: target.id }, restrict }, late, PROBE_WAIT_MS); } catch (e) { failure = e; }
|
|
747
|
+
endWrite(m);
|
|
748
|
+
c.busy = false;
|
|
749
|
+
if (made) mergeGrant(sh, made);
|
|
750
|
+
if (failure && !failure.code && !failure.refused) {
|
|
751
|
+
// 没有回应:不知道有没有写成。表单关掉,那一行显示待确认;晚到的回应与后台读列表谁先有结果听谁的。
|
|
752
|
+
if (grant) sh.rescoping.set(grant.grant, unknown); else sh.pending = [...sh.pending.filter(p => !(p.friend === unknown.friend && p.target.id === target.id)), unknown];
|
|
753
|
+
if (picker.ctx === c) closePicker();
|
|
754
|
+
recover(m);
|
|
755
|
+
} else if (picker.ctx === c) { if (made) closePicker(); else { c.problem = problemOf(c, failure); drawForm(); } }
|
|
756
|
+
draw();
|
|
757
|
+
}
|
|
758
|
+
function noticeOf(c) {
|
|
759
|
+
if (c.busy) return h('p', { class: 'progress' }, c.mode === 'dirs' ? '正在目标机上探测这些目录,最多约 30 秒,请稍候…' : '正在保存…');
|
|
760
|
+
return c.problem ? h('div', { class: 'warn-box', role: 'alert' }, h('div', {}, c.problem.text), c.problem.detail && c.problem.detail !== c.problem.text ? h('div', { class: 'detail selectable' }, c.problem.detail) : null) : null;
|
|
761
|
+
}
|
|
762
|
+
// 输入时只更新校验说明与确认按钮,不重建输入框。
|
|
763
|
+
function refreshForm() {
|
|
764
|
+
const c = picker.ctx, bad = c.mode === 'dirs' ? scopeProblem(c.dirs) : null;
|
|
765
|
+
if (c.form.hint) { c.form.hint.textContent = bad ?? ''; c.form.hint.hidden = !bad; }
|
|
766
|
+
c.form.confirm.disabled = c.busy || Boolean(bad);
|
|
767
|
+
c.form.confirm.textContent = c.busy ? (c.mode === 'dirs' ? '正在探测…' : '正在保存…') : c.grant ? '保存范围' : '授予';
|
|
768
|
+
fill(c.form.notice, noticeOf(c));
|
|
769
|
+
}
|
|
770
|
+
function dirRow(c, dir, i) {
|
|
771
|
+
const path = h('input', { type: 'text', class: 'mono', placeholder: '目标机上的绝对路径,如 /Users/me/work', autocomplete: 'off', spellcheck: 'false', 'aria-label': `第 ${i + 1} 行的路径`, disabled: c.busy,
|
|
772
|
+
oninput: e => { dir.path = e.target.value; refreshForm(); } });
|
|
773
|
+
path.value = dir.path;
|
|
774
|
+
const access = h('select', { 'aria-label': `第 ${i + 1} 行的权限`, disabled: c.busy, onchange: e => { dir.access = e.target.value; refreshForm(); } },
|
|
775
|
+
h('option', { value: 'rw' }, ACCESS.rw), h('option', { value: 'ro' }, ACCESS.ro));
|
|
776
|
+
access.value = dir.access;
|
|
777
|
+
return h('li', { class: `dir-row${c.problem?.rows?.includes(dir) ? ' bad' : ''}` }, path, access,
|
|
778
|
+
h('button', { class: 'btn quiet small', type: 'button', 'aria-label': `删除第 ${i + 1} 行`, disabled: c.busy, onclick: () => { c.dirs.splice(c.dirs.indexOf(dir), 1); c.problem = null; drawForm(); } }, '删除'));
|
|
779
|
+
}
|
|
780
|
+
function drawForm() {
|
|
781
|
+
const c = picker.ctx, { m, row, target } = c, modify = Boolean(c.grant), dirsMode = c.mode === 'dirs', scope = scopeNote(certifiedOf(m, row));
|
|
782
|
+
const option = (mode, label, note, off) => h('label', { class: `opt${c.mode === mode ? ' on' : ''}${off ? ' off' : ''}` },
|
|
783
|
+
h('input', { type: 'radio', name: 'scope', checked: c.mode === mode, disabled: off || c.busy, onchange: () => { c.mode = mode; c.problem = null; drawForm(); } }),
|
|
784
|
+
h('span', { class: 'g-info' }, h('span', { class: 'g-name' }, label), h('span', { class: 'g-sub' }, note)));
|
|
785
|
+
// 仅限目录只有 macOS 的目标机能用;已经是仅限目录的授权,选项不灰(灰了就没法留在原范围)。
|
|
786
|
+
const off = target.restrictHint !== true && !dirsMode;
|
|
787
|
+
c.form = { hint: dirsMode ? h('p', { class: 'hint', role: 'status' }) : null, notice: h('div', { 'aria-live': 'polite' }), confirm: h('button', { class: 'btn', type: 'button', onclick: confirmScope }) };
|
|
788
|
+
picker.dialog.heading.textContent = modify ? '修改范围' : '授予远程执行';
|
|
789
|
+
fill(picker.dialog.body, h('div', { class: 'stack scope-form' },
|
|
790
|
+
h('div', { class: 'target-box' }, h('span', { class: 'g-name truncate' }, target.name), target.os ? h('span', { class: 'g-sub truncate' }, `${target.os} · ${target.user}`) : null, scope ? h('span', { class: 'g-sub truncate' }, scope) : null),
|
|
791
|
+
h('div', { class: 'opts', role: 'radiogroup', 'aria-label': '范围' },
|
|
792
|
+
option('whole', '整台机器', '等同于登录这台机器上的这个账号'),
|
|
793
|
+
option('dirs', '仅限目录', off ? `第一期只支持 macOS 的机器${target.os ? `(这台是 ${target.os})` : ''}` : 'TA 的命令只能读写下面列出的目录(外加系统运行所需的只读路径和本次专用的临时目录);家目录里其余文件的内容、~/.ssh、Coda 数据读写不到', off)),
|
|
794
|
+
dirsMode ? h('div', { class: 'dirs-edit' }, h('ul', { class: 'glist' }, c.dirs.map((dir, i) => dirRow(c, dir, i))),
|
|
795
|
+
h('button', { class: 'btn quiet small', type: 'button', disabled: c.busy, onclick: () => { c.dirs.push(blankDir('ro')); c.problem = null; drawForm(); } }, '添加目录'), c.form.hint) : null,
|
|
796
|
+
c.form.notice,
|
|
797
|
+
h('div', { class: 'actions' }, c.form.confirm, modify ? null : h('button', { class: 'btn quiet', type: 'button', disabled: c.busy, onclick: () => { c.stage = 'list'; fill(picker.dialog.body, picker.list); picker.dialog.heading.textContent = '授予远程执行'; drawPicker(); } }, '换一台机器'))));
|
|
798
|
+
refreshForm();
|
|
799
|
+
}
|
|
616
800
|
|
|
617
801
|
// ---- 网络节点 ----
|
|
618
802
|
const canNet = () => typeof coda.friendNodes === 'function';
|
package/view/style.css
CHANGED
|
@@ -188,6 +188,32 @@ details[open] > summary { margin-bottom: 10px; }
|
|
|
188
188
|
.pick { width: 100%; display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); text-align: left; }
|
|
189
189
|
.pick .why { font-size: .85em; color: var(--orange); }
|
|
190
190
|
|
|
191
|
+
/* 授予、修改范围的表单;授权行、代理记录、操作记录里的范围(长路径折行、点开看全部) */
|
|
192
|
+
.target-box { display: flex; flex-direction: column; min-width: 0; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
|
|
193
|
+
.opts { display: flex; flex-direction: column; gap: 8px; }
|
|
194
|
+
.opt { display: flex; align-items: flex-start; gap: 10px; padding: 10px 12px; border-radius: 12px; border: 1px solid var(--line); background: var(--card); }
|
|
195
|
+
.opt.on { border-color: var(--accent); }
|
|
196
|
+
.opt.off { opacity: .65; }
|
|
197
|
+
.opt input { flex: none; width: auto; margin-top: 3px; }
|
|
198
|
+
.dirs-edit { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; }
|
|
199
|
+
.dirs-edit > .glist { width: 100%; }
|
|
200
|
+
.dir-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
|
|
201
|
+
.dir-row input { flex: 1 1 100%; }
|
|
202
|
+
.dir-row select { flex: none; padding: 7px 8px; border-radius: var(--coda-radius, 9px); border: 1px solid var(--line); background: var(--bg); color: var(--fg); }
|
|
203
|
+
.dir-row.bad input { border-color: var(--red); }
|
|
204
|
+
.warn-box .detail { margin-top: 4px; font-size: .9em; opacity: .85; overflow-wrap: anywhere; }
|
|
205
|
+
.scope > summary { display: flex; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
|
206
|
+
.scope > summary::after { content: "\00a0▾"; flex: none; }
|
|
207
|
+
.scope .sum-main { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
|
|
208
|
+
.scope .sum-tail { flex: none; }
|
|
209
|
+
.scope[open] > summary { display: block; margin-bottom: 4px; white-space: normal; }
|
|
210
|
+
.scope[open] .sum-main { display: inline; overflow: visible; overflow-wrap: anywhere; }
|
|
211
|
+
.scope[open] > summary::after { content: "\00a0▴"; }
|
|
212
|
+
.dirs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; font-size: .85em; }
|
|
213
|
+
.dirs li { display: flex; align-items: flex-start; gap: 8px; min-width: 0; }
|
|
214
|
+
.dirs .tag { flex: none; }
|
|
215
|
+
.dirs .mono { min-width: 0; overflow-wrap: anywhere; }
|
|
216
|
+
|
|
191
217
|
/* 网络节点:分节标题行右端的图标按钮、抽屉里的分组与行、待移除块 */
|
|
192
218
|
.sec .kebab { margin: -6px -6px -6px 0; }
|
|
193
219
|
.page > section > .netblock { margin-top: 16px; }
|