Skip to content

Commit 76987db

Browse files
committed
chore: Enhance tmpfs security settings in Docker and service files
- Updated tmpfs mount options for /tmp in Docker Compose files to include noexec, nosuid, and nodev for improved security. - Refactored sandbox execution commands to apply the new tmpfs settings consistently across service files. - Introduced dynamic handling of skill dependencies with updated mount options to enhance security and isolation.
1 parent 16807f0 commit 76987db

5 files changed

Lines changed: 41 additions & 8 deletions

File tree

docker-compose.prod.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
# to the mounted files inside the container under /app/ssl.
3131
- ${SSL_CERTS_PATH:-./ssl}:/app/ssl:ro
3232
tmpfs:
33-
- /tmp:size=512m,mode=1777
33+
- /tmp:size=512m,mode=1777,noexec,nosuid,nodev
3434
- /app/data:size=100m
3535
depends_on:
3636
redis:

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ services:
3030
# to the mounted files inside the container under /app/ssl.
3131
- ${SSL_CERTS_PATH:-./ssl}:/app/ssl:ro
3232
tmpfs:
33-
- /tmp:size=512m,mode=1777
33+
- /tmp:size=512m,mode=1777,noexec,nosuid,nodev
3434
- /app/data:size=100m
3535
depends_on:
3636
redis:

src/services/programmatic.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ async def start_execution(
187187
)
188188

189189
tmpfs_size = settings.sandbox_tmpfs_size_mb
190+
noexec_tmpfs = "noexec,nosuid,nodev,"
191+
deps_path = settings.skill_deps_path
190192

191193
wrapper_cmd = (
192194
f"mount --bind {shlex.quote(str(sandbox_info.data_dir))} /mnt/data && "
@@ -197,8 +199,17 @@ async def start_execution(
197199
f"mount -t tmpfs -o size=1k tmpfs /app/dashboard && "
198200
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
199201
f"mount --bind /var/lib/code-interpreter/empty_proc /proc && "
200-
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
201-
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
202+
# BUG-007: Ephemeral /tmp with noexec,nosuid,nodev
203+
f"mount -t tmpfs -o {noexec_tmpfs}size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
204+
# BUG-008: Lock down other writable paths
205+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /var/tmp && "
206+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /run/lock && "
207+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1733 tmpfs /var/lib/php/sessions && "
208+
# BUG-008: skill-deps nosuid,nodev (not noexec — installed CLIs need exec)
209+
f"(test -d {shlex.quote(deps_path)} && "
210+
f"mount --bind {shlex.quote(deps_path)} {shlex.quote(deps_path)} && "
211+
f"mount -o remount,bind,nosuid,nodev {shlex.quote(deps_path)} "
212+
f"|| true) && "
202213
f"{nsjail_cmd}"
203214
)
204215

src/services/sandbox/executor.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,8 @@ async def execute_command(
108108
)
109109

110110
tmpfs_size = settings.sandbox_tmpfs_size_mb
111+
noexec_tmpfs = "noexec,nosuid,nodev,"
112+
deps_path = settings.skill_deps_path
111113

112114
wrapper_cmd = (
113115
# Bind sandbox dir to /mnt/data (before hiding sandboxes dir)
@@ -124,8 +126,17 @@ async def execute_command(
124126
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
125127
# BUG-003: Hide /proc (except Java which needs /proc/self/exe)
126128
f"{proc_mask}"
127-
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
128-
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
129+
# BUG-007: Ephemeral /tmp with noexec,nosuid,nodev
130+
f"mount -t tmpfs -o {noexec_tmpfs}size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
131+
# BUG-008: Lock down other writable paths
132+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /var/tmp && "
133+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /run/lock && "
134+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1733 tmpfs /var/lib/php/sessions && "
135+
# BUG-008: skill-deps nosuid,nodev (not noexec — installed CLIs need exec)
136+
f"(test -d {shlex.quote(deps_path)} && "
137+
f"mount --bind {shlex.quote(deps_path)} {shlex.quote(deps_path)} && "
138+
f"mount -o remount,bind,nosuid,nodev {shlex.quote(deps_path)} "
139+
f"|| true) && "
129140
# Execute nsjail
130141
f"{nsjail_cmd}"
131142
)

src/services/sandbox/pool.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,8 @@ async def _start_repl_process(
391391
shlex.quote(str(a)) for a in [settings.nsjail_binary] + nsjail_args
392392
)
393393
tmpfs_size = settings.sandbox_tmpfs_size_mb
394+
noexec_tmpfs = "noexec,nosuid,nodev,"
395+
deps_path = settings.skill_deps_path
394396

395397
wrapper_cmd = (
396398
# Bind sandbox dir to /mnt/data (before hiding sandboxes dir)
@@ -407,8 +409,17 @@ async def _start_repl_process(
407409
f"mount -t tmpfs -o size=1k tmpfs /app/src && "
408410
# BUG-003: Hide /proc (REPL is Python-only, always safe to mask)
409411
f"mount --bind /var/lib/code-interpreter/empty_proc /proc && "
410-
# BUG-007: Ephemeral /tmp — prevent cross-session data persistence
411-
f"mount -t tmpfs -o size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
412+
# BUG-007: Ephemeral /tmp with noexec,nosuid,nodev
413+
f"mount -t tmpfs -o {noexec_tmpfs}size={tmpfs_size}m,mode=1777 tmpfs /tmp && "
414+
# BUG-008: Lock down other writable paths
415+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /var/tmp && "
416+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1777 tmpfs /run/lock && "
417+
f"mount -t tmpfs -o {noexec_tmpfs}size=1m,mode=1733 tmpfs /var/lib/php/sessions && "
418+
# BUG-008: skill-deps nosuid,nodev (not noexec — installed CLIs need exec)
419+
f"(test -d {shlex.quote(deps_path)} && "
420+
f"mount --bind {shlex.quote(deps_path)} {shlex.quote(deps_path)} && "
421+
f"mount -o remount,bind,nosuid,nodev {shlex.quote(deps_path)} "
422+
f"|| true) && "
412423
# Execute nsjail
413424
f"{nsjail_cmd}"
414425
)

0 commit comments

Comments
 (0)