Repository navigation
Conversation
This adds SOCKS5 proxy functionality to paramiko as requested and discussed in paramiko#955. The functionality is nearly identical feature-wise to the one in OpenSSH, with the notable exception that it only support SOCKS5 and not SOCKS4. The reasoning behind it being that SOCKS4 was already superseded by SOCKS5 25 (!) years ago and that SOCKS4 doesn't even support tunneling requests to hosts using IPv6. Common implementation details with OpenSSH include: - supports starting multiple SOCKS5 servers bound to different local addresses for a single SSH connection - exposes the SOCKS5 servers as local IPv4 or IPv6 stream sockets - only supports a subset of SOCKS5, in particular tunneling of UDP-traffic, authentication and incoming connections aren't supported - supports tunneling connections to IPv4 and IPv6 addresses, as well as connections to host names, by resolving them on the SOCKS server side - 1:1 mapping between SOCKS5 requests and direct-tcpip channels The implementation works with all Python versions supported by paramiko. It has so far only been tested with Linux, but should work on other operating systems as well. The implementation has been used productively for several weeks so far, using `requests` with its SOCKS5 proxy functionality as SOCKS5 client, and works without any problems.
|
FWIW my team has been using this branch (or the wip branch before this one) in our development code for a couple months with zero issues. We use it to proxy requests from K8s pods through a server with a static IP to hit an API with IP whitelist requirements. The tunnel is often held open for between 2 and 24+ hours without issue. |
|
Is there any expected timeline for this feature to be released? |
|
The branch also works flawlessly for me. |
|
@SSgtSpoon While the feature is slotted for the next feature release, per its milestone, unfortunately, there's no specific release timetable -- @bitprophet is also maintaining fabric and invoke, and the cadence depends on the time he has available and mutual prioritization among the three projects. |
Totally understand. Thank you for the update! |
|
Is it possible to use this within a |
Sure, that's already possible with the code implemented in this PR. If you already use a context manager for your from paramiko.client import SSHClient
with SSHClient() as ssh_client:
ssh_client.connect(…)
proxy = ssh_client.open_socks_proxy(…)
do_something()If you prefer not to use a context manager for your from paramiko.client import SSHClient
from paramiko.socks_proxy import SOCKSProxy
ssh_client = SSHClient()
with SOCKSProxy(ssh_client.get_transport(), …) as proxy:
do_something() |
|
Oh nice! |
|
@dhm116 I believe this feature got passed over in the recent releases due to multiple time- and/or security-critical fixes/features that emerged in the interim. It's flagged for inclusion soon; unfortunately there's no specific timeline to offer. Please bear in mind that @bitprophet only has a few hours per week to dedicate to OSS, and has to spread that time across all three of paramiko, fabric and invoke. As a result, the project can only move so quickly. |
|
hmm, still not merged to release yet. |
Since implementing this functionality, we've used the code from this branch without any issues in a production setup. |
|
thanks @Dunedan, I have already tried this branch today and working nicely for my sample case. I don't understand what happened Edit: |
|
Could you please add support for using a username and password with the socks proxy? |
|
I am just curious what if this feature is implemented with asyncIO, is it possible? and is it will have a good impact on performance and stability? |
I believe we should focus on getting this PR merged first. Additional features can always be considered afterwards.
Using asyncio would only make sense from my point of view if paramiko's core functionality would use it as well. There is an open discussion regarding that in #389. |
Agreed -- @Chaz6, this would be best added as a brand new issue, with a reference that it would follow implementation of the feature of this issue. |
|
@bitprophet Is there anything we can do to speed up review and merge of this PR? It's been a while since we opened it and we'd really like to get this feature shipped to all paramiko users. |
|
@Dunedan paramiko is currently on a feature freeze until bitprophet completes the drop of Python 2 and older 3.x, plus some other modernization, for the suite of projects he maintains. I don't think this or any other features are likely to be merged until after that. Please do check in periodically, though. It's good to know which fixes/features people still care about strongly. |
|
I apologize if this info is elsewhere but I'm unable to find info on the feature freeze status and/or timeline. Trying to understand what options are available for SOCKS proxy support. Hesitant to make a production environment dependent upon on out of tree branch for a variety of reasons. This PR is almost 2 years old. Is Paramiko still frozen? Is there a timeline to unfreeze? Is this PR likely to get merged? If there is blocking work on Paramiko itself, is there a way to contribute to that work? Appreciate everyone's time and effort and any info you can provide. Thanks |
|
@mechanyx No, I don't think the information is available elsewhere. The best thing to do at this time is to test out the new, experimental auth features in v3.2 (see red annotations in the 3.2 CHANGELOG section) to help get those shaken out and solidified. The paradigm of the new auth system is pretty strongly cross-coupled between paramiko and fabric, so I don't know if it's feasible for anyone to directly assist bitprophet with the architecture and code work itself. |
|
@Dunedan |
This adds SOCKS5 proxy functionality to paramiko as requested and
discussed in #955.
The functionality is nearly identical feature-wise to the one in
OpenSSH, with the notable exception that it only support SOCKS5 and not
SOCKS4. The reasoning behind it being that SOCKS4 was already
superseded by SOCKS5 25 (!) years ago and that SOCKS4 doesn't even
support tunneling requests to hosts using IPv6.
Common implementation details with OpenSSH include:
local addresses for a single SSH connection
UDP-traffic, authentication and incoming connections aren't supported
connections to host names, by resolving them on the SOCKS server side
The implementation works with all Python versions supported by paramiko.
It has so far only been tested with Linux, but should work on other
operating systems as well. The implementation has been used productively
for several weeks so far, using
requestswith its SOCKS5 proxyfunctionality as SOCKS5 client, and works without any problems.
If there are changes needed, before merging this PR, please just let me
know and I'd be happy to change it.