tutor-contrib-codejail 21.0.1__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-21.0.1.dist-info/METADATA +145 -0
- tutor_contrib_codejail-21.0.1.dist-info/RECORD +25 -0
- tutor_contrib_codejail-21.0.1.dist-info/WHEEL +4 -0
- tutor_contrib_codejail-21.0.1.dist-info/entry_points.txt +3 -0
- tutor_contrib_codejail-21.0.1.dist-info/licenses/LICENSE +671 -0
- tutorcodejail/__about__.py +3 -0
- tutorcodejail/__init__.py +1 -0
- tutorcodejail/patches/.gitignore +0 -0
- tutorcodejail/patches/cms-env +4 -0
- tutorcodejail/patches/k8s-deployments +133 -0
- tutorcodejail/patches/k8s-services +14 -0
- tutorcodejail/patches/kustomization-configmapgenerator +17 -0
- tutorcodejail/patches/lms-env +4 -0
- tutorcodejail/patches/local-docker-compose-dev-services +8 -0
- tutorcodejail/patches/local-docker-compose-services +45 -0
- tutorcodejail/plugin.py +150 -0
- tutorcodejail/templates/codejail/apps/.gitignore +0 -0
- tutorcodejail/templates/codejail/apps/codejail/tutor.py +18 -0
- tutorcodejail/templates/codejail/apps/codejail-service-v2/tutor.py +34 -0
- tutorcodejail/templates/codejail/apps/profiles/docker-edx-sandbox.profile +80 -0
- tutorcodejail/templates/codejail/apps/profiles/openedx-codejail-service.profile +132 -0
- tutorcodejail/templates/codejail/build/.gitignore +0 -0
- tutorcodejail/templates/codejail/build/codejail/Dockerfile +100 -0
- tutorcodejail/templates/codejail/build/codejail-service/Dockerfile +173 -0
- tutorcodejail/templates/codejail/build/codejail_apparmor/Dockerfile +14 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
FROM docker.io/ubuntu:22.04 AS minimal
|
|
2
|
+
LABEL mantainer="edunext.co <contact@edunext.co>"
|
|
3
|
+
|
|
4
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
5
|
+
RUN apt update && \
|
|
6
|
+
apt install -y build-essential curl git language-pack-en llvm
|
|
7
|
+
ENV LC_ALL=en_US.UTF-8
|
|
8
|
+
|
|
9
|
+
###### Install python with pyenv in /opt/pyenv and create virtualenv in /openedx/venv
|
|
10
|
+
FROM minimal AS python
|
|
11
|
+
# https://github.com/pyenv/pyenv/wiki/Common-build-problems#prerequisites
|
|
12
|
+
RUN apt update && \
|
|
13
|
+
apt install -y libssl-dev zlib1g-dev libbz2-dev \
|
|
14
|
+
libreadline-dev libsqlite3-dev wget curl llvm libncurses5-dev libncursesw5-dev \
|
|
15
|
+
xz-utils tk-dev libffi-dev liblzma-dev python3-openssl git subversion
|
|
16
|
+
ENV PYENV_ROOT=/opt/pyenv
|
|
17
|
+
RUN git clone https://github.com/pyenv/pyenv $PYENV_ROOT --branch v2.6.12 --depth 1
|
|
18
|
+
|
|
19
|
+
ARG CODEJAILSERVICE_PYTHON_VERSION=3.11.14
|
|
20
|
+
RUN $PYENV_ROOT/bin/pyenv install $CODEJAILSERVICE_PYTHON_VERSION
|
|
21
|
+
|
|
22
|
+
ARG SANDBOX_PYTHON_VERSION="{{ CODEJAIL_SANDBOX_PYTHON_VERSION }}"
|
|
23
|
+
RUN git clone https://github.com/esinker/pyenv-version-alias $PYENV_ROOT/plugins/pyenv-alias
|
|
24
|
+
RUN VERSION_ALIAS="{{ CODEJAIL_SANDBOX_PYTHON_VERSION }}_sandbox" \
|
|
25
|
+
$PYENV_ROOT/bin/pyenv install -f $SANDBOX_PYTHON_VERSION
|
|
26
|
+
|
|
27
|
+
RUN "$PYENV_ROOT/versions/$CODEJAILSERVICE_PYTHON_VERSION/bin/python" -m venv /openedx/venv
|
|
28
|
+
RUN "$PYENV_ROOT/versions/"$SANDBOX_PYTHON_VERSION"_sandbox/bin/python" -m venv --copies /sandbox/venv
|
|
29
|
+
|
|
30
|
+
###### Codejail service code
|
|
31
|
+
FROM minimal AS code
|
|
32
|
+
RUN git clone {{ CODEJAIL_SERVICE_REPOSITORY }} --branch {{ CODEJAIL_SERVICE_VERSION }} --depth 1 /openedx/codejailservice
|
|
33
|
+
WORKDIR /openedx/codejailservice
|
|
34
|
+
|
|
35
|
+
###### Install python requirements in virtualenv
|
|
36
|
+
FROM python AS codejailservice-python-requirements
|
|
37
|
+
|
|
38
|
+
ENV PATH=/openedx/venv/bin:${PATH}
|
|
39
|
+
ENV VIRTUAL_ENV=/openedx/venv/
|
|
40
|
+
|
|
41
|
+
COPY --from=code /openedx/codejailservice /openedx/codejailservice
|
|
42
|
+
WORKDIR /openedx/codejailservice
|
|
43
|
+
RUN pip3 install -r requirements/base.txt
|
|
44
|
+
RUN pip3 install uwsgi==2.0.21
|
|
45
|
+
|
|
46
|
+
###### Install python requirements in virtualenv
|
|
47
|
+
FROM python AS sandbox-python-requirements
|
|
48
|
+
|
|
49
|
+
ARG EDX_PLATFORM_REPOSITORY={{ EDX_PLATFORM_REPOSITORY }}
|
|
50
|
+
ARG EDX_PLATFORM_VERSION={{ EDX_PLATFORM_VERSION }}
|
|
51
|
+
|
|
52
|
+
ENV PATH=/sandbox/venv/bin:${PATH}
|
|
53
|
+
ENV VIRTUAL_ENV=/sandbox/venv/
|
|
54
|
+
|
|
55
|
+
WORKDIR /var/tmp
|
|
56
|
+
RUN mkdir -p common/lib/
|
|
57
|
+
|
|
58
|
+
ADD $EDX_PLATFORM_REPOSITORY#$EDX_PLATFORM_VERSION:requirements/edx-sandbox/ .
|
|
59
|
+
RUN pip3 install -r base.txt
|
|
60
|
+
|
|
61
|
+
{% if CODEJAIL_EXTRA_PIP_REQUIREMENTS %}
|
|
62
|
+
# Allows you to add extra pip requirements to your codejail sandbox.
|
|
63
|
+
RUN --mount=type=cache,target=/openedx/.cache/pip,sharing=shared pip install \
|
|
64
|
+
{%- for extra_requirements in CODEJAIL_EXTRA_PIP_REQUIREMENTS %}
|
|
65
|
+
'{{ extra_requirements }}' \
|
|
66
|
+
{%- endfor %}
|
|
67
|
+
;
|
|
68
|
+
{% endif %}
|
|
69
|
+
|
|
70
|
+
##### Prod image
|
|
71
|
+
FROM minimal AS production
|
|
72
|
+
|
|
73
|
+
# Install system requirements
|
|
74
|
+
RUN apt update && \
|
|
75
|
+
apt install -y sudo
|
|
76
|
+
|
|
77
|
+
COPY --from=code /openedx/codejailservice /openedx/codejailservice
|
|
78
|
+
COPY --from=python /opt/pyenv /opt/pyenv
|
|
79
|
+
COPY --from=codejailservice-python-requirements /openedx/venv /openedx/venv
|
|
80
|
+
COPY --from=sandbox-python-requirements /sandbox/venv /sandbox/venv
|
|
81
|
+
|
|
82
|
+
# Setup sandbox
|
|
83
|
+
ENV SANDBOX_ENV=/sandbox/venv
|
|
84
|
+
RUN groupadd -r sandbox && useradd -m -r -g sandbox sandbox && chown -R sandbox:sandbox /sandbox
|
|
85
|
+
|
|
86
|
+
ENV PATH=/openedx/venv/bin:${PATH}
|
|
87
|
+
ENV VIRTUAL_ENV=/openedx/venv/
|
|
88
|
+
ENV UWSGI_WORKERS=2
|
|
89
|
+
WORKDIR /openedx/codejailservice
|
|
90
|
+
|
|
91
|
+
EXPOSE 8550
|
|
92
|
+
|
|
93
|
+
CMD [ "uwsgi", \
|
|
94
|
+
"--http=0.0.0.0:8550", \
|
|
95
|
+
"--thunder-lock", \
|
|
96
|
+
"--single-interpreter", \
|
|
97
|
+
"--enable-threads", \
|
|
98
|
+
"--buffer-size=8192", \
|
|
99
|
+
"--max-requests=1000", \
|
|
100
|
+
"--wsgi-file=/openedx/codejailservice/wsgi.py" ]
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
FROM scratch AS codejail-service-code
|
|
2
|
+
ARG CODEJAIL_SERVICE_REPO={{ CODEJAIL_SERVICE_V2_REPOSITORY }}
|
|
3
|
+
ARG CODEJAIL_SERVICE_VERSION={{ CODEJAIL_SERVICE_V2_VERSION }}
|
|
4
|
+
ADD ${CODEJAIL_SERVICE_REPO}#${CODEJAIL_SERVICE_VERSION} /
|
|
5
|
+
|
|
6
|
+
FROM scratch AS sandbox-dependencies
|
|
7
|
+
# Where to get the Python dependencies lockfile for installing
|
|
8
|
+
# packages into the sandbox environment. Defaults to the codejail
|
|
9
|
+
# dependencies in edx-platform.
|
|
10
|
+
ARG SANDBOX_DEPS_REPO={{ EDX_PLATFORM_REPOSITORY }}
|
|
11
|
+
ARG SANDBOX_DEPS_VERSION={{ CODEJAIL_SERVICE_V2_VERSION }}
|
|
12
|
+
# Path to the lockfile in the deps repo, as dir + filename.
|
|
13
|
+
#
|
|
14
|
+
# The path base.txt will get the latest dependencies, but this needs
|
|
15
|
+
# to be coordinated with SANDBOX_PY_VER as each release has a
|
|
16
|
+
# different Python support window.
|
|
17
|
+
ARG SANDBOX_DEPS_SRC_DIR=requirements/edx-sandbox
|
|
18
|
+
ADD ${SANDBOX_DEPS_REPO}#${SANDBOX_DEPS_VERSION}:${SANDBOX_DEPS_SRC_DIR} /
|
|
19
|
+
|
|
20
|
+
FROM docker.io/ubuntu:24.04 AS app
|
|
21
|
+
ARG APP_PY_VER=3.12
|
|
22
|
+
# See codejail-service deployment and configuration docs for why we need to select
|
|
23
|
+
# a UID/GID that is unlikely to collide with anything on the host. (Short answer:
|
|
24
|
+
# RLIMIT_NPROC UID-global usage pool, and Docker not isolating UIDs.)
|
|
25
|
+
#
|
|
26
|
+
# Selected via: python3 -c 'import random; print(random.randrange(3000, 2 ** 31))'
|
|
27
|
+
ARG APP_UID=15826504
|
|
28
|
+
ARG APP_GID=$APP_UID
|
|
29
|
+
|
|
30
|
+
ARG SANDBOX_DEPS_SRC_FILE=base.txt
|
|
31
|
+
|
|
32
|
+
# Python version for sandboxed executions. This must be coordinated with
|
|
33
|
+
# `SANDBOX_DEPS_SRC_*` to ensure compatibility.
|
|
34
|
+
ARG SANDBOX_PY_VER={{ '.'.join(CODEJAIL_SANDBOX_PYTHON_VERSION.split('.')[:2]) }}
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
##### Base app installation #####
|
|
38
|
+
|
|
39
|
+
ENV DEBIAN_FRONTEND=noninteractive
|
|
40
|
+
ARG APT_INSTALL="apt-get install --quiet --yes --no-install-recommends"
|
|
41
|
+
|
|
42
|
+
# The codejail library specifies a certain structure to how the sandboxing is
|
|
43
|
+
# performed. (See the documentation in the codejail library README:
|
|
44
|
+
# https://github.com/openedx/codejail).
|
|
45
|
+
#
|
|
46
|
+
# Some of this structure can be changed, and some cannot. Any changes that are
|
|
47
|
+
# possible will also need to be coordinated with changes to the apparmor profile
|
|
48
|
+
# as well as to the `CODE_JAIL` Django settings. Accordingly, it's best to just
|
|
49
|
+
# *avoid* making changes to this part.
|
|
50
|
+
|
|
51
|
+
# The location of the virtualenv that code executions in the sandbox will use.
|
|
52
|
+
# This is a critical path, as SAND_VENV/bin/python is what is targeted by the
|
|
53
|
+
# AppArmor confinement. It must also match the Django setting
|
|
54
|
+
# `CODE_JAIL.python_bin`. The codejail docs refer to this as `<SANDENV>`.
|
|
55
|
+
ARG SAND_VENV=/sandbox/venv
|
|
56
|
+
# The user account that will run code executions, described just as "the sandbox
|
|
57
|
+
# user" in codejail docs. This needs to match the Django setting
|
|
58
|
+
# `CODE_JAIL.user` and the sudoers file.
|
|
59
|
+
ARG SAND_USER=sandbox
|
|
60
|
+
# Same situation as for APP_UID
|
|
61
|
+
ARG SAND_UID=33552349
|
|
62
|
+
ARG SAND_GID=$SAND_UID
|
|
63
|
+
# The user account that runs the regular web app, described in codejail docs as
|
|
64
|
+
# `<SANDBOX_CALLER>`. Needs to match the sudoers file.
|
|
65
|
+
ARG APP_USER=app
|
|
66
|
+
|
|
67
|
+
# The codejail-service API tests check for the visibility of this environment
|
|
68
|
+
# variable from the sandbox. (It should not be visible.) This helps test for
|
|
69
|
+
# environment leakage into the sandbox.
|
|
70
|
+
ENV CJS_TEST_ENV_LEAKAGE=yes
|
|
71
|
+
|
|
72
|
+
# Packages installed:
|
|
73
|
+
#
|
|
74
|
+
# - language-pack-en, locales: Ubuntu locale support so that system utilities
|
|
75
|
+
# have a consistent language and time zone.
|
|
76
|
+
# - sudo: Web user (`APP_USER`) needs to be able to sudo as `SAND_USER`
|
|
77
|
+
# - python*: Specific versions of Python -- the service runs with a recent version, but
|
|
78
|
+
# the sandboxed code will usually need a different (older) version. This is also why
|
|
79
|
+
# we need to pull in the deadsnakes PPA.
|
|
80
|
+
# - python*-dev: Header files for python extensions, required by many source wheels
|
|
81
|
+
# - python*-venv: Allow creation of virtualenvs
|
|
82
|
+
#
|
|
83
|
+
# We also have to do a bit of bootstrapping here installing the
|
|
84
|
+
# `software-properties-common` package gives us `add-apt-repository`, which
|
|
85
|
+
# allows us to add the deadsnakes PPA more easily (that is, without messing
|
|
86
|
+
# about with repository keys).
|
|
87
|
+
RUN <<EOCMD
|
|
88
|
+
set -eu
|
|
89
|
+
apt-get update
|
|
90
|
+
${APT_INSTALL} \
|
|
91
|
+
software-properties-common \
|
|
92
|
+
;
|
|
93
|
+
add-apt-repository ppa:deadsnakes/ppa
|
|
94
|
+
${APT_INSTALL} \
|
|
95
|
+
language-pack-en \
|
|
96
|
+
locales \
|
|
97
|
+
python${APP_PY_VER} \
|
|
98
|
+
python${APP_PY_VER}-dev \
|
|
99
|
+
python${APP_PY_VER}-venv \
|
|
100
|
+
python${SANDBOX_PY_VER} \
|
|
101
|
+
python${SANDBOX_PY_VER}-venv \
|
|
102
|
+
sudo \
|
|
103
|
+
;
|
|
104
|
+
EOCMD
|
|
105
|
+
|
|
106
|
+
RUN locale-gen en_US.UTF-8
|
|
107
|
+
ENV LANG=en_US.UTF-8
|
|
108
|
+
ENV LANGUAGE=en_US:en
|
|
109
|
+
ENV LC_ALL=en_US.UTF-8
|
|
110
|
+
|
|
111
|
+
# We'll build the virtualenv and pre-compile Python as root, but switch to app user
|
|
112
|
+
# for actually running the application.
|
|
113
|
+
RUN groupadd --gid $APP_GID $APP_USER
|
|
114
|
+
RUN useradd --no-log-init --no-create-home --shell /bin/false --uid $APP_UID --gid $APP_GID $APP_USER
|
|
115
|
+
|
|
116
|
+
COPY --from=codejail-service-code / /app
|
|
117
|
+
|
|
118
|
+
WORKDIR /app
|
|
119
|
+
|
|
120
|
+
RUN <<EOCMD
|
|
121
|
+
set -eu
|
|
122
|
+
python${APP_PY_VER} -m venv /venv
|
|
123
|
+
/venv/bin/pip install -r /app/requirements/pip.txt
|
|
124
|
+
/venv/bin/pip install -r /app/requirements/pip-tools.txt
|
|
125
|
+
EOCMD
|
|
126
|
+
|
|
127
|
+
##### Sandbox environment #####
|
|
128
|
+
|
|
129
|
+
# Codejail executions will be run under this user's account.
|
|
130
|
+
RUN groupadd --gid $SAND_GID $SAND_USER
|
|
131
|
+
RUN useradd --no-log-init --no-create-home --shell /bin/false --uid $SAND_UID --gid $SAND_GID $SAND_USER
|
|
132
|
+
|
|
133
|
+
# We need to use --copies so that there is a distinct Python
|
|
134
|
+
# executable to confine.
|
|
135
|
+
RUN mkdir -p ${SAND_VENV}
|
|
136
|
+
RUN python${SANDBOX_PY_VER} -m venv --clear --copies ${SAND_VENV}
|
|
137
|
+
|
|
138
|
+
# Install the Python libraries used by the sandbox.
|
|
139
|
+
RUN --mount=type=bind,from=sandbox-dependencies,source=/,target=/tmp/sandbox-dependencies <<EOCMD
|
|
140
|
+
${SAND_VENV}/bin/pip install -r /tmp/sandbox-dependencies/${SANDBOX_DEPS_SRC_FILE} \
|
|
141
|
+
{%- for extra_requirements in CODEJAIL_EXTRA_PIP_REQUIREMENTS %}
|
|
142
|
+
'{{ extra_requirements }}' \
|
|
143
|
+
{%- endfor %}
|
|
144
|
+
;
|
|
145
|
+
EOCMD
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
# Sudoers config as specified by codejail's docs.
|
|
149
|
+
# - `find` is used in sandbox cleanup
|
|
150
|
+
# - `pkill` is used to terminate overlong execution
|
|
151
|
+
COPY <<01-sandbox /etc/sudoers.d/
|
|
152
|
+
${APP_USER} ALL=(${SAND_USER}) SETENV:NOPASSWD:${SAND_VENV}/bin/python
|
|
153
|
+
${APP_USER} ALL=(${SAND_USER}) SETENV:NOPASSWD:/usr/bin/find
|
|
154
|
+
${APP_USER} ALL=(ALL) NOPASSWD:/usr/bin/pkill
|
|
155
|
+
01-sandbox
|
|
156
|
+
|
|
157
|
+
ENV PATH="/venv/bin:$PATH"
|
|
158
|
+
|
|
159
|
+
FROM app AS prod
|
|
160
|
+
|
|
161
|
+
RUN /venv/bin/pip-sync requirements/base.txt
|
|
162
|
+
RUN python${APP_PY_VER} -m compileall /venv /app
|
|
163
|
+
|
|
164
|
+
# Drop to unprivileged user for running service
|
|
165
|
+
USER ${APP_USER}
|
|
166
|
+
|
|
167
|
+
CMD [ "gunicorn", \
|
|
168
|
+
"--config=/app/codejail_service/docker_gunicorn_configuration.py", \
|
|
169
|
+
"--name=codejail-service", \
|
|
170
|
+
"--bind=0.0.0.0:8550", \
|
|
171
|
+
"--max-requests=1000", \
|
|
172
|
+
"--log-file=-", \
|
|
173
|
+
"codejail_service.wsgi:application" ]
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
FROM golang:1.25.4 AS go_compiler
|
|
2
|
+
|
|
3
|
+
RUN mkdir /app
|
|
4
|
+
WORKDIR /app
|
|
5
|
+
ADD https://raw.githubusercontent.com/kubernetes/kubernetes/a9593d634c6a053848413e600dadbf974627515f/test/images/apparmor-loader/loader.go loader.go
|
|
6
|
+
RUN go mod init loader
|
|
7
|
+
RUN go get k8s.io/klog/v2
|
|
8
|
+
RUN GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -a -installsuffix cgo --ldflags '-w' -o loader .
|
|
9
|
+
|
|
10
|
+
FROM alpine:3.22
|
|
11
|
+
|
|
12
|
+
RUN apk add apparmor libapparmor --repository=https://dl-cdn.alpinelinux.org/alpine/edge/main
|
|
13
|
+
COPY --from=go_compiler /app/loader /usr/bin/loader
|
|
14
|
+
|