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

AZ CLI does not install SOCKS support by default #18930

Closed
grahamhayes opened this issue Jul 19, 2021 · 5 comments · Fixed by #18931
Closed

AZ CLI does not install SOCKS support by default #18930

grahamhayes opened this issue Jul 19, 2021 · 5 comments · Fixed by #18931
Assignees

Comments

@grahamhayes
Copy link
Contributor

This is autogenerated. Please review and update as needed.

Describe the bug

Command Name
az *

Errors:

│ Error: Error obtaining Authorization Token from the Azure CLI: Error parsing json result from the Azure CLI: Error waiting for the Azure CLI: exit status 1: ERROR: The command failed with an unexpected error. Here is the traceback:
│ ERROR: Missing dependencies for SOCKS support.
│ Traceback (most recent call last):
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/knack/cli.py", line 231, in invoke
│     cmd_result = self.invocation.execute(args)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 657, in execute
│     raise ex
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 720, in _run_jobs_serially
│     results.append(self._run_job(expanded_arg, cmd_copy))
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 691, in _run_job
│     result = cmd_copy(params)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/__init__.py", line 328, in __call__
│     return self.handler(*args, **kwargs)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/commands/command_operation.py", line 121, in handler
│     return op(**command_args)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/command_modules/profile/custom.py", line 77, in get_access_token
│     creds, subscription, tenant = profile.get_raw_token(subscription=subscription, resource=resource, tenant=tenant)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/_profile.py", line 698, in get_raw_token
│     creds = self._creds_cache.retrieve_token_for_user(username_or_sp_id,
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/azure/cli/core/_profile.py", line 1104, in retrieve_token_for_user
│     token_entry = context.acquire_token(resource, username, _CLIENT_ID)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 145, in acquire_token
│     return self._acquire_token(token_func)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 128, in _acquire_token
│     return token_func(self)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/authentication_context.py", line 143, in token_func
│     return token_request.get_token_from_cache_with_refresh(user_id)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 349, in get_token_from_cache_with_refresh
│     return self._find_token_from_cache()
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 127, in _find_token_from_cache
│     return self._cache_driver.find(cache_query)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 198, in find
│     return self._refresh_entry_if_necessary(entry,
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 177, in _refresh_entry_if_necessary
│     return self._refresh_expired_entry(entry)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/cache_driver.py", line 153, in _refresh_expired_entry
│     token_response = self._refresh_function(entry, None)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 137, in _get_token_with_token_response
│     return self._get_token_with_refresh_token(refresh_token, resource, None)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 341, in _get_token_with_refresh_token
│     return self._oauth_get_token(oauth_parameters)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/token_request.py", line 112, in _oauth_get_token
│     return client.get_token(oauth_parameters)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/adal/oauth2_client.py", line 263, in get_token
│     resp = requests.post(token_url.geturl(),
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/api.py", line 119, in post
│     return request('post', url, data=data, json=json, **kwargs)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/api.py", line 61, in request
│     return session.request(method=method, url=url, **kwargs)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/sessions.py", line 542, in request
│     resp = self.send(prep, **send_kwargs)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/sessions.py", line 655, in send
│     r = adapter.send(request, **kwargs)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/adapters.py", line 412, in send
│     conn = self.get_connection(request.url, proxies)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/adapters.py", line 309, in get_connection
│     proxy_manager = self.proxy_manager_for(proxy)
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/adapters.py", line 182, in proxy_manager_for
│     manager = self.proxy_manager[proxy] = SOCKSProxyManager(
│   File "/usr/local/Cellar/azure-cli/2.26.1/libexec/lib/python3.8/site-packages/requests/adapters.py", line 47, in SOCKSProxyManager
│     raise InvalidSchema("Missing dependencies for SOCKS support.")
│ requests.exceptions.InvalidSchema: Missing dependencies for SOCKS support.

To Reproduce:

Run any Azure CLI command with ALL_PROXY set to a SOCKS5 proxy

  • Put any pre-requisite steps here...
  • export ALL_PROXY=socks5h://<host>:<port>
  • az login

Expected Behavior

Command should complete as expected

Environment Summary

macOS-10.15.7-x86_64-i386-64bit
Python 3.8.11
Installer: HOMEBREW

azure-cli 2.26.1

Extensions:
aks-preview 0.5.14
azure-devops 0.18.0
resource-graph 2.0.0
custom-providers 0.2.0
ssh 0.1.5
interactive 0.4.4
costmanagement 0.1.1

Additional Context

@ghost ghost added the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jul 19, 2021
@ghost ghost removed the needs-triage This is a new issue that needs to be triaged to the appropriate team. label Jul 19, 2021
@yonzhan yonzhan added this to the Jul 2021 (2021-08-03) milestone Jul 19, 2021
@yonzhan
Copy link
Collaborator

yonzhan commented Jul 19, 2021

@jiasli for awareness

@grahamhayes
Copy link
Contributor Author

Adding requests[socks] to the requirements should do the trick (tested on Mac via pip3 install requests[socks] --prefix /usr/local/Cellar/azure-cli/2.26.1/ --ignore-installed )

@jiasli
Copy link
Member

jiasli commented Jul 20, 2021

@grahamhayes, Azure CLI doesn't install requests[socks] by default:

'requests~=2.25.1',

as it will introduce additional dependencies for users who don't use SOCKS5 proxy.

And yes, you may install requests[socks] on-demand to Azure CLI's installation folder:

https://docs.python-requests.org/en/master/user/advanced/#socks

python -m pip install requests[socks]

@jiasli jiasli closed this as completed Jul 20, 2021
@grahamhayes
Copy link
Contributor Author

@jiasli - yeah, that is true, but with the default installation methods used by the CLI avoid using the system python site-packages (brew on OSX, an apt package that ships an entirely new python binary on ubuntu for example), the installation of the extra package is difficult

e.g. - sudo /opt/az/bin/python3 /opt/az/bin/pip3 install requests[socks]==2.25.1 --target=/opt/az/lib/python3.6/site-packages/ on ubuntu and pip3 install requests[socks] --prefix /usr/local/Cellar/azure-cli/2.26.1/ --ignore-installed OSX.

This also means each time the az cli is updated, you have to re install.

For users behind a SOCKS proxy (e.g. high security environments, managed enterprise environments) - access to pypi is also a problem.

With the advent of private link services, SOCKS proxies via SSH are a very useful tool for interacting with services without having to set up DNS forwarding, VPNs / Express Routes and VNet peerings.

This adds a quite small dependancy (especially as we ship copies of everything including an interpreter in some cases).

@jiasli
Copy link
Member

jiasli commented Jul 20, 2021

Thanks @grahamhayes for the detailed explanation. Let's work on the PR #18931 instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants