Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
PostPosted: Tue Mar 06, 2012 1:36 pm 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
Hi folks,

I'm using Node.js as my webserver.

I'd like to launch my application from a user account that has not been added to the sudoers file. As such, I need to bind to port 80 without becoming root.

The best method I've heard of so far is to create an iptables rule that forwards all traffic from port 80 to port 8080 (or whatever port), and then actually bind to that port instead of 80.

Has anyone done this on a linode? What iptables command did you use, and how did you save this configuration (I had troubles doing this)?

Finally, do you think this may reduce performance in some way, or do you know of a better way to bind to port 80?

Any feedback is highly appreciated.


Top
   
 Post subject:
PostPosted: Tue Mar 06, 2012 1:41 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
The correct approach is to run it as root and have the web server drop down to an unprivileged user once it binds the port. That's what everything else like Apache or nginx do. It's possible to do it with node.js too, although in this case you're actually implementing the behaviour:

http://onteria.wordpress.com/2011/05/31 ... n-node-js/


Top
   
 Post subject:
PostPosted: Tue Mar 06, 2012 1:46 pm 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
I used to do that, but why would that be better? I would prefer to run the application without having any kind of admin rights.


Top
   
 Post subject:
PostPosted: Tue Mar 06, 2012 2:00 pm 
Offline
Senior Member

Joined: Sun Mar 07, 2010 7:47 pm
Posts: 1970
Website: http://www.rwky.net
Location: Earth
I tend to pop nginx in front and have that proxy back to node on a high port, it allows nginx to serve static files, perform access logging etc etc and doesn't require node to run as root and drop it's privileges.

_________________
Paid support
How to ask for help
1. Give details of your problem
2. Post any errors
3. Post relevant logs.
4. Don't hide details i.e. your domain, it just makes things harder
5. Be polite or you'll be eaten by a grue


Top
   
 Post subject:
PostPosted: Tue Mar 06, 2012 2:22 pm 
Offline
Junior Member

Joined: Sat Feb 18, 2012 12:26 pm
Posts: 24
Can't comment on its suitability, but to redirect port 80 to 8080 -

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080


Top
   
 Post subject:
PostPosted: Wed Mar 07, 2012 4:50 pm 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
vickd wrote:
Can't comment on its suitability, but to redirect port 80 to 8080 -

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080


That is great, though I would like to hear from someone about its suitability. It seems great to me, as long as it doesn't degrade performance.

Do you happen to know how to properly save such new iptables configuration? I have seen numerous commands, such as "sudo service iptables save", but this gives a "iptables service does not exist".

Thanks a lot.


Top
   
 Post subject:
PostPosted: Wed Mar 07, 2012 6:13 pm 
Offline
Junior Member

Joined: Sat Feb 18, 2012 12:26 pm
Posts: 24
It depends on your distro. For Ubuntu I do it this way:

save the rules by doing:
Code:
iptables-save >/etc/iptables.rules


edit /etc/network/interfaces to include 'pre-up' commands to restore the rules before the interface is started.

Code:
# The primary network interface
auto eth0
iface eth0 inet dhcp
pre-up iptables-restore </etc/iptables.rules
pre-up ip6tables-restore </etc/iptables6.rules



ip6tables does the same job for ipv6. Use ip6tables-save to create that rule file.


Top
   
 Post subject:
PostPosted: Wed Mar 07, 2012 7:47 pm 
Offline
Senior Newbie

Joined: Tue Nov 02, 2010 11:15 am
Posts: 13
Location: Montréal, Canada
obs wrote:
I tend to pop nginx in front and have that proxy back to node on a high port, it allows nginx to serve static files, perform access logging etc etc and doesn't require node to run as root and drop it's privileges.


+1


Top
   
 Post subject:
PostPosted: Fri Mar 16, 2012 4:27 pm 
Offline
Junior Member

Joined: Wed Nov 03, 2010 4:55 pm
Posts: 28
Location: 55
vickd wrote:
Can't comment on its suitability, but to redirect port 80 to 8080 -

iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080


Do you know if its possible to do this with UFW as well?


Top
   
 Post subject:
PostPosted: Fri Mar 16, 2012 8:00 pm 
Offline
Junior Member

Joined: Sat Feb 18, 2012 12:26 pm
Posts: 24
Looks very similar to iptables.

http://serverfault.com/questions/238563/can-i-use-ufw-to-setup-a-port-forward


Top
   
 Post subject:
PostPosted: Sat Mar 17, 2012 12:19 pm 
Offline
Senior Member

Joined: Sun May 23, 2010 1:57 pm
Posts: 315
Website: http://www.jebblue.net
Kint wrote:
obs wrote:
I tend to pop nginx in front and have that proxy back to node on a high port, it allows nginx to serve static files, perform access logging etc etc and doesn't require node to run as root and drop it's privileges.


+1


+1 I use Apache but same thing. ProxyPass and ProxyPassReverse.


Top
   
 Post subject:
PostPosted: Tue Jun 05, 2012 11:44 am 
Offline
Senior Newbie

Joined: Fri May 04, 2012 12:30 pm
Posts: 8
There is a program called authbind that could be of some use to you.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group