Chroot’ing Tomcat
Something that deserves more attention that it gets: running Tomcat in a chroot jail.
Update: 5/11/2006
Some notes on following the Brittain/Darwin procedure from their fine book referenced above.
The platform: SuSe 8.2
- In addition to what ldd java outputs, I needed /lib/libm.so.6 because libjvm.so needed it. I also needed /lib/libnsl.so.1.
- I had to do cd /usr/local/chroot; mkdir proc; mount --bind /proc proc. This is unsettling, but the jvm needs access to /proc to start. Otherwise you get find_vma failed when the vm attempts to start. I'm not sure this mount step is staying in my process, but for now it's there. I'd love to hear from anyone who knows of a better way to deal with this.
If you continue to have problems chrooting Tomcat, temporarily copy /usr/bin/strace into /usr/local/chroot so you can do
/usr/local/bin/jbchroot -U tomcat -- /usr/local/chroot /strace /usr/local/jdk1.5.0_06/bin/java -version > /tmp/strace.out 2>&1
Then, file by file, examine the output of
parsetrace.pl < /tmp/strace.out
where parsetrace.pl is here and looks like
#!/usr/bin/perl -w
use Uniq; # See http://search.cpan.org/~syamal/Uniq-0.01/Uniq.pm
while( ) {
if( /^open\(\"(.*)\".*ENOENT/ ) {
push @files, "$1";
}
}
foreach $j (uniq (sort @files) ) {
if ( -e $j ) {
print "$j ";
$r = `file $j`;
chop($r);
print $r . "\n";
}
}
The script shows you what files could not be found running chroot that can be found on a non-chrooted system. It's a matter of working your way through the output found files to determine which ones whose absence chroot'd are killing the vm during startup.
Update 5/13/2006
Here is a scripted method of creating a chroot jail, and placing Tomcat and Java in it. The only external dependencies are a binary distribution of Tomcat and a binary distribution of Java (the shell-based install, not the RPM version).
With the binary Tomcat and Java distributions in the current working directory, do
$ sh makeChroot
$ /etc/init.d/tomcat start
If you end up running the script multiple times as you tune and tweak for your system, you will first find the need to do
$ umount $chroot/proc
where $chroot is the chroot prefix
Also included in the script are options to run with -security with or without Java security policy debugging.
One bothersome feature is the need to replicate /proc into the chroot jail. If anyone has a better way of dealing with the JVM's need for /proc, I would appreciate knowing.
[tags]tomcat,find_vma<webapps[/tags]
I’m still learning the concepts of chrooting Tomcat. Is it possible to have Tomcat serve web applications that are physically located outside the chroot jail within which Tomcat is running?
eg: if Tomcat runs from /opt/chroot/tomcat, can its webapps still be located under /var/www/webapps?
rvdb
July 31, 2009 at 12:33 pm