| Author |
Message |
hemi
Joined: 17 Nov 2011
Posts: 3
|
| Posted: Thu Nov 17, 2011 10:06 pm Post subject: Nodebalancer, HTTPS, and remote IP in PHP |
|
|
Hi,
We're looking at putting a couple of LAMP application servers behind a nodebalancer using HTTPS (via the TCP option).
The application will need to determine client IPs in PHP, along the lines of
Code: function ipCheck() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}
elseif (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}
elseif (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}
elseif (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}
elseif (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}
else {
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
Reading this post though: http://forum.linode.com/viewtopic.php?p=42704 I'm wondering if this is actually possible. Can anyone advise?
Thanks |
|
| Back to top |
|
hoopycat
Joined: 30 Aug 2008
Posts: 1294
Location: Rochester, New York
|
| Posted: Thu Nov 17, 2011 10:29 pm Post subject: |
|
|
With HTTPS through a load balancer, the connection is encrypted end-to-end. There's no way for the load balancer to modify (or even see) the contents, so there's no in-band way for it to communicate the client's actual IP address.
Just because you're paying for the man in the middle doesn't mean he's not a man in the middle :-)
If I had to come up with one possible method to do this right now, it would involve triggering a single, brief, non-blocking HTTPS request directly to a web server under your control (i.e. not load balanced) with an identifier (i.e. a session ID) tying it to the main session. You then have two IP addresses for that session and can eliminate the NodeBalancer one.
Also, based on that code snippet, I'm 99% sure you've never used VHDL. ;-) |
|
| Back to top |
|
hemi
Joined: 17 Nov 2011
Posts: 3
|
| Posted: Sun Nov 20, 2011 7:49 pm Post subject: |
|
|
Thanks Hoopycat. Looking into possible workarounds now.
And no I've never dealt with VHDL, although the code snippet is copypasta to illustrate the point - I didn't write it.
Cheers. |
|
| Back to top |
|
Azathoth
Joined: 07 Dec 2009
Posts: 263
|
| Posted: Mon Nov 21, 2011 5:09 am Post subject: |
|
|
hoopycat wrote:
If I had to come up with one possible method to do this right now, it would involve triggering a single, brief, non-blocking HTTPS request directly to a web server under your control (i.e. not load balanced) with an identifier (i.e. a session ID) tying it to the main session. You then have two IP addresses for that session and can eliminate the NodeBalancer one.
+1
That's what I would do too, except you don't need to bypass the nodebalancer. If your session has no remote IP set, then redirect the user to a plain http URL where the handler will store the IP and redirect back to https.
You can either have a dedicated URL handler or simply put that at the top of the request chain. |
|
| Back to top |
|
mnordhoff
Joined: 03 May 2008
Posts: 451
|
| Posted: Mon Nov 21, 2011 7:44 am Post subject: |
|
|
Azathoth wrote: +1
That's what I would do too, except you don't need to bypass the nodebalancer. If your session has no remote IP set, then redirect the user to a plain http URL where the handler will store the IP and redirect back to https.
You can either have a dedicated URL handler or simply put that at the top of the request chain.
Except for the fact that that would mean leaving HTTPS. That would be more or less safe for a little Ajax call, but doing a redirect would easily enable SSL stripping attacks. |
|
| Back to top |
|
Azathoth
Joined: 07 Dec 2009
Posts: 263
|
| Posted: Mon Nov 21, 2011 9:26 am Post subject: |
|
|
mnordhoff wrote:
Except for the fact that that would mean leaving HTTPS. That would be more or less safe for a little Ajax call, but doing a redirect would easily enable SSL stripping attacks.
Technically, yes, but that could be done regardless. SSL is broken anyways. |
|
| Back to top |
|
hoopycat
Joined: 30 Aug 2008
Posts: 1294
Location: Rochester, New York
|
| Posted: Mon Nov 21, 2011 10:05 am Post subject: |
|
|
Azathoth wrote: Technically, yes, but that could be done regardless. SSL is broken anyways.
So is the Internet, but we still use it and work around its foibles. |
|
| Back to top |
|
funkytastic
Joined: 10 Aug 2008
Posts: 99
Location: ~$
|
| Posted: Mon Nov 21, 2011 1:18 pm Post subject: |
|
|
| That VHDL reference went over my head. Are we mailing FPGAs to Caker now? |
|
| Back to top |
|
hoopycat
Joined: 30 Aug 2008
Posts: 1294
Location: Rochester, New York
|
| Posted: Tue Nov 22, 2011 9:35 am Post subject: |
|
|
The long chain of if/elseif/else squicked my optimization nerve a bit. :-) I started thinking "how could I reimplement that as a mux" before I realized it didn't matter one lick.
(That, and the conditions aren't mutually exclusive.) |
|
| Back to top |
|
| |