How to use Golang’s “go get” from behind a proxy.

In a perfect world employers would trust their employees, governments would care about the average person, and cats and dogs would get along together. Unfortunately the reality is that many organizations must use traffic proxies for both security and compliance with federal regulation. Luckily there is a way for Golang’s package manager “get” to work in such an environment. In this article we will look into how to clone a Golang based program from behind a corporate network proxy.

My Situation

This process is executed on a Windows 10 (build 1709) on a HP notebook. Inside of this is running Ubuntu 18.04 via the Windows Subsystem for Linux (WSL) feature. All of this on a corporate network, connects to a client’s network via VPN. The network chain looks like this (even before the ‘internet’): local machine -> corporate network -> VPN tunnel connection -> client corporate network.

Process

Opening Ubuntu WSL I received the typical command prompt and entered the user password. Once log in completed I changed directories (cd) to the user’s home directory.

WSL is not 100% Linux, but it works, kinda, sorta.

The first thing I tried was the recommended command as documented in the README file.

go get github.com/mtojek/aws-closest-region

But that just got me an error, not surprising really.

Interesting. GiT is not able to access the URL. So somewhere between my machine and the GitHub servers the communication routing fails. I wanted to trace the traffic to see where the requests started to fail. So I installed and ran traceroute to github.com

sudo apt-get install -y traceroute
...
traceroute github.com
...
29 * * *
30 * * *

It would seem traceroute fails. Next I tried a curl request:

More dots more dots more dots; STOP ALL THE DOTS!

Ah! “302 not allowed”. And it looks like the Location cURL was redirected to is the ProxyWarning.html page from the organizations proxy gateway.

This means we need to set the proxy setting for GiT. I knew that weeks back I have set the proxy value for Ubuntu’s APT program, so I tail’d APT”s config file for the value. To finish up I ran a git list command to ensure the value was saved.

$ tail /etc/apt/apt.conf
Acquire::http::Proxy "http://YOUR_PROXY_URL_HERE:8888";

#source https://stackoverflow.com/questions/128035/how-do-i-pull-from-a-git-repository-through-an-http-proxy/3406766#3406766
$ git config --global http.proxy YOUR_PROXY_URL_HERE:8888


$ git config --global --list
user.email=MY_AUTHOR_NAME@SOME_VALUE.com
user.name=MY_AUTHOR_NAME
http.proxy=YOUR_PROXY_URL_HERE:8888

With the GiT proxy value now set I tried the following command…

go get github.com/mtojek/aws-closest-region

After what seemed like hours (< 3 minutes) I received a different return message than before: nothing. I was back at the command prompt with no output. Could this mean return code 0? Doing a ls command of the ~/go/src directory. Hurrah! The project was indeed downloaded.

Super Green!

Conclusion

With a little troubleshooting, knowledge share, and documentation reading I was able to get leverage the configuration ability of GiT to continue using “go get” to install applications. It would seem any program that downloads on a port other that 80 will need to be configured. May I should look into http_proxt global usage.

Do you have any knowledge about configuring programs to use proxy pass-throughs? Do you think corporate proxies are useless; or a necessity for the internet of today? Comment below and let me know.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.