Were I root, I could simply create a dummy user/group, set file permissions accordingly and execute the process as that user. However I am not, so is there any way to achieve this without being root?
Permissions – How to Jail a Process Without Being Root
jailsnot-root-userpermissions
Best Answer
More similar Qs with more answers worth attention:
NOTE: Some of the answers there point to specific solutions not yet mentioned here.
Actually, there are quite a few jailing tools with different implementation, but many of them are either not secure by design (like
fakeroot
,LD_PRELOAD
-based), or not complete (likefakeroot-ng
,ptrace
-based), or would require root (chroot
, orplash
mentioned at fakechroot warning label).These are just examples; I thought of listing them all side-by-side, with indication of these 2 features ("can be trusted?", "requires root to set up?"), perhaps at Operating-system-level virtualization Implementations.
In general, the answers there cover the full described range of possibilities and even more:
virtual machines/OS
kernel extension (like SELinux)
chroot
Chroot-based helpers (which however must be setUID root, because
chroot
requires root; or perhapschroot
could work in an isolated namespace--see below):[to tell a little more about them!]
Known chroot-based isolation tools:
hsh-run
andhsh-shell
commands. (Hasher was designed for building software in a safe and repeatable manner.)ptrace
Another trustworthy isolation solution (besides a
seccomp
-based one) would be the complete syscall-interception throughptrace
, as explained in the manpage forfakeroot-ng
:Still, as you can read it,
fakeroot-ng
itself is not designed for this purpose.(BTW, I wonder why they have chosen to use the
seccomp
-based approach for Chromium rather than aptrace
-based...)Of the tools not mentioned above, I have noted Geordi for myself, because I liked that the controlling program is written in Haskell.
Known ptrace-based isolation tools:
fakeroot-ng
seccomp
One known way to achieve isolation is through the seccomp sandboxing approach used in Google Chromium. But this approach supposes that you write a helper which would process some (the allowed ones) of the "intercepted" file access and other syscalls; and also, of course, make effort to "intercept" the syscalls and redirect them to the helper (perhaps, it would even mean such a thing as replacing the intercepted syscalls in the code of the controlled process; so, it doesn't sound to be quite simple; if you are interested, you'd better read the details rather than just my answer).
More related info (from Wikipedia):
(The last item seems to be interesting if one is looking for a general
seccomp
-based solution outside of Chromium. There is also a blog post worth reading from the author of "seccomp-nurse": SECCOMP as a Sandboxing solution ?.)The illustration of this approach from the "seccomp-nurse" project:
A "flexible" seccomp possible in the future of Linux?
There used to appear in 2009 also suggestions to patch the Linux kernel so that there is more flexibility to the
seccomp
mode--so that "many of the acrobatics that we currently need could be avoided". ("Acrobatics" refers to the complications of writing a helper that has to execute many possibly innocent syscalls on behalf of the jailed process and of substituting the possibly innocent syscalls in the jailed process.) An LWN article wrote to this point:This "flexible seccomp" would bring the possibilities of Linux closer to providing the desired feature in the OS, without the need to write helpers that complicated.
(A blog posting with basically the same content as this answer: http://geofft.mit.edu/blog/sipb/33.)
namespaces (
unshare
)Isolating through namespaces (
unshare
-based solutions) -- not mentioned here -- e.g., unsharing mount-points (combined with FUSE?) could perhaps be a part of a working solution for you wanting to confine filesystem accesses of your untrusted processes.More on namespaces, now, as their implementation has been completed (this isolation technique is also known under the nme "Linux Containers", or "LXC", isn't it?..):
"One of the overall goals of namespaces is to support the implementation of containers, a tool for lightweight virtualization (as well as other purposes)".
It's even possible to create a new user namespace, so that "a process can have a normal unprivileged user ID outside a user namespace while at the same time having a user ID of 0 inside the namespace. This means that the process has full root privileges for operations inside the user namespace, but is unprivileged for operations outside the namespace".
For real working commands to do this, see the answers at:
and special user-space programming/compiling
But well, of course, the desired "jail" guarantees are implementable by programming in user-space (without additional support for this feature from the OS; maybe that's why this feature hasn't been included in the first place in the design of OSes); with more or less complications.
The mentioned
ptrace
- orseccomp
-based sandboxing can be seen as some variants of implementing the guarantees by writing a sandbox-helper that would control your other processes, which would be treated as "black boxes", arbitrary Unix programs.Another approach could be to use programming techniques that can care about the effects that must be disallowed. (It must be you who writes the programs then; they are not black boxes anymore.) To mention one, using a pure programming language (which would force you to program without side-effects) like Haskell will simply make all the effects of the program explicit, so the programmer can easily make sure there will be no disallowed effects.
I guess, there are sandboxing facilities available for those programming in some other language, e.g., Java.
Cf. "Sandboxed Haskell" project proposal.
NaCl--not mentioned here--belongs to this group, doesn't it?
Some pages accumulating info on this topic were also pointed at in the answers there: