Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SOCKS5 proxy support for uri module #67715

Open
wants to merge 3 commits into
base: devel
Choose a base branch
from

Conversation

kr3ator
Copy link
Contributor

@kr3ator kr3ator commented Feb 24, 2020

SUMMARY

Because SOCKS proxies are not currently supported by the urllib on which Ansible is dependent, this patch provides a simple workaround to enable SOCKS5 support for the uri module.
For the same reason there is no option to give that support more generally - through handler to the urllib's opener.

Fixes #44338

ISSUE TYPE
  • Feature Pull Request
COMPONENT NAME

uri

ADDITIONAL INFORMATION
Patch introduces a new module argument which is the location of a SOCKS5 proxy in the format of ip_address:port_number.

@ansibot ansibot added affects_2.10 core_review feature module needs_triage net_tools support:community support:core labels Feb 24, 2020
@ansibot
Copy link
Contributor

@ansibot ansibot commented Feb 24, 2020

The test ansible-test sanity --test validate-modules [explain] failed with 1 error:

lib/ansible/modules/net_tools/basics/uri.py:0:0: option-incorrect-version-added: version_added for new option (socks5_proxy) should be '2.10'. Currently StrictVersion ('0.0')

click here for bot help

@ansibot ansibot added ci_verified needs_revision and removed core_review labels Feb 24, 2020
@ansibot ansibot added core_review and removed ci_verified needs_revision labels Feb 25, 2020
if socks5_proxy:
host, port = socks5_proxy.split(':')
socks.set_default_proxy(socks.SOCKS5, host, port=int(port))
socket.socket = socks.socksocket
Copy link
Member

@sivel sivel Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't believe this should be a function of the uri module, but probably implemented in ansible.module_utils.urls instead. However, with that being said, we wouldn't be able to use this specific line, as it could cause other issues, in that this would become a global change, and not specific to just a single request.

As such, we'd probably want to make use of sockshandler instead.

Copy link
Contributor Author

@kr3ator kr3ator Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. I also wanted to do that in ansible.module_utils.urls with use of sockshandler (as mentioned earlier) but that is not possible because urllib which ansible.module_utils.urls uses doesn't support SOCKS handlers.

With that being said, until urllib supports SOCKS it is actually beneficial that this default socket redirect is scoped to a single request only.

Copy link
Member

@sivel sivel Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

urls.py does not use urllib. It uses urllib2 on py2, and urllib.request on py3.

Copy link
Contributor Author

@kr3ator kr3ator Feb 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used urllib as a shortcut :) As far as I checked this doesn't change anything, or am I wrong?

@samdoran samdoran added P3 and removed needs_triage labels Mar 3, 2020
Copy link
Contributor

@jamescassell jamescassell left a comment

Should be a wider change, and honor the appropriate http_proxy environment variables.

@ansibot ansibot added the stale_ci label Mar 12, 2020
@ansibot ansibot added needs_revision and removed core_review labels Mar 28, 2020
@ansibot ansibot added the needs_rebase label May 15, 2020
@ansibot ansibot added pre_azp and removed stale_ci labels Dec 5, 2020
@ansibot ansibot removed the support:community label Mar 4, 2021
@iavael
Copy link

@iavael iavael commented Jun 18, 2021

This would be an interesting feature in conjunction with openssh-client's remote socks proxy via -R flag.
May there be expected any updates of this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 feature module needs_rebase needs_revision net_tools P3 pre_azp support:core
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants