Skip to content

Fix SSH relay installs on split shell/SFTP namespaces - #10645

Merged
AmethystLiang merged 2 commits into
mainfrom
jinjing/sta-2618-bug-ssh-relay-installation-fails-on-synology-dsm-with-no
Jul 26, 2026
Merged

AmethystLiang merged 2 commits into
mainfrom
jinjing/sta-2618-bug-ssh-relay-installation-fails-on-synology-dsm-with-no

Conversation

@AmethystLiang

@AmethystLiang AmethystLiang commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #10619

Summary

  • Adds SFTP namespace discovery for relay install uploads so Synology-style hosts can keep shell commands on the canonical home path while SFTP writes target the session-visible path.
  • Creates per-install marker files under .install-lock to prove redirected SFTP paths belong to the current install, including repair flows for missing native dependencies.
  • Keeps Windows and system-SSH transfers unmapped, preserves abort/session-limit behavior, and redacts marker tokens from diagnostics.
  • Centralizes relay install transfer helpers and validates shared relay path segments to avoid shell/SFTP path drift.

Testing

  • Added unit coverage for namespace resolution, relay install namespace mapping, SFTP transfer integration, first-install/repair behavior, abort cleanup, and real ssh2 SFTP wire upload behavior.

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.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ab7db692-730c-40fe-8e7b-8aa67dce479e

📥 Commits

Reviewing files that changed from the base of the PR and between 46f2eb7 and 0b6954e.

📒 Files selected for processing (4)
  • src/main/ssh/sftp-namespace-resolution.test.ts
  • src/main/ssh/sftp-namespace-resolution.ts
  • src/main/ssh/ssh-connection-sftp-wire.test.ts
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts

📝 Walkthrough

Walkthrough

Adds 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)

Check name Status Explanation Resolution
Description check ⚠️ Warning Missing required template sections: Screenshots, detailed Testing checklist, AI Review Report, Security Audit, and Notes. Add all required headings and fill in the testing checklist, AI review report, security audit, notes, and screenshots or a no-visual-change note.
Docstring Coverage ⚠️ Warning Docstring coverage is 21.67% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: fixing SSH relay installs for split shell/SFTP namespaces.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (5)
src/main/ssh/ssh-relay-deploy-helpers.test.ts (1)

277-311: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover the remaining redaction branches.

These tests cover non-zero exits and timeouts, but not conn.exec(...) startup failures or channel error events. Add focused cases for both and assert that the marker is absent from both error.message and error.stack.

src/main/ssh/ssh-relay-cross-version-isolation.test.ts (1)

65-86: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider 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 in src/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 win

Import RELAY_INSTALL_LOCK_NAME instead of hardcoding '.install-lock'.

The producer (ssh-relay-install-namespace.ts) builds this segment from RELAY_INSTALL_LOCK_NAME; a rename there would make every mapping fail this assertion. Importing the constant from ./ssh-relay-install-lock adds 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 value

Destroy the write stream when settling on error, as uploadBuffer does.

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 win

Duplicated 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.uploadDirectory and SshConnection.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

📥 Commits

Reviewing files that changed from the base of the PR and between 2e64677 and 46f2eb7.

📒 Files selected for processing (19)
  • src/main/ssh/sftp-namespace-resolution.test.ts
  • src/main/ssh/sftp-namespace-resolution.ts
  • src/main/ssh/sftp-upload.ts
  • src/main/ssh/ssh-connection-sftp-namespace.test.ts
  • src/main/ssh/ssh-connection-sftp-wire.test.ts
  • src/main/ssh/ssh-connection.ts
  • src/main/ssh/ssh-relay-cross-version-isolation.test.ts
  • src/main/ssh/ssh-relay-deploy-helpers.test.ts
  • src/main/ssh/ssh-relay-deploy.test.ts
  • src/main/ssh/ssh-relay-deploy.ts
  • src/main/ssh/ssh-relay-exec-command.ts
  • src/main/ssh/ssh-relay-gc-retry.test.ts
  • src/main/ssh/ssh-relay-install-marker.ts
  • src/main/ssh/ssh-relay-install-namespace.test.ts
  • src/main/ssh/ssh-relay-install-namespace.ts
  • src/main/ssh/ssh-relay-install-transfers.ts
  • src/main/ssh/ssh-relay-native-deps-install.test.ts
  • src/main/ssh/ssh-relay-sftp-namespace-install.test.ts
  • src/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.
@AmethystLiang
AmethystLiang merged commit 9f81f97 into main Jul 26, 2026
1 check passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
* 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: SSH relay installation fails on Synology DSM with "No such file" during SFTP upload

1 participant