How to run a process on Linux with very limited privileges?

I would like (from code) to start a process with very limited privileges.

  • It can save files, but only in its own folder and is limited by a quota.
  • Can use memory within the quota.
  • CPU time (including any running subprocesses) is limited by quota.
  • It is impossible to talk to any other process except its own and the interface with my controller program via stdin / out.
  • Unable to interact with any devices.
  • Nothing is visible on the network.

(I am building a grid-esque system. Running code may be hostile.)

Here is what I have so far ... - Create some users in advance, grid00-grid99. Give each disk / memory / CPU quota as configured.

To start the process ...

  • Select an unused gridxx user.
  • Create a folder inside the user's home folder.
  • Hard link / bin, / usr, etc. in this folder.
  • Create new folders / home / gridxx and / tmp in this folder.
  • Copy to program files.
  • Switch to gridxx user.
  • chroot to a new folder.
  • Launch a new process.

Did I miss something?

Many thanks.

+4
source share
3 answers

The standard limits for resource use (via ulimit ) can handle the first three, and SELinux can handle the other three. Just create a new domain for the application, assign the correct permissions and release (but not it).

+4
source

It looks like you are looking for something like the FreeBSD jail function . (This is for FreeBSD, of course, but this page has links to similar technologies for Linux.)

+3
source

You should be able to accomplish this with ulimit, chroot, disk quotas, and a firewall. Limiting all forms of β€œtalk” (IPC) is difficult. In the end, you can go with a set of virtual machines.

+1
source

Source: https://habr.com/ru/post/1316234/


All Articles