Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
configuration
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
OpenEdx
configuration
Commits
abb347a8
Commit
abb347a8
authored
Jan 09, 2014
by
Jason Bau
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #612 from edx/jbau/edxapp/codejail
Sets up codejail
parents
a8a56acc
ceb4d8d1
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
172 additions
and
6 deletions
+172
-6
playbooks/roles/edxapp/defaults/main.yml
+22
-3
playbooks/roles/edxapp/tasks/deploy.yml
+58
-3
playbooks/roles/edxapp/tasks/main.yml
+4
-0
playbooks/roles/edxapp/tasks/python_sandbox_env.yml
+57
-0
playbooks/roles/edxapp/templates/95-sandbox-sudoer.j2
+3
-0
playbooks/roles/edxapp/templates/code.sandbox.j2
+28
-0
No files found.
playbooks/roles/edxapp/defaults/main.yml
View file @
abb347a8
...
@@ -116,6 +116,13 @@ EDXAPP_GRADE_ROOT_PATH: '/tmp/edx-s3/grades'
...
@@ -116,6 +116,13 @@ EDXAPP_GRADE_ROOT_PATH: '/tmp/edx-s3/grades'
# Configure rake tasks in edx-platform to skip Python/Ruby/Node installation
# Configure rake tasks in edx-platform to skip Python/Ruby/Node installation
EDXAPP_NO_PREREQ_INSTALL
:
1
EDXAPP_NO_PREREQ_INSTALL
:
1
# whether to setup the python codejail or not
EDXAPP_PYTHON_SANDBOX
:
false
# this next setting, if true, turns on actual sandbox enforcement. If not true,
# it puts the sandbox in 'complain' mode, for reporting but not enforcement
EDXAPP_SANDBOX_ENFORCE
:
true
#-------- Everything below this line is internal to the role ------------
#-------- Everything below this line is internal to the role ------------
#Use YAML references (& and *) and hash merge <<: to factor out shared settings
#Use YAML references (& and *) and hash merge <<: to factor out shared settings
...
@@ -163,6 +170,13 @@ edxapp_workers:
...
@@ -163,6 +170,13 @@ edxapp_workers:
service_variant
:
lms
service_variant
:
lms
concurrency
:
2
concurrency
:
2
# setup for python codejail
edxapp_sandbox_venv_dir
:
'
{{
edxapp_venvs_dir
}}/edxapp-sandbox'
edxapp_sandbox_user
:
'
sandbox'
# I think something about the codejail requires hardcoding this to sandbox:sandbox
# apparmor command
edxapp_aa_command
:
"
{%
if
EDXAPP_SANDBOX_ENFORCE
%}aa-enforce{%
else
%}aa-complain{%
endif
%}"
# Requirement files we explicitely
# Requirement files we explicitely
# check for changes before attempting
# check for changes before attempting
# to update the venv
# to update the venv
...
@@ -361,6 +375,14 @@ lms_auth_config:
...
@@ -361,6 +375,14 @@ lms_auth_config:
lms_env_config
:
lms_env_config
:
<<
:
*edxapp_generic_env
<<
:
*edxapp_generic_env
'
CODE_JAIL'
:
# from https://github.com/edx/codejail/blob/master/codejail/django_integration.py#L24, '' should be same as None
'
python_bin'
:
'
{%
if
EDXAPP_PYTHON_SANDBOX
%}{{
edxapp_sandbox_venv_dir
}}/bin/python{%
endif
%}'
'
limits'
:
'
VMEM'
:
0
'
REALTIME'
:
5
'
user'
:
'
{{
edxapp_sandbox_user
}}'
cms_auth_config
:
cms_auth_config
:
<<
:
*edxapp_generic_auth
<<
:
*edxapp_generic_auth
cms_env_config
:
cms_env_config
:
...
@@ -430,9 +452,6 @@ sandbox_base_requirements: "{{ edxapp_code_dir }}/requirements/edx-sandbox/base
...
@@ -430,9 +452,6 @@ sandbox_base_requirements: "{{ edxapp_code_dir }}/requirements/edx-sandbox/base
sandbox_local_requirements
:
"
{{
edxapp_code_dir
}}/requirements/edx-sandbox/local.txt"
sandbox_local_requirements
:
"
{{
edxapp_code_dir
}}/requirements/edx-sandbox/local.txt"
sandbox_post_requirements
:
"
{{
edxapp_code_dir
}}/requirements/edx-sandbox/post.txt"
sandbox_post_requirements
:
"
{{
edxapp_code_dir
}}/requirements/edx-sandbox/post.txt"
#do we want to install the sandbox requirements into the regular virtual env
install_sandbox_reqs_into_regular_venv
:
true
edxapp_debian_pkgs
:
edxapp_debian_pkgs
:
-
npm
-
npm
# for compiling the virtualenv
# for compiling the virtualenv
...
...
playbooks/roles/edxapp/tasks/deploy.yml
View file @
abb347a8
...
@@ -164,7 +164,9 @@
...
@@ -164,7 +164,9 @@
# Need to use shell rather than pip so that we can maintain the context of our current working directory; some
# Need to use shell rather than pip so that we can maintain the context of our current working directory; some
# requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# installs everything into that virtual environment.
# installs everything into that virtual environment.
shell
:
cd {{ edxapp_code_dir }} && {{ edxapp_venv_dir }}/bin/pip install -i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors -r {{ item }}
shell
:
>
{{ edxapp_venv_dir }}/bin/pip install -i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors -r {{ item }}
chdir={{ edxapp_code_dir }}
with_items
:
with_items
:
-
"
{{
repo_requirements_file
}}"
-
"
{{
repo_requirements_file
}}"
-
"
{{
github_requirements_file
}}"
-
"
{{
github_requirements_file
}}"
...
@@ -181,12 +183,14 @@
...
@@ -181,12 +183,14 @@
# Need to use shell rather than pip so that we can maintain the context of our current working directory; some
# Need to use shell rather than pip so that we can maintain the context of our current working directory; some
# requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# requirements are pathed relative to the edx-platform repo. Using the pip from inside the virtual environment implicitly
# installs everything into that virtual environment.
# installs everything into that virtual environment.
shell
:
cd {{ edxapp_code_dir }} && {{ edxapp_venv_dir }}/bin/pip install -i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors -r {{ item }}
shell
:
>
{{ edxapp_venv_dir }}/bin/pip install -i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors -r {{ item }}
chdir={{ edxapp_code_dir }}
with_items
:
with_items
:
-
"
{{
sandbox_base_requirements
}}"
-
"
{{
sandbox_base_requirements
}}"
-
"
{{
sandbox_local_requirements
}}"
-
"
{{
sandbox_local_requirements
}}"
-
"
{{
sandbox_post_requirements
}}"
-
"
{{
sandbox_post_requirements
}}"
when
:
install_sandbox_reqs_into_regular_venv
when
:
not EDXAPP_PYTHON_SANDBOX
sudo_user
:
"
{{
edxapp_user
}}"
sudo_user
:
"
{{
edxapp_user
}}"
when
:
not inst.stat.exists or new.stat.md5 != inst.stat.md5
when
:
not inst.stat.exists or new.stat.md5 != inst.stat.md5
notify
:
notify
:
...
@@ -194,6 +198,57 @@
...
@@ -194,6 +198,57 @@
-
"
edxapp
|
restart
edxapp_workers"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
deploy
tags
:
deploy
# The next few tasks set up the python code sandbox
# need to disable this profile, otherwise the pip inside the sandbox venv has no permissions
# to install anything
-
name
:
edxapp | code sandbox | put sandbox apparmor profile in complain mode
command
:
/usr/sbin/aa-complain /etc/apparmor.d/code.sandbox
when
:
EDXAPP_PYTHON_SANDBOX
tags
:
-
deploy
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | Install base sandbox requirements and create sandbox virtualenv
pip
:
>
requirements="{{sandbox_base_requirements}}"
virtualenv="{{edxapp_sandbox_venv_dir}}"
state=present
extra_args="-i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors"
sudo_user
:
"
{{
edxapp_sandbox_user
}}"
when
:
EDXAPP_PYTHON_SANDBOX
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
deploy
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | Install sandbox requirements into sandbox venv
shell
:
>
{{ edxapp_sandbox_venv_dir }}/bin/pip install -i {{ edxapp_pypi_local_mirror }} --exists-action w --use-mirrors -r {{ item }}
chdir={{ edxapp_code_dir }}
with_items
:
-
"
{{
sandbox_local_requirements
}}"
-
"
{{
sandbox_post_requirements
}}"
sudo_user
:
"
{{
edxapp_sandbox_user
}}"
when
:
EDXAPP_PYTHON_SANDBOX
register
:
sandbox_install_output
changed_when
:
"
'installed'
in
sandbox_install_output"
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
deploy
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | put code sandbox into aa-enforce or aa-complain mode, depending on EDXAPP_SANDBOX_ENFORCE
command
:
/usr/sbin/{{ edxapp_aa_command }} /etc/apparmor.d/code.sandbox
when
:
EDXAPP_PYTHON_SANDBOX
tags
:
-
deploy
-
edxapp-sandbox
-
name
:
edxapp | compiling all py files in the edx-platform repo
-
name
:
edxapp | compiling all py files in the edx-platform repo
shell
:
"
{{
edxapp_venv_bin
}}/python
-m
compileall
{{
edxapp_code_dir
}}"
shell
:
"
{{
edxapp_venv_bin
}}/python
-m
compileall
{{
edxapp_code_dir
}}"
sudo_user
:
"
{{
edxapp_user
}}"
sudo_user
:
"
{{
edxapp_user
}}"
...
...
playbooks/roles/edxapp/tasks/main.yml
View file @
abb347a8
...
@@ -68,6 +68,10 @@
...
@@ -68,6 +68,10 @@
mode=0750
mode=0750
with_items
:
service_variants_enabled
with_items
:
service_variants_enabled
# Set up the python sandbox execution environment
-
include
:
python_sandbox_env.yml
when
:
EDXAPP_PYTHON_SANDBOX
-
include
:
deploy.yml
-
include
:
deploy.yml
-
name
:
edxapp | create a symlink for venv python
-
name
:
edxapp | create a symlink for venv python
...
...
playbooks/roles/edxapp/tasks/python_sandbox_env.yml
0 → 100644
View file @
abb347a8
-
name
:
edxapp | code sandbox | Create edxapp sandbox user
user
:
name={{ edxapp_sandbox_user }} shell=/bin/false home={{ edxapp_sandbox_venv_dir }}
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | Install apparmor utils system pkg
apt
:
pkg=apparmor-utils state=present
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | write out apparmor code sandbox config
template
:
src=code.sandbox.j2 dest=/etc/apparmor.d/code.sandbox mode=0644 owner=root group=root
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | write out sandbox user sudoers config
template
:
src=95-sandbox-sudoer.j2 dest=/etc/sudoers.d/95-{{ edxapp_sandbox_user }} mode=0440 owner=root group=root validate='visudo -c -f %s'
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
# we boostrap and enable the apparmor service here. in deploy.yml we disable, deploy, then re-enable
# so we need to enable it in main.yml
-
name
:
edxapp | code sandbox | start apparmor service
service
:
name=apparmor state=started
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | (bootstrap) load code sandbox profile
command
:
apparmor_parser -r /etc/apparmor.d/code.sandbox
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
-
name
:
edxapp | code sandbox | (bootstrap) put code sandbox into aa-enforce or aa-complain mode depending on EDXAPP_SANDBOX_ENFORCE
command
:
/usr/sbin/{{ edxapp_aa_command }} /etc/apparmor.d/code.sandbox
notify
:
-
"
edxapp
|
restart
edxapp"
-
"
edxapp
|
restart
edxapp_workers"
tags
:
-
edxapp-sandbox
playbooks/roles/edxapp/templates/95-sandbox-sudoer.j2
0 → 100644
View file @
abb347a8
{{ edxapp_user }} ALL=({{ edxapp_sandbox_user }}) SETENV:NOPASSWD:{{ edxapp_sandbox_venv_dir }}/bin/python
{{ edxapp_user }} ALL=(ALL) NOPASSWD:/bin/kill
{{ edxapp_user }} ALL=(ALL) NOPASSWD:/usr/bin/pkill
playbooks/roles/edxapp/templates/code.sandbox.j2
0 → 100644
View file @
abb347a8
#include <tunables/global>
{{ edxapp_sandbox_venv_dir }}/bin/python flags=(complain) {
#include <abstractions/base>
{{ edxapp_sandbox_venv_dir }}/** mr,
{{ edxapp_code_dir }}/common/lib/sandbox-packages/** r,
/tmp/codejail-*/ rix,
/tmp/codejail-*/** rix,
#
# Whitelist particiclar shared objects from the system
# python installation
#
/usr/lib/python2.7/lib-dynload/_json.so mr,
/usr/lib/python2.7/lib-dynload/_ctypes.so mr,
/usr/lib/python2.7/lib-dynload/_heapq.so mr,
/usr/lib/python2.7/lib-dynload/_io.so mr,
/usr/lib/python2.7/lib-dynload/_csv.so mr,
/usr/lib/python2.7/lib-dynload/datetime.so mr,
/usr/lib/python2.7/lib-dynload/_elementtree.so mr,
#
# Allow access to selections from /proc
#
/proc/*/mounts r,
}
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