Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

On Linux do people chroot a Java Web Application or use IPTables and run as non-root?

When you run a Java Servlet Container that you would like to serve both static and dynamic content on port 80 you have the classic question of whether to run the server as:

  1. As root in hopefully a chroot jail if you can (haven't gotten this working yet)
  2. As a non root user and then use IPTables to forward port 80 to some other port (>1024) that the container is running on
  3. Both: As a non root user, IPTables, and chroot jail.

The problem with opt. 1 is the complexity of chrooting and still the security problems of running root.The problem with opt. 2 is that each Linux distro has a different way of persisting IPTables. Option 3 of course is probably idea but very hard to setup.

Finally every distro has the annoying differences in daemon scripts.

What do people find as the best distro agnostic solution and are there resources to show how to do this?

EDIT: I would rather not run Apache in front of the servlet container because the site is mostly dynamic and total memory footprint is important (hosting costs).

like image 672
Adam Gent Avatar asked Jun 17 '10 15:06

Adam Gent


People also ask

Why would you use chroot?

A chroot environment can be used to create and host a separate virtualized copy of the software system. This can be useful for: Testing and development. A test environment can be set up in the chroot for software that would otherwise be too risky to deploy on a production system.

Is chroot secure?

When you take the whole system into consideration, you do not gain any real security from your chroot(). Putting a regular user in a chroot() will prevent them from having access to the rest of the system. This means using a chroot is not less secure, but it is not more secure either.


2 Answers

Run as non-root and use a standard webserver (apache) or a lightweight one (such as lighttpdor nginx) on port 80 to redirect to your instance.

This has the advantage that the standard webserver can serve static content, reducing the load on your web application. You could even have it reverse-proxy and cache the web application traffic.

like image 131
jmanning2k Avatar answered Sep 25 '22 02:09

jmanning2k


Check out authbind, which is designed specifically to allow non-root users controlled access to privileged ports.

This way, you can effectively escalate your Tomcat user's privileges to just the root powers you want (open privileged ports) without giving your webapp process unnecessary powers to wreak havoc.

like image 38
Andrzej Doyle Avatar answered Sep 22 '22 02:09

Andrzej Doyle