<div dir="ltr">If you have the ability to compile a vmod, you can use split() from vmod-str (disclaimer: I wrote that) <a href="https://github.com/gquintard/libvmod-str/blob/master/src/vmod_str.vcc">https://github.com/gquintard/libvmod-str/blob/master/src/vmod_str.vcc</a><div><br></div><div>otherwise, to get the second ip, something like :</div><div><br></div><div>regsub(req.http.xff, "([^,]+), *([^ ,]+)[ ,]?.*", "\2")<br></div><div><br></div><div>should work. Fell free to test, using <a href="http://regex101.com">regex101.com</a> for example. or better, a Varnish Test case Case: <a href="https://gist.github.com/gquintard/ee47432bb8b5c97b615d973b57b6338e">https://gist.github.com/gquintard/ee47432bb8b5c97b615d973b57b6338e</a></div><div>test it using: varnishtest foo.vtc</div></div><div class="gmail_extra"><br clear="all"><div><div class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><div>-- <br></div>Guillaume Quintard<br></div></div></div>
<br><div class="gmail_quote">On Fri, Mar 17, 2017 at 1:33 PM, Hernán Marsili <span dir="ltr"><<a href="mailto:hernan@cmsmedios.com" target="_blank">hernan@cmsmedios.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you! so, I figure I can parse the x-forwarded-for in which I have 3 ips. The first one is the customer, the second one is the one 1 need (the CDN) and the third I think is the load balancer.<div><br></div><div>I can assign it to a new header x-cdn-ip and use apache_remoteip to use that ip as the connecting ip. </div><div><br></div><div>What do you think?</div><div><br></div><div>Only problem here is to parse the second iP. I have something like this:</div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:menlo"><span style="font-variant-ligatures:no-common-ligatures"><span class="m_5660521226061879830inbox-Apple-tab-span" style="white-space:pre-wrap">               </span>set req.http.x-cdn-ip = regsub(req.http.X-Forwarded-<wbr>For, "^([^,]+),?.*$", "\1");</span></p><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div></div><div><span style="font-variant-ligatures:no-common-ligatures">I was able to get the first IP but not the second only which is the one I need. Any one can point me in the right direction with the regsub?</span></div><div><span style="font-variant-ligatures:no-common-ligatures"><br></span></div><div><span style="font-variant-ligatures:no-common-ligatures">Thank you!</span></div></div><div class="HOEnZb"><div class="h5"><br><div class="gmail_quote"><div dir="ltr">On Fri, Mar 17, 2017 at 4:43 AM Andrei <<a href="mailto:lagged@gmail.com" target="_blank">lagged@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_5660521226061879830gmail_msg">Authenticated requests should typically bypass cache, unless you want to hash the related session id(s), however that can get "interesting". I suggest using an Apache module such as rpaf or remoteip in order for Apache to set the client IP from the X-Forwarded-For header set by Varnish. This way, you will not need to worry about whitelisting localhost, or other cucumbersome iptables rules, and your IP restrictions will work as intended.</div><div class="gmail_extra m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"><div class="gmail_quote m_5660521226061879830gmail_msg">On Fri, Mar 17, 2017 at 1:32 AM, Jason Price <span dir="ltr" class="m_5660521226061879830gmail_msg"><<a href="mailto:japrice@gmail.com" class="m_5660521226061879830gmail_msg" target="_blank">japrice@gmail.com</a>></span> wrote:<br class="m_5660521226061879830gmail_msg"><blockquote class="gmail_quote m_5660521226061879830gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="m_5660521226061879830gmail_msg">I don't believe there's a trivial way to do this.<div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">Varnish will return the cached response to any IP address that comes calling.  Even if the first request comes from a valid IP, which gets passed through via X-Forward or similar, and mod_auth is tweaked to respond to that, any subsequent request will not be seen by either apache or mod_auth at all.</div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">You have a few options:</div><div class="m_5660521226061879830gmail_msg">1) IP Whitelists are a rather poor means of authentication.  Moving to something else might be prudent.  But that's not easy.</div><div class="m_5660521226061879830gmail_msg">2) There are probably VMODs that do something similar.  If not and if the list of IPs isn't too long, you could limit the IPs in VCL rather than mod_auth.</div><div class="m_5660521226061879830gmail_msg">3) Push the list of IP addresses that can connect to the external port down to IPTables or similar.</div><div class="m_5660521226061879830gmail_msg">4) Push the list of IP addresses to external Firewall, or Security Group or whatever.</div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div></div><div class="gmail_extra m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"><div class="gmail_quote m_5660521226061879830gmail_msg"><div class="m_5660521226061879830gmail_msg"><div class="m_5660521226061879830m_-7363131261474093851h5 m_5660521226061879830gmail_msg">On Thu, Mar 16, 2017 at 5:46 PM, Hernán Marsili <span dir="ltr" class="m_5660521226061879830gmail_msg"><<a href="mailto:hernan@cmsmedios.com" class="m_5660521226061879830gmail_msg" target="_blank">hernan@cmsmedios.com</a>></span> wrote:<br class="m_5660521226061879830gmail_msg"></div></div><blockquote class="gmail_quote m_5660521226061879830gmail_msg" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="m_5660521226061879830gmail_msg"><div class="m_5660521226061879830m_-7363131261474093851h5 m_5660521226061879830gmail_msg"><div dir="ltr" class="m_5660521226061879830gmail_msg">Hi,<div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">We are having an issue with VARNISH and apache mod_auth. Varnish is on port 80 serving users and Apache is the backend. </div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">We have servers restricting access only to authenticated users or certain IP addresses. Since we installed Varnish the issue is that we need to enable 127.0.0.1 as a permitted IP (required ip rule) so the Varnish can fetch content. The problem, is that the real IP is not used and all the other rules does not apply. </div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">Bottom line, how can we still control who is requesting using MOD_AUTH and having Varnish?</div><div class="m_5660521226061879830gmail_msg"><br class="m_5660521226061879830gmail_msg"></div><div class="m_5660521226061879830gmail_msg">Regards</div><span class="m_5660521226061879830m_-7363131261474093851m_3758069336204431268HOEnZb m_5660521226061879830gmail_msg"><font color="#888888" class="m_5660521226061879830gmail_msg"><div class="m_5660521226061879830gmail_msg">Hernán.</div></font></span></div>
<br class="m_5660521226061879830gmail_msg"></div></div>______________________________<wbr>_________________<br class="m_5660521226061879830gmail_msg">
varnish-misc mailing list<br class="m_5660521226061879830gmail_msg">
<a href="mailto:varnish-misc@varnish-cache.org" class="m_5660521226061879830gmail_msg" target="_blank">varnish-misc@varnish-cache.org</a><br class="m_5660521226061879830gmail_msg">
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" class="m_5660521226061879830gmail_msg" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/<wbr>varnish-misc</a><br class="m_5660521226061879830gmail_msg"></blockquote></div><br class="m_5660521226061879830gmail_msg"></div>
<br class="m_5660521226061879830gmail_msg">______________________________<wbr>_________________<br class="m_5660521226061879830gmail_msg">
varnish-misc mailing list<br class="m_5660521226061879830gmail_msg">
<a href="mailto:varnish-misc@varnish-cache.org" class="m_5660521226061879830gmail_msg" target="_blank">varnish-misc@varnish-cache.org</a><br class="m_5660521226061879830gmail_msg">
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" class="m_5660521226061879830gmail_msg" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/<wbr>varnish-misc</a><br class="m_5660521226061879830gmail_msg"></blockquote></div><br class="m_5660521226061879830gmail_msg"></div>
</blockquote></div>
</div></div><br>______________________________<wbr>_________________<br>
varnish-misc mailing list<br>
<a href="mailto:varnish-misc@varnish-cache.org">varnish-misc@varnish-cache.org</a><br>
<a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" rel="noreferrer" target="_blank">https://www.varnish-cache.org/<wbr>lists/mailman/listinfo/<wbr>varnish-misc</a><br></blockquote></div><br></div>