Skip to content

Add support for Caddy 2#74

Merged
mholt merged 58 commits into
masterfrom
caddy2
Feb 12, 2024
Merged

Add support for Caddy 2#74
mholt merged 58 commits into
masterfrom
caddy2

Conversation

@mholt

@mholt mholt commented Apr 20, 2020

Copy link
Copy Markdown
Member

All the tests pass. I tried to keep as much as possible the same, but a
few things don't translate well to Caddy 2, notably one test in
probe_resist_test.go on L200, I had to change that test case since I
didn't quite understand why it was the way it was before.

Have not vetted this for privacy or security guarantees. Do not rely on this code.

Example config:

{
	"apps": {
		"http": {
			"servers": {
				"srv0": {
					"listen": [
						":443"
					],
					"logs": {},
					"routes": [
						{
							"handle": [
								{
									"handler": "forward_proxy"
								}
							]
						},
						{
							"match": [
								{
									"host": ["foo.localhost"]
								}
							],
							"handle": [
								{
									"handler": "static_response",
									"body": "Yahaha! You found me!"
								}
							]
						}
					]
				}
			}
		}
	}
}

@sergeyfrolov Please give this a once-over if you have a chance. Or better yet, ping me in Slack so I can give you a brief walkthrough of the changes. It'd be good to have an extra set of eyeballs review any sensitive parts that I might have (probably) botched up.

I also wonder if we can remove basicauth logic out from this code and use Caddy 2's existing basicauth module instead. Let's chat when you have a chance. But, if I don't hear from you in the next couple weeks I might just go ahead anyway.

Thanks!

All the tests pass. I tried to keep as much as possible the same, but a
few things don't translate well to Caddy 2, notably one test in
probe_resist_test.go on L200, I had to change that test case since I
didn't quite understand why it was the way it was before.

Does not yet have v2 Caddyfile support.
@mholt
mholt requested a review from sergeyfrolov April 20, 2020 23:25
@mholt mholt mentioned this pull request Apr 20, 2020
Comment thread forwardproxy.go Outdated
@mholt mholt mentioned this pull request Jun 20, 2020
4 tasks
* Fix probe_resistance config parsing

* Support Caddyfile

* Support HTTP/3

* Revert "Support HTTP/3"

This reverts commit f01c163.

* Fix review comments

* Update README.md to new directive names

* Use Caddy 2 logger
@mholt

mholt commented Dec 3, 2020

Copy link
Copy Markdown
Member Author

@sergeyfrolov Do you think you'd have a chance to look this over or try it out soon?

@sergeyfrolov sergeyfrolov left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @mholt!
Sorry I haven't paid much attention to my open-source projects lately. Between academia and new full-time job I don't have much extra energy.

I took a look at the code and left some comments.

I specifically looked through the new ServeHTTP function to see if correct probe-resistance behavior is preserved, and it appears to be. Haven't yet checked why probe-resistance tests fail, but we can fix them after ensuring that it does actually work correctly. The most bulletproof way to do that would be to spin up 2 Caddy servers: one without forwardproxy, and another with forwardproxy and probe_resistance and see if there's a difference in their responses to requests. How about we try to do that today or tomorrow evening (or some other evening)?

Comment thread acl.go
Comment thread forwardproxy.go
Comment thread forwardproxy.go Outdated
Comment on lines +72 to +73
BasicauthUser string `json:"auth_user,omitempty"`
BasicauthPass string `json:"auth_pass,omitempty"`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we add those 2 fields, instead of using the existing authCredentials slice? How does this temporary solution help tests and why can't we re-use existing credentials checking code?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields are here so users can access them via configuration. Otherwise the authCredentials field is unexported so the JSON unmarshaler can't reach it.

I am hoping to remove auth from this module entirely, and let Caddy's existing authentication handler deal with it. Do you think that's possible?

Comment thread forwardproxy.go Outdated
@mholt
mholt marked this pull request as ready for review December 4, 2020 17:17
@mholt

mholt commented Dec 4, 2020

Copy link
Copy Markdown
Member Author

@sergeyfrolov Thanks for taking a look!

I guess the main thing to verify now is the probe resistance and authentication. I'm hoping we can remove the authentication logic entirely...

When do you have time today or this weekend? (Feel free to ping me in Slack at your convenience.)

@mholt mholt changed the title Begin refactor for Caddy 2 Support Caddy 2 Dec 4, 2020
@mholt

mholt commented Sep 12, 2021

Copy link
Copy Markdown
Member Author

Btw, I think this is probably good to go for most people, if we are OK with being complacent about the failing test case.

@mholt mholt mentioned this pull request Dec 28, 2021
@gaby gaby changed the title Support Caddy 2 Add support for Caddy 2 Nov 5, 2023
@klzgrad

klzgrad commented Nov 7, 2023

Copy link
Copy Markdown
Contributor

All tests are green. Any remaining issues?

@WeidiDeng

Copy link
Copy Markdown
Member

There are some uses of http.Flusher which won't work if logging is enabled. These two parts need to be changed 361 and 500. This diff only covers part of the issue.

@johnzhanghua

Copy link
Copy Markdown
Contributor

There are some uses of http.Flusher which won't work if logging is enabled. These two parts need to be changed 361 and 500. This diff only covers part of the issue.

Is that related to this PR ? @gaby what is blocking this merge ?

@WeidiDeng

Copy link
Copy Markdown
Member

There are some uses of http.Flusher which won't work if logging is enabled. These two parts need to be changed 361 and 500. This diff only covers part of the issue.

Is that related to this PR ? @gaby what is blocking this merge ?

It's related in that if it's not fixed, this plugin won't work if you need access logs.

@gaby

gaby commented Nov 9, 2023

Copy link
Copy Markdown
Collaborator

@WeidiDeng I will fix it thus weekend. Thanks!

@johnzhanghua Only a few things left, cleaning up the readme, updating the docker file + workflow,

We could probably merge after that and do a release candidate.

@FrostKiwi

Copy link
Copy Markdown

So happy to see the commit yesterday. Looking forward to a potential merge.

@gaby

gaby commented Jan 27, 2024

Copy link
Copy Markdown
Collaborator

Tests are now run in:

  • Linux
  • Windows
  • MacOS This one gets stuck

TODO:

  • Add coverage report
  • Update dependencies
  • Migrate default branch to main
  • Add Benchmarks
  • Migrate tests to testify
  • Update/Cleanup README
  • Docker

@fbuetler

fbuetler commented Feb 1, 2024

Copy link
Copy Markdown

Just stumbled over this PR as I am looking for a way to use caddy as a forward proxy. Nice work!

I reviewed the caddy2 branch and would like to note some points:

  • The module handles proxy authentication itself. But I'd argue this functionality can be removed in favor of http.authentication.providers like http_basic. A comment even mentioned this should only be temporary.
  • It would be nice to have the same plugin functionality for the transport as there is in the reverse proxy module, but I don't know how this is gonna work with the custom dial functionality (this is more of a nice-to-have feature for the future).

@klzgrad

klzgrad commented Feb 1, 2024

Copy link
Copy Markdown
Contributor

Please reduce scope and get this merged first after 3 years and we can talk about more improvements.

Including

Add coverage report
Add Benchmarks
Migrate tests to testify
Update/Cleanup README
Docker

which I argue are non-essential work before the merge.

@gaby

gaby commented Feb 12, 2024

Copy link
Copy Markdown
Collaborator

@mholt This should be good to merge now. Pending issues and documentation can be handle in a separate PR.

@mholt

mholt commented Feb 12, 2024

Copy link
Copy Markdown
Member Author

Acknowledged. Thank you for your help with it!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants