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
.
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
or objdump
. 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 using dlopen
need to be checked separately./dev
tree.
/dev
such as random
or zero
. You can create those with the mknod
command. Please refer to the mknod
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With