-
-
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
A way to get actual client IP #4924
Comments
That's by design. The logs show the original headers as Caddy received them. The log entry is provisioned before any handling happens. To clarify, the |
No apology needed. 😃 |
@francislavoie @mholt Thank you for your prompt responses. Do you think it's possible to achieve what i want using any currently available method? right now i can only think of the following possible means all probably involve caddy modifications either via plugin or official support.
|
If I understand correctly, you want to emit a value to your log entries that basically is the result of this Javascript-like-pseudocode: |
Indeed thats what i want. |
Thanks for taking time to consider this. Is there any specific approach you would like to see this implemented in? i have little golang experience i may be able to contribute something if it's not too deep. |
Thanks for offering! Well, the implementation itself should be simple enough. But I think we may need to answer some questions first, like how to know whether to trust the X-Forwarded-For header. The reverse proxy has configuration to allow the header only from certain clients. We would need something similar for this mechanism to be trustworthy. That will require some thought/discussion. |
Thinking out loud here, if i was to propose a caddy wide solution i think something like this might be appropriate.
Of course this probably huge undertaking, but i think it's the correct way. On personal note, having alternative value for the transformer plugin is enough for majority of the cases. For example, |
That actually sounds like a pretty good solution. Definitely some work there, but would be happy to review a PR for it. (Am a little busy currently!) |
Sorry for the late reply, dealing with COVID infection is not fun, I'll see if i can make PR for it |
I have other priorities to focus on first, but I can work on this later. My rough plan:
|
@francislavoie Thank you, Sadly my golang and caddy internal experience is too weak to attempt this. So, instead i switched my focus to attempt to add support for defualt/alternative value for the transformer plugin. |
FYI @arabcoders I implemented the first half of what I was talking about in #5103 |
Thank you this is really great |
@francislavoie thanks for your work on this, this is going to be epic 🥳 |
This can be closed, we merged the aforementioned pull requests which implement first-party client IP support! |
Hello,
It seems using
request_header
directive to alter request headers does not make it to thelog
directive, i mainly use the transformer plugin to alter the logged IP, some requests are via CDN others directly, and it seems caddy does not always setX-Forwarded-For
which i think is probably the intended behavior. Anyway here is an example of the behavior i am describingas you can see from the output, it's clearly being set.
However, the logger does not show the header.
i expect to see the added header to show up, however it seems the log directive receive the unmodified request object. If that's the intended behavior, then i apologize.
I have log analyzers and they are failing due to missing IP in logs as some requests originating locally or someone hitting the IP directly instead of the frontend proxies.
The text was updated successfully, but these errors were encountered: