Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

azure

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.

like image 688
CodeClimber Avatar asked Dec 10 '13 17:12

CodeClimber


People also ask

How do I run a proxy command?

Click Start, click Run, type cmd, and then click OK. At the command prompt, type netsh winhttp set proxy proxyservername:portnumber, and then press ENTER. In this command, replace proxyservername with the fully qualified domain name of the proxy server.

Is Azure CLI A command-line tool?

The Azure Command-Line Interface (CLI) is a cross-platform command-line tool to connect to Azure and execute administrative commands on Azure resources. It allows the execution of commands through a terminal using interactive command-line prompts or a script.


2 Answers

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.

like image 60
y6nH Avatar answered Oct 20 '22 21:10

y6nH


You could use HTTP_PROXY or HTTPS_PROXY environment variables to set a proxy.

like image 36
André Rodrigues Avatar answered Oct 20 '22 22:10

André Rodrigues