tutor-contrib-codejail 18.0.0__py2.py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- tutor_contrib_codejail-18.0.0.dist-info/LICENSE +671 -0
- tutor_contrib_codejail-18.0.0.dist-info/METADATA +210 -0
- tutor_contrib_codejail-18.0.0.dist-info/RECORD +30 -0
- tutor_contrib_codejail-18.0.0.dist-info/WHEEL +6 -0
- tutor_contrib_codejail-18.0.0.dist-info/entry_points.txt +2 -0
- tutor_contrib_codejail-18.0.0.dist-info/top_level.txt +1 -0
- tutorcodejail/__about__.py +2 -0
- tutorcodejail/__init__.py +1 -0
- tutorcodejail/patches/.gitignore +0 -0
- tutorcodejail/patches/cms-env +4 -0
- tutorcodejail/patches/k8s-deployments +93 -0
- tutorcodejail/patches/k8s-jobs +21 -0
- tutorcodejail/patches/k8s-services +12 -0
- tutorcodejail/patches/kustomization-configmapgenerator +6 -0
- tutorcodejail/patches/kustomization-resources +1 -0
- tutorcodejail/patches/lms-env +4 -0
- tutorcodejail/patches/local-docker-compose-dev-services +8 -0
- tutorcodejail/patches/local-docker-compose-jobs-services +9 -0
- tutorcodejail/patches/local-docker-compose-services +13 -0
- tutorcodejail/plugin.py +131 -0
- tutorcodejail/templates/codejail/apps/.gitignore +0 -0
- tutorcodejail/templates/codejail/apps/config/tutor.py +18 -0
- tutorcodejail/templates/codejail/apps/profiles/docker-edx-sandbox +80 -0
- tutorcodejail/templates/codejail/build/.gitignore +0 -0
- tutorcodejail/templates/codejail/build/codejail/Dockerfile +92 -0
- tutorcodejail/templates/codejail/build/codejail_apparmor/Dockerfile +15 -0
- tutorcodejail/templates/codejail/k8s/.gitignore +0 -0
- tutorcodejail/templates/codejail/k8s/hpa.yml +18 -0
- tutorcodejail/templates/codejail/tasks/.gitignore +0 -0
- tutorcodejail/templates/codejail/tasks/codejail-apparmor/init +5 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: tutor-contrib-codejail
|
|
3
|
+
Version: 18.0.0
|
|
4
|
+
Summary: Codejail plugin for Tutor
|
|
5
|
+
Home-page: https://github.com/github/tutor-contrib-codejail
|
|
6
|
+
Author: eduNEXT
|
|
7
|
+
License: AGPLv3
|
|
8
|
+
Project-URL: Code, https://github.com/edunext/tutor-contrib-codejail
|
|
9
|
+
Project-URL: Issue tracker, https://github.com/edunext/tutor-contrib-codejail/issues
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: GNU Affero General Public License v3
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
20
|
+
Requires-Python: >=3.8
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Requires-Dist: tutor<19,>=18.0.0
|
|
23
|
+
|
|
24
|
+
Codejail plugin for `Tutor`_
|
|
25
|
+
============================
|
|
26
|
+
|
|
27
|
+
Tutor plugin that configures and runs a `Codejail Service`_ using a REST API. `Codejail`_ allows for the
|
|
28
|
+
secure execution of untrusted code within sandboxes, providing a safe environment for running potentially dangerous code.
|
|
29
|
+
|
|
30
|
+
.. _Tutor: https://docs.tutor.overhang.io
|
|
31
|
+
.. _Codejail Service: https://github.com/eduNEXT/codejailservice
|
|
32
|
+
.. _Codejail: https://github.com/openedx/codejail
|
|
33
|
+
|
|
34
|
+
Installation
|
|
35
|
+
------------
|
|
36
|
+
|
|
37
|
+
To install the latest version run:
|
|
38
|
+
|
|
39
|
+
.. code-block:: bash
|
|
40
|
+
|
|
41
|
+
pip install git+https://github.com/edunext/tutor-contrib-codejail
|
|
42
|
+
|
|
43
|
+
You can install a specific version by adding the tag, branch, or commit:
|
|
44
|
+
|
|
45
|
+
.. code-block:: bash
|
|
46
|
+
|
|
47
|
+
pip install git+https://github.com/edunext/tutor-contrib-codejail@v18.0.0
|
|
48
|
+
|
|
49
|
+
Usage
|
|
50
|
+
-----
|
|
51
|
+
Enable the plugin with:
|
|
52
|
+
|
|
53
|
+
.. code-block:: bash
|
|
54
|
+
|
|
55
|
+
tutor plugins enable codejail
|
|
56
|
+
|
|
57
|
+
Run the initialization jobs to install the required AppArmor profile on your host:
|
|
58
|
+
|
|
59
|
+
.. code-block:: bash
|
|
60
|
+
|
|
61
|
+
tutor config save
|
|
62
|
+
tutor local do init --limit codejail
|
|
63
|
+
|
|
64
|
+
Finally, the platform can be run as usual:
|
|
65
|
+
|
|
66
|
+
.. code-block:: bash
|
|
67
|
+
|
|
68
|
+
tutor local launch
|
|
69
|
+
|
|
70
|
+
**Please remember:** If the host is rebooted, the AppArmor profile needs to be reloaded.
|
|
71
|
+
|
|
72
|
+
Configuration
|
|
73
|
+
-------------
|
|
74
|
+
|
|
75
|
+
To customize the configuration, update the following settings in Tutor:
|
|
76
|
+
|
|
77
|
+
- ``CODEJAIL_APPARMOR_DOCKER_IMAGE``: (default: ``docker.io/ednxops/codejail_apparmor_loader:latest``)
|
|
78
|
+
- ``CODEJAIL_DOCKER_IMAGE``: (default: ``docker.io/ednxops/codejailservice:{{__version__}}``)
|
|
79
|
+
- ``CODEJAIL_ENFORCE_APPARMOR`` (default: ``True``)
|
|
80
|
+
- ``CODEJAIL_ENABLE_K8S_DAEMONSET`` (default: ``False``)
|
|
81
|
+
- ``CODEJAIL_SKIP_INIT`` (default: ``False``)
|
|
82
|
+
- ``CODEJAIL_SANDBOX_PYTHON_VERSION`` (default: ``3.8.6``)
|
|
83
|
+
- ``CODEJAIL_EXTRA_PIP_REQUIREMENTS`` (optional) A list of pip requirements to add to your sandbox.
|
|
84
|
+
- ``CODEJAIL_SERVICE_VERSION`` (default: ``release/redwood.1``),
|
|
85
|
+
- ``CODEJAIL_SERVICE_REPOSITORY`` (default ``https://github.com/edunext/codejailservice.git```)
|
|
86
|
+
|
|
87
|
+
.. code-block:: yaml
|
|
88
|
+
|
|
89
|
+
CODEJAIL_EXTRA_PIP_REQUIREMENTS:
|
|
90
|
+
- pybryt
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
Custom Image
|
|
94
|
+
~~~~~~~~~~~~
|
|
95
|
+
|
|
96
|
+
In most cases, you can work with the provided docker image for the release. However, you will need to re-build the docker image when:
|
|
97
|
+
|
|
98
|
+
. Additional requirements are included in the sandbox via ``CODEJAIL_EXTRA_PIP_REQUIREMENTS``.
|
|
99
|
+
- A different version of Python is set for the sandbox environment via ``CODEJAIL_SANDBOX_PYTHON_VERSION``.
|
|
100
|
+
- The custom version of edx-platform that changes the contents of requirements/edx-sandbox.
|
|
101
|
+
|
|
102
|
+
Create a new image running:
|
|
103
|
+
|
|
104
|
+
.. code-block:: bash
|
|
105
|
+
|
|
106
|
+
# Add the tutor configuration with the custom value
|
|
107
|
+
tutor config save \
|
|
108
|
+
--set 'CODEJAIL_EXTRA_PIP_REQUIREMENTS=["pybryt"]'
|
|
109
|
+
|
|
110
|
+
# Build the image
|
|
111
|
+
tutor images build codejail
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
Compatibility
|
|
115
|
+
-------------
|
|
116
|
+
|
|
117
|
+
+------------------+---------------+
|
|
118
|
+
| Open edX Release | Tutor Version |
|
|
119
|
+
+==================+===============+
|
|
120
|
+
| Lilac | >= 12.x |
|
|
121
|
+
+------------------+---------------+
|
|
122
|
+
| Maple | >= 13.x |
|
|
123
|
+
+------------------+---------------+
|
|
124
|
+
| Nutmeg | >= 14.x |
|
|
125
|
+
+------------------+---------------+
|
|
126
|
+
| Olive | >= 15.x |
|
|
127
|
+
+------------------+---------------+
|
|
128
|
+
| Palm | >= 16.x |
|
|
129
|
+
+------------------+---------------+
|
|
130
|
+
| Quince | >= 17.x |
|
|
131
|
+
+------------------+---------------+
|
|
132
|
+
| Redwood | >= 18.x |
|
|
133
|
+
+------------------+---------------+
|
|
134
|
+
|
|
135
|
+
**NOTE**: For the Open edX version of the Lilac release, the changes required for the Codejail service to interact with ``edx-platform`` are
|
|
136
|
+
not included in ``open-release/lilac.master``. To use the service with the changes, please review `this PR`_.
|
|
137
|
+
|
|
138
|
+
.. _this PR: https://github.com/openedx/edx-platform/pull/27795
|
|
139
|
+
|
|
140
|
+
Kubernetes Support
|
|
141
|
+
------------------
|
|
142
|
+
|
|
143
|
+
The CodeJail service provides a sandbox to run arbitrary code. Security enforcement
|
|
144
|
+
in the sandbox is done through *AppArmor*, this means that AppArmor must be installed
|
|
145
|
+
in the host machine and the `provided profile`_ must be loaded.
|
|
146
|
+
|
|
147
|
+
.. _provided profile: tutorcodejail/templates/codejail/apps/profiles/docker-edx-sandbox
|
|
148
|
+
|
|
149
|
+
The plugin provides an init task running a privileged container capable of loading the AppArmor profile onto your machine.
|
|
150
|
+
This is only compatible with a docker installation.
|
|
151
|
+
|
|
152
|
+
For Kubernetes environments, ensure each node has AppArmor installed and the profile loaded. Optionally,
|
|
153
|
+
set ``CODEJAIL_ENABLE_K8S_DAEMONSET`` to True to use a DaemonSet for loading the AppArmor profile,
|
|
154
|
+
assuming the nodes are already running AppArmor.
|
|
155
|
+
|
|
156
|
+
If you choose to run the service without enforcing the AppArmor profile, you can set ``CODEJAIL_ENFORCE_APPARMOR`` to ``False``.
|
|
157
|
+
|
|
158
|
+
More info about this discussion can be found on `this issue`_.
|
|
159
|
+
|
|
160
|
+
.. _this issue: https://github.com/eduNEXT/tutor-contrib-codejail/issues/24
|
|
161
|
+
|
|
162
|
+
Testing Functionality
|
|
163
|
+
---------------------
|
|
164
|
+
|
|
165
|
+
To verify if Codejail is working, use a course with loncapa problems in ``Studio`` and check for correct execution.
|
|
166
|
+
You can import the provided `example course`_.
|
|
167
|
+
|
|
168
|
+
Once the course is imported, go to any section and select an exercise (`section example`_), the proper result is:
|
|
169
|
+
|
|
170
|
+
.. _example course: https://github.com/eduNEXT/tutor-contrib-codejail/blob/main/docs/resources/course_codejail_example.tar.gz
|
|
171
|
+
.. _section example: http://studio.local.overhang.io:8001/container/block-v1:edX+DemoX+Demo_Course+type@vertical+block@v-integral1
|
|
172
|
+
|
|
173
|
+
.. image:: ./docs/resources/Codejailworking.png
|
|
174
|
+
:width: 725px
|
|
175
|
+
:align: center
|
|
176
|
+
:alt: Example when codejail is working
|
|
177
|
+
|
|
178
|
+
In this case, the section's content will render correctly and work as specified in the instructions of the problem.
|
|
179
|
+
|
|
180
|
+
Possible failure case
|
|
181
|
+
~~~~~~~~~~~~~~~~~~~~~
|
|
182
|
+
|
|
183
|
+
In case you forget to run ``tutor local do init --limit codejail`` for AppArmor profile, this error in
|
|
184
|
+
``Studio`` will arise::
|
|
185
|
+
|
|
186
|
+
Error formatting HTML for the problem:
|
|
187
|
+
cannot create LoncapaProblem block-v1:edX+DemoX+Demo_Course+type@problem+block@integral1: Error while
|
|
188
|
+
executing script code: Codejail API Service is unavailable. Please try again in a few minutes.
|
|
189
|
+
|
|
190
|
+
.. image:: ./docs/resources/Codejailfail.png
|
|
191
|
+
:width: 750px
|
|
192
|
+
:align: center
|
|
193
|
+
:alt: Example when codejail is not working
|
|
194
|
+
|
|
195
|
+
This indicates that the Codejail service is either not turned on or not working properly. Please ensure to follow
|
|
196
|
+
the steps outlined in the usage section to prevent this issue.
|
|
197
|
+
|
|
198
|
+
How to Contribute
|
|
199
|
+
-----------------
|
|
200
|
+
|
|
201
|
+
Contributions are welcome! See our `CONTRIBUTING`_ file for more
|
|
202
|
+
information – it also contains guidelines for how to maintain high code
|
|
203
|
+
quality, which will make your contribution more likely to be accepted.
|
|
204
|
+
|
|
205
|
+
.. _CONTRIBUTING: https://github.com/eduNEXT/tutor-contrib-codejail/blob/main/CONTRIBUTING.rst
|
|
206
|
+
|
|
207
|
+
License
|
|
208
|
+
-------
|
|
209
|
+
|
|
210
|
+
This software is licensed under the terms of the AGPLv3. See the LICENSE file for details.
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
tutorcodejail/__about__.py,sha256=-scQ7rPD2LlzTahmFbCrZs9PI7XUPW09oAKsOAPMHX0,113
|
|
2
|
+
tutorcodejail/__init__.py,sha256=OEfOPh3AfOhZMr7Htulro8oImpx8KM8B13EcU7fNKcE,46
|
|
3
|
+
tutorcodejail/plugin.py,sha256=oJZgovXhPG9_fpxdMpojzRjrYMij7LRyiesjl6lqCaM,3820
|
|
4
|
+
tutorcodejail/patches/.gitignore,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
tutorcodejail/patches/cms-env,sha256=p3sNpSho5ey_GAqzLwRnv5WD4PK3O8LPwaN1T17Ft0A,183
|
|
6
|
+
tutorcodejail/patches/k8s-deployments,sha256=t_eDvGXsrKQcWTjFz4R25WwLALq0YlkR-EmydUg2KMY,2689
|
|
7
|
+
tutorcodejail/patches/k8s-jobs,sha256=L_bZ-ePFE0wlVXWvnF05q-S56ZfnStqdOiu6kUSCf20,522
|
|
8
|
+
tutorcodejail/patches/k8s-services,sha256=pBO5ZxQnpxmOxQgHZIIy82KxyQOWTb7Z8Pvpj0Imc6o,193
|
|
9
|
+
tutorcodejail/patches/kustomization-configmapgenerator,sha256=EwWmH03W6vjO2_UB5NAwqDCKVH3U-vpUC9ZJNKI_yoc,165
|
|
10
|
+
tutorcodejail/patches/kustomization-resources,sha256=Ie5PntIydxYMlgWBqq_4NdF4sRF6iVaeNLF083s94vs,30
|
|
11
|
+
tutorcodejail/patches/lms-env,sha256=p3sNpSho5ey_GAqzLwRnv5WD4PK3O8LPwaN1T17Ft0A,183
|
|
12
|
+
tutorcodejail/patches/local-docker-compose-dev-services,sha256=HIdoPNxxiv5kyiDp60mduV8Clqi-1qOE1Kk08Q5hIF0,224
|
|
13
|
+
tutorcodejail/patches/local-docker-compose-jobs-services,sha256=5o-1WyRjv3WYZnj0dM4HR5HDN2_1hkfSCKcJGCsD6gk,301
|
|
14
|
+
tutorcodejail/patches/local-docker-compose-services,sha256=6tqDVIXJIwNsMTAXY0D53iD8HfTR0vQKWpKz-_VgAqQ,478
|
|
15
|
+
tutorcodejail/templates/codejail/apps/.gitignore,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
16
|
+
tutorcodejail/templates/codejail/apps/config/tutor.py,sha256=_3wK0fmvlYo4MF5zVxJWamRna9i9dsbU10SwkNZatD0,698
|
|
17
|
+
tutorcodejail/templates/codejail/apps/profiles/docker-edx-sandbox,sha256=rfguP5ehEybL82c9QeAfDWjp5b7vXJmtCUeziXvoJwk,2648
|
|
18
|
+
tutorcodejail/templates/codejail/build/.gitignore,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
19
|
+
tutorcodejail/templates/codejail/build/codejail/Dockerfile,sha256=u4YgvhV9Q_9S8hJ1hLDpaXBmtfMdZRucpLsJing1_9k,3429
|
|
20
|
+
tutorcodejail/templates/codejail/build/codejail_apparmor/Dockerfile,sha256=8B61J1HI1dOHjRrpowbcyaD3GDDwvoc3Z68vRf8G-F0,633
|
|
21
|
+
tutorcodejail/templates/codejail/k8s/.gitignore,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
|
+
tutorcodejail/templates/codejail/k8s/hpa.yml,sha256=iPDtdXZ69NjXRAKtlLEioGq3L4wpq9CqjS2ImOZ4IhE,460
|
|
23
|
+
tutorcodejail/templates/codejail/tasks/.gitignore,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
24
|
+
tutorcodejail/templates/codejail/tasks/codejail-apparmor/init,sha256=PbumwdF-njODp4D62MfktmOlXnT2sM_RUnUaMS2nEbc,136
|
|
25
|
+
tutor_contrib_codejail-18.0.0.dist-info/LICENSE,sha256=mMDJ5pDEC9Gsj98_TBQD_6JLz7nx5ICJ5beKL5fc_TQ,35117
|
|
26
|
+
tutor_contrib_codejail-18.0.0.dist-info/METADATA,sha256=n0vEOn--a7JvyGdobwV78o-coTWVgURKO-QK-FPUnJg,7754
|
|
27
|
+
tutor_contrib_codejail-18.0.0.dist-info/WHEEL,sha256=pxeNX5JdtCe58PUSYP9upmc7jdRPgvT0Gm9kb1SHlVw,109
|
|
28
|
+
tutor_contrib_codejail-18.0.0.dist-info/entry_points.txt,sha256=CYvFlLWVZFt8EI6cIljt_h1VuuiVBqgu70VKQMzK8VQ,50
|
|
29
|
+
tutor_contrib_codejail-18.0.0.dist-info/top_level.txt,sha256=E_PNKFpVao4Hb2ts3ynlyok8jKPHEMz24QxuD0s_jEE,14
|
|
30
|
+
tutor_contrib_codejail-18.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
tutorcodejail
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Tutor contrib codejail for plugin APIs."""
|
|
File without changes
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
apiVersion: apps/v1
|
|
3
|
+
kind: Deployment
|
|
4
|
+
metadata:
|
|
5
|
+
name: codejailservice
|
|
6
|
+
labels:
|
|
7
|
+
app.kubernetes.io/name: codejailservice
|
|
8
|
+
spec:
|
|
9
|
+
selector:
|
|
10
|
+
matchLabels:
|
|
11
|
+
app.kubernetes.io/name: codejailservice
|
|
12
|
+
template:
|
|
13
|
+
metadata:
|
|
14
|
+
labels:
|
|
15
|
+
app.kubernetes.io/name: codejailservice
|
|
16
|
+
annotations:
|
|
17
|
+
{% if CODEJAIL_ENFORCE_APPARMOR %}
|
|
18
|
+
container.apparmor.security.beta.kubernetes.io/codejailservice: "localhost/docker-edx-sandbox-{{ CODEJAIL_SANDBOX_PYTHON_VERSION }}"
|
|
19
|
+
{% endif %}
|
|
20
|
+
spec:
|
|
21
|
+
containers:
|
|
22
|
+
- name: codejailservice
|
|
23
|
+
image: {{ CODEJAIL_DOCKER_IMAGE }}
|
|
24
|
+
ports:
|
|
25
|
+
- containerPort: 8550
|
|
26
|
+
volumeMounts:
|
|
27
|
+
- mountPath: /openedx/codejailservice/codejailservice/tutor.py
|
|
28
|
+
name: settings-codejail
|
|
29
|
+
subPath: tutor.py
|
|
30
|
+
resources:
|
|
31
|
+
limits:
|
|
32
|
+
cpu: "{{ CODEJAIL_LIMIT_CPU }}"
|
|
33
|
+
memory: "{{ CODEJAIL_LIMIT_MEMORY }}"
|
|
34
|
+
requests:
|
|
35
|
+
cpu: "{{ CODEJAIL_REQUEST_CPU }}"
|
|
36
|
+
memory: "{{ CODEJAIL_REQUEST_MEMORY }}"
|
|
37
|
+
volumes:
|
|
38
|
+
- name: settings-codejail
|
|
39
|
+
configMap:
|
|
40
|
+
name: settings-codejail
|
|
41
|
+
{% if CODEJAIL_ENABLE_K8S_DAEMONSET %}
|
|
42
|
+
---
|
|
43
|
+
apiVersion: apps/v1
|
|
44
|
+
kind: DaemonSet
|
|
45
|
+
metadata:
|
|
46
|
+
name: codejail-aa-loader
|
|
47
|
+
labels:
|
|
48
|
+
app.kubernetes.io/name: codejail-aa-loader
|
|
49
|
+
spec:
|
|
50
|
+
selector:
|
|
51
|
+
matchLabels:
|
|
52
|
+
app.kubernetes.io/name: codejail-aa-loader
|
|
53
|
+
template:
|
|
54
|
+
metadata:
|
|
55
|
+
name: codejail-aa-loader
|
|
56
|
+
labels:
|
|
57
|
+
app.kubernetes.io/name: codejail-aa-loader
|
|
58
|
+
spec:
|
|
59
|
+
containers:
|
|
60
|
+
- name: apparmor-loader
|
|
61
|
+
image: google/apparmor-loader:latest
|
|
62
|
+
args:
|
|
63
|
+
# Tell the loader to pull the /profiles directory every 30 seconds.
|
|
64
|
+
- -poll
|
|
65
|
+
- 30s
|
|
66
|
+
- /profiles
|
|
67
|
+
securityContext:
|
|
68
|
+
# The loader requires root permissions to actually load the profiles.
|
|
69
|
+
privileged: true
|
|
70
|
+
volumeMounts:
|
|
71
|
+
- name: sys
|
|
72
|
+
mountPath: /sys
|
|
73
|
+
readOnly: true
|
|
74
|
+
- name: apparmor-includes
|
|
75
|
+
mountPath: /etc/apparmor.d
|
|
76
|
+
readOnly: true
|
|
77
|
+
- name: profiles
|
|
78
|
+
mountPath: /profiles
|
|
79
|
+
readOnly: true
|
|
80
|
+
volumes:
|
|
81
|
+
# The /sys directory must be mounted to interact with the AppArmor module.
|
|
82
|
+
- name: sys
|
|
83
|
+
hostPath:
|
|
84
|
+
path: /sys
|
|
85
|
+
# The /etc/apparmor.d directory is required for most apparmor include templates.
|
|
86
|
+
- name: apparmor-includes
|
|
87
|
+
hostPath:
|
|
88
|
+
path: /etc/apparmor.d
|
|
89
|
+
# Map in the profile data.
|
|
90
|
+
- name: profiles
|
|
91
|
+
configMap:
|
|
92
|
+
name: codejail-profile
|
|
93
|
+
{% endif %}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
---
|
|
2
|
+
# Dummy job that doesn't actually load the profile.
|
|
3
|
+
# To enforce apparmor we need to load the profile
|
|
4
|
+
# on each node, for that reason we use a DaemonSet
|
|
5
|
+
# defined in the k8s-deployments patch.
|
|
6
|
+
apiVersion: batch/v1
|
|
7
|
+
kind: Job
|
|
8
|
+
metadata:
|
|
9
|
+
name: codejail-apparmor-job
|
|
10
|
+
labels:
|
|
11
|
+
app.kubernetes.io/component: job
|
|
12
|
+
spec:
|
|
13
|
+
template:
|
|
14
|
+
spec:
|
|
15
|
+
restartPolicy: Never
|
|
16
|
+
containers:
|
|
17
|
+
- name: codejail-apparmor-loader
|
|
18
|
+
image: busybox:1.28
|
|
19
|
+
env:
|
|
20
|
+
- name: SKIP_INIT
|
|
21
|
+
value: "True"
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
- plugins/codejail/k8s/hpa.yml
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
codejail-apparmor-job:
|
|
2
|
+
image: {{ CODEJAIL_APPARMOR_DOCKER_IMAGE }}
|
|
3
|
+
privileged: true
|
|
4
|
+
environment:
|
|
5
|
+
SKIP_INIT: "{{ CODEJAIL_SKIP_INIT }}"
|
|
6
|
+
volumes:
|
|
7
|
+
- ../plugins/codejail/apps/profiles/docker-edx-sandbox:/profiles/docker-edx-sandbox:ro
|
|
8
|
+
- /sys:/sys
|
|
9
|
+
- /etc/apparmor.d:/etc/apparmor.d
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#############Codejail service
|
|
2
|
+
codejailservice:
|
|
3
|
+
image: {{ CODEJAIL_DOCKER_IMAGE }}
|
|
4
|
+
environment:
|
|
5
|
+
FLASK_APP_SETTINGS: codejailservice.tutor.ProductionConfig
|
|
6
|
+
{% if CODEJAIL_ENFORCE_APPARMOR %}
|
|
7
|
+
security_opt:
|
|
8
|
+
- apparmor:docker-edx-sandbox-{{ CODEJAIL_SANDBOX_PYTHON_VERSION }}
|
|
9
|
+
{% endif %}
|
|
10
|
+
volumes:
|
|
11
|
+
- ../plugins/codejail/apps/config/tutor.py:/openedx/codejailservice/codejailservice/tutor.py:ro
|
|
12
|
+
- ../../data/codejail:/openedx/data
|
|
13
|
+
restart: unless-stopped
|
tutorcodejail/plugin.py
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""Manage the plugin for the tutorcodejail."""
|
|
2
|
+
from __future__ import annotations
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
from glob import glob
|
|
6
|
+
|
|
7
|
+
import importlib_resources
|
|
8
|
+
from tutor import hooks
|
|
9
|
+
|
|
10
|
+
from .__about__ import __version__
|
|
11
|
+
|
|
12
|
+
config = {
|
|
13
|
+
"unique": {
|
|
14
|
+
"SECRET_KEY": "{{ 24|random_string }}",
|
|
15
|
+
},
|
|
16
|
+
"defaults": {
|
|
17
|
+
"VERSION": __version__,
|
|
18
|
+
"APPARMOR_DOCKER_IMAGE": "docker.io/ednxops/codejail_apparmor_loader:latest",
|
|
19
|
+
"DOCKER_IMAGE": f"docker.io/ednxops/codejailservice:{__version__}",
|
|
20
|
+
"ENABLE_K8S_DAEMONSET": False,
|
|
21
|
+
"ENFORCE_APPARMOR": True,
|
|
22
|
+
"HOST": "codejailservice",
|
|
23
|
+
"SANDBOX_PYTHON_VERSION": "3.11.9",
|
|
24
|
+
"SKIP_INIT": False,
|
|
25
|
+
"LIMIT_CPU": "1",
|
|
26
|
+
"LIMIT_MEMORY": "1Gi",
|
|
27
|
+
"REQUEST_CPU": "512m",
|
|
28
|
+
"REQUEST_MEMORY": "512Mi",
|
|
29
|
+
"ENABLE_HPA": False,
|
|
30
|
+
"MIN_REPLICAS": 1,
|
|
31
|
+
"MAX_REPLICAS": 4,
|
|
32
|
+
"AVG_CPU": 65,
|
|
33
|
+
"SERVICE_VERSION": "release/redwood.1",
|
|
34
|
+
"SERVICE_REPOSITORY": "https://github.com/edunext/codejailservice.git",
|
|
35
|
+
},
|
|
36
|
+
"overrides": {},
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
# To add a custom initialization task, create a bash script template under:
|
|
41
|
+
# tutorcodejail/templates/codejail/tasks/
|
|
42
|
+
# and then add it to the MY_INIT_TASKS list. Each task is in the format:
|
|
43
|
+
# ("<service>", ("<path>", "<to>", "<script>", "<template>"))
|
|
44
|
+
MY_INIT_TASKS: list[tuple[str, tuple[str, ...], int]] = [
|
|
45
|
+
("codejail-apparmor", ("codejail", "tasks", "codejail-apparmor", "init"), hooks.priorities.HIGH),
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
# For each task added to MY_INIT_TASKS, we load the task template
|
|
50
|
+
# and add it to the CLI_DO_INIT_TASKS filter, which tells Tutor to
|
|
51
|
+
# run it as part of the `init` job.
|
|
52
|
+
for service, template_path, priority in MY_INIT_TASKS:
|
|
53
|
+
full_path: str = str(
|
|
54
|
+
importlib_resources.files("tutorcodejail") / os.path.join("templates", *template_path)
|
|
55
|
+
)
|
|
56
|
+
with open(full_path, encoding="utf-8") as init_task_file:
|
|
57
|
+
init_task: str = init_task_file.read()
|
|
58
|
+
hooks.Filters.CLI_DO_INIT_TASKS.add_item((service, init_task), priority=priority)
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
hooks.Filters.IMAGES_BUILD.add_item((
|
|
62
|
+
"codejail",
|
|
63
|
+
("plugins", "codejail", "build", "codejail"),
|
|
64
|
+
"{{ CODEJAIL_DOCKER_IMAGE }}",
|
|
65
|
+
(),
|
|
66
|
+
))
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
hooks.Filters.IMAGES_BUILD.add_item((
|
|
70
|
+
"codejail_apparmor",
|
|
71
|
+
("plugins", "codejail", "build", "codejail_apparmor"),
|
|
72
|
+
"{{CODEJAIL_APPARMOR_DOCKER_IMAGE}}",
|
|
73
|
+
(),
|
|
74
|
+
))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
hooks.Filters.IMAGES_PULL.add_item((
|
|
78
|
+
"codejail",
|
|
79
|
+
"{{ CODEJAIL_DOCKER_IMAGE }}",
|
|
80
|
+
))
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
hooks.Filters.IMAGES_PULL.add_item((
|
|
84
|
+
"codejail_apparmor",
|
|
85
|
+
"{{CODEJAIL_APPARMOR_DOCKER_IMAGE}}",
|
|
86
|
+
))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
hooks.Filters.IMAGES_PUSH.add_item((
|
|
90
|
+
"codejail",
|
|
91
|
+
"{{ CODEJAIL_DOCKER_IMAGE }}",
|
|
92
|
+
))
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
hooks.Filters.IMAGES_PUSH.add_item((
|
|
96
|
+
"codejail_apparmor",
|
|
97
|
+
"{{CODEJAIL_APPARMOR_DOCKER_IMAGE}}",
|
|
98
|
+
))
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
# Boilerplate code
|
|
102
|
+
# Add the "templates" folder as a template root
|
|
103
|
+
hooks.Filters.ENV_TEMPLATE_ROOTS.add_item(
|
|
104
|
+
str(importlib_resources.files("tutorcodejail") / "templates")
|
|
105
|
+
)
|
|
106
|
+
# Render the "build" and "apps" folders
|
|
107
|
+
hooks.Filters.ENV_TEMPLATE_TARGETS.add_items(
|
|
108
|
+
[
|
|
109
|
+
("codejail/build", "plugins"),
|
|
110
|
+
("codejail/apps", "plugins"),
|
|
111
|
+
("codejail/k8s", "plugins"),
|
|
112
|
+
],
|
|
113
|
+
)
|
|
114
|
+
# Load patches from files
|
|
115
|
+
for path in glob(str(importlib_resources.files("tutorcodejail") / "patches" / "*")):
|
|
116
|
+
with open(path, encoding="utf-8") as patch_file:
|
|
117
|
+
hooks.Filters.ENV_PATCHES.add_item((os.path.basename(path), patch_file.read()))
|
|
118
|
+
# Add configuration entries
|
|
119
|
+
hooks.Filters.CONFIG_DEFAULTS.add_items(
|
|
120
|
+
[
|
|
121
|
+
(f"CODEJAIL_{key}", value)
|
|
122
|
+
for key, value in config.get("defaults", {}).items()
|
|
123
|
+
]
|
|
124
|
+
)
|
|
125
|
+
hooks.Filters.CONFIG_UNIQUE.add_items(
|
|
126
|
+
[
|
|
127
|
+
(f"CODEJAIL_{key}", value)
|
|
128
|
+
for key, value in config.get("unique", {}).items()
|
|
129
|
+
]
|
|
130
|
+
)
|
|
131
|
+
hooks.Filters.CONFIG_OVERRIDES.add_items(list(config.get("overrides", {}).items()))
|
|
File without changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"""Module with the configuration of config classes."""
|
|
2
|
+
from codejailservice.config import DevelopmentConfig, ProductionConfig
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class DevelopmentConfig(DevelopmentConfig):
|
|
6
|
+
"""Class to use for development context that inherits from DevelopmentConfig."""
|
|
7
|
+
|
|
8
|
+
CODE_JAIL = DevelopmentConfig.CODE_JAIL
|
|
9
|
+
{{patch("codejail-common-settings") | indent(4)}}
|
|
10
|
+
{{patch("codejail-development-settings") | indent(4)}}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class ProductionConfig(ProductionConfig):
|
|
14
|
+
"""Class to use for production context that inherits from ProductionConfig."""
|
|
15
|
+
|
|
16
|
+
CODE_JAIL = ProductionConfig.CODE_JAIL
|
|
17
|
+
{{patch("codejail-common-settings") | indent(4)}}
|
|
18
|
+
{{patch("codejail-production-settings") | indent(4)}}
|