diff options
author | 2021-01-10 13:52:08 -0800 | |
---|---|---|
committer | 2021-01-10 17:04:58 -0800 | |
commit | 0f67e369a4ac443ebf796a9eaefe48216503d7e3 (patch) | |
tree | 469e790ccaea658193dac3bec51d6be70df227b1 | |
parent | Compile the NsJail config protobuf into Python code (diff) |
Read the nsjail config into a protobuf Message object
-rw-r--r-- | snekbox/nsjail.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/snekbox/nsjail.py b/snekbox/nsjail.py index 2e38db1..0b6d1c6 100644 --- a/snekbox/nsjail.py +++ b/snekbox/nsjail.py @@ -9,7 +9,10 @@ from subprocess import CompletedProcess from tempfile import NamedTemporaryFile from typing import Iterable +from google.protobuf import text_format + from snekbox import DEBUG +from snekbox.config import NsJailConfig log = logging.getLogger(__name__) @@ -42,10 +45,20 @@ class NsJail: def __init__(self, nsjail_binary: str = NSJAIL_PATH, python_binary: str = sys.executable): self.nsjail_binary = nsjail_binary self.python_binary = python_binary + self.config = self._read_config() self._create_parent_cgroups() @staticmethod + def _read_config() -> NsJailConfig: + """Read the NsJail config at `NSJAIL_CFG` and return a protobuf Message object.""" + config = NsJailConfig() + with open(NSJAIL_CFG, encoding="utf-8") as f: + text_format.Parse(f.read(), config) + + return config + + @staticmethod def _create_parent_cgroups( pids: Path = CGROUP_PIDS_PARENT, mem: Path = CGROUP_MEMORY_PARENT |