0

I would like to set up a server that can receive source code directly, compile/interpret it and execute it.

The code could be C#, Java, C++, C, Javascript, PHP...

There will obviously be security concerns, I would like to know if you have any recommendations to prevent the server from being compromised?

From what I look on the internet, Docker seems to be a good solution. Is that correct?

I would like each code to be independent, so if malicious code destroys it's own virtual machine, it does not matter.

To explain more in detail, I think of a game of programming, the players will write their codes, locally on their machine and send them in an arena to compete for example in 1 vs 1 with, in between, the engine Game.

The idea would be to have 3 programs, for a game in 1 against 1 (2 players and the arena) the information exchanged between each of the programs would be characters strings I would also like to the player program to be compiled on a server (in the vm docker for example).

I would like the code to run on the server side so that each player has the same computing power.

  • 2
    Docker is not secure, it was never designed to be. Your kernel is exposed, and kernel exploits can be used to escape the cgroup isolation and wreck real havoc. If you really are concerned about the code, a real VM is more secure, or even better use a physical box which is airgaped. – Aron Feb 9 at 5:34
  • Do you need support for arbitrary binaries, i.e. whatever can be compiled, or is it sufficient to target a single language? A common way how it's solved is to pick a single interpretable language that allows user-provided code to be sandboxed, e.g. like javascript execution in your browser, which does effectively limit what websites can execute on your computer. – Peteris Mar 9 at 1:02
2

What you're looking to do, if I read your question correctly, is to isolate possibly hostile code to be compiled and run on a server you control.

So you need some kind of sandbox/isolation to do that.

The question you need to think about is "how much isolation do I need"

Docker will provide reasonable isolation but it still exposes the Linux kernel on the host (all containers, by default, share the same Linux kernel) so an attacker could try and exploit an issue there. Also attacker code could do things like scan the local network to try and find other things to attack.

Some possible options to improve the isolation provided by base Docker.

1) Drop capabilities from the running containers using the --cap-drop=ALL option. This reduces the privileges that the container has and makes it harder to break out

2) If the running container doesn't need network access use --network=none so it can't attempt to make connections out to other machines.

3) Don't run the containers as root, make sure you set a specific user for each container.

You could also isolate each task inside a different Virtual machine, although there's a resource hit over Docker for that.

0

One of the main concerns I can see is cross site-scripting or injection attacks. Need to check all input is escaped and checked for formatting before sending it across to the server. Essentially you will have to limit the type of program that each user can write because they could insert malicious code.

Also I would recommend looking into the secure socket layer (SSL) protocol to exchange data from client to server.

If you are using docker there are additional concerns, such as access to containers and to the docker client.

Finally, you would also need to secure your server before you can host it.

  • I realize that I am not clear enough, the idea would be to have 3 programs, for a game in 1 against 1 (2 players and the arena) the information exchanged between each of the programs would be characters strings I would also like to the player program to be compiled on a server (in the vm docker for example) – Hadou Feb 6 at 9:34
  • @Hadou Please update your question so that it covers all the details. – Tom K. Feb 6 at 9:40
  • @Samar If I turn the 2 players and the "arena" program on a docker vm, and that I remove the access to the internet for the programs, that I make sure that each program is users / rights independent, would it be enough ? – Hadou Feb 6 at 14:26
  • @hadou No, because a malicious input has the potential to cause damage regardless of it being disconnected from the internet. Somebody could put code that may exit the program on the server or cause some other off-target effect that you may not have considered. – Samar Sajnani Feb 6 at 16:01
  • @Samar Yes, precisely, this is the kind of case I would like to avoid, without having to check the source code, but rather by isolating a maximum with the OS (linux). It's possible ? – Hadou Feb 6 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.