README 1.56 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
Choose a place for the virtualenv, call it <SANDENV>.  It will be automatically
detected and used if you put it right alongside your existing virtualenv, but
with -sandbox appended.  So if your existing virtualenv is in ~/mitx_all/python,
make <SANDENV> be ~/mitx_all/python-sandbox (but you'll need to spell out your
home directory instead of ~).

Other details here that depend on your configuration:

    - Your mitx working tree is <MITX>, for example, ~/mitx_all/mitx

    - The user running the LMS is <USER>, for example, you on a dev machine,
      or www-data on a server.
13 14 15

Create a virtualenv:

16
    $ sudo virtualenv <SANDENV>
17 18 19

Install the sandbox requirements

20 21 22 23 24 25 26 27 28 29
    $ source <SANDENV>/bin/activate
    $ sudo pip install -r sandbox-requirements.txt

Add a sandbox user:

    $ sudo addgroup sandbox
    $ sudo adduser --disabled-login sandbox --ingroup sandbox

Let the web server run the sandboxed Python as sandbox.  Create the file
/etc/sudoers.d/01-sandbox:
30

31 32 33 34 35 36 37 38 39
    $ visudo -f /etc/sudoers.d/01-sandbox

    <USER> ALL=(sandbox) NOPASSWD:<SANDENV>/bin/python
    <USER> ALL=(ALL) NOPASSWD:/bin/kill

Edit an AppArmor profile.  The file must be named for the python executable,
but with slashes changed to dots:

    #include <tunables/global>
40 41

    <SANDENV>/bin/python {
42 43 44 45 46 47 48 49
        #include <abstractions/base>

        <SANDENV>/** mr,
        <MITX>/common/lib/sandbox-packages/** r,
        /usr/local/lib/python2.7/** r,
        /usr/lib/python2.7/** rix,

        /tmp/** rix,
50 51 52 53
    }

Parse the profiles

54
    $ sudo apparmor_parser <APPARMOR_FILE>
55

56
Reactivate your real virtualenv again