Proxy, Proxy on the Wall...
…who annoys the most in the land.
Proxy servers are still a popular tool in many enterprise environments to channel outbound web traffic, scan and prevent threats. Unfortunately, very few companies use transparent proxy solutions and force you to configure the proxy server in the respective application.
Since the configuration of the proxy is different for each application, I collect some examples here.
Windows
You can do a lot of things right with a system-wide proxy. This is easily set in Windows via netsh
.
netsh winhttp set proxy "myproxy.local.bader.cloud:3128" bypass-list="\*.local.bader.cloud;<local>"
ARMClient / .NET applications
The ARMClient is a great way to easily use Microsoft’s REST API. As with any .NET application, to explicitly specify the proxy, you need to create a .config file. For ARMClient this is called ARMClient.exe.config
<configuration>
<system.net>
<defaultProxy>
<proxy usesystemdefault="false" autoDetect="false" proxyaddress="http://myproxy.local.bader.cloud:3128" bypassonlocal="true"/>
<bypasslist>
<add address="\[a-z\]+\.local\.bader\.cloud$" />
</bypasslist>
</defaultProxy>
</system.net>
</configuration>
Unfortunately, the ADAL login used does not provide any proxy support, so the current release 1.3 must be used. This supports login via the Azure CLI and thus also a proxy.
machine.config
To set the setting system wide the machine.config
must be adjusted.
The exact path to the file can be found with the following command.
[System.Runtime.InteropServices.RuntimeEnvironment]::SystemConfigurationFile
Chocolatey
The configuration is well documented in the doc, I extended my script a bit to automate the complete installation in PowerShell.
\# Install Chocolatey through a proxy
$env:chocolateyProxyLocation = "http://myproxy.local.bader.cloud:3128"
$proxy = new-object System.Net.WebProxy
$proxy.Address = $env:chocolateyProxyLocation
$wc = New-Object System.Net.WebClient
$wc.proxy = $proxy
iex ($wc.DownloadString('https://chocolatey.org/install.ps1'))
# Set Proxy for package download
choco config set proxy $env:chocolateyProxyLocation
PowerShell
A proxy can also be defined in PowerShell. The configuration is loaded at every start of the $PROFILE
.
$proxyString = "http://myproxy.local.bader.cloud:3128"
$proxyUri = new-object System.Uri($proxyString)
\[System.Net.WebRequest\]::DefaultWebProxy = new-object System.Net.WebProxy ($proxyUri, $true)
PowerShell Package Provider
In order to enjoy Install-Module
on a Windows 7 system, the package provider must be installed first. If a proxy is in the way, it must be specified.
$proxy = "http://myproxy.local.bader.cloud:3128"
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Proxy $proxy
Register-PSRepository -Default -InstallationPolicy Trusted -Proxy $proxy
Git
Last but not least, of course, you want to store your source code in Git.
git config --global http.proxy http://myproxy.local.bader.cloud:3128