caddy -version)?Caddy 0.9.4 (on windows 10)
Protect a reverse proxy via basicauth
example.com:801 {
errors errors.log
log access.log
tls off
basicauth /admin "r" "r"
proxy /admin/monitor 192.168.3.9:80
}
caddy.exe in the command prompt
> curl -u r:r http://example.com:801/admin/monitor
<!doctype html>...
> curl -u hacker:r http://example.com:801/admin/monitor
401 Unauthorized
The first command should return the page from the proxy, while the second should return a 404 (the r is missing - meaning the auth was successful)
> curl -u r:r http://example.com:801/admin/monitor
{"message":"Basic auth failed"}
> curl -u hacker:r http://example.com:801/admin/monitor
401 Unauthorized
The first command fails to authenticate!
If I request a page not behind the proxy admin/test for instance, I get an error 404 or 401 as expected (depending if the auth was successful).
Caddy doesn't write a JSON response when basic auth fails... it looks like Caddy's basic auth is succeeding but your backend is seeing it as failed and writing some sort of JSON response.
Thanks for your very quick reply!
Can I prevent caddy from forwarding the basic auth info to the backend?
Edit: I'm looking at header_upstream which should do this
Try this in your proxy directive:
header_upstream -Authorization
We changed proxy recently so that it _will_ forward the Authorization header, but in the cases where Caddy's basicauth successfully completes the authorization, perhaps that header should be removed.
In any case, what I showed you should work.
Great, it works!
Thank you very much for this quick and efficient support :1st_place_medal:
@oliverpool No problem, see #1325. This _should_ mean you won't need to manually unset that header. I don't think my change will break anyone but we'll see. (If it does break someone, I think they're doing something strange...)
Most helpful comment
Try this in your proxy directive:
We changed proxy recently so that it _will_ forward the Authorization header, but in the cases where Caddy's basicauth successfully completes the authorization, perhaps that header should be removed.
In any case, what I showed you should work.