Secure way to run other people code (sandbox) on my server?

后端 未结 9 1478
一个人的身影
一个人的身影 2020-12-01 06:37

I want to make a web service that run other people code locally... Naturally, I want to limit their code access to certain \"sandbox\" directory, and that they wont be able

相关标签:
9条回答
  • Try learning a little about setting up policies for SELinux. If you're running a Red Hat box, you're good to go since they package it into the default distro.

    This will be useful if you know the things to which the code should not have access. Or you can do the opposite, and only grant access to certain things.

    However, those policies are complicated, and may require more investment in time than you may wish to put forth.

    0 讨论(0)
  • 2020-12-01 07:30

    To limit CPU and memory, you want to set limits for groups of processes (POSIX resource limits only apply to individual processes). You can do this using cgroups.

    For example, to limit memory start by mounting the memory cgroups filesystem:

    # mount cgroup -t cgroup -o memory /cgroups/memory

    Then, create a new sub-directory for each group, e.g.

    # mkdir /cgroups/memory/my-users
    

    Put the processes you want constrained (process with PID "1234" here) into this group:

    # cd /cgroups/memory/my-users
    # echo 1234 >> tasks
    

    Set the total memory limit for the group:

    # echo 1000000 > memory.limit_in_bytes

    If processes in the group fork child processes, they will also be in the group.

    The above group sets the resident memory limit (i.e. constrained processes will start to swap rather than using more memory). Other cgroups let you constrain other things, such as CPU time.

    You could either put your server process into the group (so that the whole system with all its users fall under the limits) or get the server to put each new session into a new group.

    0 讨论(0)
  • 2020-12-01 07:30

    Reading the codepad.org/about page might give you some cool ideas.

    http://codepad.org/about

    0 讨论(0)
提交回复
热议问题