<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div class="">This is a possible regsub() to extract the next-to-last IP address (it assumes at lest two are available):</div><div class=""><br class=""></div><div class="">    set req.http.X-Client-Ip = regsub(</div><div class="">        req.http.X-Forwarded-For,</div><div class="">        "^.*(?:^|,)\s*([^,\s]+)\s*,[^,]+$", </div><div class="">        "\1");</div><div class=""><br class=""></div><div class="">Best,</div><div class=""><br class=""></div><div class="">--</div><div class="">Carlos Abalde</div><div><br class=""><blockquote type="cite" class=""><div class="">On 20 Aug 2021, at 13:08, Justin Lloyd <<a href="mailto:justinl@arena.net" class="">justinl@arena.net</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta charset="UTF-8" class=""><div class="WordSection1" style="page: WordSection1; caret-color: rgb(0, 0, 0); font-family: Menlo-Regular; font-size: 14px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; text-decoration: none;"><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I was just trying to get varnish-modules to build (having to install varnish and build tools on my dev manager server) and hit the limitation that vmod_str isn’t available until Varnish 6.6. I’m on Varnish 6.5 so I’d need to test the 6.6 upgrade in dev and then roll that out to live, which will take some time (higher priority and urgency issues and projects on my plate). I’ll play with regsub() some more to see if I can figure out a temporary approach.<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks,<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Justin<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>varnish-misc <<a href="mailto:varnish-misc-bounces+justinl=arena.net@varnish-cache.org" class="">varnish-misc-bounces+justinl=arena.net@varnish-cache.org</a>><span class="Apple-converted-space"> </span><b class="">On Behalf Of<span class="Apple-converted-space"> </span></b>Justin Lloyd<br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Thursday, August 19, 2021 2:39 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Guillaume Quintard <<a href="mailto:guillaume.quintard@gmail.com" class="">guillaume.quintard@gmail.com</a>>; Carlos Abalde <<a href="mailto:carlos.abalde@gmail.com" class="">carlos.abalde@gmail.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span><a href="mailto:varnish-misc@varnish-cache.org" class="">varnish-misc@varnish-cache.org</a><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>RE: Varnish and AWS ALBs<o:p class=""></o:p></div></div></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi Guillaume!<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">It looks like you and Carlos are both correct. For some reason, before I was not seeing the Varnish XFF values from faked XFFs, not sure why, but now I’m seeing the fakes I’m using against one of my dev sites and I’m seeing the three values where it’s FAKED_IP, REAL_IP, ALB_IP. So with a little bit more VCL code (or probably easier once I move to Varnish Enterprise next year), I should be able to handle this. I’ll give it a whirl and see how it goes.<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Thanks!<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Justin<o:p class=""></o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div style="border-style: solid none none; border-top-width: 1pt; border-top-color: rgb(225, 225, 225); padding: 3pt 0in 0in;" class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><b class="">From:</b><span class="Apple-converted-space"> </span>Guillaume Quintard <<a href="mailto:guillaume.quintard@gmail.com" style="color: blue; text-decoration: underline;" class="">guillaume.quintard@gmail.com</a>><span class="Apple-converted-space"> </span><br class=""><b class="">Sent:</b><span class="Apple-converted-space"> </span>Thursday, August 19, 2021 2:00 PM<br class=""><b class="">To:</b><span class="Apple-converted-space"> </span>Carlos Abalde <<a href="mailto:carlos.abalde@gmail.com" style="color: blue; text-decoration: underline;" class="">carlos.abalde@gmail.com</a>><br class=""><b class="">Cc:</b><span class="Apple-converted-space"> </span>Justin Lloyd <<a href="mailto:justinl@arena.net" style="color: blue; text-decoration: underline;" class="">justinl@arena.net</a>>;<span class="Apple-converted-space"> </span><a href="mailto:varnish-misc@varnish-cache.org" style="color: blue; text-decoration: underline;" class="">varnish-misc@varnish-cache.org</a><br class=""><b class="">Subject:</b><span class="Apple-converted-space"> </span>Re: Varnish and AWS ALBs<o:p class=""></o:p></div></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi,<o:p class=""></o:p></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">If I read this correctly: <a href="https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html" style="color: blue; text-decoration: underline;" class="">https://docs.aws.amazon.com/elasticloadbalancing/latest/application/x-forwarded-headers.html</a><span class="Apple-converted-space"> </span>, you can trust the before-last IP, because it was added by the ALB, always. (and using vmod_str makes it easy to retrieve<span class="Apple-converted-space"> </span><a href="https://github.com/varnish/varnish-modules/blob/master/src/vmod_str.vcc#L42" style="color: blue; text-decoration: underline;" class="">https://github.com/varnish/varnish-modules/blob/master/src/vmod_str.vcc#L42</a>)<br clear="all" class=""><o:p class=""></o:p></div><div class=""><div class=""><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Side question: would an NLB work? They support proxy-protocol, that would also solve your problem.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Cheers,<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">--<span class="Apple-converted-space"> </span><o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Guillaume Quintard<o:p class=""></o:p></div></div></div></div></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">On Thu, Aug 19, 2021 at 1:52 PM Carlos Abalde <<a href="mailto:carlos.abalde@gmail.com" style="color: blue; text-decoration: underline;" class="">carlos.abalde@gmail.com</a>> wrote:<o:p class=""></o:p></div></div><blockquote style="border-style: none none none solid; border-left-width: 1pt; border-left-color: rgb(204, 204, 204); padding: 0in 0in 0in 6pt; margin: 5pt 0in 5pt 4.8pt;" class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Hi,<o:p class=""></o:p></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">No so sure about that. Let's assume the client address is 1.1.1.1. Two possible scenarios:<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div></div><blockquote style="margin: 5pt 0in 5pt 30pt;" class=""><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">- The client request reaches the ALB without XFF. The ALB will inject XFF with value 1.1.1.1. Then Varnish will modify XFF adding the ALB's address (i.e., 1.1.1.1,<ALB IP>). Using the next-to-last IP you're using the right client address.<o:p class=""></o:p></div></div></div><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div></div><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">- The client request reaches the ALB with a forged XFF (e.g. 127.0.0.1). The ALB will will modify XFF (i.e. 127.0.0.1,1.1.1.1). The Varnish will do the same (i.e. 127.0.0.1,1.1.1.1,<ALB IP>). Using the next-to-last IP you're still using the right client address.<o:p class=""></o:p></div></div></div></blockquote><div class=""><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">I've not checked using a ALB, but that should be the expected behaviour for me.<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Best,<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">--<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">Carlos Abalde<o:p class=""></o:p></div></div><div class=""><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class=""><o:p class=""> </o:p></div></div></div></div><div style="margin: 0in; font-size: 11pt; font-family: Calibri, sans-serif;" class="">_______________________________________________<br class="">varnish-misc mailing list<br class=""><a href="mailto:varnish-misc@varnish-cache.org" target="_blank" style="color: blue; text-decoration: underline;" class="">varnish-misc@varnish-cache.org</a><br class=""><a href="https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc" target="_blank" style="color: blue; text-decoration: underline;" class="">https://www.varnish-cache.org/lists/mailman/listinfo/varnish-misc</a></div></blockquote></div></div></div></blockquote></div><br class=""></body></html>