I am about to develop a little script to gather information for a chroot-jail.
In my case this looks (at the first glance) pretty simple: The application has a clean rpm-install and did install almost all files into a sub-directory of /opt.
My idea is:
- Do a find of all binaries
- Check their library-dependencies
- Record the results into a list
- Do a rsync of that list into the chroot-target-directory before startup of the application
Now I wonder - ist there any script around that already does such a job (perl/bash/python)?
So far I found only specialized solutions for single applications (like sftp-chroot).
Although is does not matter (imho) - OS is CentOS 5 x86_64 current minor release and patch-level.
rpm -ql
is IMHO not generic enough, since it will only cover rpm-based distributions. The mention of the "clean install" above was just to mention that the files of the software are not distributed across the whole file-system. So my starting point is - at the moment - a find /opt/directory/
... that should work on almost any system (even not Linux).
I would suggest creating a template chroot and installing all the packages you want just like it was a normal OS. After that you can manage the chroot using your typical tools (update scripts, package manager, etc.) and rsync the updates into each chroot built using that template.
There are a few advantages to this approach. The two big ones are you can manage the template using familiar tools (no strange hoops to jump through to upgrade your chroot), and if you have one chroot which can't be updated for some reason (say it needs a particular version of some package) you can exclude it from the
rsync
upgrade process and manage it independently as though it were a standalone machine, marking the package as "held" or equivalent so it doesn't get stomped on.Your mileage (and implementation requirements) may vary...
First approach (service is the application itself): Do a bind-ro-mount in the chroot for all the "usual" binaries, libs, etc...:
Now this was ok to test if the service runs in the chroot. To my astonishment my HIDS told me that there was a write located in a sub-directory in /opt/service.
So I manually chrooted into this with a shell and tested write-access - which worked!
So if nothing else helps - RTFM.
man mount
hinted that a read-only-bind-mount only works with kernel 2.6.26 or greater (bad luck here: CentOS 5 is 2.6.18).Another drawback: This leaves a potential attacker with the full set of operating-system-tools.
Now this is, where my scipt is at the moment:
mkchroot.cfg:
mkchroot.sh
Problem that still exists: There are shell-files within my chroot. They might reference some other binaries.
As workaround these have to be put manually into $FILES.
There is a set of tools named jailkit.
This may work with linux, too. According to its home-page it is confirmed to work with
Its dependencies look good: