rust-lang / rust-lang/ssh2-rs

read() blocks after calling request_auth_agent_forwarding()

Open
#200 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Rust
Stars
566
Forks
163
Avg merge
4h 51m
Merged PRs (30d)
2

Description

Hello,

I'm new to both rust and ssh2-rs, so excuse me if I'm just doing something stupid.

Here's simplest case that I can't get working:

use std::net::TcpStream;
use ssh2::Session;
use std::io::Read;

fn main() {
    let remote_user = "john";
    let remote_addr = "tester.example.com:22";
    let remote_cmd = "echo $SSH_AUTH_SOCK; ssh-add -l";

    let stream = TcpStream::connect(&remote_addr).unwrap();

    let mut sess = Session::new().unwrap();
    sess.set_tcp_stream(stream);
    sess.handshake().unwrap();
    sess.userauth_agent(remote_user).unwrap();

    let mut channel = sess.channel_session().unwrap();
    channel.handle_extended_data(ssh2::ExtendedData::Merge).unwrap();
    // channel.request_auth_agent_forwarding().unwrap();

    channel.exec(remote_cmd).unwrap();

    let mut out = String::new();
    channel.read_to_string(&mut out).unwrap();

    channel.close().unwrap();
    channel.wait_close().unwrap();

    let _exit_status = channel.exit_status().unwrap();

    println!("{}", out);
}

It works as expected if there's no request_auth_agent_forwarding():

Could not open a connection to your authentication agent.

But if I start agent forwarding it just hangs there. If i remove the ssh-add part and leave only the echo I see the SSH_AUTH_SCOKET is set up ok.

I think the problem is that ssh-agent connection coming back from server to client somehow messes with my read_to_string(). I guess the local agent is supposed to write() back to server at this moment and that's why my read would block.

Any ideas how to go about this?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Rust reproducer in the issue, especially request_auth_agent_forwarding(), channel.exec(), and channel.read_to_string(). Trace how agent-forwarding traffic is serviced while reading command output, then compare behavior with and without ssh-add. Done means the blocking behavior is explained and a targeted fix or documented limitation is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.