I'm using CloudFront as a proxy for my EC2 instance, so all traffic is routed through CloudFront first.
The issue is that I also need the original client's IP address for each request to my EC2 instance, so I need to examine the X-Forwarded-For
to find out the original IP address (as the default IP my EC2 receives is just the CloudFront server's)
I found this article which discusses how to find the original client IP when using a middle-man proxy such as CloudFront.
Their proposed solution is to list of all CloudFront's Edge Server IP ranges in your NGINX configuration, and then read X-Forwarded-For
IP's from right-to-left, and forward the first one that isn't a trusted IP address (one listed in the NGINX config)
This all sounds well and good, but what if a CloudFront edge server IP range changes, such that I would have to update the NGINX configuration? I really don't want to have to write some sort of custom script that constantly downloads their ip ranges JSON file, parses it, updates my NGINX configuration file, and restarts NGINX if it has changed. That seems like a lot of work and potential failure points.
I suppose it wouldn't be much of an issue if I am relatively guaranteed that these CloudFront ip ranges are rarely going to change (as in, perhaps only once every 5 years or so), but I can't find whether or not there is some sort of guarantee like that, or any individuals reporting their experience with such.
How should this situation be handled?