How to use Golang's "go get" from behind a proxy.
Tags: devops, go, howto, networking
Published: 2018-11-26 19:33:22

---
title: How to use Golang's "go get" from behind a proxy.
published: true
description: How to use Golang's "go get" from behind a proxy.
tags: devops, go, howto, networking
cover_image: https://blog.davidjeddy.com/wp-content/uploads/2018/11/golang-gopher-930x620.png
---

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>My Situation</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>This process is executed on a <a href="https://www.microsoft.com/en-us/software-download/windows10">Windows 10</a> (build 1709) on a HP notebook. Inside of this is running <a href="http://releases.ubuntu.com/18.04.1/">Ubuntu 18.04</a> via the <a href="https://docs.microsoft.com/en-us/windows/wsl/install-win10">Windows Subsystem for Linux (WSL)</a> 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.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Process</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1207,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://blog.davidjeddy.com/wp-content/uploads/2018/11/golang_get_proxy_step_1.png" alt="" class="wp-image-1207"/><figcaption>WSL is not 100% Linux, but it works, kinda, sorta.</figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>The first thing I tried was the recommended command as documented in the README file.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted"><code>go get github.com/mtojek/aws-closest-region</code></pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p> But that just got me an error, not surprising really.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1215,"align":"center"} -->
<div class="wp-block-image"><figure class="aligncenter"><img src="https://blog.davidjeddy.com/wp-content/uploads/2018/11/golang_get_proxy_step_2-1.png" alt="" class="wp-image-1215"/><figcaption><a href="https://www.youtube.com/watch?v=UHRGqJDA1zk">Why does this always have to happen to me?</a></figcaption></figure></div>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>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 <a href="https://en.wikipedia.org/wiki/Traceroute">traceroute</a> to github.com</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">sudo apt-get install -y traceroute<br>...<br>traceroute github.com<br>...<br>29 * * *<br>30 * * *</pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p>It would seem traceroute fails. Next I tried a <a href="https://curl.haxx.se/">curl</a> request:</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1216} -->
<figure class="wp-block-image"><img src="https://blog.davidjeddy.com/wp-content/uploads/2018/11/golang_get_proxy_step_3-2.png" alt="" class="wp-image-1216"/><figcaption><a href="https://www.youtube.com/watch?v=5lo9kmcEw0w">More dots more dots more dots; STOP ALL THE DOTS!</a></figcaption></figure>
<!-- /wp:image -->

<!-- wp:paragraph -->
<p>Ah! "302 not allowed". And it looks like the Location cURL was redirected to is the <strong>ProxyWarning.html</strong> page from the organizations proxy gateway. </p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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 <a href="https://git-scm.com/">git</a> list command to ensure the value was saved.</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">$ tail /etc/apt/apt.conf<br>Acquire::http::Proxy "http://YOUR_PROXY_URL_HERE:8888";<br><br>#source https://stackoverflow.com/questions/128035/how-do-i-pull-from-a-git-repository-through-an-http-proxy/3406766#3406766<br>$ git config --global http.proxy YOUR_PROXY_URL_HERE:8888<br><br><br>$ git config --global --list<br>user.email=MY_AUTHOR_NAME@SOME_VALUE.com<br>user.name=MY_AUTHOR_NAME<br>http.proxy=YOUR_PROXY_URL_HERE:8888<br></pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p>With the GiT proxy value now set I tried the following command...</p>
<!-- /wp:paragraph -->

<!-- wp:preformatted -->
<pre class="wp-block-preformatted">go get github.com/mtojek/aws-closest-region<br></pre>
<!-- /wp:preformatted -->

<!-- wp:paragraph -->
<p>After what seemed like hours (&lt; 3 minutes) I received a different return message than before: nothing. I was back at the command prompt with no output. Could this mean <a href="https://www.tldp.org/LDP/abs/html/exit-status.html">return code 0</a>? Doing a <a href="https://en.wikipedia.org/wiki/Ls">ls</a> command of the ~/go/src directory. Hurrah! The project was indeed downloaded.</p>
<!-- /wp:paragraph -->

<!-- wp:image {"id":1211} -->
<figure class="wp-block-image"><img src="https://blog.davidjeddy.com/wp-content/uploads/2018/11/golang_get_proxy_step_4-1.png" alt="" class="wp-image-1211"/><figcaption><a href="https://www.youtube.com/watch?v=rKHh3EIFcZw">Super Green!</a></figcaption></figure>
<!-- /wp:image -->

<!-- wp:heading -->
<h2>Conclusion</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>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.</p>
<!-- /wp:paragraph -->