Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
codejail
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
codejail
Commits
d4e00a66
Commit
d4e00a66
authored
Feb 13, 2017
by
J. Cliff Dyer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update docs with arch diagrams.
parent
c62051af
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
41 additions
and
17 deletions
+41
-17
README.rst
+41
-17
doc/jail_code.png
+0
-0
doc/safe_exec.png
+0
-0
No files found.
README.rst
View file @
d4e00a66
...
@@ -126,14 +126,24 @@ Using CodeJail
...
@@ -126,14 +126,24 @@ Using CodeJail
--------------
--------------
If your CodeJail is properly configured to use safe_exec, try these
If your CodeJail is properly configured to use safe_exec, try these
commands at your Python terminal:
:
commands at your Python terminal:
import codejail.jail_code
.. code:: python
codejail.jail_code.configure('python', '<SANDENV>/bin/python')
import codejail.safe_exec
codejail.safe_exec.safe_exec("import os\nos.system('ls /etc')", {})
This should fail with an exception.
import codejail
jail = codejail.configure('python', '<SANDENV>/bin/python')
jail = codejail.get_codejail('python') # this works anytime after configuration has happened
jail.safe_exec("import os\nos.system('ls /etc')", {})
This should fail with a SafeExecException. Similarly, the following will
return a JailResult indicating that an exception was raised:
.. code:: python
result = jail.jail_code("import os\nos.system('ls /etc')")
assert result.status != 0
assert result.stdout == ''
assert 'Error' in result.stderr
If you need to change the packages installed into your sandbox's virtualenv,
If you need to change the packages installed into your sandbox's virtualenv,
you'll need to disable AppArmor, because your sandboxed Python doesn't have
you'll need to disable AppArmor, because your sandboxed Python doesn't have
...
@@ -171,12 +181,30 @@ Design
...
@@ -171,12 +181,30 @@ Design
CodeJail is general-purpose enough that it can be used in a variety of projects
CodeJail is general-purpose enough that it can be used in a variety of projects
to run untrusted code. It provides two layers:
to run untrusted code. It provides two layers:
* `
jail_code.py
` offers secure execution of subprocesses. It does this by
* `
`codejail.Jail.jail_code()`
` offers secure execution of subprocesses. It does this by
running the program in a subprocess managed by AppArmor.
running the program in a subprocess managed by AppArmor.
* `safe_exec.py` offers specialized handling of Python execution, using
This takes a program to run, files to copy into its environment, command-line
arguments, and a stdin stream. It creates a temporary directory, creates or
copies the needed files, spawns a subprocess to run the code, and returns the
output and exit status of the process.
.. image:: https://raw.githubusercontent.com/edx/codejail/master/doc/jail_code.png
:alt: Data flow when running Jail.jail_code()
:width: 800px
* ``codejail.Jail.safe_exec()`` offers specialized handling of Python execution, using
jail_code to provide the semantics of Python's exec statement.
jail_code to provide the semantics of Python's exec statement.
This emulates Python's exec statement. It takes a chunk of Python code, and
runs it using jail_code, modifying the globals dictionary as a side-effect.
safe_exec does this by serializing the globals into and out of the subprocess
run by ``codejail.Jail.jail_code()`` as JSON.
.. image:: https://raw.githubusercontent.com/edx/codejail/master/doc/safe_exec.png
:alt: Data flow when running Jail.safe_exec()
:width: 800px
CodeJail runs programs under AppArmor. AppArmor is an OS-provided feature to
CodeJail runs programs under AppArmor. AppArmor is an OS-provided feature to
limit the resources programs can access. To run Python code with limited access
limit the resources programs can access. To run Python code with limited access
to resources, we make a new virtualenv, then name that Python executable in an
to resources, we make a new virtualenv, then name that Python executable in an
...
@@ -185,12 +213,8 @@ execute the provided Python program with that executable, and AppArmor will
...
@@ -185,12 +213,8 @@ execute the provided Python program with that executable, and AppArmor will
automatically limit the resources it can access. CodeJail also uses setrlimit
automatically limit the resources it can access. CodeJail also uses setrlimit
to limit the amount of CPU time and/or memory available to the process.
to limit the amount of CPU time and/or memory available to the process.
`CodeJail.jail_code` takes a program to run, files to copy into its
For backwards compatibility, the methods ``codejail.Jail.jail_code`` and
environment, command-line arguments, and a stdin stream. It creates a
``codejail.Jail.safe_exec`` are also available as functions
temporary directory, creates or copies the needed files, spawns a subprocess to
(``codejail.jail_code.jail_code`` and ``codejail.safe_exec.safe_exec``) that take
run the code, and returns the output and exit status of the process.
in an extra argument which is a string naming the configured Jail object
(``"python"`` in the above examples).
`CodeJail.safe_exec` emulates Python's exec statement. It takes a chunk of
Python code, and runs it using jail_code, modifying the globals dictionary as a
side-effect. safe_exec does this by serializing the globals into and out of
the subprocess as JSON.
doc/jail_code.png
0 → 100644
View file @
d4e00a66
51.3 KB
doc/safe_exec.png
0 → 100644
View file @
d4e00a66
51.7 KB
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment