diff --git a/Makefile b/Makefile index 2e83bf8fc03c..fe00809d59c7 100644 --- a/Makefile +++ b/Makefile @@ -86,7 +86,7 @@ compile-requirements: ## Regenerate uv.lock for the root project and all uv sub- @# independent of the root project's dependency graph) before exporting any @# compat file below, so a failure in one halts the whole target before @# anything downstream of it is (re)generated. - @for d in requirements/edx-sandbox scripts/xblock scripts/user_retirement scripts/structures_pruning; do \ + @for d in scripts/xblock scripts/user_retirement scripts/structures_pruning; do \ echo ; \ echo "== $$d ===============================" ; \ uv run --no-project --isolated --with edx-lint edx_lint write_uv_constraints $$d/pyproject.toml && \ @@ -126,13 +126,6 @@ compile-requirements: ## Regenerate uv.lock for the root project and all uv sub- uv export --frozen --no-hashes --group development --group ci --no-emit-project; \ } > requirements/edx/development.txt - @# requirements/edx-sandbox, scripts/xblock: single compat export, no dependency-groups. - @{ \ - echo "# GENERATED FILE, DO NOT EDIT DIRECTLY."; \ - echo "# Compatibility export for anyone still 'pip install -r requirements/edx-sandbox/base.txt'"; \ - echo "# directly instead of using uv. Source of truth: requirements/edx-sandbox/pyproject.toml / uv.lock."; \ - (cd requirements/edx-sandbox && uv export --frozen --no-hashes --no-emit-project); \ - } > requirements/edx-sandbox/base.txt @{ \ echo "# GENERATED FILE, DO NOT EDIT DIRECTLY."; \ echo "# Compatibility export for anyone still 'pip install -r scripts/xblock/requirements.txt'"; \ diff --git a/README.rst b/README.rst index 380ffa700237..726f93ccf1de 100644 --- a/README.rst +++ b/README.rst @@ -119,11 +119,13 @@ Language Packages: Codejail Setup -------------- -As a part of the baremetal setup, you will need to configure your system to -work properly with codejail. See the `codejail installation steps`_ for more -details. +While not strictly required, some components of the platform require sandboxing +capabilites. Such sandboxing is achieved through the use of a remote REST +service `codejail-service`_. -.. _codejail installation steps: https://github.com/openedx/codejail?tab=readme-ov-file#installation +Instructions on how to deploy such service can be found in https://github.com/openedx/codejail-service/blob/main/docs/deployment.rst + +.. _codejail-service: https://github.com/openedx/codejail-service/blob/main/docs/deployment.rst Build Steps ----------- diff --git a/cms/envs/common.py b/cms/envs/common.py index 9e999c03da72..d2c14c417794 100644 --- a/cms/envs/common.py +++ b/cms/envs/common.py @@ -425,8 +425,6 @@ def make_lms_template_path(settings): # Detects user-requested locale from 'accept-language' header in http request 'django.middleware.locale.LocaleMiddleware', - 'codejail.django_integration.ConfigureCodeJailMiddleware', - # for expiring inactive sessions 'openedx.core.djangoapps.session_inactivity_timeout.middleware.SessionInactivityTimeout', @@ -478,11 +476,6 @@ def make_lms_template_path(settings): DEFAULT_AUTO_FIELD = 'django.db.models.AutoField' -#################### Python sandbox ############################################ - -# Needs to be non-zero so that jailed code can use it as their temp directory.(1MiB in bytes) -CODE_JAIL['limits']['FSIZE'] = 1048576 # noqa: F405 - ############################ DJANGO_BUILTINS ################################ COURSE_IMPORT_EXPORT_BUCKET = '' diff --git a/cms/envs/mock.yml b/cms/envs/mock.yml index 3b219071ddf1..c45e37d023d3 100644 --- a/cms/envs/mock.yml +++ b/cms/envs/mock.yml @@ -167,28 +167,6 @@ CLOSEST_CLIENT_IP_FROM_HEADERS: - index: 0 name: CF-Connecting-IP CMS_BASE: studio.localhost -CODE_JAIL: - limit_overrides: - codejail_expanded_limits: - CPU: 10 - FSIZE: 2097152 - PROXY: 1 - REALTIME: 60 - VMEM: 1073741824 - course-v1:Org+Course+Run: - CPU: 5 - FSIZE: 5 - PROXY: 5 - REALTIME: 5 - VMEM: 5 - limits: - CPU: 2 - FSIZE: 1048576 - PROXY: 1 - REALTIME: 6 - VMEM: 536870912 - python_bin: /edx/app/edxapp/venvs/edxapp-sandbox/bin/python - user: sandbox COMMENTS_SERVICE_KEY: test_COMMENTS_SERVICE_KEY COMMENTS_SERVICE_URL: https://forum.localhost COMPLETION_VIDEO_COMPLETE_PERCENTAGE: 0.9 diff --git a/lms/djangoapps/courseware/tests/test_submitting_problems.py b/lms/djangoapps/courseware/tests/test_submitting_problems.py index 3df373936eb9..828c97609c39 100644 --- a/lms/djangoapps/courseware/tests/test_submitting_problems.py +++ b/lms/djangoapps/courseware/tests/test_submitting_problems.py @@ -21,7 +21,6 @@ from django.urls import reverse from django.utils.timezone import now from submissions import api as submissions_api -from xblock_problem.capa.testing.codejail import UseUnsafeCodejail from xblock_problem.capa.testing.response_xml_factory import ( CodeResponseXMLFactory, CustomResponseXMLFactory, @@ -816,7 +815,6 @@ def test_three_files(self, mock_xqueue_post): self.assertEqual(list(kwargs['files'].keys()), filenames.split()) # noqa: PT009 -@UseUnsafeCodejail() class TestPythonGradedResponse(TestSubmittingProblems): """ Check that we can submit a schematic and custom response, and it answers properly. diff --git a/lms/djangoapps/debug/views.py b/lms/djangoapps/debug/views.py index 8d43c67385cd..089a70d0c908 100644 --- a/lms/djangoapps/debug/views.py +++ b/lms/djangoapps/debug/views.py @@ -4,11 +4,11 @@ import pprint import traceback -from codejail.safe_exec import safe_exec from django.contrib.auth.decorators import login_required from django.http import Http404, HttpResponse from django.utils.html import escape from django.views.decorators.csrf import ensure_csrf_cookie +from xblock_problem.capa.safe_exec import safe_exec from common.djangoapps.edxmako.shortcuts import render_to_response from openedx.core.djangolib.markup import HTML diff --git a/lms/djangoapps/instructor_task/tests/test_integration.py b/lms/djangoapps/instructor_task/tests/test_integration.py index 3cd541dfdcf0..506d15e7df65 100644 --- a/lms/djangoapps/instructor_task/tests/test_integration.py +++ b/lms/djangoapps/instructor_task/tests/test_integration.py @@ -20,7 +20,6 @@ from django.test.utils import override_settings from django.urls import reverse from xblock_problem.capa.responsetypes import StudentInputError -from xblock_problem.capa.testing.codejail import UseUnsafeCodejail from xblock_problem.capa.testing.response_xml_factory import CodeResponseXMLFactory, CustomResponseXMLFactory from common.test.utils import assert_dict_contains_subset @@ -73,7 +72,6 @@ def _assert_task_failure(self, entry_id, task_type, problem_url_name, expected_m @ddt.ddt @override_settings(RATELIMIT_ENABLE=False) -@UseUnsafeCodejail() class TestRescoringTask(TestIntegrationTask): """ Integration-style tests for rescoring problems in a background task. diff --git a/lms/envs/common.py b/lms/envs/common.py index a40555461278..a97b318af3ac 100644 --- a/lms/envs/common.py +++ b/lms/envs/common.py @@ -1018,31 +1018,6 @@ #################### Python sandbox ############################################ -CODE_JAIL = { - # from https://github.com/openedx/codejail/blob/master/codejail/django_integration.py#L24, '' should be same as None - 'python_bin': '/edx/app/edxapp/venvs/edxapp-sandbox/bin/python', - # User to run as in the sandbox. - 'user': 'sandbox', - - # Configurable limits. - 'limits': { - # How many CPU seconds can jailed code use? - 'CPU': 1, - # Limit the memory of the jailed process to something high but not - # infinite (512MiB in bytes) - 'VMEM': 536870912, - # Time in seconds that the jailed process has to run. - 'REALTIME': 3, - 'PROXY': 0, - }, - - # Overrides to default configurable 'limits' (above). - # Keys should be course run ids (or, in the special case of code running - # on the /debug/run_python page, the key is 'debug_run_python'). - # Values should be dictionaries that look like 'limits'. - "limit_overrides": {}, -} - # .. setting_name: PYTHON_LIB_FILENAME # .. setting_default: python_lib.zip # .. setting_description: Name of the course file to make available to code in @@ -1307,7 +1282,6 @@ 'django.middleware.locale.LocaleMiddleware', 'lms.djangoapps.discussion.django_comment_client.utils.ViewNameMiddleware', - 'codejail.django_integration.ConfigureCodeJailMiddleware', # for expiring inactive sessions 'openedx.core.djangoapps.session_inactivity_timeout.middleware.SessionInactivityTimeout', diff --git a/lms/envs/mock.yml b/lms/envs/mock.yml index 3c52f27e0209..5a24cec063f7 100644 --- a/lms/envs/mock.yml +++ b/lms/envs/mock.yml @@ -231,28 +231,6 @@ CHAT_COMPLETION_MAX_TOKENS: 16385 CHAT_COMPLETION_RESPONSE_TOKENS: 1000 CLOSEST_CLIENT_IP_FROM_HEADERS: [] CMS_BASE: studio-deploy_host -CODE_JAIL: - limit_overrides: - codejail_expanded_limits: - CPU: 5 - FSIZE: 5 - PROXY: 5 - REALTIME: 5 - VMEM: 5 - course-v1:Org+Course+Run: - CPU: 5 - FSIZE: 5 - PROXY: 5 - REALTIME: 5 - VMEM: 5 - limits: - CPU: 1 - FSIZE: 1048576 - PROXY: 0 - REALTIME: 3 - VMEM: 536870912 - python_bin: /edx/app/edxapp/venvs/edxapp-sandbox/bin/python - user: sandbox COMMENTS_SERVICE_KEY: password COMMENTS_SERVICE_URL: http://localhost:18080 COMMERCE_COORDINATOR_REFUND_PATH: /lms/refund/ diff --git a/openedx/envs/common.py b/openedx/envs/common.py index a7c8bd8a790a..23f2d52d580e 100644 --- a/openedx/envs/common.py +++ b/openedx/envs/common.py @@ -2243,54 +2243,20 @@ def add_optional_apps(optional_apps, installed_apps): ############################## Python sandbox ############################## -CODE_JAIL = { - # from https://github.com/openedx/codejail/blob/master/codejail/django_integration.py#L24, '' should be same as None - 'python_bin': '/edx/app/edxapp/venvs/edxapp-sandbox/bin/python', - # User to run as in the sandbox. - 'user': 'sandbox', - - # Configurable limits. - 'limits': { - # How many CPU seconds can jailed code use? - 'CPU': 1, - # Limit the memory of the jailed process to something high but not - # infinite (512MiB in bytes) - 'VMEM': 536870912, - # Time in seconds that the jailed process has to run. - 'REALTIME': 3, - 'PROXY': 0, - }, - # Overrides to default configurable 'limits' (above). - # Keys should be course run ids (or, in the special case of code running - # on the /debug/run_python page, the key is 'debug_run_python'). - # Values should be dictionaries that look like 'limits'. - "limit_overrides": {}, -} - -# Some courses are allowed to run unsafe code. This is a list of regexes, one -# of them must match the course id for that course to run unsafe code. -# -# For example: -# -# COURSES_WITH_UNSAFE_CODE = [ -# r"Harvard/XY123.1/.*" -# ] -COURSES_WITH_UNSAFE_CODE = [] - -# Code jail REST service -ENABLE_CODEJAIL_REST_SERVICE = False +# CodeJail REST service # .. setting_name: CODE_JAIL_REST_SERVICE_REMOTE_EXEC -# .. setting_default: 'xmodule.capa.safe_exec.remote_exec.send_safe_exec_request_v0' +# .. setting_default: 'xblock_problem.capa.safe_exec.remote_exec.send_safe_exec_request_v0' # .. setting_description: Set the python package.module.function that is reponsible of # calling the remote service in charge of jailed code execution -CODE_JAIL_REST_SERVICE_REMOTE_EXEC = 'xmodule.capa.safe_exec.remote_exec.send_safe_exec_request_v0' +CODE_JAIL_REST_SERVICE_REMOTE_EXEC = 'xblock_problem.capa.safe_exec.remote_exec.send_safe_exec_request_v0' # .. setting_name: CODE_JAIL_REST_SERVICE_HOST -# .. setting_default: 'http://127.0.0.1:8550' -# .. setting_description: Set the codejail remote service host -CODE_JAIL_REST_SERVICE_HOST = 'http://127.0.0.1:8550' +# .. setting_default: None +# .. setting_description: Set the codejail remote service host. When not set problem blocks may return an +# ImproperlyConfigured error. +CODE_JAIL_REST_SERVICE_HOST = None # .. setting_name: CODE_JAIL_REST_SERVICE_CONNECT_TIMEOUT # .. setting_default: 0.5 diff --git a/openedx/envs/test.py b/openedx/envs/test.py index 8c0fafe6c372..f683737e3fd1 100644 --- a/openedx/envs/test.py +++ b/openedx/envs/test.py @@ -222,6 +222,12 @@ def make_staticfile_dirs(settings): DEFAULT_MOBILE_AVAILABLE = True +# Execute Codejail code locally in tests instead of calling a remote service. +CODE_JAIL_REST_SERVICE_HOST = "http://localhost:8550" +CODE_JAIL_REST_SERVICE_REMOTE_EXEC = ( + "xblock_problem.capa.testing.codejail.send_safe_exec_request_locally" +) + # Override production settings for testing AWS_QUERYSTRING_AUTH = False AWS_S3_CUSTOM_DOMAIN = "SET-ME-PLEASE (ex. bucket-name.s3.amazonaws.com)" diff --git a/requirements/edx-sandbox/README.rst b/requirements/edx-sandbox/README.rst deleted file mode 100644 index 9acbe9ebb823..000000000000 --- a/requirements/edx-sandbox/README.rst +++ /dev/null @@ -1,116 +0,0 @@ -edx-sandbox: a Python environment for sandboxed execution with CodeJail -####################################################################### - -The requirements in this directory describe a Python environment separate from -the general edx-platform environment. When correctly configured with -`CodeJail `_, edx-platform can use -it to execute untrusted code, particularly instructor-authored Python code -within ``