-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
caddyhttp: Determine real client IP if trusted proxies configured #5104
Conversation
ac1cb56
to
7628d2d
Compare
3352853
to
1c91e53
Compare
7628d2d
to
f0fbc85
Compare
a2ef35e
to
cff0884
Compare
f0fbc85
to
470c728
Compare
cff0884
to
907b596
Compare
907b596
to
c90256a
Compare
I think this is essentially good to go. Un-drafting. |
@francislavoie Thank you for your work on this feature, is there any way I can help in getting this PR merged? |
I had a few other details I wanted to look at first, haven't had time yet. I need to think about changes to the I might need to adjust the type of the |
96fe028
to
7f97181
Compare
Okay, I think I'm done now?
|
7f97181
to
4325b3f
Compare
4325b3f
to
41be6d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wow, this is impressive.
Thank you for working on this, I think it will provide a lot of value and added security for Caddy services.
Wow, @francislavoie this works amazingly, tested it fully and also with the "Rate Limit" plugin and it works just perfectly. Thanks so much for working on this 🥇 |
Tried! Just wow @francislavoie 🤗 working fine, it was a really necessary requirement when we do "Rate Limit". Waiting for official release 😊
|
2.7 beta 1 will be coming soon :) |
Followup on #5103 and #5328.
This introduces first-class support for determining the client IP, at the HTTP server level. Also adds a placeholder and writes it to the access logs.
I'm marking this as a draft for now, because this has a certain level of risk, and needs discussion. We need to be extra careful about the implementation.
I'm taking @adam-p's guidance on this from his excellent article https://adam-p.ca/blog/2022/03/x-forwarded-for/. There's a few different valid approaches to this. This implementation takes the left-most, first valid IP. I'm not excluding private IPs, because actually it happens frequently that users want their LAN IP to be used as the real client IP, in home networking contexts.
Currently, the header used is not configurable, I have it just set toI implemented this as a fallback list of headers. This is configured on the server itself, alongside theX-Forwarded-For
which is typically good enough, but I think to be robust we'll need to make that configurable. Do we only allow a single header field, or do we allow a fallback list?trusted_proxies
.Another open question (also applicable to #5103, maybe we should figure this out before merging that), should we make trusted IP sources pluggable?We did make it pluggable in #5328. We provide a "static" module by default. The argument for that is that proxies like Cloudflare have a ton of IP ranges, and users managing that in their config is annoying. So a plugin module would be able to periodically fetch and cache their IP list.I decided that the
client_ip
should always be set (as long as theRemoteAddr
is a valid IP address). So in the logs, it will be identical to theremote_ip
unless trusted proxies is configured and the proxy passed the client IP in a trusted header.