Skip to content

Commit cc731d4

Browse files
authored
docs: More accurate NPROC documentation (#239)
1 parent a0d0f7e commit cc731d4

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

README.rst

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,25 @@ Limitations
265265
* Sandbox isolation is achieved via AppArmor confinement. Codejail facilitates
266266
this, but cannot isolate execution without the use of AppArmor.
267267
* Resource limits can only be constrained using the mechanisms that Linux's
268-
rlimit makes available. While rlimit can limit the size of any one file that
269-
a process can create, and can limit the number of files it has open at any
270-
one time, it cannot limit the total number of files written, and therefore
271-
cannot limit the total number of bytes written across *all* files.
272-
A partial mitigation is to constrain the max execution time. (All files
273-
written in the sandbox will be deleted at end of execution, in any case.)
268+
rlimit makes available. Some notable deficiencies:
269+
270+
* While rlimit's ``FSIZE`` can limit the size of any one file that
271+
a process can create, and can limit the number of files it has open at any
272+
one time, it cannot limit the total number of files written, and therefore
273+
cannot limit the total number of bytes written across *all* files.
274+
A partial mitigation is to constrain the max execution time. (All files
275+
written in the sandbox will be deleted at end of execution, in any case.)
276+
* The ``NPROC`` limit constrains the ability of the *current* process to
277+
create new threads and processes, but the usage count (how many processes
278+
already exist) is the sum across *all* processes with the same UID, even in
279+
other containers on the same host where the UID may be mapped to a different
280+
username. This constraint also applies to the app user due to how the
281+
rlimits are applied. Even if a UIDs are chosen so they aren't used by other
282+
software on the host, multiple codejail sandbox processes on the same host
283+
will share this usage pool and can reduce each other's ability to create
284+
processes. In this situation, ``NPROC`` will need to be set higher than it
285+
would be for a single codejail instance taking a single request at a time.
286+
274287
* Sandboxes do not have strong isolation from each other. Under proper
275288
configuration, untrusted code should not be able to discover other actively
276289
running code executions, but if this assumption is violated then one sandbox

codejail/jail_code.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ def is_configured(command):
8888
"VMEM": 0,
8989
# Size of files creatable, in bytes, defaulting to nothing can be written.
9090
"FSIZE": 0,
91-
# The number of processes and threads to allow.
91+
# The number of processes and threads to allow for the sandbox user (total
92+
# across entire host).
9293
"NPROC": 15,
9394
# Whether to use a proxy process or not. None means use an environment
9495
# variable to decide. NOTE: using a proxy process is NOT THREAD-SAFE, only
@@ -127,14 +128,17 @@ def set_limit(limit_name, value):
127128
* `"FSIZE"`: the maximum size of files creatable by the jailed code,
128129
in bytes. The default is 0 (no files may be created).
129130
130-
* `"NPROC"`: the maximum number of process or threads creatable by the
131-
jailed code. The default is 15.
131+
* `"NPROC"`: the maximum number of process or threads allowed for
132+
jailed code across the entire host (combined across all instances
133+
in all containers). This includes processes owned by the same UID
134+
in containers where that UID is mapped to a different username.
135+
The default is 15.
132136
133137
* `"PROXY"`: 1 to use a proxy process, 0 to not use one. This isn't
134138
really a limit, sorry about that.
135139
136140
Limits are process-wide, and will affect all future calls to jail_code.
137-
Providing a limit of 0 will disable that limit.
141+
Providing a limit of 0 will disable that limit, unless otherwise specified.
138142
139143
"""
140144
LIMITS[limit_name] = value

0 commit comments

Comments
 (0)