Monday, September 24, 2007

Reverse SSH Tunnel For Facebook Application Development

I have been playing around with developing Facebook applications recently, and I have found it difficult to setup a development environment because to test my application, Facebook needs to access it on a remote server. If my application is running on my workstation which is behind a firewall, then Facebook has no way to access it.

A friend at work told me about The RFacebook Tunnel which allows Facebook to connect to a port on a remote server which tunnels its traffic to a local computer. That is exactly what I need, except that I'm using Java instead of Ruby to develop my application. I started looking into doing this reverse tunneling myself just using the command line and found out that it is very easy!

All I needed to do was to issue this command from my workstation:

ssh -gNR 8888:localhost:8080 www.myremoteserver.com

This creates the tunnel so that any requests to www.myremoteserver.com:8888 are forwarded to my workstation on port 8080. Voila! Now Facebook can easily access the web application I'm running locally behind a firewall.

There was one little thing I left out. In order to get the tunneling to forward traffic from machines other than myremoteserver.com, I had to edit /etc/ssh/sshd_config and add the following line:

GatewayPorts yes

This site has some more information on why I had to do that.

9 comments:

Anonymous said...

dude, thanks.

Anonymous said...

this is really helpful. thanks so much

raj said...

Thanks for the info. However, I would like to be able to do the same but debug my application using Zend Studio (in PHP)... if anyone has any pointers on how that might be achievable, I'd be very interested..

makuchaku said...

Thanks alot! This helped! :)

chacha said...

Hi Ken,

I was also trying my hand at heroku. (my first try at heroku, RoR and facebook app collectively)

A simple test program using Facebooker app is running quite nice on my dev env. And I have ported it to http://evntize.heroku.com/evntize
But now when I go to http://apps.facebook.com/evntize I see a blank page there. My canvas url is http://evntize.heroku.com/evntize
Facebooker.yml has public port as 80 local port as 3000 (not sure how can I check my local port though) have used my mail id (abhishek.mancoha@gmail.com) as my public_host_user_name

I am almost 100% sure that the problem is with the tunnel setup.
My first question is do I need to be running heroku rake facebooker:tunnel:background-start on heroku? Is it even possible because on lots of blog post I have seen that heroku doesn’t support ssh and root access. Then how to go about it?

Do you have facebook app demo/video on heroku?

Also I have included Facebooker in tmp\vendor\plugins of my app. Haven't been able to install rails plugin Facebooker on heroku was getting the wrong version of marshal file on trying to install that?

Would be very thankful if you can help me out. Really want to go as fast as possible.

chacha said...

hi,

As I understand /etc/ssh/sshd_config on your local machine or on the www.myremoteserver.com needs to be modified with this line (this line added)

GatewayPorts yes

which sshd_config i mean?

Ken said...

chacha, sorry but I don't have much experience with Heroku. Regarding your question about which ssh_config to modify, it was the one on your local machine.

chacha said...

ok, no probs, thanks, i will give it a shot.had hard time on gfreaku sunday yesterday to get that working though. and my OS was windows that didnt help the cause a lot too.

facebook fanpage said...

HI ! One of the most frustrating things I found early on when working on facebook applications, was that there was no simple way to create a local development environment. Because so many of the features of the platform existed only when the code was executed THROUGH the facebook proxy (fbml parsing, fb:ref cache content, etc), I found myself in an almost endless cycle of “svn commit”, “svn up” on the test server.