Skip to content
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

Add ability to read client's real IP from other HTTP headers #429

Closed
GUI opened this issue Feb 1, 2018 · 1 comment
Closed

Add ability to read client's real IP from other HTTP headers #429

GUI opened this issue Feb 1, 2018 · 1 comment

Comments

@GUI
Copy link
Member

GUI commented Feb 1, 2018

We had a new situation crop up where a specific agency subdomain needed had another proxy in front of our api.data.gov service. This meant that by default, we were treating all of the traffic as though it was coming from this other proxy's IP. This in turn would skew our analytics and rate limiting, since all of the traffic would appear to come from just a couple IPs (the proxy IPs), rather than the real IPs used by the clients.

In order to fix this, we need to be able to read the original client's IP address from a different HTTP header. Normally, we read this information from the X-Forwarded-For HTTP header, and we configure which servers we trust this forwarded information from. However, for this specific case, we need to read this information from the True-Client-IP header.

@GUI
Copy link
Member Author

GUI commented Feb 1, 2018

Implemented in NREL/api-umbrella@ace38b9

This doesn't expose this functionality within the admin, but does give us a way to manually configure this behavior on a per-host basis with our hosts configuration (so api.data.gov server admins can make this tweak). We're basically just exposing a way to configure nginx's realip module for individual hosts. The various settings can be tweaked to adjust which HTTP header is used, and how to trust this header based on its origin. Since the realip module directly hooks into nginx's IP handling, this propagates everywhere else we need within the app, since it automatically affects the IP we read everywhere else (for logging, rate limiting, and appending to our own X-Forwarded-For).

Our server configuration tweaks to enable this: https://github.com/18F/api.data.gov-ops/commit/9d92df3be708c470bb61c0fdbea3524e1078cc3c

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant