Skip to content

Commit 88c45b0

Browse files
authored
Allow dropping capabilities + prevent additional capabilities (#81)
* Allow dropping certain capabilities * Allow setting "--security-opt no-new-privileges" * Fix code style * Fix default value * Fix handling of PYTHON_RUNNER_DROPPED_CAPABILITIES * Fix code style * Fix option * Fix options --------- Co-authored-by: Simon Hammes <[email protected]>
1 parent 00438a8 commit 88c45b0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

starter/runner.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@
4949
TMPFS_MOUNT_SIZE_IN_BYTES = os.environ.get(
5050
"PYTHON_RUNNER_TMPFS_MOUNT_SIZE_IN_BYTES", "104857600"
5151
)
52+
DROPPED_CAPABILITIES = [
53+
cap
54+
for cap in os.environ.get("PYTHON_RUNNER_DROPPED_CAPABILITIES", "").split(",")
55+
if cap.strip()
56+
]
57+
NO_NEW_PRIVILEGES = (
58+
os.environ.get("PYTHON_RUNNER_NO_NEW_PRIVILEGES", "false").lower() == "true"
59+
)
5260
OTHER_OPTIONS = os.environ.get("PYTHON_RUNNER_OTHER_OPTIONS", "[]")
5361
try:
5462
OTHER_OPTIONS = ast.literal_eval(OTHER_OPTIONS)
@@ -308,6 +316,13 @@ def run_python(data):
308316
command.extend(
309317
["--mount", f"type=tmpfs,dst=/tmp,tmpfs-size={TMPFS_MOUNT_SIZE_IN_BYTES}"]
310318
)
319+
if DROPPED_CAPABILITIES:
320+
command.extend(
321+
f"--cap-drop={capability}" for capability in DROPPED_CAPABILITIES
322+
)
323+
if NO_NEW_PRIVILEGES:
324+
# Prevent container from gaining additional privileges
325+
command.extend(["--security-opt", "no-new-privileges"])
311326
# other options, these options are experimental, may cause failure to start script
312327
if OTHER_OPTIONS and isinstance(OTHER_OPTIONS, list):
313328
for option in OTHER_OPTIONS:

0 commit comments

Comments
 (0)