Varnish 4 Basic Authentication constantly prompts for username and password
<p>I'm using Varnish 4 on a test environment and want to protect access to content using Basic Authentication.</p>

<p>What I want to happen is that the first request causes a prompt for Basic Auth and then it no longer asks once the user has entered their username and password.  I have setup a rule with Varnish to check for the correct Authroization and ask the user to provide it if they have not.</p>

<p>My end users are complaining that they are repeatedly challenged for Basic Authentication details in their browser sometimes having to enter it 20 times before the first page is shown.</p>

<p>When using Chrome browser, this doesn't seem to happen unless I have the dev tools panel open and have the do not cache requests with dev tools panel open ticked. In various versions of IE, this happens all the time.</p>

<p>In my VCL, the basic auth rule looks like this in the sub vcl_recv section:</p>

<pre><code>if (!req.http.Authorization ~ "Basic xxxxxxxxxxxxxxxxxx=="
    # Don't require auth if IP on the authpass list.
    &amp;&amp; !client.ip ~ authpass
    # Don't require auth if this is the live website.
    &amp;&amp; !req.http.Host == "www.mylivesite.com") {
    return(synth(401, "Authentication required"));
}
unset req.http.Authorization;
</code></pre>