Repository navigation
Fix SSH relay installs on split shell/SFTP namespaces - #10645
AmethystLiang merged 2 commits into
Conversation
On Synology DSM and similar hosts, the SSH shell and SFTP subsystem expose different absolute paths for the same directory (e.g., /var/services/homes/alice vs /homes/alice). The relay installer silently picked the wrong path and failed discovery. This fix implements SFTP namespace detection: each install creates an unguessable ownership marker and probes both namespaces to detect divergence. When paths differ, SFTP writes redirect to the candidate namespace while shell commands keep the canonical path. Markers are random tokens redacted from logs.
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughAdds SFTP namespace mappings and marker-based discovery for split shell/SFTP directory trees. Relay installation and native dependency repair now create namespaces and route uploads and metadata writes through mapped SFTP paths when supported. SFTP transfer helpers handle aborts, session teardown, and late events. Marker tokens are redacted from diagnostics. New tests cover path validation, probing, platform behavior, abort handling, real SFTP wire operations, installation, repair, and mock lifecycle behavior. 🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (3 passed)
✨ Finishing Touches📝 Generate docstrings
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (5)
src/main/ssh/ssh-relay-deploy-helpers.test.ts (1)
277-311: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winCover the remaining redaction branches.
These tests cover non-zero exits and timeouts, but not
conn.exec(...)startup failures or channelerrorevents. Add focused cases for both and assert that the marker is absent from botherror.messageanderror.stack.src/main/ssh/ssh-relay-cross-version-isolation.test.ts (1)
65-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low valueConsider extracting the emitter-backed SFTP fake.
This mock is now duplicated near-verbatim in
src/main/ssh/ssh-relay-native-deps-install.test.ts(lines 94-114) and partially insrc/main/ssh/ssh-relay-sftp-namespace-install.test.ts(lines 160-189). A single fixture module (e.g.sftp-session-fake.ts) would keep realpath/lstat semantics from drifting as namespace resolution evolves.src/main/ssh/sftp-namespace-resolution.ts (1)
68-76: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winImport
RELAY_INSTALL_LOCK_NAMEinstead of hardcoding'.install-lock'.The producer (
ssh-relay-install-namespace.ts) builds this segment fromRELAY_INSTALL_LOCK_NAME; a rename there would make every mapping fail this assertion. Importing the constant from./ssh-relay-install-lockadds no cycle.♻️ Proposed change
- probeSegments[lockSegmentIndex] !== '.install-lock' || + probeSegments[lockSegmentIndex] !== RELAY_INSTALL_LOCK_NAME ||src/main/ssh/sftp-upload.ts (1)
136-161: 🩺 Stability & Availability | 🔵 Trivial | 💤 Low valueDestroy the write stream when settling on error, as
uploadBufferdoes.On a session/stream error the stream is left open here;
uploadBuffer(Line 116) destroys it. Aligning avoids a dangling handle when the SFTP session outlives the failed write.♻️ Proposed change
const onError = (err: Error): void => { if (settled) { return } settled = true cleanup() + ws.destroy() reject(err) }src/main/ssh/ssh-relay-install-transfers.ts (1)
72-101: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winDuplicated SFTP session lifecycle block.
This swallow-late-error / end-once / race-with-abort sequence is byte-for-byte the same as the blocks in
SshConnection.uploadDirectoryandSshConnection.writeFile. Worth extracting one helper so the teardown contract can only be changed in one place.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 693cbfa6-13f1-403d-9c78-715fdfdeb76e
📒 Files selected for processing (19)
src/main/ssh/sftp-namespace-resolution.test.tssrc/main/ssh/sftp-namespace-resolution.tssrc/main/ssh/sftp-upload.tssrc/main/ssh/ssh-connection-sftp-namespace.test.tssrc/main/ssh/ssh-connection-sftp-wire.test.tssrc/main/ssh/ssh-connection.tssrc/main/ssh/ssh-relay-cross-version-isolation.test.tssrc/main/ssh/ssh-relay-deploy-helpers.test.tssrc/main/ssh/ssh-relay-deploy.test.tssrc/main/ssh/ssh-relay-deploy.tssrc/main/ssh/ssh-relay-exec-command.tssrc/main/ssh/ssh-relay-gc-retry.test.tssrc/main/ssh/ssh-relay-install-marker.tssrc/main/ssh/ssh-relay-install-namespace.test.tssrc/main/ssh/ssh-relay-install-namespace.tssrc/main/ssh/ssh-relay-install-transfers.tssrc/main/ssh/ssh-relay-native-deps-install.test.tssrc/main/ssh/ssh-relay-sftp-namespace-install.test.tssrc/main/ssh/ssh-relay-versioned-install.ts
Strengthen path validation to catch traversal and empty segments in absolute POSIX paths, preventing security issues. Improve split-namespace handling with comprehensive wire tests for uploads and file writes. Ensure system SSH connections bypass namespace mapping entirely rather than attempting incorrect retargeting.
* Fix ssh-relay install on hosts with split shell/SFTP namespaces On Synology DSM and similar hosts, the SSH shell and SFTP subsystem expose different absolute paths for the same directory (e.g., /var/services/homes/alice vs /homes/alice). The relay installer silently picked the wrong path and failed discovery. This fix implements SFTP namespace detection: each install creates an unguessable ownership marker and probes both namespaces to detect divergence. When paths differ, SFTP writes redirect to the candidate namespace while shell commands keep the canonical path. Markers are random tokens redacted from logs. * Fix ssh-relay install on hosts with split shell/SFTP namespaces Strengthen path validation to catch traversal and empty segments in absolute POSIX paths, preventing security issues. Improve split-namespace handling with comprehensive wire tests for uploads and file writes. Ensure system SSH connections bypass namespace mapping entirely rather than attempting incorrect retargeting.
Fixes #10619
Summary
.install-lockto prove redirected SFTP paths belong to the current install, including repair flows for missing native dependencies.Testing