Sign inSign up

quantumsheep/godbox

By quantumsheep

Updated about 5 years ago

Secure sandboxing system for untrusted code execution

Image
0

2.9K

quantumsheep/godbox repository overview

Godbox

Secure sandboxing system for untrusted code execution.

It uses isolate which uses specific functionnalities of the Linux kernel, thus godbox not able to run properly outside of Linux.

Installation

Kubernetes

Helm Chart
helm repo add godbox-charts https://quantumsheep.github.io/godbox-helm/charts
helm install my-godbox godbox-charts/godbox

Docker Compose

version: "3"

services:
  godbox:
    image: quantumsheep/godbox:2
    privileged: true
    ports:
      - 8080:8080

Docker

docker run -it -d --privileged -p 8080:8080 quantumsheep/godbox:2

Environment variables

NameTypeDefaultDescription
API_MAX_PAYLOAD_SIZEnumber32768API maximum payload size
ALLOW_PROFILINGbooleantrueEnable or disable profiling
MAX_RUN_TIME_LIMITnumber5Maximum run time limit
MAX_EXTRA_TIME_LIMITnumber0Maximum extra time limit
MAX_WALL_TIME_LIMITnumber10Maximum wall time limit
MAX_STACK_SIZE_LIMITnumber128000Maximum stack size limit
MAX_PROCESS_COUNT_LIMITnumber120Maximum process count limit
MAX_MEMORY_LIMITnumber512000Maximum memory limit
MAX_STORAGE_LIMITnumber10240Maximum storage limit

Run commands

Send a POST HTTP request to http://localhost:8080/run containing the wanted configuration in JSON. See below for properties.

Properties

NameTypeDescription
phases*Phase[]Execution phases (check examples bellow)
files*stringBase64-encoded zip file containing the files used in the phases
environmentRecord<string, string>Environment variables used in all phases
sandbox_settingsSandboxSettingsOverride default sandbox limitation settings
Phase
NameTypeDefaultDescription
script*stringMulti-line bash script that will be executed inside the isolated environment
namestringPhase's indexName that will be used in result output
stdinstringContent used in stdin
environmentRecordEnvironment variables available inside script execution. This will override global environment variables with the same given keys
sandbox_settingsSandboxSettingsOverrides default sandbox limitation settings. This will override global sandbox settings with the same given keys
profilingbooleanfalseRun a profiler on script. This functionnality is WIP
SandboxSettings
NameTypeDefaultDescription
run_time_limitnumber5Limit run time of the whole control group in seconds. Fractional numbers are allowed
extra_time_limitnumber0When a time limit is exceeded, wait for extra time seconds before killing the program. This has the advantage that the real execution time is reported, even though it slightly exceeds the limit. Fractional numbers are again allowed
wall_time_limitnumber10Limit wall-clock time to time seconds. Fractional values are allowed. This clock measures the time from the start of the program to its exit, so it does not stop when the program has lost the CPU or when it is for an external event. It is recommend to use run_time_limit as the main limit, but set wall_time_limit to a much higher value as a precaution against sleeping programs
stack_size_limitnumber128000Limit process stack to size kilobytes. It is subject to memory_limit
process_count_limitnumber120Permit the program to create up to max processes and/or threads
memory_limitnumber512000Limit total memory usage by the whole control group in kilobytes
storage_limitnumber10240Limit size of files created (or modified) by the program in kilobytes

Example

The files should be passed as a base64 zip archive.

The folowing demonstration uses the folowing file architecture:

.
└── src
    └── main.c

Encoded using command zip -q -r - * | base64 (could have been a library, it doesn't matter while it keeps beeing files -> zip -> base64).

{
  "phases": [
    {
      "name": "Compilation",
      "script": "/usr/local/gcc-11.1.0/bin/gcc src/main.c -o out",
      "sandbox_settings": {
        "run_time_limit": 20,
        "wall_time_limit": 40
      }
    },
    {
      "name": "Execution",
      "script": "./out"
    }
  ],
  "environment": {
    "ENABLE_AWESOME_SHEEP": "true"
  },
  "files": "UEsDBAoAAAAAAJe1pVIAAAAAAAAAAAAAAAAEABwAc3JjL1VUCQADvgOTYNQDk2B1eAsAAQT1AQAABBQAAABQSwMEFAAIAAgABbalUgAAAAAAAAAATQAAAAoAHABzcmMvbWFpbi5jVVQJAAOKBJNgjASTYHV4CwABBPUBAAAEFAAAAFPOzEvOKU1JVbApLknJzNfLsOPiyswrUchNzMzT0OSq5lIAgoLSkmINJY/UnJx8HYXw/KKcFEUlTWsusFxRaklpUZ6CgTVXLRcAUEsHCMUkHr9KAAAATQAAAFBLAQIeAwoAAAAAAJe1pVIAAAAAAAAAAAAAAAAEABgAAAAAAAAAEADtQQAAAABzcmMvVVQFAAO+A5NgdXgLAAEE9QEAAAQUAAAAUEsBAh4DFAAIAAgABbalUsUkHr9KAAAATQAAAAoAGAAAAAAAAQAAAKSBPgAAAHNyYy9tYWluLmNVVAUAA4oEk2B1eAsAAQT1AQAABBQAAABQSwUGAAAAAAIAAgCaAAAA3AAAAAAA"
}
Output
{
  "phases": [
    {
      "name": "Compilation",
      "status": 0,
      "stdout": "",
      "stderr": "",
      "time": 0.037,
      "time_wall": 0.043,
      "used_memory": 6640,
      "sandbox_status": null,
      "csw_voluntary": 18,
      "csw_forced": 16
    },
    {
      "name": "Execution",
      "status": 0,
      "stdout": "Hello, World!\n",
      "stderr": "",
      "time": 0.002,
      "time_wall": 0.007,
      "used_memory": 856,
      "sandbox_status": null,
      "csw_voluntary": 7,
      "csw_forced": 0
    }
  ]
}

Tag summary

Content type

Image

Digest

Size

1.3 GB

Last updated

about 5 years ago

docker pull quantumsheep/godbox