Repository navigation
feat: connect the remote core and core move through the system ssh - #1843
Merged
Merged
Conversation
The node's link to its core, its screens' relay and pages of the core's machine, a core update, and a core move's steps and copies now go through one owned system ssh process, signed in once per session, instead of the in-process SSH client. The start script gained run, fput, fget and attach steps; after the core accepts a node, one multiplexed stream carries the link and every loopback connection to the core's machine. russh, russh-config and russh-sftp are removed with the in-process SSH test server and the SFTP code; the remote_core and core_move fixtures run against the system's sshd.
A node role running where no hide sits beside its program, as in an in-process test, now dials with BatchMode instead of refusing as a missing helper, so ssh asks no terminal and keys and the agent still sign in. Also formats the ssh modules.
Each stream of the node's connection to its core now owns its socket until its threads end and stays counted among the 64 until then: an overflow, a failed write or the connection's end shuts the socket both ways, which wakes a write stuck on a peer that stopped reading, and a write that waits past 30 s ends its stream. One thread writes the connection from a bounded outbox with answers ahead of data, a ping's bound covers its write and an unanswered ping ends the connection, and a page of the core's machine keeps its connection permit until its stream ends.
…es however the script ends
# Conflicts: # docs/TESTING.md
…e connection an owner
yansfil
added a commit
that referenced
this pull request
Oct 30, 2026
…s attempt ends (#1847) Closes with-hide/hide-private#335 Closes with-hide/hide-private#337 Related: #1843, #1830 ## Summary - 장비 `ssh`가 띄운 프로세스가 `setsid`로 떨어져 나가고 부모가 바로 끝나면, 그 프로세스가 `ssh`보다 오래 살아남을 수 있었습니다(#335). 지금까지는 표본을 떠서 기억해 둔 프로세스만 정리했기 때문입니다. - 이제 `ssh`를 감독하는 프로세스는 셸이 아니라 Hide 자신의 프로그램입니다. 같은 프로그램을 감독 역할로 한 번 더 띄우고, `main`보다 먼저 감독 일을 시작합니다. - 정리 방법은 하나뿐이고, `ssh`가 끝날 때, 취소할 때, Hide가 갑자기 죽을 때 모두 그 하나를 씁니다. - "찾아봤는데 없다"는 끝난 증거가 아닙니다. Linux는 커널이 "남은 자식이 없다"고 답할 때만 끝난 것으로 칩니다. macOS는 프로세스 표를 빠짐없이 읽고 하나도 못 찾은 look이 두 번 연달아 나올 때만 끝난 것으로 칩니다. 표를 읽고 거르는 사이에 사라진 프로세스가 있었다면 그 look은 세지 않습니다. - 정해진 시간(5초) 안에 증거가 없으면 "끝났다"고 답하지 않고 오류로 답합니다. - `ssh`는 Hide가 "시작해도 된다"(`go`)고 답한 뒤에만 돌기 시작합니다. 시작을 기다리다 포기한 Hide는 답하지 않으므로, 감독이 붙잡고 있던 `ssh`를 스스로 끝냅니다. 그래서 Hide가 모르는 `ssh`가 남지 않습니다. - 끝을 확인하지 못해도 Hide는 멈추지 않습니다. 감독과 Hide가 남기는 로그 한 줄은 막히지 않는 통로로만 쓰고, 못 쓰면 버립니다. 제때 거두지 못한 프로세스는 프로세스마다 하나인 스레드가 최대 64개까지 맡고, 넘치면 로그만 남깁니다. - 앱이 업데이트된 뒤 예전 hided가 계속 돌면(macOS) `ssh`를 띄울 수 없습니다. 이제 장비 줄, core 연결 띠, core 옮기기 점검이 "Hide를 종료하고 다시 열면 연결돼요"라고 네 언어로 말하고, 다시 시도 버튼을 내지 않습니다. 다시 시도해도 같은 이유로 실패하기 때문입니다. - CI에서 자꾸 깨지던 #337은 순서 문제였습니다. 감독만 거두고, 아직 죽어 가던 나머지를 기다리지 않았습니다.  ## Review - **판단해 주세요**: 감독을 Hide 자신의 프로그램으로 다시 띄우는 방식(`ctor` 크레이트의 생성자가 `main`보다 먼저 돌며, 표시 변수가 없으면 `getenv` 한 번만 하고 바로 돌아갑니다). - Linux는 `/proc/self/exe`를 띄워서, 업데이트로 파일이 바뀌어도 지금 돌고 있는 그 파일을 씁니다. - macOS는 경로로만 띄울 수 있어서, 그 경로의 파일이 처음 시작한 파일과 다르면 띄우지 않고 `program_replaced` 오류로 답합니다. - 표시 변수에는 프로토콜 버전(이번에 2)이 들어갑니다. 버전이 다른 감독은 그렇다고 말하고, 어느 쪽도 다른 방식으로 대신 띄우지 않습니다. - **판단해 주세요**: 시작 약속. 감독은 `spawned`를 말한 뒤 자식을 붙잡은 채 `go`를 10초까지 기다립니다. Hide는 자기 시작 한도 안에서만 `go`를 씁니다. 그 뒤에는 `failed`가 아닌 모든 결과(침묵, 감독의 끝)에서 자식을 호출자에게 넘기고, 그 끝은 다른 끝과 같은 정리를 거칩니다. - **판단해 주세요**: macOS의 증거 기준. ESRCH가 아닌 이유로 id를 못 읽은 프로세스가 하나라도 있으면 그 look은 증거가 되지 않습니다. 어떤 프로세스가 늘 그렇게 실패하면 모든 끝이 5초 뒤 "확인 안 됨"이 됩니다(이 Mac에서는 모든 프로세스가 답했습니다). - **판단해 주세요**: 로그 통로. stderr가 일반 파일이면 그대로 쓰고, 아니면 이름으로 다시 열어 막히지 않는 통로를 따로 만듭니다(Linux는 소켓 말고 모두, macOS는 터미널만). 그 밖에는 `/dev/null`입니다. `hide connect`가 띄운 hided는 stderr가 `/dev/null`이라 이 줄들은 거기서 사라집니다. 이번 변경 전부터 그랬고, `hide-platform`에서 hided의 로그로 가는 길은 없습니다. - **판단해 주세요**: 업데이트된 Hide의 장비 줄에도 "테스트" 버튼은 남습니다. 서버 키가 바뀐 줄과 같습니다. 테스트는 진단이고 다시 연결하지 않습니다. - **조심해서 볼 파일**: - `hide-platform/src/process.rs` - ownership, failure path: - `started`와 감독의 `start`/`answered`: `go`를 주고받는 시작 약속. - `Tree::look_between`: macOS에서 두 번 연달아 조용한 look. - `diagnostics_of_its_own`, `diagnose`, `Reaping`/`admit`/`reap_waiting`, `drop_tied`. - `supervisor` 모듈은 생성자 안에서 돕니다. 그래서 C 라이브러리 호출과 `main` 준비가 필요 없는 표준 라이브러리만 씁니다. - `hide-node-link/src/device.rs`, `herdr-core/src/model.rs`, `contracts/snapshot-wire-enums.json` - snapshot wire: 새 값 `hide_updated`, 새 동작 `reopen_hide`. - `web/src/settings.ts`(`retryCanHelp`), `web/src/connection.ts`, `web/src/settings/CoreMoveDialog.tsx`: 다시 시도를 숨기는 세 곳. - `hide-node/src/ssh/host.rs`: 끝이 확인되지 않으면 `host.child_end_unconfirmed`를 남기고 시도를 놓지 않습니다. - **비용 검토**: - 상시 작업은 없습니다. 감독은 자식이 끝나거나 말을 들을 때까지 `poll`에서 잡니다. - spawn마다 `/bin/sh` 대신 Hide 프로그램을 한 번 exec 하고, 시작 때 왕복 한 번(`spawned`/`go`)이 더 있습니다. - 트리를 끝낼 때만 프로세스 표를 걷습니다. macOS는 마지막에 한 번 더 걷습니다. - 거두는 스레드는 프로세스마다 하나이고, 맡은 것이 있을 때만 100ms마다 기다리지 않고 묻습니다. ## Evidence - **이전 커밋(d7fe335)에서 실패하는 테스트** (macOS, 새 테스트를 옛 `process.rs`에 붙여 돌림): - `a_tied_supervisor_lets_its_child_go_only_once_its_owner_answers`: 옛 감독은 버전 1이라 거절합니다. 버전 1 표시로 다시 돌리면, 답하지 않았는데도 자식을 돌렸습니다(`failed 60` 대신 `started`). - `unconfirmed_tied_drops_leave_no_thread_or_child_behind`(stderr를 가득 채움): drop 6번에 스레드가 2개에서 8개로 늘었습니다. - `a_member_that_ends_between_the_table_and_the_look_leaves_no_proof`(macOS 단위): 옛 코드에는 `look_between`이 없어 붙일 수 없습니다. 규칙을 한 번의 look으로 되돌리면 실패합니다. - `hide_updated` 테스트들(core, web): 옛 코드에는 그 값이 없어 컴파일되지 않습니다. - **확인한 것** (main 병합 전 07cb645, 병합 후 2f09251): - macOS 15.1: `hide-platform`, `herdr-core`, `hide-node`, `hided`, `hide-node-link`, `hide-agent-hooks` 5118/5118. `scripts/verify-cargo.sh lint`, Windows 대상 `hide-platform` clippy가 깨끗합니다. - main 병합 뒤: lint가 깨끗하고, `hide-node`, `hide-node-link`, `herdr-core`, `hided` 4418/4419입니다. 실패 하나는 이 PR이 건드리지 않는 `hided link_mux::tests::the_connection_ending_frees_every_stream`입니다. 전체 병렬 실행 3번 중 2번 실패했고(한 번은 EINVAL, 한 번은 15초 대기), 혼자 20번 돌리면 모두 통과합니다. - `scripts/verify-web.sh`: 2283 통과(1 건너뜀), desktop 298 통과(4 건너뜀). `node scripts/check-design-contract.mjs` 통과. - Linux(CI와 같은 `ubuntu:26.04` 이미지, 이 Mac의 Docker): `process` 68/68, 단위 48/48, 끝난 뒤 남은 프로세스 없음. 워크스페이스 `cargo clippy --locked --workspace --all-targets -- -D warnings`가 깨끗합니다. - **확인하지 못한 것**: - Windows 테스트는 CI에서만 돕니다(Windows 호스트 없음). - 실제 sshd를 쓰는 system_ssh 테스트는 CI의 remote mailbox 레인에서만 돕니다. - 실제 앱 업데이트 중의 장비 줄은 돌려 보지 않았습니다. 화면은 갤러리 캡처뿐이고, 설치된 앱은 건드리지 않았습니다. - macOS `start()`에서 감독이나 자식의 id 읽기가 실패하는 경로는 테스트가 없습니다. - 이번에는 부하 반복을 돌리지 않았습니다(공용 Mac). <details><summary>Verification record</summary> </details>
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.
Related: #1830 (장비 연결을 시스템 ssh로 옮긴 PR, 이 PR이 같은 설계를 씁니다)
Summary
ssh하나를 띄워서 씁니다.ssh <alias>가 되면 core 연결도 됩니다. ProxyJump, ssh-agent, Tailscale SSH가 그대로 적용됩니다.sign_in_needed로 멈춥니다. 지금 russh도 묻지 않으므로 퇴보는 아닙니다.Review
link_mux)를 core의 attach 서비스에 두어,hided attach는 어떤 빌드여도 바이트 파이프로 남고, core 기계sshd의 포워딩 설정과 무관해졌습니다.다시 시도버튼.connect_again(앱 실행,hide connect, 창의 Retry)도 같은 다시 시도로 세되, 시도가 진행 중일 때 온 것은 그 시도에 합쳐 앱을 처음 열 때 ssh가 한 번만 붙습니다.hided/src/link_mux.rs- high-frequency path, ownership: 모든 화면 릴레이와 링크 바이트가 지나갑니다. 쓰기 스레드 하나가 bounded outbox(제어 256, 데이터 64)에서 보내고, 스트림 슬롯은 소켓을 양쪽 다 닫고 읽기·쓰기 스레드가 끝나야 풀립니다. outbox 자리를 기다리던 읽기 스레드는 스트림이 닫히면 깨어나 멈춥니다. 연결의 끝은 node의Mux와 core의Served가 쥐고, 시작이 중간에 실패하면 시작한 스레드를 끝내고 기다립니다. 읽지 않는 상대에게는 30초 쓰기 제한, ping은 한 deadline 안에서 끝나지 않으면 연결을 끝냅니다.hided/src/page_forward.rs- core 기계 페이지가 장비 페이지와 같은 forward를 타고, 16개 permit을 스트림이 끝날 때까지 쥡니다.hided/src/node_role.rs- failure path:LinkFailure::Operator는 backoff 없이 기다리고, 잠자기·네트워크 변경·포트 probe로 깨지 않습니다.hide-node/src/ssh/openssh.rs- desk가 없어BatchMode=yes로 돈 연결의 "묻지 못함"을sign_in_needed로 읽습니다(Asking::Nobody). 바뀐 키, 정책, 네트워크는 그대로.hide-node/src/ssh/bootstrap.rs- start script의run은 셸 문자열 없이command "$@"로 실행하고, 쓰는 동안head -c로 cap+1에서 끊고, EXIT/HUP/INT/PIPE/TERM trap으로 임시 파일을 지웁니다.hided/src/attach.rs- snapshot/link wire, ownership: 수락 줄 다음부터 프레임으로 바뀝니다. 같은 빌드끼리만 링크되므로 섞이는 경우가 없습니다. core는 링크가 닫힐 때Served를 놓아 연결을 끝냅니다.contracts/hided-ws.schema.json,web/src/connection.ts- snapshot wire:core_link에stoppedphase와problem,{action: "retry"}가 늘었습니다.spikes/web-shell/hided-spike/Cargo.lock에는 russh가 남아 있습니다. 동결된 spike 기록이고 작업공간 밖이라(docs/README.md가 고치지 말라고 함) 그대로 둡니다.docs/VERIFICATION.md의 2026-10-09 SFTP 사고 기록과 브라우저의sftp:차단 목록도 그대로입니다.Evidence
remote_core24/24,core_move44/44가 macOS의 시스템sshd에 대해 통과(테스트 고정물이 실제sshd를 띄웁니다).remote_core의 Memory 테스트 하나가 첫 시도에서table projects already exists로 실패하고 재시도에서 통과했는데, 이미 격리된 flaky(with-hide/hide-private#179)이고 이 PR이 건드리지 않은 곳입니다.remote_core테스트: 첫 dial을 중계에서 붙잡아 둔 채 창이 연결하는(hide connect처럼) 순간을 재현합니다. 서버 키를 모르는 alias는sign_in_needed로 멈추고, sshd 연결은 1개, 7초 대기 뒤에도 1개, 키를 신뢰한 뒤connect_again한 번에 1개 더 붙어 링크됩니다. 고치기 전 코드에서는 첫 실패 직후 두 번째 연결이 생겨 실패했습니다. 2분 대기로 돌렸을 때도 sshd 연결은 노드의 첫 시도 1개(preauth에서 닫힘)뿐이었고, 그 대기의retry_ms는 null입니다.link_mux단위 테스트 10개 5회 통과: 읽지 않는 상대에 대해 close/링크 끝을 3번 반복해도 양쪽 슬롯이 0으로 돌아오고, 아무것도 읽지 않는 carrier에서alive(300ms)가 5초 안에 false를 돌려주며 연결이 끝납니다.link_mux테스트 4개는 각각 고치기 전 동작으로 되돌리면 실패합니다: 연결이 받지 않는 동안 정상으로 끝난 스트림의 CLOSE가 이미 줄 선 DATA 뒤에 가서 상대가 데이터를 모두 받은 다음 끝을 봄(고치기 전에는 5번 모두 CLOSE가 앞질러 끝부분이 잘림), 데이터 큐가 가득 차 기다리던 스트림이 상대의 CLOSE로 깨어나 슬롯과Carried가 풀림, 링크 읽기 스레드가 막힌 채 core의Served를 놓으면 모든 스레드가 끝나고 링크와 carrier가 끝을 봄, 두 번째·세 번째 스레드 시작을 일부러 실패시키면 먼저 시작한 스레드가 끝나고 carrier가 닫힘.sign_in_needed, 바뀐 키는host_key_changed, Tailscale 정책은policy_refused, 연결 거부는unreachable.core_move의 업로드 중간 끊김 테스트가 처음에 실패한 것은 고정물의head대역이run의 출력 cap용head -c까지 세었기 때문이라, 파일로 쓰는head는 세지 않게 고쳤습니다.verify-cargo.sh lint,verify-web.sh(pnpm 10으로), 스크립트 suite 723개, design contract 통과. 0f79a3b(CLOSE 순서 수정)에서 nextest 6335/6335, lint,remote_core24/24 다시 통과.core-move-window,window-sign-in)에서 한국어 다크, 영어 라이트로 캡처해 확인했습니다./Applications/hide.app)은 건드리지 않았습니다. 창 위 줄은 gallery로만 봤고 네이티브 창에서는 보지 않았습니다.Verification record