sshnet / sshnet/SSH.NET

Using bastion jump host proxy gateway times out

Offen
#852 11 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
C#
Sterne
4.4k
Forks
993
Ø Merge
9 T. 21 Std.
Gemergte PRs (30 T.)
1

Beschreibung

I have verified that the following two lines work on fine on both my WSL2 (Linux on Windows) as well as Windows 10 (finally, Windows comes with ssh):

ssh -J user@1.2.3.4 user@5.6.7.8 -L 127.0.0.1:60006:9.10.11.12:1521 -fnNT

sqlplus myRdsUser/myRdsPass@127.0.0.1:60006/abc.defgh

I have also verified that,
if I start the ssh connection using

ssh -J user@1.2.3.4 user@5.6.7.8 -L 127.0.0.1:60006:9.10.11.12:1521 -fnNT

then the following code successfully connects and I'm able to query my database.

new OracleConnection($"Data Source={_hostConnectionProvider.GetHost()/*9.10.11.12*/}:{_hostConnectionProvider.GetPort()/*1521*/}/{config.ServiceName/*abc.defgh*/};User Id={config.Username/*myRdsUser*/};Password={config.Password/*myRdsPassword*/}");

But the equivalent .NET code times out (yes, I did kill the command line SSH connection first). The contents of my .ssh/id_rsa file is the same as what I'm passing into config.PrivateKey and I know it worked because I am able to connect to bastion/jump host/proxy/gateway directly using the private key as configured.

_logger.LogDebug("Getting config");
var config = options.Value;

_logger.LogDebug("Converting private key into memory stream");
var privateKeyStream = new MemoryStream(Encoding.UTF8.GetBytes(config.PrivateKey));
var privateKeyFile = new PrivateKeyFile(privateKeyStream);

var sshConnectionInfo = new ConnectionInfo(
    config.DestinationHost, // 5.6.7.8
    22, 
    config.DestinationHostUsername, // user
    ProxyTypes.None, 
    config.GatewayHost, // 1.2.3.4
    22, 
    config.GatewayHostUsername, // user
    null, 
    new PrivateKeyAuthenticationMethod(config.DestinationHostUsername, privateKeyFile));
_sshClient = new SshClient(sshConnectionInfo);
_sshClient.Connect(); // This line throws after 30 seconds: System.Net.Sockets.SocketException (10060): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

_sshForwardedPort = new ForwardedPortLocal("localhost", config.ProxyDestinationHost /*9.10.11.12*/, config.ProxyDestinationPort /*1521*/);
_sshClient.AddForwardedPort(_sshForwardedPort);
_sshForwardedPort.Start();

return new OracleConnection($"Data Source={_hostConnectionProvider.GetHost()/*9.10.11.12*/}:{_hostConnectionProvider.GetPort()/*1521*/}/{config.ServiceName/*abc.defgh*/};User Id={config.Username/*myRdsUser*/};Password={config.Password/*myRdsPassword*/}");

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Es wird keine Quelldatei oder kein Test genannt; beginne bei der ConnectionInfo-Konstruktion und dem SshClient.Connect-Aufruf und verfolge dann, wie das Gateway im Vergleich zum funktionierenden ssh -J-Befehl konfiguriert ist. Als abgeschlossen gilt die erfolgreiche Herstellung der äquivalenten Jump-Host-Verbindung und des weitergeleiteten Ports ohne Timeout, gefolgt von einer Oracle-Verbindung.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
csharp
Bereich
networking
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.