Replies: 5 comments
-
|
In your AsyncSSH server on host 1, have you enabled port forwarding? To do so, you'd need to have your own subclass of SSHServer which implements the If you just need to do standard port forwarding to the host/port requested by the SSH client, you can have this method always return You can also return a custom session class or callable if you want to actually get involved in viewing and/or modifying the data being forwarded, but you probably don't need that here. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks so much for responding so quickly!
Yes, we've done this.
Yes, I think we need to, so we've written this. Here's the If I simply return If I don't return True and go through the rest of the code there in _open_backend_stream() I should be returning a tuple of an SSHTCPChannel and SSHTCPSession. In that case I get a similar traceback saying So I'm obviously not returning the right thing, and I'm confused. To add a little extra detail, to test I'm ssh'ing with Thanks again! |
Beta Was this translation helpful? Give feedback.
-
|
Does the example at https://asyncssh.readthedocs.io/en/latest/#id16 work for you? It shows an example of implementing You can also try the example at https://asyncssh.readthedocs.io/en/latest/#forwarded-tcp-connections to see if returning a custom TCPSession works. It should accept a TCPChannel and TCPSession tuple as well, but there's very little reason to create your own custom TCPChannels. It's mainly useful if you want to read & write Unicode strings instead of bytes or set different window or max packet sizes. If you do decide you need to be involved in reading/writing the data, you can also return a callable that takes reader & writer arguments. That's typically simpler than building your own custom TCPSession with things like |
Beta Was this translation helpful? Give feedback.
-
|
FYI here's the code which handles the value you return from if not result:
raise ChannelOpenError(OPEN_CONNECT_FAILED, 'Connection refused')
if result is True:
result = cast(SSHTCPSession[bytes],
self.forward_connection(dest_host, dest_port))
elif isinstance(result, SSHClientConnection):
result = cast(Awaitable[SSHTCPSession[bytes]],
self.forward_tunneled_connection(
result, dest_host, dest_port))
if isinstance(result, tuple):
chan, result = result
else:
chan = self.create_tcp_channel()
session: SSHTCPSession[bytes]
if callable(result):
session = SSHTCPStreamSession[bytes](result)
else:
session = cast(SSHTCPSession[bytes], result)As you can see, it converts |
Beta Was this translation helpful? Give feedback.
-
|
Is async def forward_tunneled_connection(
self, conn: SSHClientConnection,
dest_host: str, dest_port: int) -> SSHForwarder:
"""Forward a tunneled TCP connection between SSH connections"""
_, peer = await conn.create_connection(
cast(SSHTCPSessionFactory[bytes], SSHForwarder),
dest_host, dest_port)
self.logger.info(' Forwarding TCP connection to %s via SSH tunnel',
(dest_host, dest_port))
return SSHForwarder(cast(SSHForwarder, peer)) |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Greetings,
I'm building an SSH proxy server that dynamically looks up its target and I have it almost completely working.
I can ssh to host 1 with a specially-formed username, the server on host 1 dynamically looks up what host the container is running on, connects to the right host (host 2 in the diagram). The Asyncssh script picks a random port and spawns a socat pointing from the random port to port 22 on the non-routable IP where the container is, then directs the incoming connection from host 1 to use that port. Thus the client connects transparently to the ssh daemon in the container.
Where I'm getting tripped up is the ssh port-forwarding functionality. Without any additional logic I can do
ssh special-username@host1 -L 9000:localhost:9000butnc localhost 9000on the client seems to connect me to host2's ssh daemon (or maybe the container's?). So clearly I need to override something somewhere but I'm not sure what. Any suggestions?Beta Was this translation helpful? Give feedback.
All reactions