Paxxs / traefik-get-real-ip

traefik get the real IP from the X-Forwarded-For or CDN specified header field.
59 stars 11 forks source link

Support for CloudFront-Viewer-Address #8

Closed ymc-dabe closed 1 year ago

ymc-dabe commented 1 year ago

Hi @Paxxs

Would it be possible to add support for the header CloudFront-Viewer-Address, which AWS CloudFront is using? It is in the format CloudFront-Viewer-Address: IP:PORT - e.g.: CloudFront-Viewer-Address: 192.0.2.99:4321

AWS documents this here: https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/adding-cloudfront-headers.html

It should be rather easy to add support for this with the function net.SplitHostPort(), which already is used in your plugin's code (for the header RemoteAddr). Maybe it would be an idea to always split out the port from the IP (and not just for RemoteAddr and potentially CloudFront-Viewer-Address).

Thanks a lot for the plugin for your plugin and your continued support for it.

Paxxs commented 1 year ago

Hi @ymc-dabe

Thank you for your issue, I'm very glad that you are interested in my plugin and have made valuable suggestions. :)

I have added the support of parsing IP addresses with port numbers, and now the plugin can identify IP address in the following formats regardless of whether they have port numbers:

so you can use the following configuration to support the CloudFront-Viewer-Address header in v1.0.3:

# CloudFront-Viewer-Address: IP:PORT
   - proxyHeadername: X-From-Cdn
     proxyHeadervalue: cf-foo
     realIP: CloudFront-Viewer-Address

Please try the new version, if you have any questions or feedback, please feel free to contact me. Thank you again for your support and contribution! 🙏

ymc-dabe commented 8 months ago

Hi @Paxxs

I just wanted to let you know, that this works like a charm. Thanks a lot and sorry for not providing a timely feedback.