Repository navigation
feat(remote-access): 远程访问插件与自托管中继(关联 #116) - #192
Merged
Merged
Conversation
Noise IK channel over a WebSocket with fragmentation and a backlog limit, request and stream multiplexing that follows DSH's worker tunnel frames with per-body credit, device authentication by a non-extractable WebCrypto key signing the handshake hash, pairing links and codes, and relay registration signatures. Unit tests cover connection-bound results, carrier failures and flow control; scripts/check-browser.ts runs the device side in Chromium and WebKit.
Hosts register with an operator-issued key and an Ed25519 signature over a one-time nonce bound to the relay origin; a newer verified registration replaces the old one. Every device connection is paired with a fresh Host socket and forwarded without decryption, pausing the source while the destination is backed up. Covers refused registrations, replacement, offline and unanswered Hosts, per-Host limits, close-code forwarding and heartbeats.
The device pings through the tunnel and the Host closes a channel that stays silent for 90 seconds. The Host pings the relay on its control socket. The relay now forwards a deliberate normal close so the device can tell a Host that hung up from a lost path. Noise key pairs can be restored from a stored secret.
- gate: the endpoints and fetch routes a remote device may use, checked against the full DSH 0.2.1-rc.2 web surface; everything else is refused with a reason. The mapping starts from Paraso42's work in ECNU#180. - host: the adapter over the DSH seams (owner Peer, shared fetch handler, wire streams, rendered index and frontend files). - connections: one Peer per connection, disposed when it closes; revocation ends every connection of the device. - devices: the persisted Host identity and paired devices, and admission by single-use invite plus the owner's confirmation of the pairing code. - relay-link: registration, liveness and reconnection with backoff. - RemoteAccess ties them together; the tests drive a real relay and Host over loopback WebSockets.
The plugin runs remote access while it is switched on and the relay and access key are set; any settings change restarts it. Its methods give the settings page the status, the pairing invite, confirmation of waiting devices and revocation; the gate refuses them to remote devices. The Host plugin is bundled with the pure JavaScript sodium, so the package installs with no dependencies and no native addon. The remote document is served as the Host renders it; the web client adds its own transport hook, which keeps the Host and the relay's web client coupled only through the tunnel protocol version.
The loader page pairs this browser with a Host from an invite link and keeps paired Hosts connected, reconnecting after losses. The DSH interface runs in an iframe: a preamble hands DSH's client the carrier hooks it already supports, so RPCs and streams use that page's own tunnel and Peer, and a Service Worker answers the document, static files, downloads and uploads through the loader. Values cross into the iframe's realm by structured cloning. The relay binary serves the web client with a strict CSP. scripts/check-web.ts checks the whole flow in Chromium and WebKit; it replaces check-browser.ts.
…age product-neutral Field hints are described-by text rather than part of the label, the page intro no longer names a product, and the logger uses the plugin's entry id.
README in Chinese and English, the protocol of the current version, license and third-party notices. The build collects the license of every bundled package into lib/THIRD_PARTY_LICENSES.txt and fails on an unreviewed one. The package joins the catalog, so CI checks and packs it like the others; it is not assembled into the client before it is published.
…nowledge the preview notice Endpoints of the EduWork 0.4.6 desktop composition are classified like the official ones: Studio results, the calendar and read-only views are allowed; desktop actions, accounts, memories, skills and data imports stay on the computer. A desktop Host never shows DSH's preview notice, so a device must be able to record it as read; settings/mutate is allowed for that one write.
Browsers start an <a download> link without asking the Service Worker, so the request reached the relay. The preamble fetches such links through the Service Worker and saves a local copy; check-web now downloads a file in both engines.
…t switched them on Connections started from a settings change carried DSH's configuration transaction into every later request, so DSH refused settings writes from remote devices as nested transactions.
The settings page stores the relay access key as the DSH credential EDUWORK_REMOTE_ACCESS_KEY instead of a plugin setting, so it no longer sits in plain text in the profile's cordis.patch.yml. The plugin resolves it when remote access starts and restarts when the credential changes.
A first load moved about 12.7 MB of script and style through the relay. The Service Worker now asks for gzip and unpacks it; the Host compresses only the frontend's public files, keeping a compressed copy of each file that never changes at its URL, so the official frontend's first load drops to about 4.6 MB. RPC results, downloads and streams stay uncompressed, since their compressed lengths could hint at their content.
Remote devices now use DSH's full interface, adjusted only where a phone needs it. Below 768px the sidebar rail is hidden and the sidebar opens over the whole width, with its workspace tree, search and new session unchanged. It closes once a Session or a global panel is picked. The sidebar's open and new-session controls sit at the top left, as DSH places them while its sidebar is hidden on macOS. Conversations keep DSH's own durations, retries, approvals and questions. The preamble marks the remote document with data-eduwork-remote. The client plugin applies the layout only there and no longer shows the remote access settings, whose methods the gate refuses to remote devices.
At phone width DSH keeps the settings dialog at its desktop layout, with the section list beside the section, which leaves a section a column a few characters wide. On a remote device the dialog now fills the screen and the section list becomes a row of tabs above the section, with the header's actions and close button beside the title. Sections render unchanged, and opening settings at a given section still shows it.
The gate refuses every settings change from a device, and DSH shows the refusal only as the control springing back to its old value. On a remote device the settings header now says the settings are view only and to change them on the computer. The other header actions, which act on the Host's desktop (such as opening the settings file), are hidden there.
- The open Session's row in the drawer shows its actions (menu, archive, pin) in place of its time: DSH reveals them on hover, and a touch opens the Session instead. - On iOS, fields use at least 16px text, below which Safari zooms into the page as a field takes focus and stays zoomed. - The loading page keeps the frame clear of the notch and the home indicator, which DSH cannot see from inside the frame, and pulling down at the top no longer reloads the page and reconnects.
Gateway sign-in in oidc identity mode keeps the ID Token it verified at login and on refresh. The Host-only identityToken(profileID) returns it, refreshing once first when the Access Token is due or the ID Token has less than ten minutes left, so a service the organization runs can confirm who is signed in.
The relay can admit a Host by the ID Token of an OpenID Connect issuer it is configured for (RELAY_OIDC_ISSUER, RELAY_OIDC_CLIENT_IDS), beside access keys. It verifies the token against the issuer's published keys, keeps only the subject, and ends the registration when the token expires; the Host registers again on a new control socket five minutes before, so connected devices stay up. The relay now also limits refused registrations per address (the address can come from a proxy header, RELAY_CLIENT_IP_HEADER), Hosts per member and connections per Host. A distribution can set the plugin's organization: its relay and the dsh-oidc profile whose sign-in admits the Host. The relay is then fixed and not shown on the settings page, so the token goes nowhere else, and remote access starts and stops with that sign-in.
A top-level remoteAccess section names the organization's relay and the sign-in (an organizations[] id) that admits a computer to it. It is validated with the rest of the file, may come from a signed configuration update like organizations, features and media, and reaches the installed remote access plugin as its fixed organization. Users still switch remote access on themselves.
Say what the user can do rather than how the relay works: no relay close reasons, error messages or Service Worker in the interface (the Host logs them), no relay address for an organization's relay, a version mismatch told apart from a refusal, and the per-account computer limit named when an organization's relay refuses.
# Conflicts: # docs/PACKAGES.md # docs/PACKAGES_EN.md # source-receipt.json # tests/package-maintenance.test.mjs
JunieXD
marked this pull request as ready for review
October 22, 2026 06:00
The relay is now configured by RELAY_URL, its public base URL, which may carry a path such as https://example.edu/eduwork-remote/. Its endpoints, pages, files and health check are all below that path, and anything outside it is not the relay's, so a reverse proxy passes the path on unchanged. A Host signs the full base URL when it registers, which keeps relays on different paths of one domain apart, and pairing links start with it. The web client's own URLs are relative: the relay names its base in the loader page's <base>, the manifest's start URL and scope are relative, and the Service Worker is scoped to h/ below the base and finds the base from its scope. remoteAccess.relay in the EduWork configuration accepts a path and is kept in that canonical form. check-web.ts runs each engine against a relay at the root and one below a path, checking that the worker's scope stays within it and that no request reaches the domain outside it. The READMEs note that a shared domain also shares the browser's storage with the other sites.
A frame the WebSocket library cannot parse, such as an unmasked client frame on a connection that has not registered, made it emit an error with no listener, which took the whole relay down. Every socket now ends on its own error, and its close handlers clean up as on any close. A regression test sends such a frame and then uses another connection.
An expired ID Token closed the Host's control socket, but the device connections already paired under it kept forwarding. The relay now keeps, per Host, when the credential that admitted it runs out and the connections paired under it, and at that moment ends them all. A Host that registers again with a newer token moves the deadline; one that only lost its control socket, as on a brief network loss, keeps its connections until then. On the Host, a renewal that fails, because no new token could be had or its socket closed before registering, no longer drops the registration it was to replace. That registration lasts until its credential expires, and the renewal is tried again with backoff, so a slow issuer does not disconnect devices early.
…clients The relay checked the authorized party only for a token with several audiences. It now takes the client a token was issued to, its azp or else its only audience, and requires it to be one of the configured client IDs and in the audience, as dsh-oidc does on the desktop. A single-audience token authorized to another party is refused. The protocol document states this rule and what an expiring token ends.
When the ID Token is due for renewal and the refresh fails for a moment, identityToken rejects without ending the sign-in and the next call renews it; when the issuer rejects the refresh token, the sign-in ends and identityToken asks for a new sign-in.
The deadline for registering on a Host socket, or for accepting on an accept socket, was cleared only by the first message. A connection that closed before sending one left its timer, and the socket the timer holds, until the deadline passed. Both deadlines now end with their connection.
…n lapses When the sign-in had ended, or its issuer no longer renewed the ID Token, the Host kept retrying with backoff for as long as it ran, refreshing the sign-in on every attempt, while the settings page said it could not reach the relay. The plugin now reports no credential in those cases; the link then stops in a new lapsed state, and the settings page asks the user to sign in again, after which remote access resumes. A brief failure, such as an unreachable issuer, is still tried again. A renewal that brings a token expiring no later than the one it replaces is no longer repeated every 30 seconds until the expiry: the relay ends the registration when it lapses, and the Host then finds no credential.
All relays of one domain shared one list of paired computers, so a relay below one path listed computers paired through another, which it cannot reach. Each relay's web client now keeps its own list, named after its path.
…he browser Browsers separate data only by domain, and the DSH interface a paired computer provides runs on the relay's domain. It can therefore use the browser's pairings with other computers, and on a shared domain it can use the other sites there as the user. The pairing page now asks users to pair only their own computers. The README explains why, recommends a domain of the relay's own, never one shared with a sign-in service or sites that need signing in to, and notes that a Service Worker covering a shared domain must leave the relay's path alone.
# Conflicts: # docs/PACKAGES.md # docs/PACKAGES_EN.md # source-receipt.json
freedomkk-qfeng
approved these changes
Oct 22, 2026
freedomkk-qfeng
left a comment
Member
There was a problem hiding this comment.
复核通过。已检查远控协议、每连接独立 Peer、宿主接口门禁、配对与撤销、OIDC 接入和子路径支持。之前的畸形 WebSocket 帧导致中继退出、ID Token 过期后已有连接继续存活、azp 校验问题已修复。
本地远控类型检查、构建及 71 项测试通过,OIDC 相关 28 项测试通过,配置与包维护测试 63 项通过、1 项跳过。同步 #147 后仅重新生成 source-receipt.json,远控与 OIDC 业务代码保持原样;源码清单审计通过。安装包验收曾遇到一次目录重命名被拒绝,单独重跑后公版/学校版、正式/开发版四种合成包全部通过。
按维护者确认,本次先合入源码,继续复用 DSH 现有远控 UI。公版由用户配置中继和 Key,机构装配可预置中继及 OIDC。ChatECNU 的 iframe 嵌入配置在中继服务侧继续跟进,不将统一服务器前端作为本轮合并前提;现有同源信任边界保留文档说明。npm 发布、默认产品装配及学校部署留待后续执行。
This was referenced Oct 22, 2026
freedomkk-qfeng
added a commit
that referenced
this pull request
Oct 22, 2026
Record the integration mapping, endpoint gate, device lifecycle and validation scenarios contributed in #180 and carried forward into #192. Keep both language entries aligned and refresh the source receipt without changing runtime code. Co-authored-by: Paraso42 <[email protected]>
This was referenced Oct 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题与修改
#116 远程接入的首版:在手机或其他电脑的浏览器中使用本机的 DSH/EduWork,经可自托管的中继连接,端到端加密,由本机确认和撤销设备。
本 PR 在 @Paraso42 的原型 #180 基础上,按 #180 的 review 重新设计实现。沿用了 #180 的以下结论和做法:endpoint 白名单门禁及拒绝原因;设备的待确认、已信任、已撤销三种状态,以及“撤销即断开已有连接”;对 DSH 宿主接入点的梳理;未配对拒绝、断线重连不重复执行、撤销即断开等验收场景;中继部署和真机验收的经验。
新增包
packages/dsh-remote-access(@eduwork/dsh-remote-access0.1.0,未发布),按目录分为:protocol:浏览器、宿主、中继共用的协议与加密(Noise IK,纯 JS 实现);host:宿主适配层,唯一调用 DSH 的地方。每条远程连接一个 owner Peer(interactions: 'answer'),撤销或断开时释放;connections、devices、gate:连接管理、设备登记、门禁;relay-link、relay:宿主到中继的连接,以及中继服务(eduwork-remote-relay,同时提供网页客户端);client:本机设置页;在远程设备上,按手机宽度调整 DSH 自己的界面;web:加载页、Service Worker 与预置脚本。对 #180 review 的逐条对应:
requestId__DSH_TRANSPORT__挂钩;官方界面由宿主renderIndex现场提供,不做快照、不替换全局 WebSocket;端到端检查走真实的加载页、SW 和 iframedocs/PROTOCOL.md:消息格式、状态转换、关闭码、版本兼容ready后才发业务流量/api路由均已归类,测试要求每一项都有归类用户可见的变化:
RELAY_URL配置公开地址,可以独占域名,也可以放在共用域名的路径下(如https://example.edu/eduwork-remote/)。连接、配对链接、网页文件、manifest、Service Worker 和健康检查都在这个路径下,Service Worker 只管<路径>/h/;反向代理按原路径转发。宿主注册时签名覆盖完整地址,同一域名下不同路径的中继互不通用;各中继的已配对电脑列表分开保存。学校版开箱即用:
dsh-oidc:新增仅限宿主调用的identityToken(profileID),返回当前已验证的 ID Token,快到期时先刷新。网关登录刷新时一并保存新的 ID Token。RELAY_OIDC_ISSUER、RELAY_OIDC_CLIENT_IDS),只记录用户标识,不记录 Token。Token 的签发对象(有azp取azp,否则取唯一的aud)须是配置的 client ID 之一并在aud中,与 dsh-oidc 的规则一致。接入密钥方式保留,两者可同时启用。remoteAccess: { relay, oidcProfileId },可随签名配置更新下发。设置了它时,设置页不显示中继和密钥,只说明由哪个机构提供;用户开启“允许远程访问”后,登录机构账号期间自动连接中继,退出登录后停止。ID Token 只发给这个预置的中继,设置页无法更改。计划中、本 PR 未做的:手机提醒(方案待定)、大文件流式下载、远程浏览目录和注册工作区(review 要求暂缓)、点对点直连。
验证
packages/dsh-remote-access:npm run check,含类型检查、构建与 71 个测试,全部通过。node scripts/check-web.ts:真实中继、加载页、SW、iframe,配对、RPC、流、下载、上传、断线重连、撤销;Chromium 与 WebKit 各在根路径和/eduwork-remote/下运行,均通过,并检查 SW 的作用范围、没有请求落在中继路径之外。packages/dsh-oidc:scripts/packages/manage.mjs check dsh-oidc,142 个测试通过、1 个跳过;覆盖刷新不返回新 ID Token、刷新暂时失败(503)、刷新令牌被拒(invalid_grant)和退出登录。dsh-host与相关桌面测试,172 个通过、17 个跳过。a758fb4本机构建,装入本分支插件):经公网中继两种内核通过;用真实学校账号、只接受学校登录的中继,两种内核通过。a758fb4的 CI 开发包,装入本分支插件,Windows 11 ARM 虚拟机中以 x64 仿真运行):用真实学校账号、经公网中继,Chromium 3 次、WebKit 2 次通过;退出学校账号后远程访问自动停止,重新登录后自动恢复。dd276f1)之后重跑了官方 DSH 两种内核的闭环与手机界面流程、EduWork macOS 的 Chromium 闭环与 WebKit 手机界面流程。0493067起):公网中继改为部署在/eduwork-remote/下(OpenResty 按原路径转发)后:/eduwork-remote/之外的请求。手机界面流程(本机子路径中继)两种内核通过。iat、exp依次递增),电脑每次用新 Token 重新注册成功。04aa635)后重跑上述三组单元测试,结果不变。兼容性与后续事项
RELAY_URL、RELAY_OIDC_ISSUER、RELAY_OIDC_CLIENT_IDS。中继需要可从外网访问的 HTTPS 地址,建议使用单独的域名;反向代理须转发 WebSocket、保留路径,空闲超时不低于 60 秒。@eduwork/dsh-remote-access与包含identityToken的@eduwork/dsh-oidc,加入默认产品装配(默认装配使用已发布的 npm 锁),并在scripts/settings-navigation-icons.mjs中补上设置导航图标;随后发布客户端,机构发行版跟进到该版本。remoteAccess: { relay, oidcProfileId },relay与中继的RELAY_URL相同,oidcProfileId填机构登录在organizations中的id。旧版客户端会拒收含未知键的配置更新,因此须声明package:@eduwork/dsh-remote-access能力,并把minClient设为第 2 步发布的版本(已写入docs/CONTENT_UPDATES.md)。合作贡献者
@Paraso42(#180)贡献了远程访问原型及本 PR 沿用的宿主接入点、接口门禁、设备生命周期与验收场景。插件中英文贡献记录和 Git
Co-authored-by署名已通过 #206 补齐。