Skip to content

Commit a9c3b31

Browse files
authored
test: load aa-profiles with compatible ABIs for the host (#207)
When not specified AppArmor fallbacks to a default policy specified in the `/etc/apparmor/parser.conf` file. Ubuntu 24.04 does not pin an ABI with network features and such rules are not enforced. From Ubuntu 22.04 onwards, the ABI 3.0 is available so we use that one. For Ubuntu 20.04 we rely on the fallback ABI (2.13).
1 parent 6e3491e commit a9c3b31

File tree

5 files changed

+105
-9
lines changed

5 files changed

+105
-9
lines changed

.github/workflows/ci.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,19 @@ jobs:
1919
- python_version: '3.11'
2020
ubuntu_version: '22.04'
2121
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"
22+
- python_version: '3.11'
23+
ubuntu_version: '24.04'
24+
os: "ubuntu-24.04"
2725

2826
steps:
2927
- uses: actions/checkout@v4
30-
- name: Parse custom apparmor profile
31-
run: sudo apparmor_parser -r -W apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python
28+
- name: Parse custom apparmor profile with default feature ABI
29+
if: ${{ matrix.ubuntu_version == '20.04' }}
30+
run: sudo apparmor_parser -r -W apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python-default-abi
31+
32+
- name: Parse custom apparmor profile with ABI 3.0
33+
if: ${{ matrix.ubuntu_version != '20.04' }}
34+
run: sudo apparmor_parser -r -W apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python-abi3
3235

3336
- name: Build latest code changes into CI image
3437
run: |

README.rst

+30
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Ubuntu:
6161

6262
* 20.04
6363
* 22.04
64+
* 24.04
6465

6566
Installation
6667
------------
@@ -137,6 +138,35 @@ Other details here that depend on your configuration:
137138
/tmp/codejail-*/** wrix,
138139
}
139140

141+
Depending on your OS and AppArmor version you may need to specify a policy
142+
ABI to ensure the restrictions are being correctly applied. Modern ubuntu
143+
versions using AppArmor V3 should use the 3.0 ABI in order to enable
144+
network confinment rules. A profile using the ABI 3.0 would look as
145+
follows::
146+
147+
$ sudo vim /etc/apparmor.d/home.chris.ve.myproj-sandbox.bin.python
148+
149+
abi <abi/3.0>,
150+
#include <tunables/global>
151+
152+
<SANDENV>/bin/python {
153+
#include <abstractions/base>
154+
#include <abstractions/python>
155+
156+
<CODEJAIL_CHECKOUT>/** mr,
157+
<SANDENV>/** mr,
158+
# If you have code that the sandbox must be able to access, add lines
159+
# pointing to those directories:
160+
/the/path/to/your/sandbox-packages/** r,
161+
162+
/tmp/codejail-*/ rix,
163+
/tmp/codejail-*/** wrix,
164+
}
165+
166+
You can also look at the
167+
``apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python-abi3``
168+
file which is used for testing for a full profile example.
169+
140170
6. Parse the profiles::
141171

142172
$ sudo apparmor_parser <APPARMOR_FILE>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
abi <abi/3.0>,
2+
#include <tunables/global>
3+
profile apparmor_profile /home/sandbox/codejail_sandbox-python{3.[0-9],3.[1-9][0-9]}/bin/python {
4+
#include <abstractions/base>
5+
#include <abstractions/python>
6+
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+
17+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/**.{pyc,so,so.*[0-9]} mr,
18+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/**.{egg,py,pth} r,
19+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/ r,
20+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/**/ r,
21+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/*.dist-info/{METADATA,namespace_packages.txt} r,
22+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/*.VERSION r,
23+
/usr/{local/,}lib{,32,64}/python{2.[4-7],3,3.[0-9],3.[1-9][0-9]}/{site,dist}-packages/*.egg-info/PKG-INFO r,
24+
/usr/{local/,}lib{,32,64}/python3.{1,}[0-9]/lib-dynload/*.so mr,
25+
26+
# Site-wide configuration
27+
/etc/python{2.[4-7],3.[0-9],3.[1-9][0-9]}/** r,
28+
29+
# shared python paths
30+
/usr/share/{pyshared,pycentral,python-support}/** r,
31+
/{var,usr}/lib/{pyshared,pycentral,python-support}/** r,
32+
/usr/lib/{pyshared,pycentral,python-support}/**.so mr,
33+
/var/lib/{pyshared,pycentral,python-support}/**.pyc mr,
34+
/usr/lib/python3/dist-packages/**.so mr,
35+
36+
# wx paths
37+
/usr/lib/wx/python/*.pth r,
38+
39+
# python build configuration and headers
40+
/usr/include/python{2.[4-7],3.[0-9],3.[1-9][0-9]}*/pyconfig.h r,
41+
42+
# Include additions to the abstraction
43+
include if exists <abstractions/python.d>
44+
45+
/home/sandbox/codejail_sandbox-python{3.[0-9],3.[1-9][0-9]}/** mr,
46+
/tmp/codejail-*/ rix,
47+
/tmp/codejail-*/** wrix,
48+
49+
# Whitelist particiclar shared objects from the system
50+
# python installation
51+
#
52+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_json.so mr,
53+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_ctypes.so mr,
54+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_heapq.so mr,
55+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_io.so mr,
56+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_csv.so mr,
57+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/datetime.so mr,
58+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/_elementtree.so mr,
59+
/usr/lib/python{3.[0-9],3.[1-9][0-9]}/lib-dynload/pyexpat.so mr,
60+
#
61+
# Allow access to selections from /proc
62+
#
63+
/proc/*/mounts r,
64+
}

apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python apparmor-profiles/home.sandbox.codejail_sandbox-python3.bin.python-default-abi

-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#include <tunables/global>
2-
32
profile apparmor_profile /home/sandbox/codejail_sandbox-python{3.[0-9],3.[1-9][0-9]}/bin/python {
43
#include <abstractions/base>
54
#include <abstractions/python>

codejail/__init__.py

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

3-
__version__ = '3.5.1'
3+
__version__ = '3.5.2'

0 commit comments

Comments
 (0)