I’m building a system based on OpenVPN, where clients will connect to a website, secured by Basic Authentication (that’s the way it is, no way to change this).
I wish I could go through a nginx proxy that would add for me the correct basic authentication header before reaching the website. This way, based on the IP address the client uses (coming from OpenVPN configuration), I would retrieve it’s user/password in a DB and forge the header accordingly. So user don’t have to enter any login/password.
Injecting the basic-authentication header is easy with:
location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://6.6.6.6:80;
proxy_set_header Authorization "Basic a2luZzppc25ha2Vk";
}
Where ‘a2luZzppc25ha2Vk' is of course the base64 for this login:password.
So now I need to replace a2luZzppc25ha2Vk with a value found in a DB, according to the $remote_addr