caddyauth: Allow user-configurable headers and status code#7289
caddyauth: Allow user-configurable headers and status code#7289tie wants to merge 1 commit intocaddyserver:masterfrom
Conversation
|
Thanks, the code looks good (though it seems to be missing Caddyfile support but that may be on purpose?) but I don't understand the motivation. Why would alternate headers ever be used for basic auth? What's the real-world usecase here? What would this allow you to do exactly? |
This allows using
Yes, I don’t think it makes sense to expose this as-is in basic_auth Caddyfile syntax — it’s not really designed to extensible. I find the following confusing e.g. compared to |
|
That doesn't answer my question. In what situation would you need Caddy to solve proxy authentication like this? What is in front of or behind Caddy that would necessitate that? Why not just use the forwardproxy plugin, doesn't it already do that? Describe an actual real-world example (what other software would be used alongside Caddy for this, etc) Also yes I agree the single line Caddyfile syntax does not make sense, but the block syntax you showed is not actually implemented by your code changes. You didn't update the Caddyfile unmarshal code to add support for those options. Also should have a Caddyfile adapt test (see |
|
I’ve looked at the PR as a whole and my concern is less about any one implementation detail and more about the overall value/reason for this. The patch is reasonably complete now but it still feels like a technically competent solution to a problem that has not been shown to belong in Caddy core, to my knowledge. It expands the auth surface with configurable request/response headers, a generic unauthenticated status code, a So the question for me is not whether it works code-wise because it seems to but why should core own this? Right now I do not see a compelling reason. The PR demonstrates protocol similarity and code reuse potential but not a compelling need for new core API/config surface. Without that stronger justification this feels like a fair amount of added maintenance burden for limited real benefit. |
|
Yeah, without proper justification for this feature to exist in Caddy, I think I'll close this. We can reopen if a good argument is made. |
Summary
This change alllows user-configurable headers and status code for HTTP basic authentication handler.
Motivation
This change allows using
basic_authauthentication provider for web proxies (i.e. http_proxy). E.g. forwardproxy currently implements its own authentication that is identical to basic_auth, except that forward proxies use different headers (Authorization→Proxy-Authorization,WWW-Authentication→Proxy-Authenticate) and respond with HTTP status code 407 Proxy Authentication Required instead of 401 Unauthorized.See https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Authentication#proxy_authentication
Changes
authorization_headerandauthenticate_headerfields tobasic_authauthentication provider.status_codefield toauthenticationhandler (with support for expressions, similar to static response).net/http/internal/asciipackage source tointernal/ascii.parseBasicAuthwith tests based onnet/http.parseBasicAuth. The function itself was copied as is, the tests were modified to cover more edge cases.authenticationhandler withbasic_authprovider (with proxy authentication).Assistance Disclosure
No AI was used.