<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Passing Curiosity: Posts tagged enterprise</title>
    <link href="https://passingcuriosity.com/tags/enterprise/enterprise.xml" rel="self" />
    <link href="https://passingcuriosity.com" />
    <id>https://passingcuriosity.com/tags/enterprise/enterprise.xml</id>
    <author>
        <name>Thomas Sutton</name>
        
        <email>me@thomas-sutton.id.au</email>
        
    </author>
    <updated>2018-05-02T00:00:00Z</updated>
    <entry>
    <title>Surviving behind an enterprise proxy</title>
    <link href="https://passingcuriosity.com/2018/surviving-behind-enterprise-proxy/" />
    <id>https://passingcuriosity.com/2018/surviving-behind-enterprise-proxy/</id>
    <published>2018-05-02T00:00:00Z</published>
    <updated>2018-05-02T00:00:00Z</updated>
    <summary type="html"><![CDATA[<p>Many large organisations require all machines in their network to use a
corporate proxy for all access to the internet. Often these proxies
force a terrible user experience on anyone who isn’t using a Microsoft
web browser on Windows platform using centralised authentication. There
are some tools that can help make life less terrible for developers in
such situations.</p>
<h2 id="authenticating-proxy-requests">Authenticating proxy requests</h2>
<p>Many corporate proxies require client authentication (so they can
monitor your Facebook or whatever). Entering your password every time
some new process makes a request is awful but it’s also moderately easy
to solve this problem: install a local proxy configured to add
authentication details and forward all requests to the official proxy.</p>
<p><a href="http://squidman.net/squidman/">SquidMan</a> and <a href="http://cntlm.sourceforge.net/">cntlm</a> are both quick and easy ways to get a local
proxy server up and running. SquidMan is a GUI app that configures and
runs a <code>squid</code> proxy for you while <code>cntlm</code> is a cut down proxy server
designed to forward requests with NTLM authentication to an upstream
proxy.</p>
<h2 id="proxy-settings-for-the-shell">Proxy settings for the shell</h2>
<p>Configuring your local proxy in <em>System Preferences.app</em> will get almost
all native Mac apps to use it but what about command line applications?
Here’s a small script which will interrogate your system preferences and
translate them into environment variables for command line applications.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode .bash"><code class="sourceCode bash"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co">#!/usr/bin/env bash</span></span>
<span id="cb1-2"><a href="#cb1-2" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-3"><a href="#cb1-3" aria-hidden="true" tabindex="-1"></a><span class="fu">proxy ()</span> <span class="kw">{</span></span>
<span id="cb1-4"><a href="#cb1-4" aria-hidden="true" tabindex="-1"></a>    <span class="va">p</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$1</span><span class="st">&quot;</span></span>
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a>    <span class="va">enable</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="ex">scutil</span> <span class="at">--proxy</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;</span><span class="va">${p}</span><span class="st">Enable&quot;</span> <span class="kw">|</span> <span class="fu">cut</span> <span class="at">-d:</span> <span class="at">-f2</span><span class="va">)</span><span class="st">&quot;</span></span>
<span id="cb1-6"><a href="#cb1-6" aria-hidden="true" tabindex="-1"></a>    <span class="va">host</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="ex">scutil</span> <span class="at">--proxy</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;</span><span class="va">${p}</span><span class="st">Proxy&quot;</span> <span class="kw">|</span> <span class="fu">cut</span> <span class="at">-d:</span> <span class="at">-f2</span> <span class="kw">|</span> <span class="fu">tr</span> <span class="at">-d</span> <span class="st">&quot; &quot;</span><span class="va">)</span><span class="st">&quot;</span></span>
<span id="cb1-7"><a href="#cb1-7" aria-hidden="true" tabindex="-1"></a>    <span class="va">port</span><span class="op">=</span><span class="st">&quot;</span><span class="va">$(</span><span class="ex">scutil</span> <span class="at">--proxy</span> <span class="kw">|</span> <span class="fu">grep</span> <span class="st">&quot;</span><span class="va">${p}</span><span class="st">Port&quot;</span> <span class="kw">|</span> <span class="fu">cut</span> <span class="at">-d:</span> <span class="at">-f2</span> <span class="kw">|</span> <span class="fu">tr</span> <span class="at">-d</span> <span class="st">&quot; &quot;</span><span class="va">)</span><span class="st">&quot;</span></span>
<span id="cb1-8"><a href="#cb1-8" aria-hidden="true" tabindex="-1"></a>    <span class="cf">if</span> <span class="kw">[[</span> <span class="st">&quot;</span><span class="va">$enable</span><span class="st">&quot;</span> <span class="ot">-eq</span> 1 <span class="kw">]]</span> <span class="kw">;</span> <span class="cf">then</span></span>
<span id="cb1-9"><a href="#cb1-9" aria-hidden="true" tabindex="-1"></a>        <span class="bu">echo</span> <span class="st">&quot;</span><span class="va">${host}</span><span class="st">:</span><span class="va">${port}</span><span class="st">&quot;</span></span>
<span id="cb1-10"><a href="#cb1-10" aria-hidden="true" tabindex="-1"></a>    <span class="cf">fi</span></span>
<span id="cb1-11"><a href="#cb1-11" aria-hidden="true" tabindex="-1"></a><span class="kw">}</span></span>
<span id="cb1-12"><a href="#cb1-12" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-13"><a href="#cb1-13" aria-hidden="true" tabindex="-1"></a><span class="va">http</span><span class="op">=</span><span class="va">$(</span><span class="ex">proxy</span> HTTP<span class="va">)</span></span>
<span id="cb1-14"><a href="#cb1-14" aria-hidden="true" tabindex="-1"></a><span class="va">https</span><span class="op">=</span><span class="va">$(</span><span class="ex">proxy</span> HTTPS<span class="va">)</span></span>
<span id="cb1-15"><a href="#cb1-15" aria-hidden="true" tabindex="-1"></a><span class="va">ftp</span><span class="op">=</span><span class="va">$(</span><span class="ex">proxy</span> FTP<span class="va">)</span></span>
<span id="cb1-16"><a href="#cb1-16" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb1-17"><a href="#cb1-17" aria-hidden="true" tabindex="-1"></a><span class="bu">[</span> <span class="ot">-n</span> <span class="st">&quot;</span><span class="va">$http</span><span class="st">&quot;</span> <span class="bu">]</span> <span class="kw">&amp;&amp;</span> <span class="bu">echo</span> export http_proxy=<span class="dt">\&quot;</span><span class="va">$http</span><span class="dt">\&quot;</span></span>
<span id="cb1-18"><a href="#cb1-18" aria-hidden="true" tabindex="-1"></a><span class="bu">[</span> <span class="ot">-n</span> <span class="st">&quot;</span><span class="va">$https</span><span class="st">&quot;</span> <span class="bu">]</span> <span class="kw">&amp;&amp;</span> <span class="bu">echo</span> export https_proxy=<span class="dt">\&quot;</span><span class="va">$https</span><span class="dt">\&quot;</span></span>
<span id="cb1-19"><a href="#cb1-19" aria-hidden="true" tabindex="-1"></a><span class="bu">[</span> <span class="ot">-n</span> <span class="st">&quot;</span><span class="va">$ftp</span><span class="st">&quot;</span> <span class="bu">]</span> <span class="kw">&amp;&amp;</span> <span class="bu">echo</span> export ftp_proxy=<span class="dt">\&quot;</span><span class="va">$ftp</span><span class="dt">\&quot;</span></span></code></pre></div>
<p>You can run it from your <code>.bashrc</code> file like so (assuming it’s installed
in your <code>~/bin</code> directory):</p>
<div class="sourceCode" id="cb2"><pre class="sourceCode .bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1" aria-hidden="true" tabindex="-1"></a><span class="bu">eval</span> <span class="va">$($HOME</span><span class="ex">/bin/proxy</span><span class="va">)</span></span></code></pre></div>
<p>If you use some other shell than <code>bash</code> you should be able to figure out
how to modify this yourself. You might also like to modify it to export
the capitalised variables (<code>HTTP_PROXY</code>, etc.) and make the values a
full URI (<code>http://${host}:${port}</code>) as appropriate.</p>
<h2 id="docker">Docker</h2>
<p>If you use Docker for Mac in the default configuration, it should be
able to pull images via the proxy configured in <em>System
Preferences.app</em>. Getting processes <em>inside</em> containers to use the proxy
needs some additional configuration. If you run a local proxy as
described above (listening on port <code>2138</code>) then you can get Docker to
define the appropriate environment variables (as least <a href="https://github.com/docker/for-mac/issues/2320#issuecomment-354887432">for <code>docker build</code> and <code>docker run</code></a>) by editing <code>$HOME/.docker/config.json</code>:</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode .json"><code class="sourceCode json"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="fu">{</span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a>  <span class="dt">&quot;proxies&quot;</span><span class="fu">:</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a>  <span class="fu">{</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a>    <span class="dt">&quot;default&quot;</span><span class="fu">:</span></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a>    <span class="fu">{</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&quot;httpProxy&quot;</span><span class="fu">:</span> <span class="st">&quot;http://host.docker.internal:3128&quot;</span><span class="fu">,</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&quot;httpsProxy&quot;</span><span class="fu">:</span> <span class="st">&quot;http://host.docker.internal:3128&quot;</span><span class="fu">,</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&quot;noProxy&quot;</span><span class="fu">:</span> <span class="st">&quot;http://host.docker.internal:3128&quot;</span><span class="fu">,</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a>      <span class="dt">&quot;ftpProxy&quot;</span><span class="fu">:</span> <span class="st">&quot;http://host.docker.internal:3128&quot;</span></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a>    <span class="fu">}</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a>  <span class="fu">}</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="fu">}</span></span></code></pre></div>
<p>Incidentally <code>host.docker.internal</code> is a magical hostname provided by
Docker (or maybe just Docker for Mac? Who knows!) that resolves to your
host.</p>
<h2 id="ssh">SSH</h2>
<p>Sometimes you just want an SSH connection but all outgoing connections
are blocked unless they go via the proxy. You can use tools like
<a href="https://github.com/bryanpkc/corkscrew"><code>corkscrew</code></a> to tunnel SSH (and most other TCP protocols) through a
proxy.</p>
<p>With the <code>ProxyCommand</code> directive in your <code>.ssh/config</code> OpenSSH can use
some other command to manage the shipping the bytes back and forth to
the server. A command like <code>corkscrew</code> can do this shipping via your
proxy server:</p>
<pre><code>Host eg1
    Hostname host1.example.com
    ProxyCommand corkscrew $HTTP_PROXY $PROXY_PORT %h %p</code></pre>
<p>Now <code>ssh eg1</code> will invoke <code>corkscrew</code> which will <code>CONNECT</code> through the
proxy. Some particularly obnoxious proxies will be configured to block
this, YMMV.</p>
<h2 id="what-about-those-crazy-access-rules">What about those crazy access rules</h2>
<p>Complex environments will often have ludicrous rules requiring you
access some internal services directly, using a special purpose proxy
for third-party service A, and so on. These requirements are usually
implemented using perhaps the world’s stupidest use of JavaScript:
Proxy Automatic Configuration scripts.</p>
<p>Alas, there’s not much you can do about these. On current versions of OS
X configuring a PAC and HTTP and HTTPS proxies will not do anything
useful: it just ignores the HTTP and HTTPS proxy settings and always
uses the PAC. The best alternative I’ve found is to use a browser
extension like <a href="https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif?hl=en">Proxy SwitchyOmega</a> to control which requests use the
PAC and which use your local proxy server. Generally you’ll only
actually want to use the policy in the PAC from your web browser anyway.</p>]]></summary>
</entry>

</feed>
