Skip to content

Commit 0c5e04d

Browse files
authored
Merge pull request #201 from openedx/feanil/publish_ubuntu_images
Drop ECR for testing builds
2 parents 8bbe401 + 1b99481 commit 0c5e04d

19 files changed

+121
-166
lines changed

Diff for: .github/workflows/ci.yml

+18-22
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,40 @@ on:
88
jobs:
99
codejail_ci:
1010
name: tests
11-
runs-on: ubuntu-20.04
11+
runs-on: ${{ matrix.os }}
1212
strategy:
13+
fail-fast: false
1314
matrix:
1415
include:
15-
- python_version: '3.8'
16-
docker_tag: latest
1716
- python_version: '3.11'
18-
docker_tag: '3.11'
17+
ubuntu_version: '20.04'
18+
os: "ubuntu-20.04"
19+
- python_version: '3.11'
20+
ubuntu_version: '22.04'
21+
os: "ubuntu-22.04"
22+
# Disabling this for now because it's failing and we need to figure out
23+
# next steps to fix this.
24+
# - python_version: '3.11'
25+
# ubuntu_version: '24.04'
26+
# os: "ubuntu-24.04"
1927

2028
steps:
2129
- uses: actions/checkout@v4
22-
- name: Configure AWS credentials
23-
uses: aws-actions/configure-aws-credentials@v4
24-
with:
25-
aws-access-key-id: ${{ secrets.TOOLS_EDX_ECR_USER_AWS_ACCESS_KEY_ID }}
26-
aws-secret-access-key: ${{ secrets.TOOLS_EDX_ECR_USER_AWS_SECRET_ACCESS_KEY }}
27-
aws-region: us-east-1
28-
29-
- name: Login to Amazon ECR
30-
id: login-ecr
31-
uses: aws-actions/amazon-ecr-login@v2
32-
3330
- name: Parse custom apparmor profile
3431
run: sudo apparmor_parser -r -W apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python
3532

36-
- name: Pull codejail CI image
37-
run: docker pull 257477529851.dkr.ecr.us-east-1.amazonaws.com/openedx-codejail:latest
38-
3933
- name: Build latest code changes into CI image
4034
run: |
41-
docker build --cache-from 257477529851.dkr.ecr.us-east-1.amazonaws.com/openedx-codejail \
42-
-t 257477529851.dkr.ecr.us-east-1.amazonaws.com/openedx-codejail \
43-
--build-arg python_version=${{ matrix.python_version }} .
35+
docker build -t openedx-codejail \
36+
--cache-to type=gha \
37+
--cache-from type=gha \
38+
--build-arg python_version=${{ matrix.python_version }} \
39+
--build-arg ubuntu_version=${{ matrix.ubuntu_version }} .
4440
4541
- name: Run container with custom apparmor profile and codejail CI image
4642
run: |
4743
docker run --name=codejail --privileged -d --security-opt apparmor=apparmor_profile \
48-
257477529851.dkr.ecr.us-east-1.amazonaws.com/openedx-codejail tail -f /dev/null
44+
openedx-codejail tail -f /dev/null
4945
5046
- name: Run Non Proxy Tests
5147
run: docker exec -t codejail bash -c 'make clean && make test_no_proxy'

Diff for: .github/workflows/push-docker-image.yml

-40
This file was deleted.

Diff for: Dockerfile

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
FROM ubuntu:focal
1+
ARG ubuntu_version="20.04"
2+
3+
FROM ubuntu:${ubuntu_version}
24
SHELL ["/bin/bash", "-c"]
35

4-
ARG python_version=3.8
6+
ARG python_version="3.8"
57

68
# Install Codejail Packages
79
ENV TZ=Etc/UTC
@@ -33,8 +35,15 @@ RUN addgroup $CODEJAIL_GROUP
3335
RUN adduser --disabled-login --disabled-password $CODEJAIL_TEST_USER --ingroup $CODEJAIL_GROUP
3436

3537
# Switch to non root user inside Docker container
36-
RUN addgroup ubuntu
37-
RUN adduser --disabled-login --disabled-password ubuntu --ingroup ubuntu
38+
RUN getent group ubuntu || groupadd ubuntu
39+
RUN getent passwd ubuntu || adduser --disabled-login --disabled-password ubuntu --ingroup ubuntu
40+
41+
# Remove using PAM to set limits for sudo.
42+
# We want codejail to manage the limits so we remove this line from the sudo pam config
43+
# if we don't the forked process gets limits based on /etc/security/limits.conf which by
44+
# default does not set any limits on the forked process.
45+
# This line was not there on Ubuntu 20.04 but was added in 22.04
46+
RUN sed -i '/pam_limits.so/d' /etc/pam.d/sudo
3847

3948
# Give Ownership of sandbox env to sandbox group and user
4049
RUN chown -R $CODEJAIL_TEST_USER:$CODEJAIL_GROUP $CODEJAIL_TEST_VENV

Diff for: README.rst

+22-4
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ using the same API, but will not guard against malicious code. This allows the
1919
same code to be used on safe-configured or non-safe-configured developer's
2020
machines.
2121

22-
A CodeJail sandbox consists of several pieces:
22+
A CodeJail sandbox consists of several pieces:
2323

2424
#) Sandbox environment. For a Python setup, this would be Python and
2525
associated core packages. This is denoted throughout this document
26-
as **<SANDENV>**. This is read-only.
26+
as **<SANDENV>**. This is read-only.
2727

2828
#) Sandbox packages. These are additional packages needed for a given
2929
run. For example, this might be a grader written by an instructor
@@ -34,7 +34,7 @@ A CodeJail sandbox consists of several pieces:
3434
#) Untrusted packages. This is typically the code submitted by the
3535
student to be tested on the server, as well as any data the code
3636
may need to modify. This is denoted throughout this document as
37-
**<UNTRUSTED_PACK>**. This is currently read-only, but may need to
37+
**<UNTRUSTED_PACK>**. This is currently read-only, but may need to
3838
be read-write for some applications.
3939

4040
#) OS packages. These are standard system libraries needed to run
@@ -48,6 +48,20 @@ sandboxes. This will be referred to as **<SANDBOX_CALLER>**. The
4848
second account is the account under which the sandbox runs. This is
4949
typically the account 'sandbox.'
5050

51+
Supported Versions
52+
------------------
53+
54+
This library currently is tested to work with the following versions
55+
56+
Python:
57+
58+
* 3.11
59+
60+
Ubuntu:
61+
62+
* 20.04
63+
* 22.04
64+
5165
Installation
5266
------------
5367

@@ -129,6 +143,10 @@ Other details here that depend on your configuration:
129143

130144
7. Reactivate your project's main virtualenv again.
131145

146+
8. Disable using PAM to set rlimits::
147+
148+
sed -i '/pam_limits.so/d' /etc/pam.d/sudo
149+
132150
Using CodeJail
133151
--------------
134152

@@ -142,7 +160,7 @@ commands at your Python terminal::
142160
codejail.safe_exec.safe_exec("output=open('/etc/passwd').read()", jailed_globals)
143161
print(jailed_globals) # should be unreachable if codejail is working properly
144162

145-
This should fail with an exception.
163+
This should fail with an exception.
146164

147165
If you need to change the packages installed into your sandbox's virtualenv,
148166
you'll need to disable AppArmor, because your sandboxed Python doesn't have

Diff for: apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python

+10
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ profile apparmor_profile /home/sandbox/codejail_sandbox-python{3.[0-9],3.[1-9][0
44
#include <abstractions/base>
55
#include <abstractions/python>
66

7+
# Deny network access and socket operations
8+
# Note: If this profile is being run on a docker container
9+
# then this directive might not be sufficient. Docker network
10+
# interfaces are created in a different namespace from the one that
11+
# apparmor can monitor and manage and so apparmor can't always deny
12+
# network access to the container. Please be sure to test
13+
# network access from within your container for the jailed process
14+
# to be sure that everything is secure.
15+
deny network,
16+
717
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/**.{pyc,so,so.*[0-9]} mr,
818
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/**.{egg,py,pth} r,
919
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/ r,

Diff for: codejail/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
"""init"""
22

3-
__version__ = '3.4.1'
3+
__version__ = '3.5.0'

Diff for: codejail/jail_code.py

+2
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ def __init__(self):
184184
self.stdout = self.stderr = self.status = None
185185

186186

187+
# pylint: disable=too-many-positional-arguments
187188
def jail_code(command, code=None, files=None, extra_files=None, argv=None,
188189
stdin=None, limit_overrides_context=None, slug=None):
189190
"""
@@ -229,6 +230,7 @@ def jail_code(command, code=None, files=None, extra_files=None, argv=None,
229230
# pylint: disable=too-many-statements
230231

231232
if not is_configured(command):
233+
# pylint: disable=broad-exception-raised
232234
raise Exception("jail_code needs to be configured for %r" % command)
233235

234236
# We make a temp directory to serve as the home of the sandboxed code.

Diff for: codejail/proxy.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def run_subprocess_through_proxy(*args, **kwargs): # pylint: disable=inconsiste
7171
proxy_stdout = proxy.stdout.readline()
7272
if not proxy_stdout:
7373
# EOF: the proxy must have died.
74-
raise Exception("Proxy process died unexpectedly!")
74+
raise Exception("Proxy process died unexpectedly!") # pylint: disable=broad-exception-raised
7575
status, stdout, stderr, log_calls = deserialize_out(proxy_stdout.rstrip())
7676

7777
# Write all the log messages to the log, and return.

Diff for: codejail/safe_exec.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class SafeExecException(Exception):
3737
"""
3838

3939

40+
# pylint: disable=too-many-positional-arguments
4041
def safe_exec(
4142
code,
4243
globals_dict,
@@ -235,6 +236,7 @@ def decode_object(obj):
235236
return json.loads(json.dumps(jd))
236237

237238

239+
# pylint: disable=too-many-positional-arguments
238240
def not_safe_exec(
239241
code,
240242
globals_dict,

Diff for: codejail/subproc.py

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
log = logging.getLogger("codejail")
1212

1313

14+
# pylint: disable=too-many-positional-arguments
1415
def run_subprocess(
1516
cmd, stdin=None, cwd=None, env=None, rlimits=None, realtime=None,
1617
slug=None,

Diff for: codejail/tests/test_safe_exec.py

+2
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ def test_importing_lots_of_crap(self):
101101
set_limit('REALTIME', 10)
102102
globs = {}
103103
self.safe_exec(textwrap.dedent("""\
104+
import os
105+
os.environ['OPENBLAS_NUM_THREADS'] = '1'
104106
from numpy import *
105107
a = 1723
106108
"""), globs)

Diff for: pylintrc

+2-35
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
# pygtk.require().
88
#init-hook=
99

10-
# Profiled execution.
11-
profile=no
12-
1310
# Add files or directories to the blacklist. They should be base names, not
1411
# paths.
1512
ignore=CVS, migrations
@@ -40,7 +37,6 @@ disable=
4037

4138
# Might use these when the code is in better shape
4239
# C0302: Too many lines in module
43-
# R0201: Method could be a function
4440
# R0901: Too many ancestors
4541
# R0902: Too many instance attributes
4642
# R0903: Too few public methods (1/2)
@@ -49,7 +45,7 @@ disable=
4945
# R0912: Too many branches
5046
# R0913: Too many arguments
5147
# R0914: Too many local variables
52-
C0301,C0302,R0201,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,
48+
C0301,C0302,R0901,R0902,R0903,R0904,R0911,R0912,R0913,R0914,
5349
unspecified-encoding,consider-using-with,consider-using-f-string,invalid-name
5450

5551

@@ -59,14 +55,6 @@ disable=
5955
# (visual studio) and html
6056
output-format=text
6157

62-
# Include message's id in output
63-
include-ids=yes
64-
65-
# Put messages in a separate file for each module / package specified on the
66-
# command line instead of printing them on stdout. Reports (if any) will be
67-
# written in a file name "pylint_global.[txt|html]".
68-
files-output=no
69-
7058
# Tells whether to display a full report or only the messages
7159
reports=no
7260

@@ -77,10 +65,6 @@ reports=no
7765
# (RP0004).
7866
evaluation=10.0 - ((float(5 * error + warning + refactor + convention) / statement) * 10)
7967

80-
# Add a comment according to your evaluation note. This is used by the global
81-
# evaluation report (RP0004).
82-
comment=no
83-
8468

8569
[TYPECHECK]
8670

@@ -92,10 +76,6 @@ ignore-mixin-members=yes
9276
# (useful for classes with attributes dynamically set).
9377
ignored-classes=SQLObject
9478

95-
# When zope mode is activated, add a predefined set of Zope acquired attributes
96-
# to generated-members.
97-
zope=no
98-
9979
# List of members which are set dynamically and missed by pylint inference
10080
# system, and so shouldn't trigger E0201 when accessed. Python regular
10181
# expressions are accepted.
@@ -115,12 +95,6 @@ generated-members=
11595

11696
[BASIC]
11797

118-
# Required attributes for module, separated by a comma
119-
required-attributes=
120-
121-
# List of builtins function names that should not be used, separated by a comma
122-
bad-functions=map,filter,apply,input
123-
12498
# Regular expression which should only match correct module names
12599
module-rgx=(([a-z_][a-z0-9_]*)|([A-Z][a-zA-Z0-9]+))$
126100

@@ -238,9 +212,6 @@ max-locals=15
238212
# Maximum number of return / yield for function / method body
239213
max-returns=6
240214

241-
# Maximum number of branch for function / method body
242-
max-branchs=12
243-
244215
# Maximum number of statements in function / method body
245216
max-statements=50
246217

@@ -259,10 +230,6 @@ max-public-methods=20
259230

260231
[CLASSES]
261232

262-
# List of interface methods to ignore, separated by a comma. This is used for
263-
# instance to not check methods defines in Zope's Interface base class.
264-
ignore-iface-methods=isImplementedBy,deferred,extends,names,namesAndDescriptions,queryDescriptionFor,getBases,getDescriptionFor,getDoc,getName,getTaggedValue,getTaggedValueTags,isEqualOrExtendedBy,setTaggedValue,isImplementedByInstancesOf,adaptWith,is_implemented_by
265-
266233
# List of method names used to declare (i.e. assign) instance attributes.
267234
defining-attr-methods=__init__,__new__,setUp
268235

@@ -274,4 +241,4 @@ valid-classmethod-first-arg=cls
274241

275242
# Exceptions that will emit a warning when being caught. Defaults to
276243
# "Exception"
277-
overgeneral-exceptions=Exception
244+
overgeneral-exceptions=builtins.Exception

0 commit comments

Comments
 (0)