How to set a proxy for the azure-cli command line tool?

azure

Solution

The environment variables mentioned in the other answer are part of the solution, so you do need to set them by running these commands before `az login`. Note that (in my case, at least) both URLs start with http, not https.

In PowerShell:

$env:HTTP_PROXY="http://my-proxy-details"
$env:HTTPS_PROXY="http://my-proxy-details"

In cmd:

SET HTTP_PROXY http://my-proxy-details
SET HTTPS_PROXY http://my-proxy-details

Or, to set them permanently:

`[Environment]::SetEnvironmentVariable("HTTP_PROXY", "http://my-proxy-details", "Machine")`

`[Environment]::SetEnvironmentVariable("HTTPS_PROXY", "http://my-proxy-details", "Machine")`

If that fixes it for you, you can stop reading here. If not, and you see a certificate error, the extra step is to find the Azure CLI's private Python installation, and add your root certificate to its `cacert.pem` files. While Python itself uses the Windows certificate store, some packages (notably certifi) do not.

You will need your proxy's root certificate in PEM format - that is, as base64 text rather than as a binary. It may well have the `.cer` extension.

Find the site-packages folder inside Azure CLI's program folder. For me, it's `C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\Lib\site-packages`. Search it for files named `cacert.pem`. I found three of them. Copy the contents of your certificate and paste it at the bottom of each of these files. Save them and try again.

Problem

I'm behind a corporate firewall and cannot connect using the command line interface, which probably doesn't get proxy information from the system configuration, but I cannot find a way to set the correct options.

Original source