Is it possible to start a process in Linux, and restrict its access to certain files/directories? For example:
$ start-process --enable-dir=./sandbox --exec="some-script.sh"
some-script.sh
won't be able to do anything outside of ./sandbox
.
Is it possible to start a process in Linux, and restrict its access to certain files/directories? For example:
$ start-process --enable-dir=./sandbox --exec="some-script.sh"
some-script.sh
won't be able to do anything outside of ./sandbox
.
Typically you want to
chroot
the process, so that it can only access a directory and its sub-directories, and only execute some defined commands.See How to chroot.
You can use
chroot
to set the root directory of your process tree. This means however, that all dependencies of that process must be available in it's new root.There are a number of packages that can help you setup chroot-environments for your needs. Google is your friend ;)
Some pointers on building a chroot environment
When builing a chroot for some program or daemon you have to have a complete environment for the program you want to chroot. This means you have to provide a minimum system in a directory. That might contain:
ldd
orobjdump
. Every library that appears has to be in your private root directory. This step might be repeated several times for every executable and library you need. Note that some libraries, which are linked explicitly at runtime usingdlopen
need to be checked separately./dev
tree./dev
such asrandom
orzero
. You can create those with themknod
command. Please refer to themknod
documentation, as well as the linux documentation on which major/minor numbers which device should have./etc
. Files needed therein are:mtab
containing/
.group
(again, not your system group file).You have to start somewhere, so it's best to start with the prerequisites for you program. Refer to your documentation for specifics.