Query for authorization username

Justin Lloyd justinl at arena.net
Mon Oct 25 18:21:54 UTC 2021


In my dev environment, I have a few users configured to use Basic authorization (configured in the Nginx backend) and I'd like to be able to perform VSL queries based on the auth user. This is what I was able to come up with, but I'm wondering if there is a simpler way that I'm just not seeing.

require blob;
if (req.http.Authorization) {
    set req.http.X-Auth-User = regsub(blob.encode(IDENTITY,
                                                  blob=blob.decode(BASE64,
                                                                   encoded=regsub(req.http.Authorization, "^Basic (.*)", "\1"))),
                                      ":.*$", "");
}

varnishtop -I ReqHeader:X-Auth-User
varnishlog -i ReqURL -q 'ReqHeader:X-Auth-User ~ "someuser"'

Thanks,
Justin

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.varnish-cache.org/lists/pipermail/varnish-misc/attachments/20211025/feb5580b/attachment.html>


More information about the varnish-misc mailing list