People's changes now reach the target branch the same way the agent's do. The IDE credential carries a ref prefix and the Git service runs a pre-receive hook on every push that refuses updates outside it, so the IDE can push only `ide/` branches; the platform's own integration is unaffected. - A wish may name a source branch. The run starts from that branch's head, the agent builds on it, and verification, repair rounds, merging onto a moved target and conflict repair work as before. A missing branch makes the run wait (git_storage) until it is pushed. - Release risk is now computed from the target branch before integration, not from where the run started: a migration committed on the source branch would otherwise have been missed and could have skipped approval. - Clones work on `ide/work`; a plain `git push` publishes it. - The console lists a project's IDE branches with a button to submit a wish that merges one, and the new-wish form has a starting-point field; MCP `submit_wish` accepts `sourceBranch`. The Git service lists branches under a prefix for this (`POST /refs`). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4.6 KiB
4.6 KiB
IDE 网关
浏览器访问 Theia 的唯一入口,负责 HTTP 与 WebSocket 的身份校验。每个租户运行一个网关。本地用 npm run dev:ide 与 Theia 一起启动。
| 变量 | 说明 |
|---|---|
WF_DEPLOYMENT_MODE |
只有 development 允许 HTTP 公网地址与默认的本机 Theia |
WF_API_URL |
控制面 API 地址 |
WF_TENANT_ID |
网关所属租户 |
WF_WORKSPACE_GATEWAY_TOKEN |
调用 API /internal/workspaces/* 的网关令牌 |
WF_IDE_PUBLIC_URL |
浏览器访问网关的地址,生产必须是 HTTPS(Cookie 才会带 Secure) |
WF_IDE_ALLOWED_UPSTREAM_ORIGINS |
允许的 Theia 上游地址(本地为 http://127.0.0.1:4300) |
WF_IDE_ALLOWED_SERVICE_NAMESPACE |
Kubernetes 中工作区 Service 所在命名空间:上游必须是 wf-ide-<24 位十六进制>.<命名空间>.svc:3000,协作端口为 8100 |
WF_COLLABORATION_ALLOWED_UPSTREAM_ORIGINS |
本地允许的协作服务上游 |
WF_IDE_GATEWAY_HOST、WF_IDE_GATEWAY_PORT |
监听地址,默认 127.0.0.1:4400 |
会话
- Web 服务端用用户的 access token 调用
POST /launch(body{workspaceId}),网关向 API 校验后返回launchUrl,其中只有 30 秒有效的一次性随机码,不含用户令牌。 - 浏览器访问
GET /session?code=…,网关再次校验、消费启动码,设置不透明的 HttpOnly、SameSite=Strict Cookie 并跳转到/workspaces/:id/。访问日志必须隐去启动码查询串。 - 会话空闲 15 分钟失效;每次成功的请求与打开的 WebSocket 的周期复核都会续期,最长 12 小时。会话建立后,网关按已授权的用户 ID 复核,用户的 access token 过期不会中断正在使用的 IDE。
校验
- 每个 HTTP 请求与 WebSocket 握手都以网关令牌和固定的
X-WishForge-Tenant调用 APIPOST /internal/workspaces/:id/authorize。打开的 WebSocket 每秒复核一次(复核超时 3 秒);被拒绝、会话过期、上游变化或控制面不可用时立即断开,因此撤销成员资格后现有连接会被关闭。 - 上游地址只来自 API 的授权结果,并且必须在允许列表内;调用方不能选择上游,也不能把操作降级为只读。viewer 不能进入编辑会话。
- 转发前去掉用户凭据、浏览器 Cookie 与调用方伪造的
x-wishforge-*头。Theia 自己的theia-connection-token保存在网关进程中,不会下发给浏览器,也不会转发给协作服务。 /workspaces/:id/collaboration/*把 HTTP 与 Socket.IO 转发到授权结果中该工作区专用的 OCT 实例,每个请求都要求编辑权限。POST /internal/lifecycle-state(网关令牌)告诉控制面某个工作区当前的连接数,用于空闲自动暂停。
仓库凭据
- 申请:会话建立时,以及打开的 WebSocket 复核时令牌快到期(剩 5 分钟),网关以会话用户的身份调用 API
POST /internal/workspaces/:id/git-credential,取得 15 分钟的仓库令牌。这个令牌只能推送ide/开头的分支,由平台 Git 执行这条限制。 - 投递:网关把令牌交给工作区的
POST /wishforge-internal/git-credential,并附带 Theia 的连接令牌(没有就先请求一次 Theia 首页取得;Theia 重启后会自动重新取得)。投递内容还包括项目、仓库地址、目标分支和提交身份。 - 提交身份:取最近建立的会话用户,来自 API 首次授权时按 OIDC name/email 给出的
author。 - 失败与例外:失败时 30 秒后重试。外部仓库的项目 API 返回 409;工作区没有配置仓库时 Theia 返回 404。这两种情况在 30 分钟内不再申请,重新打开 IDE 会立即再试。
- 路径保护:浏览器请求
/workspaces/:id/wishforge-internal/*一律返回 404,只有网关自己能投递凭据。
限制
- 会话与启动码保存在进程内存中:网关重启后需要重新打开 IDE;多副本需要共享会话存储或会话亲和。
- 生产中必须让 Theia 与 OCT 只能经由网关访问,这需要在真实集群上验证网络隔离。
测试
需要先 npm run ide:install,然后运行 npm run test:ide。
gateway.test.mjs使用真实的本地 HTTP/WebSocket 服务,覆盖凭据不转发、启动码不可重放、viewer 拒绝、上游允许列表、Origin 检查、撤销后断开、使用中的会话续期与生命周期接口。gateway-handler.test.mjs不打开端口,直接驱动网关的请求处理器并使用伪造的fetch,覆盖启动时提交用户令牌、仓库凭据的申请与投递、Theia 重启后重新取得连接令牌、凭据路径对浏览器不可见以及外部仓库不投递。