-
Notifications
You must be signed in to change notification settings - Fork 92
Log X-Forwarded-For (or similar) for every request #193
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
Log X-Forwarded-For (or similar) for every request #193
Conversation
Signed-off-by: Michel Hollands <[email protected]>
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.
Thanks for the PR; I made some comments below, mostly stylistic.
I think I can see three different changes here: removing lines from go.mod, adding source logging, and making standard middleware optional. Those should at least be three commits, but I wouldn't expect go.mod deletions in a PR like this. Maybe go.mod is wrong, but that would be a separate issue.
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
I've reverted the go.mod and go.sum changes. My mistake about the separate commits. I keep forgetting to do that. |
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
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.
Good job @MichelHollands! I left few comments, but overall LGTM 👍
Signed-off-by: Michel Hollands <[email protected]>
Signed-off-by: Michel Hollands <[email protected]>
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.
LGTM! (modulo a couple of nits)
Signed-off-by: Michel Hollands <[email protected]>
|
Can you explain a bit more where you envisage the optional header and regex flags being useful? |
Some enterprise customers use non-standard headers (ie different from Forwarded, X-Real-IP and X-Forwarded-For) in their custom reverse proxies. Using a regex as a way to configure this was suggested by Dee Kitchen. He used to work at Cloudflare where they used this successfully. An added benefit is that customers can configure the headers themselves. Some customers are not keen on giving details about their internal proxies or any internal networking setup for that matter. |
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.
I fear this feature is too complicated for a library like this, but I cannot spot any more flaws and it's behind a flag so I'll merge it.
Thanks!
This adds a field with the SourceIPs derived from X-Forwarded-For and the request address to the logging and tracing middleware. The
server.log-source-ipssetting is used to turn this one. By default it is not turned on.The
Forwarded,X-Real-IPandX-Forwardedheaders are examined in this order. If you want to use your own header provide a header name inserver.log-source-ips-headerand a regex to extract it inserver.log-source-ips-regex.Logs for successful requests are logged at debug level. This is how the log looks like after this change and after the logging level has been set to debug:
A sourceIPs tag is added while tracing:
Signed-off-by: Michel Hollands [email protected]