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 This issue/PR affects Ansible v2.10 core_review In order to be merged, this PR must follow the core review workflow. feature This issue/PR relates to a feature request. module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. net_tools Net-tools category support:community This issue/PR relates to code supported by the Ansible community. support:core This issue/PR relates to code supported by the Ansible Engineering Team. labels Feb 24, 2020
@ansibot
Copy link
Contributor

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 Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Feb 24, 2020
@ansibot ansibot added core_review In order to be merged, this PR must follow the core review workflow. and removed ci_verified Changes made in this PR are causing tests to fail. needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. 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

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

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

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 Priority 3 - Approved, No Time Limitation and removed needs_triage Needs a first human triage before being processed. labels Mar 3, 2020
Copy link
Contributor

@jamescassell jamescassell left a comment

Choose a reason for hiding this comment

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

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

@ansibot ansibot added the stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. label Mar 12, 2020
@ansibot ansibot added needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. and removed core_review In order to be merged, this PR must follow the core review workflow. labels Mar 28, 2020
@ansibot ansibot added the needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html label May 15, 2020
@ansibot ansibot added pre_azp This PR was last tested before migration to Azure Pipelines. and removed stale_ci This PR has been tested by CI more than one week ago. Close and re-open this PR to get it retested. labels Dec 5, 2020
@ansibot ansibot removed the support:community This issue/PR relates to code supported by the Ansible community. label Mar 4, 2021
@iavael
Copy link

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?

@ansibot ansibot added needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html and removed needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html labels Oct 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects_2.10 This issue/PR affects Ansible v2.10 feature This issue/PR relates to a feature request. has_issue module This issue/PR relates to a module. needs_rebase https://docs.ansible.com/ansible/devel/dev_guide/developing_rebasing.html needs_revision This PR fails CI tests or a maintainer has requested a review/revision of the PR. net_tools Net-tools category P3 Priority 3 - Approved, No Time Limitation pre_azp This PR was last tested before migration to Azure Pipelines. support:core This issue/PR relates to code supported by the Ansible Engineering Team.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add SOCKS proxy support to uri module
6 participants