views:

346

answers:

8

We have a product we are deploying to some small businesses. It is basically a RESTful API over SSL using Tomcat. This is installed on the server in the small business and is accessed via an iPhone or other device portable device. So, the devices connecting to the server could come from any number of IP addresses.

The problem comes with the installation. When we install this service, it seems to always become a problem when doing port forwarding so the outside world can gain access to tomcat. It seems most time the owner doesn't know router password, etc, etc.

I am trying to research other ways we can accomplish this. I've come up with the following and would like to hear other thoughts on the topic.

  1. Setup a SSH tunnel from each client office to a central server. Basically the remote devices would connect to that central server on a port and that traffic would be tunneled back to Tomcat in the office. Seems kind of redundant to have SSH and then SSL, but really no other way to accomplish it since end-to-end I need SSL (from device to office). Not sure of performance implications here, but I know it would work. Would need to monitor the tunnel and bring it back up if it goes done, would need to handle SSH key exchanges, etc.

  2. Setup uPNP to try and configure the hole for me. Would likely work most of the time, but uPNP isn't guaranteed to be turned on. May be a good next step.

  3. Come up with some type of NAT transversal scheme. I'm just not familiar with these and uncertain of how they exactly work. We have access to a centralized server which is required for the authentication if that makes it any easier.

What else should I be looking at to get this accomplished?

A: 

Set up an Apache in front of your Tomcat. This Apache should be visible from the internet, where the Tomcat should not.

Configure Apache to forward all traffic to the Tomcat. This can easily be accomplished using mod_proxy (check out the ProxyPass and ProxyPassReverse directives).

Have your SSL certificate located in the Apache, so that all clients can talk HTTPS with the Apache server, which in turn talks plain HTTP with Tomcat.

No tunneling or other nastyness + you will be surprised how easy it is to configure Apache to do this.

Eric Eijkelenboom
I don't think you understood the question. Tomcat is on a private IP address behind the Nat. Putting Apache in front of it won't solve anything. People outside the Nat still need to access the service be it Tomcat or Apache. I already have Tomcat running SSL answering on a port. It's just that I need to punch the hole in the firewall and I'm trying to avoid that.
jr
Yes, the solution above assumes that Apache is outside your private network, and that Apache and Tomcat talk with each other through a hole in the firewall. Sorry for not being more explicit about that. With this setup, clients do not need direct access to your private network, since all requests come in via the Apache server. In my eyes, this makes for a safe and maintainable setup. Especially since the hole in the firewall is only open for the IP address of the Apache server, and you can secure the Apache all you like.
Eric Eijkelenboom
I would still need to punch the hole in the firewall, which is what I am trying to avoid.
jr
Yes, I realize that (bwt: it is not clear from your original question that you are trying to avoid that). I guess my point is that punching a hole in the firewall might be worth it, if the result is a clean, secure and user-friendly setup.
Eric Eijkelenboom
+5  A: 

Is there no way this service can by hosted publicly by you or a hosting provider rather than with the customer?

I had a similar situation when i was developing kiosks. I never knew what type of network environment i'd have to deal with on the next installation.

I ended up creating a PPTP VPN to allow all the kiosks to connect to one server i hosted publicly. We then created a controller web service to expose access to the kiosks that were all connected via the VPN. I'm not sure how familiar you are with VPN's but with the VPN connection i was able to completely circumvent the firewall in front of each kiosk by accessing the kiosk via the VPN assigned IP.

Each kiosk node was incredibly easy to setup once i had a VPN server setup. It also brought management benefits and licensing revenue i originally didn't think about. with this infrastructure i was easily able to roll out services accessible via mobile phones.

Best of luck!

used2could
+2  A: 

Solutions exist to "dynamically" access a software on a computer behind a NAT, but usually mostly for UDP communication.

The UDP hole punching technique is one of them. However, this isn't guranteed to work in every possible situation. If both sides of the communication are behind a "Symmetric Cone NAT" it won't.

You obivously can reduce the probability a client can't communicate using UPnP as a backup (or even primary) alternative.

I don't know Web Services enough and don't even know if using UDP for your webservice is an option (or if it is even possible).

Using the same technique for directly TCP is likely to fail (TCP connections aren't stateless - that causes a lot of problems here).

An alternative using the same technique, would be to set up some VPN based on UDP (just like OpenVPN), but as you stated, you'll have to manage keys, certificates, and so on. This can be automated (I did it) but still, it's not really trivial.

===EDIT===

If you really want to use TCP, you could create a simple "proxy" software on the client boxes which would serve as a relay.

You would have the following schema:

  1. Web Service on client boxes, behind a NAT
  2. The "proxy" software on the same boxes, establishing an outgoing (thus non-blocked) TCP connection to your company servers
  3. Your company servers host a WebService as well, which requires a something like a "Client Identifier" to redirect the request to the adequate established TCP connection.
  4. The proxy program interrogates the local WebService and send back the response to the company servers, which relay the response to the originate requester as well.

An alternative: you might ask the proxy software to directly connect to the requester to enhance performance, but then you might encounter the same NAT problems you're trying to avoid.

ereOn
Thanks. I'd like to keep things based on HTTP, so need to stick with TCP. I really need a solution where the server behind the nat initiates an outbound TCP connection and maintains it, allowing inbound TCP connects to come across it and be destined for a certain port.
jr
@jr You're welcome. I wish there was a solution similar to UDP for TCP. Unfortunately, routers and firewalls are usually smart enough to figure out when a TCP connection is an inbound or an outbound one. Thus, the described technique can't work. I however updated my answer to suggest a **new possible solution**.
ereOn
+1 this is how Hamachi and Skype (and, someday in the distant future, Cryptolink) work.
BlueRaja - Danny Pflughoeft
@BlueRaja: What is Cryptolink ?
ereOn
VPN software that's supposed to work 100x better (and easier) than anything we have now. Steve Gibson keeps talking about it on his amazing podcast, [Security Now!](http://www.grc.com/securitynow.htm) - he's been writing it (single-handedly, in assembly language) for years...
BlueRaja - Danny Pflughoeft
A: 

I had to do something similar in the past and I believe the best option is the first one you proposed.

You can do in the easy way, using ssh with its -R option, using publick key auth and a couple of scripts to check for connectivity. Don't forget the various keep alive and timeout features of ssh.

Don't worry about the performances. Use unprivileged users and ports if you can. Don't bother to setup a CA, the public key of each remote server is easier to maintain unless you are in the thousands.

Monitoring is quite simple. Each server should test the service on the central server. If it fails either the tunnel is down or there's no connectivity. Restarting the tunnel will not harm in any case.

Or you can do it at the network level, using IPsec (strongswan). This can be trickier to setup and it's the option I used but I will use SSH the next time, it would have saved me a lot of time.

dwery
A: 

If you want to have a RESTful integration to the client server, a tunnel to the central server that works as a proxy, seems the best approach.

But if this is not a hard requirement, you can let the central server handle the RESTfull stuff and integrate the central server and client server with other middleware. Good candidates would be RMI or JMS. For example, a RMI connection initiated by the client allows the server to do RMI calls to the client.

Kdeveloper
Does RMI work over straight HTTP when the request is initiated on the server? I haven't looked at RMI for years, at that time RMI couldn't do a push from the server over HTTP.
mdma
I don’t think the RMI http tunnel will solve anything. The problem is that the ‘clients server’ is behind a NAT firewall and thus must always initiate the connection to the ‘central server’ (if you don’t do port forwarding). With RMI you initiate that connection to the ‘central server’ so that the ‘central server’ can use callbacks to connect to the ‘clients server’ (BTW RMI over http does not support callbacks).
Kdeveloper
A: 

+1 for going with a SSH tunnel. It's well known, widely available and not too hard to configure.

However, as you point out, you are running SSL already, so the SSH encryption is redundant. Instead of SSH you could just use a regular tunneling proxy, that provides the tunnelling without the encryption. I've used this one in the past, and it has worked well, although I didn't load test it - it was used with just a handful of users.

Here's a blog from someone who used the tunnelling proxy to access his webcam from outside his firewall.

mdma
+2  A: 

It's things like this that are the reason people are tunneling everything over http now, and why certain hardware vendors charge a small fortune for Layer 7 packet filtering.

This is a tremendous amount of work to fix one problem when the customer has at least three problems. Besides the one you've identified, if they don't know their own password, then who does? An administrator who doesn't work there anymore? That's a problem.

Second, if they don't know the password, that means they're almost certainly far behind on firmware updates to their firewall.

I think they should seriously consider doing a PROM reset on their firewall and reconfiguring from scratch (and upgrading the firmware while they're at it).

3 birds, one stone.

Jason
+1 - although I've frequently used hole-punching techniques for quick one-off tests or demos, for a long-term solution this is the REAL answer...
Stobor
In a perfect world yes... but in a real world, the client just never listens, and asks you to resolve *his* problem, not the *real* one. :/
ereOn
A: 

You could try to connect to an pc/ server and tunnel all the data via hamachi (Free VPN Software) because this tool you can install and it will create a reverse connection (from inside your nat to outside) so you can connect to it

site: http://hamachi.cc/

Spidfire