Repository navigation
Conversation
…GT-4002) A /terminal page with an xterm.js client and a /terminal/ws WebSocket that runs `bash -l` inside the daemon's container, for operating a remote daemon from the browser. Security model: - Off unless OPENSWARM_WEB_TERMINAL=1; unset, neither the page route nor the upgrade listener is registered. - The upgrade never enters web.ts's request handler, so terminalServer.ts applies the mutation gate from webAuth.ts explicitly (token, or loopback / trusted Tailscale with a trusted Origin) and additionally requires any browser Origin to be this daemon's own host and port. Refused upgrades get 401 and the socket is destroyed. - Browsers cannot set WebSocket headers, so the web token is offered as a Sec-WebSocket-Protocol entry (openswarm.token.<base64url>) and re-checked through hasValidWebToken; it never appears in the URL, and only the plain protocol name is echoed back. - At most 4 sessions (extra ones closed with 1013), 15-minute idle timeout, start/stop logged with the peer address, pty and socket cleaned up on either side closing. Dependencies: ws (runtime), node-pty (optional, imported lazily only when a session starts), @xterm/xterm + @xterm/addon-fit (dev; postbuild copies them to dist/web-static/vendor/xterm since the dashboard loads no CDN). README and docker-compose document the flag and that terminal access equals access to the container's environment and tokens.
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.
무엇
OPENSWARM_WEB_TERMINAL=1일 때만/terminal페이지(xterm.js)와/terminal/wsWebSocket이 생긴다. 셸은 데몬 컨테이너 안의bash -l이고 uid는 데몬과 같다. cwd는OPENSWARM_WORKSPACE_ROOT(기본/work, 없으면 home)이다.src/support/terminalServer.ts: upgrade 처리, 인증, 세션 상한·idle·정리, 프로토콜 파싱.web.ts에는 시작/정지 호출 두 줄만 넣었다(크기 게이트 때문에 줄 수는 늘리지 않음).web/static/terminal.html+web/static/js/terminal.js: 풀스크린 xterm, fit addon, 연결 상태 표시, 재연결 버튼.ws(runtime),node-pty(optionalDependencies, 세션을 시작할 때만 lazy import),@xterm/xterm·@xterm/addon-fit(dev). postbuild가scripts/copy-web-vendor.mjs로dist/web-static/vendor/xterm/에 복사한다(CDN을 쓰지 않음).인증 게이트 — 운영자 리뷰 필요
web.ts의 요청 핸들러를 거치지 않는다. 그래서 기존 HTTP 게이트가 자동으로 돌지 않는다.authorizeTerminalUpgrade()가webAuth.ts의isAuthorizedMutation(토큰, 또는 loopback/신뢰 Tailscale + 신뢰 Origin)을 직접 호출한다. 실패하면401을 쓰고 socket을 destroy한다.Sec-WebSocket-Protocol항목openswarm.token.<base64url>로 보낸다. 서버는 그 값을x-openswarm-token에 넣은 뷰로 기존hasValidWebToken에 다시 묻는다(비교 로직을 새로 만들지 않음). URL에는 절대 넣지 않고, 응답 프로토콜로는openswarm.terminal.v1만 돌려준다. 이 운반 방식은 새로 만든 것이라 승인이 필요하다.검증
src/support/terminalServer.test.ts18건(가짜 pty 주입, 실제 http+ws): 미설정 시 upgrade listener·/terminal라우트 없음, foreign Origin(loopback이어도, 토큰이 있어도) 거부, 원격 peer는 토큰(헤더/subprotocol) 없거나 틀리면 거부, 다른 경로 upgrade 404, 입출력·resize 중계, 소켓 종료 시 pty kill, 상한 초과 1013, idle 종료, 셸 종료 시 소켓 closesrc/support102 files / 1069 tests 통과,tsc --noEmit -p tsconfig.check.json통과, oxlint 신규 경고 0npm run build→dist/web-static/vendor/xterm/3개 파일 생성 확인/terminal200, vendor 200, foreign Origin upgrade 401, 정상 세션에서echo SMOKE-$((6*7))출력과 resize 반영(tput cols/lines= 133/41), 종료 로그 확인Docker Build CheckCI가 돈다.