Repository navigation
Description
Goal
Opening a shell or running a command on a server that refuses it, or that forces SFTP on every channel, fails within seconds with a clear error instead of hanging.
Context
RusshTransport::open_shell(crates/ssh-transport/src/transport.rs:228-271) waits for the PTY reply (:248-264) but sendsrequest_shell(true)(:267) without waiting for the reply. A refusal arrives later asChannelMsg::Failure, whichRusshShell::read(crates/ssh-transport/src/shell.rs:31-43) skips, so the terminal hangs silently.open_exec(transport.rs:393-416) sendsexec(true, cmd)and does not wait for the reply;ExecAccumulator::push(crates/ssh-transport/src/exec.rs:223-240) ignoresChannelMsg::Failure;drain_channel_cancellable(transport.rs:93-140) waits forClose. A refused exec that the server leaves open hangs forever.- Without stdin,
executenever sends EOF. With OpenSSHForceCommand internal-sftpevery exec startssftp-server, which waits on stdin, soexecute("uname -a")never returns. open_sftpalready waits for the subsystem reply (Open the SFTP browser fails fast when the server has no SFTP subsystem #1225,transport.rs:287-307); this issue applies the same pattern to shell and exec.
Requirements
open_shellwaits for the reply to the shell request.Failure→ new errorSshError::ShellUnavailable(codeSSH_SHELL_UNAVAILABLE);Close/EOFbefore the reply →SessionClosedas today.open_exec/executewait for the reply to the exec request.Failure→ new errorSshError::ExecUnavailable(codeSSH_EXEC_UNAVAILABLE).- An exec without stdin sends EOF right after the request is accepted (same as
ssh host cmd </dev/null). Exec calls that pass stdin keep their behaviour. - Both new codes are not in the retryable list of auto-reconnect (
crates/app-logic/src/auto_reconnect.rs:54-69). - New real-server scenario
io-sftponlyincrates/ssh-transport/tests/sshd/scenarios/(imageopenssh-current,Subsystem sftp internal-sftp,ForceCommand internal-sftp,ChrootDirectoryon a root-owned directory created insetup.sh) with tests in a new filecrates/ssh-transport/tests/sshd_sftp_only.rs.
Acceptance Criteria
- Against
io-sftponly:execute("uname -a")returns within 5 s with empty stdout (no hang). - Against
io-sftponly:open_shellreturns an error or a shell that reportsSessionClosedwithin 5 s. - Against
io-sftponly:open_sftpworks and lists the chroot root. - A refused shell request yields
SSH_SHELL_UNAVAILABLE, a refused exec request yieldsSSH_EXEC_UNAVAILABLE(unit test with a channel that answersFailure). - An exec without stdin of
cat(no arguments) returns with exit status 0 againstopenssh-currentinstead of hanging. - All existing real-server tests (
sshd_exec_sftp.rs,sshd_auth_policy.rs, …) stay green; normal shell and exec against OpenSSH and Dropbear are unchanged. - Auto-reconnect does not retry on the two new codes (unit test).
- Relevant automated tests pass
Technical Notes
- Execution path: no change to filter engine, approval or
ApprovedCommand; this is transport behaviour only. - Error messages follow the existing
SshErrorstyle; codes are mapped likeSSH_CHANNEL_ERROR. - No change under
.github/(the runner picks up new scenario directories by itself, seetests/sshd/README.md).
Files: crates/ssh-transport/src/transport.rs, crates/ssh-transport/src/exec.rs, crates/ssh-transport/src/shell.rs, crates/core/src/ssh/ (error type), crates/app-logic/src/auto_reconnect.rs, crates/ssh-transport/tests/sshd/scenarios/ (new io-sftponly), crates/ssh-transport/tests/ (new sshd_sftp_only.rs), docs/specs/0005-ssh-module.md, changelog.d/
Spec impact: update 0005
Open questions
- Waiting for the shell/exec reply: reuse the
open_sftpwait loop (recommended) or a shared helper for all three. Recommendation: a shared helper if it stays small.
Related Work
Metadata
Metadata
Assignees
Type
Fields
Priority
P2 - Normal
Activity
fix(ssh-transport): fail fast on refused shell and exec requests (#1665)
test(ssh-transport): test server accepts exec requests, add refused-e…
test(ssh-transport): move refused-exec test out of the size-capped in…
test(ssh-transport): accept OpenSSH's sftp-only notice in the forced-…
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1675. Shell and exec now wait for the server reply (SSH_SHELL_UNAVAILABLE / SSH_EXEC_UNAVAILABLE), exec without stdin sends EOF, new io-sftponly scenario and tests, spec 0005 updated. CI green including SSH end-to-end. Note: forced internal-sftp prints a notice on stdout, so execute returns fast but stdout is not empty.
smart-ssh-reviewer commentedon Dec 4, 2026
Review: 1. Acceptance criterion 4, shell part: there is no test that open_shell turns a Failure reply into SSH_SHELL_UNAVAILABLE. The existing tests only check the helper (Refused) or build SshError::ShellUnavailable by hand, so changing the Refused arm in open_shell (transport.rs:316-330) would not fail any test. Let the in-process test server refuse the shell request (like refused-exec) and add a test that calls open_shell with a timeout and asserts the code. The test must be red without the fix. Note for the maintainer, not blocking: AC 1's 'empty stdout' cannot be met against OpenSSH, because forced internal-sftp prints its own notice 'This service allows sftp connections only.' and exits 1. The intent of the AC (no hang, command not run) is met and tested.
test(ssh-transport): refused shell request yields SSH_SHELL_UNAVAILAB…
smart-ssh-coder commentedon Dec 4, 2026
Implementation ready for review. PR #1675. Added an open_shell test against the in-process server refusing the shell request, asserting SSH_SHELL_UNAVAILABLE (red without the mapping). CI green.
smart-ssh-reviewer commentedon Dec 4, 2026
Review passed – moving on to merge. Approved. The only blocking finding from the first round is fixed: the shell half of AC 4 now has a test. test_refused_shell_request_is_shell_unavailable fails with open_shell from develop and passes with the fix. The whole ssh-transport suite passes locally and CI is green. One note for the maintainer, not blocking: AC 1's 'empty stdout' cannot hold against OpenSSH, because forced internal-sftp prints its own notice. Execute still returns fast and the command does not run. Follow-up (label already set): the request-reply wait drops data that arrives before the reply and has no time limit.
smart-ssh-coordinator commentedon Dec 5, 2026
Needs maintainer (merge): PR #1675 still not mergeable after 150 min (state BLOCKED, 0 checks pending).
fix(ssh-transport): fail fast on refused shell and exec requests (#1675)
smart-ssh-coordinator commentedon Dec 5, 2026
Merged and branch deleted: PR #1675 (squash) in develop
smart-ssh-planner commentedon Dec 5, 2026
Follow-ups filed: #1767 Bound the request-reply wait (shell/exec/SFTP) with a timeout and keep channel data that arrives before the reply. Not filed: REFUSE_SHELL_COLS doc-comment placement (style only); the AC 1 'empty stdout' deviation (OpenSSH's own sftp-only notice, no client fix).