POC for using the basic_auth provisions from caddy internals #147
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
1. What does this change do, exactly?
Hello!
as suggested, I tried to modify the
forwardproxycurrent authentication to re-use caddy's (main) code. I think I am getting there, but there are a few things that - if you are interested - may need discussion.In the code, I marked the relevant parts with a
[POC]comment tag and a brief discussion.Some explanations:
AuthenticateandparseCaddyFileto do the authentication and parsing, but they do just a little bit too much - the logic is adherent to where they're originally used (of course). For instance,Authenticatewrites to theResponseWriterand I don't think we need that; andparseCaddyFileis internal, uses ahttpcaddyfile.Helperthat is not available, and expects a slightly different "position" in the config file layout.adapter.gofile.basicauth.go(as it is, basically) because it contains some internal fields and methods I need to access from those new methods.caddyfile.goandforwardproxy.go- should be quite straightforward; the changes in error messages are also marked with[POC]. Please mainly review if these files suits you, what I described in the earlier points are "just" to make these changes work and can be optimized, as I said.xcaddy run...compiles against the latest caddy and my code is done against that version,go testcompiles against v2.7.6, and there's a breaking change inbasicauth.go#Comparerthat makes things difficult.ctxI don't have available at initialization time. I tried to work around this, but the point before makes it really difficult; so I hope that it's possible to update the "base" version before (possibly, eventually) finalizing all this.To test:
caddyfileRun with
xcaddy run -- --config caddyfileTry with
Thanks for the great code and the fun ride! Even if this will go nowhere, which is of course ok, I definitely learned something.
2. Please link to the relevant issues.
None
3. Which documentation changes (if any) need to be made because of this PR?
README.md, breaking changes should be explained in thebasic_authsection(s).4. Checklist