Trouble with Logging Changes

Hello,

in Caddy 2.5, logging remote_addr was depreciated in favor of remote_ip. I maintain the RealIP plugin which changes the remote_addr of a request to be the value of a specific header, usually X-Forwarded-For:

Historically the operation of the plugin has always been a bit weird, since if you look directly at the system logs you see the unaltered IP as remote_addr, but if you enable access logging with common_log format you’d see the replaced value

That is because the original request was logged before passing to the handlers. However the common_log variables got updated after the handlers as shown at these 2 lines prior to v2.5:

With Caddy 2.5, the request variables that would allow the plugin to function are not updated after the request passes thru the handlers as shown here:

What options would be available to repair the original functionality?

2 Likes

I don’t think we can reasonably make it possible for a request handler to modify the logs being output. Your plugin has a flawed design, it’s trying to mutate something that’s inherently immutable. The point of the request log is to show the request as Caddy received it.

The correct thing to do would be to use the PROXY protocol for your downstream proxy to pass the original client IP. See https://www.haproxy.org/download/1.8/doc/proxy-protocol.txt and GitHub - mastercactapus/caddy2-proxyprotocol.

Or alternatively, post-process the logs with some tool/script to read the X-Forwarded-For header values in the log and shove it in the remote_ip field.

2 Likes

I just wanted to leave a note to Thank You for writing this very useful plugin.

Would you plan to use the PROXY protocol for your downstream proxy to pass the original client IP? It would open up the plugin a lot

1 Like

thanks for the info @francislavoie

@gcss thank you, i need some time to look into this and figure out options.

2 Likes

This topic was automatically closed after 30 days. New replies are no longer allowed.