az extension add --name azure-devops failing with SSL error
az feedbackauto-generates most of the information requested below, as of CLI version 2.0.62
Describe the bug Unable to install az cli extensions
To Reproduce
az extension add --name azure-devops
Errors:
Unable to get extension index.
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
Expected behavior Able to install az cli extensions
Environment summary
Shell Type: zsh OS Version: macOS Catalina 10.15.7 Installer: HOMEBREW
$ az --version
azure-cli 2.22.1
core 2.22.1
telemetry 1.0.6
Extensions:
interactive 0.4.3
Python location '/usr/local/Cellar/azure-cli/2.22.1/libexec/bin/python'
Extensions directory '/Users/gl741q/.azure/cliextensions'
Python (Darwin) 3.8.9 (default, Apr 3 2021, 01:50:09)
[Clang 12.0.0 (clang-1200.0.32.29)]
Legal docs and information: aka.ms/AzureCliLegal
Additional context
I am working from behind my company's proxy. They are inserting their own self-signed cert to decrypt our traffic for inspection. I have a copy of this certificate on my computer
I have followed the instructions here: https://docs.microsoft.com/en-us/cli/azure/use-cli-effectively#work-behind-a-proxy
I have exported my company's internal certificate location on my laptop:REQUESTS_CA_BUNDLE=$HOME/certs/internal.pem
Other az commands work just fine like az login or az group list. So far I am only having issues with az extension add.
Seems like whatever is making the call to https://azcliextensionsync.blob.core.windows.net/index1/index.json isn't picking up the appropriate certificate bundle. Even when I go off of my corporate proxy I get the same SSLError
@jiasli for awareness
We have the same problem, please provide any update/steps how/if this can be fixed on our end!
@georgejdli
My company sort of fixed it for me (but I have found some workaround as well) - by skipping SSL verification on aka.m, so now it works for me without private cert. (but I had issues with installing stream-analytics package)
I think the problem you are facing is the fact that your company is bypassing some of the SSL verifications, but not all. It seems the installation of extentions is following process:
- Request to https://aka.ms
- Request redirected to: https://azcliextensionsync.blob.core.windows.net (to map name to extension URL)
- New request to https://azurecliprod.blob.core.windows.net to finally download the extension
For me the problem was everything under *.windows.net skipped SSL verification, but aka.ms didn't. The problem is if you skip SSL verification, but still apply self-signed one, it will fail (at least this is my understanding).
You can try direct download call to download the extension by doing following steps:
- Navigate to: https://azcliextensionsync.blob.core.windows.net/index1/index.json this should give you the URL to the extension you want to install.
- (At the time of the writing I guess it is: https://github.com/Azure/azure-devops-cli-extension/releases/download/20190805.1/azure_devops-0.12.0-py2.py3-none-any.whl
- Invoke command: az extension add --source https://github.com/Azure/azure-devops-cli-extension/releases/download/20190805.1/azure_devops-0.12.0-py2.py3-none-any.whl
That should hopefully work for you, if github.com is exempt from SSL verification, you shouldn't provide the self-signed certificate path under ENV variable as it is actually going to break it.
@akomisarek's comment is correct. Thanks!
It's very likely that your company skipped SSL/TLS verification for some domains, like .windows.net.
An easier solution would be to append standard Python root CAs to your pem file:
REQUESTS_CA_BUNDLE=$HOME/certs/internal.pem
You may get it from https://github.com/certifi/python-certifi/blob/master/certifi/cacert.pem
Then Azure CLI will use both your internal certificate and Python's public certificate. This is mentioned at https://docs.microsoft.com/en-us/cli/azure/use-cli-effectively#work-behind-a-proxy
Append the proxy server's certificate to this file or copy the contents to another certificate file, then set
REQUESTS_CA_BUNDLEto it.
You may test the connectivity to a domain using
python -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net/').status_code)"
Sorry for the late response but appending the standard root python certs on top of my company's internal root certs worked for me
@akomisarek's comment is correct. Thanks!
It's very likely that your company skipped SSL/TLS verification for some domains, like
.windows.net.An easier solution would be to append standard Python root CAs to your
pemfile:REQUESTS_CA_BUNDLE=$HOME/certs/internal.pemYou may get it from https://github.com/certifi/python-certifi/blob/master/certifi/cacert.pem
Then Azure CLI will use both your internal certificate and Python's public certificate. This is mentioned at https://docs.microsoft.com/en-us/cli/azure/use-cli-effectively#work-behind-a-proxy
Append the proxy server's certificate to this file or copy the contents to another certificate file, then set
REQUESTS_CA_BUNDLEto it.You may test the connectivity to a domain using
python -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net/').status_code)"
@georgejdli
My company sort of fixed it for me (but I have found some workaround as well) - by skipping SSL verification on aka.m, so now it works for me without private cert. (but I had issues with installing stream-analytics package)
I think the problem you are facing is the fact that your company is bypassing some of the SSL verifications, but not all. It seems the installation of extentions is following process:
- Request to https://aka.ms
- Request redirected to: https://azcliextensionsync.blob.core.windows.net (to map name to extension URL)
- New request to https://azurecliprod.blob.core.windows.net to finally download the extension
For me the problem was everything under *.windows.net skipped SSL verification, but aka.ms didn't. The problem is if you skip SSL verification, but still apply self-signed one, it will fail (at least this is my understanding).
You can try direct download call to download the extension by doing following steps:
- Navigate to: https://azcliextensionsync.blob.core.windows.net/index1/index.json this should give you the URL to the extension you want to install.
- (At the time of the writing I guess it is: https://github.com/Azure/azure-devops-cli-extension/releases/download/20190805.1/azure_devops-0.12.0-py2.py3-none-any.whl
- Invoke command: az extension add --source https://github.com/Azure/azure-devops-cli-extension/releases/download/20190805.1/azure_devops-0.12.0-py2.py3-none-any.whl
That should hopefully work for you, if github.com is exempt from SSL verification, you shouldn't provide the self-signed certificate path under ENV variable as it is actually going to break it.
Worked for me too, Corp proxy error.
C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9> az extension add --name azure-devops
Unable to get extension index.
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1125)')))
Your process of going to the index site and grabbing the GIT URL fixed it,
az extension add --source https://github.com/Azure/azure-devops-cli-extension/releases/download/20190805.1/azure_devops-0.12.0-py2.py3-none-any.whl
@eschrader, Installing from whl is the last resort for solving issues like this, as it doesn't work with az upgrade which upgrades all your extensions automatically. You will also have to repeat this process for all extensions you need to install.
We still recommend adding your corp proxy root CA to Azure CLI's pem file to avoid further obstruction.
I think this should be re-opened. I am installing the azcli with the official packages for ubuntu:
curl -sL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor | tee /etc/apt/trusted.gpg.d/microsoft.gpg > /dev/null \
&& export AZ_REPO=$(lsb_release -cs) && echo "deb [arch=amd64] https://packages.microsoft.com/repos/azure-cli/ $AZ_REPO main" | \
tee /etc/apt/sources.list.d/azure-cli.list \
&& apt-get update && apt-get install -y azure-cli
I faced the same problem and the only way is to add the extension was with the full URL
export REQUESTS_CA_BUNDLE=~/my_custom_ca.pem
vscode ➜ /tmp $ az extension add --name azure-devopsUnable to get extension index.
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
vscode ➜ /tmp $ az extension add --source https://github.com/Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whlAre you sure you want to install this extension? (y/n): y
to notice that without the REQUESTS_CA_BUNDLE the download with the full URL also fail:
vscode ➜ /tmp $ az extension remove --name azure-devops
vscode ➜ /tmp $ unset REQUESTS_CA_BUNDLE
vscode ➜ /tmp $ az extension add --source https://github.com/Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whl
Are you sure you want to install this extension? (y/n): y
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='github.com', port=443): Max retries exceeded with url: /Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whl (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
I created then a new cert file with /opt/az/lib/python3.6/site-packages/certifi/cacert.pem and my custom cert file:
cat /opt/az/lib/python3.6/site-packages/certifi/cacert.pem /home/vscode/ma_custom_ca.pem.orig > /home/vscode/my_custom_ca.pem
export REQUESTS_CA_BUNDLE=~/my_custom_ca.pem
az extension add --name azure-devops
The above procedure worked, but I do not understand why. The certs are imported in the system are different from waht provided in /opt/az/lib/python3.6/site-packages/certifi/cacert.pem
Further analysis. To me it looks like something with the azcliextensionsync.blob.core.windows.net SSL cert.
vscode ➜ /tmp $ az extension add --name azure-devops
Unable to get extension index.
Please ensure you have network connection. Error detail: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
vscode ➜ /tmp $ /opt/az/bin/python3 -c "import ssl; print(ssl.get_default_verify_paths())"
DefaultVerifyPaths(cafile=None, capath='/usr/lib/ssl/certs', openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/lib/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/lib/ssl/certs')
unset REQUESTS_CA_BUNDLE
vscode ➜ /tmp $ unset REQUESTS_CA_BUNDLE vscode ➜ /tmp $ /opt/az/bin/python3 -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net').status_code);" ; python3 -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net/index1/index.json').status_code)"; python3 -c "import requests; print(requests.get('https://github.com/Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whl').status_code)"
400
200
200
# But if I set the REQUESTS_CA_BUNDLE, the requests fail unless the the full URL https://github.com/Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whl
vscode ➜ /tmp $ export REQUESTS_CA_BUNDLE=~/my_custom_ca.pem
vscode ➜ /tmp $ /opt/az/bin/python3 -c "import ssl; print(ssl.get_default_verify_paths())"DefaultVerifyPaths(cafile=None, capath='/usr/lib/ssl/certs', openssl_cafile_env='SSL_CERT_FILE', openssl_cafile='/usr/lib/ssl/cert.pem', openssl_capath_env='SSL_CERT_DIR', openssl_capath='/usr/lib/ssl/certs')
vscode ➜ /tmp $ /opt/az/bin/python3 -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net').status_code);" ; python3 -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net/index1/index.json').status_code)"; python3 -c "import requests; print(requests.get('https://github.com/Azure/azure-devops-cli-extension/releases/download/20210805.1/azure_devops-0.20.0-py2.py3-none-any.whl').status_code)"
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 696, in urlopen
self._prepare_proxy(conn)
File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 964, in _prepare_proxy
conn.connect()
File "/opt/az/lib/python3.6/site-packages/urllib3/connection.py", line 421, in connect
tls_in_tls=tls_in_tls,
File "/opt/az/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 450, in ssl_wrap_socket
sock, context, tls_in_tls, server_hostname=server_hostname
File "/opt/az/lib/python3.6/site-packages/urllib3/util/ssl_.py", line 493, in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock, server_hostname=server_hostname)
File "/opt/az/lib/python3.6/ssl.py", line 407, in wrap_socket
_context=self, _session=session)
File "/opt/az/lib/python3.6/ssl.py", line 817, in __init__
self.do_handshake()
File "/opt/az/lib/python3.6/ssl.py", line 1077, in do_handshake
self._sslobj.do_handshake()
File "/opt/az/lib/python3.6/ssl.py", line 689, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/az/lib/python3.6/site-packages/requests/adapters.py", line 449, in send
timeout=timeout
File "/opt/az/lib/python3.6/site-packages/urllib3/connectionpool.py", line 756, in urlopen
method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
File "/opt/az/lib/python3.6/site-packages/urllib3/util/retry.py", line 574, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/opt/az/lib/python3.6/site-packages/requests/api.py", line 76, in get
return request('get', url, params=params, **kwargs)
File "/opt/az/lib/python3.6/site-packages/requests/api.py", line 61, in request
return session.request(method=method, url=url, **kwargs)
File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 542, in request
resp = self.send(prep, **send_kwargs)
File "/opt/az/lib/python3.6/site-packages/requests/sessions.py", line 655, in send
r = adapter.send(request, **kwargs)
File "/opt/az/lib/python3.6/site-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:852)'),))
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 485, in wrap_socket
cnx.do_handshake()
File "/home/vscode/.local/lib/python3.8/site-packages/OpenSSL/SSL.py", line 1894, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/home/vscode/.local/lib/python3.8/site-packages/OpenSSL/SSL.py", line 1632, in _raise_ssl_error
_raise_current_error()
File "/home/vscode/.local/lib/python3.8/site-packages/OpenSSL/_util.py", line 57, in exception_from_error_queue
raise exception_type(errors)
OpenSSL.SSL.Error: [('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')]
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 662, in urlopen
self._prepare_proxy(conn)
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 950, in _prepare_proxy
conn.connect()
File "/usr/lib/python3/dist-packages/urllib3/connection.py", line 366, in connect
self.sock = ssl_wrap_socket(
File "/usr/lib/python3/dist-packages/urllib3/util/ssl_.py", line 370, in ssl_wrap_socket
return context.wrap_socket(sock, server_hostname=server_hostname)
File "/usr/lib/python3/dist-packages/urllib3/contrib/pyopenssl.py", line 491, in wrap_socket
raise ssl.SSLError("bad handshake: %r" % e)
ssl.SSLError: ("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])",)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
resp = conn.urlopen(
File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 719, in urlopen
retries = retries.increment(
File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 436, in increment
raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/lib/python3/dist-packages/requests/api.py", line 75, in get
return request('get', url, params=params, **kwargs)
File "/usr/lib/python3/dist-packages/requests/api.py", line 60, in request
return session.request(method=method, url=url, **kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 533, in request
resp = self.send(prep, **send_kwargs)
File "/usr/lib/python3/dist-packages/requests/sessions.py", line 646, in send
r = adapter.send(request, **kwargs)
File "/usr/lib/python3/dist-packages/requests/adapters.py", line 514, in send
raise SSLError(e, request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='azcliextensionsync.blob.core.windows.net', port=443): Max retries exceeded with url: /index1/index.json (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')])")))
200
@zioalex, I don't really understand your point and question.
/opt/az/lib/python3.6/site-packages/certifi/cacert.pem is where the bundled python (/opt/az/bin/python3) of Azure CLI reads the root certs from. That's why you need to trust the content of it via REQUESTS_CA_BUNDLE.
No problem is observed with https://azcliextensionsync.blob.core.windows.net as it is simply an Azure Storage account.
/opt/az/bin/python3 -c "import requests; print(requests.get('https://azcliextensionsync.blob.core.windows.net').status_code);"
400
Azure CLI doesn't interact with the system python (/usr/bin/python3) in any way.
Hi @jiasli , I never talked about the system´s python3. I found inconsistent the response I get with the AZCLI's python version when querying the endpoints reported above.
Nevertheless setting the REQUESTS_CA_BUNDLE variable to the CA Bundle containing the original python certs plus my proxy's one, solved the issue.
An improvement would be to have the AZCLI's Python to read directly from the windows certificate store using the python-certifi-win32 library.
I resolved this problem by not using my (protected) company WiFi. Just connected to the guest network the time of the download. Maybe it helps
FWIW, I get this error running in a Windows VM in Azure. No corporate proxy. Win 2022 Datacenter. I'd have hoped that this wouldn't happen there as well?
I received the same error message when I had fiddler running!
@jgentil had a solution that worked for me: https://github.com/Azure/azure-cli/issues/20921#issuecomment-1190714888
Basically run "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -m pip install pip-system-certs.
Just a note on this.
I came across this when running az extension add --name aks-preview and the pip install pip-system-certs approach didn't work for me.
$env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1 was the only way to work around the error.
I had to allow https traffic to *.aka.ms and aka.ms as well as *.github.com and github.com. This allowed me to install the az cli extensions. Previously we only had *.aka.ms and *.github.com allowed but that didn't also allow aka.ms and github.com.
I also had to sadly disable SSL verification. Basically every other application I use has proper proxy configuration for corporate networks with proxies. Only AZ Extensions seems to have this problem. @jsntcy closing the ticket saying users need to request multiple wildcard proxy bypasses from their internal I.T. is hardly a proper solution.
@jgentil had a solution that worked for me: #20921 (comment)
Basically run
"C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -m pip install pip-system-certs.
This is the correct path to take. Thanks for the find, @jeffchiou!
Personally speaking, I find this to be a better version of the (PowerShell) command to use:
& "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\python.exe" -m pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pip-system-certs
Do note, that if using the newer 64-bit version of Azure CLI, the path will use Program Files instead of Program Files (x86).
None of the solutions listed here worked for me. But I was able to install the extension by locating its download URL in the public index at https://raw.githubusercontent.com/Azure/azure-cli-extensions/main/src/index.json and then running
az extension add --source <download-url>