Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get forwarded IP after Caddy 2.4.6. #15

Closed
JackBailey opened this issue Feb 8, 2023 · 16 comments · Fixed by #19
Closed

Get forwarded IP after Caddy 2.4.6. #15

JackBailey opened this issue Feb 8, 2023 · 16 comments · Fixed by #19

Comments

@JackBailey
Copy link

JackBailey commented Feb 8, 2023

realip doesn't work after Caddy 2.4.6.

How should retrieving remote ips be done behind a proxy after Caddy 2.4.6?

@hslatman
Copy link
Owner

hslatman commented Feb 8, 2023

Interesting. Thank you for the heads-up.

I think a solution would involve using the changes that are being worked on as discussed in this issue: caddyserver/caddy#4924. I'll have to check it out to see if changes are required for this bouncer.

@JackBailey
Copy link
Author

Caddy v2.6.3 has been released adding a global trusted_proxies option - caddyserver/caddy#5103

Does this addition help at all with this issue?

@dd310
Copy link

dd310 commented Jun 17, 2023

Caddy 2.7.0-beta1 introduced client_ip in the logs.
Maybe the bouncer could be updated to support this new feature?

caddyserver/caddy#5104

@hslatman
Copy link
Owner

hslatman commented Jun 20, 2023

@dd310 thank you 🙂

I've started a PR to upgrade the dependencies. Will need to do some testing with the new Caddy beta.

If things look good, I can cut a new release. After that I'll upgrade other dependencies too for yet another release.

@dd310
Copy link

dd310 commented Jun 24, 2023

Thank you for your time!

I noticed caddy 2.7 beta 2 is out, and I guess the next release will be stable.

@JackBailey
Copy link
Author

Looks like Caddy 2.7 stable is out now, any updates on this?

@hslatman
Copy link
Owner

hslatman commented Aug 9, 2023

@JackBailey you're right! 🙂

I've been working on the PR and updating it several times, because there were some last-minute breaking issues in Caddy. But on v2.7.3 things are looking OK: #18.

I intend to release this very soon now. Need to find a bit of time, because I have some follow-up wants/wishes and also want to find out what's the best way to go about the "real client IP": would it only be some configuration, or will code changes be required; or maybe both? This issue will likely help me do the right thing 🙂

@serfriz
Copy link

serfriz commented Aug 16, 2023

Hey, I saw there is a new release, does it already include the additional changes to use the real IP of clients when the proxy is behind Cloudflare? Thank you!

@JackBailey
Copy link
Author

JackBailey commented Aug 16, 2023

Need to find a bit of time, because I have some follow-up wants/wishes and also want to find out what's the best way to go about the "real client IP": would it only be some configuration, or will code changes be required

It looks like client_ip will return the proper ip, works fine for me @hslatman

Trying to use Crowdsec with Caddy 2.7 gives me the error in #17, not sure if that's because of Caddy 2.7 or not, but looks like an issue trying to retrieve api_url from the config.

@iurab
Copy link

iurab commented Aug 16, 2023

With Caddy 2.7, I can also see the real ip in the client_ip field.
I've tried a temporary ban in crowdsec for my ip and the site was still reachable. So I guess caddy-crowdsec-bouncer it's not yet updated to use it.

@dd310
Copy link

dd310 commented Aug 16, 2023

I can also confirm that caddy 2.7.3 will return client_ip correctly when i set client_ip_headers Cf-Connecting-Ip

@hslatman
Copy link
Owner

I still need to take a look at the client_ip; it's not in the latest release yet, but I'll make a new one when it works with that. Will do it ASAP when time allows.

@dd310
Copy link

dd310 commented Aug 17, 2023

Thank you for the great work!

@hslatman
Copy link
Owner

hslatman commented Aug 17, 2023

The release is out: https://github.com/hslatman/caddy-crowdsec-bouncer/releases/tag/v0.3.1. I've tested it locally only, but the results look OK 🙂

@JackBailey do you still have that issue with the API URL? I don't think it's related to the Caddy version, as mine parsed fine, but then again, I'm usually testing with a local config.json. Maybe pushing it via the admin API makes a difference?

@iurab did you test it with a proxy in front, or without? Without a proxy it should still have worked on the old release, but it depends on whether you use the streaming bouncer or the live bouncer. The streaming bouncer will poll every X period of time, based on the ticker interval. The live bouncer will perform a look up every HTTP request. If you're using the streaming bouncer (the default), the decision may not have been received by the bouncer yet.

The streaming bouncer is technically not really a streaming bouncer, but it's the name the CrowdSec team gave to the Go package I'm using in this bouncer.

@dd310
Copy link

dd310 commented Aug 17, 2023

Just for the sake of clarity, I think it may be helpful to include in the readme that trusted_proxies needs to be set globally and that it might be necessary to use client_ip_header to choose where client_ip is read from (e.g. with Cloudflare it only works by specifing Cf-Connecting-Ip)

@hslatman
Copy link
Owner

@dd310 thanks! I've pushed a commit that directs users to the Caddy docs on those: 12a8d66.

I might add some example configurations using that in the near future. I've also been thinking about some more elaborate example setups, so it might become part of that too.

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 a pull request may close this issue.

5 participants