azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

SSL Issues When Using Powershell Behind Proxy

Open dkonyayev opened this issue 7 years ago • 8 comments

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug When running a command to tail log I get SSL errors from Python script.

To Reproduce Steps to reproduce the behavior.

I have tried to disable the SSL verfication as per some articles I found but it did not work set ADAL_PYTHON_SSL_NO_VERIFY=1 set AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1 az webapp log tail --name <app_service_resource> --resource-group <resource_group>

Error received: Connection verification disabled by environment variable AZURE_CLI_DISABLE_CONNECTION_VERIFICATION C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings Connection verification disabled by environment variable AZURE_CLI_DISABLE_CONNECTION_VERIFICATION C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings Connection verification disabled by environment variable AZURE_CLI_DISABLE_CONNECTION_VERIFICATION C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings Connection verification disabled by environment variable AZURE_CLI_DISABLE_CONNECTION_VERIFICATION C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\site-packages\urllib3\connectionpool.py:847: InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings Exception in thread Thread-1: Traceback (most recent call last): File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\contrib\pyopenssl.py", line 456, in wrap_socket File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qxmmnr17\pyOpenSSL\OpenSSL\SSL.py", line 1915, in do_handshake File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qxmmnr17\pyOpenSSL\OpenSSL\SSL.py", line 1647, in _raise_ssl_error File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qxmmnr17\pyOpenSSL\OpenSSL_util.py", line 54, in exception_from_error_queue 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 "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 600, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 343, in _make_request File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 839, in validate_conn File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connection.py", line 344, in connect File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\util\ssl.py", line 347, in ssl_wrap_socket File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\contrib\pyopenssl.py", line 462, in wrap_socket 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 "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\threading.py", line 916, in _bootstrap_inner self.run() File "C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\lib\threading.py", line 864, in run self._target(*self._args, **self._kwargs) File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-qxmmnr17\azure-cli\azure\cli\command_modules\appservice\custom.py", line 1810, in _get_log File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\request.py", line 68, in request File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\request.py", line 89, in request_encode_url File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\poolmanager.py", line 324, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 667, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 667, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 667, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\connectionpool.py", line 638, in urlopen File "C:\Users\VSSADM~1\AppData\Local\Temp\pip-install-4ppkskoa\urllib3\urllib3\util\retry.py", line 399, in increment urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='chb008e1dv.scm.ase01e1np.metlife.com', port=443): Max retries exceeded with url: /logstream (Caused by SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),))

Expected behavior A clear and concise description of what you expected to happen.

Start to tail the log.

Environment summary Install Method (e.g. pip, interactive script, apt-get, Docker, MSI, edge build) / CLI version (az --version) / OS version / Shell Type (e.g. bash, cmd.exe, Bash on Windows)

Powershell on Windows 10 Pro

Additional context Add any other context about the problem here.

dkonyayev avatar Nov 05 '19 16:11 dkonyayev

Is this command run in cmd instead of PowerShell? set shouldn't work in PowerShell because PowerShell's set is an alias to Set-Variable, which only changes the script's variables. See about_environment_variables.

Correct way is

$Env:AZURE_CLI_DISABLE_CONNECTION_VERIFICATION=1

However, this env var doesn't always work. For recommended way of working with proxy, please check https://github.com/Azure/azure-cli/blob/dev/doc/use_cli_effectively.md#working-behind-a-proxy

jiasli avatar Nov 06 '19 03:11 jiasli

I have a similar problem. I'm trying to do a POST request to a website with a valid SSL Certificate. When I run it I get:

Unverified HTTPS request is being made to host '*'. Adding certificate verification is strongly advised

When I add verify=true during create session I get a new error:

connection broken by 'SSLError(SSLError("bad handshake: Error([('SSL routines', 'tls_process_server_certificate', 'certificate verify failed')],)",),)'

I've downloaded the websites certificate, changed it to a PEM file and added it to my cacert.pem file. I've also created a pip.ini file in ${APPDATA}$/pip/ and added path=path leading to cacert.pem file

I've also added the certificate to the CA Store.

Nothing seems to be working to stop these errors. I don't want to just ignore them as I feel its a deeper issue. Note: I'm using Robot Framework

ellieCallcutART avatar Mar 27 '20 09:03 ellieCallcutART

add to S169

yonzhan avatar Mar 27 '20 10:03 yonzhan

Hi @ellieCallcutART, are you using Azure CLI? If so, could you share the command you used?

For Azure CLI to use the added root CA, please make sure the cacert.pem file you changed is correct by running

$ which az
/usr/bin/az

$ cat /usr/bin/az
#!/usr/bin/env bash
/opt/az/bin/python3 -Im azure.cli "$@"

$ cat /opt/az/lib/python3.6/site-packages/certifi/cacert.pem

jiasli avatar Mar 30 '20 05:03 jiasli

Hi @ellieCallcutART, are you using Azure CLI? If so, could you share the command you used?

For Azure CLI to use the added root CA, please make sure the cacert.pem file you changed is correct by running

$ which az
/usr/bin/az

$ cat /usr/bin/az
#!/usr/bin/env bash
/opt/az/bin/python3 -Im azure.cli "$@"

$ cat /opt/az/lib/python3.6/site-packages/certifi/cacert.pem

Hi @jiasli, I'm using Pycharm. I tried running the lines you sent but it doesn't recognise the syntax (I'm new to python, sorry). I tried it for a .py file and a .robot file.

ellieCallcutART avatar Mar 30 '20 08:03 ellieCallcutART

I would love to help but PyCharm and Python are not Microsoft products so we don't support it.

The lines I sent you are Bash commands you can use to find where the cacert.pem file that Azure CLI uses is. For your environment, here are some places you may be interested in

  1. The Python's installation folder, like C:\Users\{myname}\AppData\Local\Programs\Python\Python38\Lib\site-packages\certifi\cacert.pem
  2. The virtual environment's folder, like D:\cli\env38\Lib\site-packages\certifi\cacert.pem

You may also check the doc from requests on SSL Cert Verification.

For general Python questions, you may post them at https://stackoverflow.com/.

jiasli avatar Mar 30 '20 09:03 jiasli

I would love to help but PyCharm and Python are not Microsoft products so we don't support it.

The lines I sent you are Bash commands you can use to find where the cacert.pem file that Azure CLI uses is. For your environment, here are some places you may be interested in

  1. The Python's installation folder, like C:\Users\{myname}\AppData\Local\Programs\Python\Python38\Lib\site-packages\certifi\cacert.pem
  2. The virtual environment's folder, like D:\cli\env38\Lib\site-packages\certifi\cacert.pem

You may also check the doc from requests on SSL Cert Verification.

For general Python questions, you may post them at https://stackoverflow.com/.

Thank you for your help @jiasli I'll try there! :)

ellieCallcutART avatar Mar 30 '20 09:03 ellieCallcutART

You are welcome. Let me know if the resources I provided work for you. You may also drop me an email at {my_github_id}@microsoft.com. We can discuss about this offline.

jiasli avatar Mar 30 '20 09:03 jiasli