|
| 1 | +# AppArmor profile for running codejail-service in devstack. |
| 2 | +# |
| 3 | +# #=========# |
| 4 | +# # WARNING # |
| 5 | +# #=========# |
| 6 | +# |
| 7 | +# This is not a complete and secure apparmor profile! Do not use this |
| 8 | +# in any deployed environment (even a staging environment) without |
| 9 | +# careful inspection and modification to fit your needs. |
| 10 | +# |
| 11 | +# Failure to apply a secure apparmor profile *will* likely result in a |
| 12 | +# compromise of your environment by an attacker. |
| 13 | +# |
| 14 | +# We may at some point make this file good enough for confinement in |
| 15 | +# production, but for now it is only intended to be used in devstack. |
| 16 | + |
| 17 | + |
| 18 | +#include <tunables/global> |
| 19 | + |
| 20 | +# Declare ABI version explicitly to ensure that confinement is |
| 21 | +# actually applied appropriately on newer Ubuntu. |
| 22 | +abi <abi/3.0>, |
| 23 | + |
| 24 | +# This outer profile applies to the entire container, and isn't as |
| 25 | +# important. If the sandbox profile doesn't work, it's not likely that |
| 26 | +# the outer one is going to help. But there may be some small value in |
| 27 | +# defense-in-depth, as it's possible that a bug in the child (sandbox) |
| 28 | +# profile isn't present in the outer one. |
| 29 | +profile codejail_service flags=(attach_disconnected,mediate_deleted) { |
| 30 | + #include <abstractions/base> |
| 31 | + |
| 32 | + # Filesystem access -- self-explanatory |
| 33 | + file, |
| 34 | + |
| 35 | + # `network` is required for sudo |
| 36 | + # TODO: Restrict this so that general network access is not permitted |
| 37 | + network, |
| 38 | + |
| 39 | + # Various capabilities required for sudoing to sandbox (setuid, |
| 40 | + # setgid, audit_write) and for sending a kill signal (kill). |
| 41 | + capability setuid setgid audit_write kill, |
| 42 | + |
| 43 | + # Allow sending a kill signal to the sandbox when the execution |
| 44 | + # runs beyond time limits. |
| 45 | + signal (send) set=(kill) peer=codejail_service//child, |
| 46 | + |
| 47 | + # Allow executing this binary, but force a transition to the specified |
| 48 | + # profile (and scrub the environment). |
| 49 | + /sandbox/venv/bin/python Cx -> child, |
| 50 | + |
| 51 | + # This is the important apparmor profile -- the one that actually |
| 52 | + # constrains the sandbox Python process. |
| 53 | + profile child flags=(attach_disconnected,mediate_deleted) { |
| 54 | + #include <abstractions/base> |
| 55 | + |
| 56 | + # Read and run binaries and libraries in the virtualenv. This |
| 57 | + # includes the sandbox's copy of Python as well as any |
| 58 | + # dependencies that have been installed for inclusion in |
| 59 | + # sandboxes. |
| 60 | + /sandbox/venv/** rm, |
| 61 | + |
| 62 | + # Codejail has a hardcoded reference to this file path, although the |
| 63 | + # use of /tmp specifically may be controllable with environment variables: |
| 64 | + # https://github.com/openedx/codejail/blob/0165d9ca351/codejail/util.py#L15 |
| 65 | + /tmp/codejail-*/ r, |
| 66 | + /tmp/codejail-*/** rw, |
| 67 | + |
| 68 | + # Allow interactive terminal during development |
| 69 | + /dev/pts/* rw, |
| 70 | + |
| 71 | + # Allow receiving a kill signal from the webapp when the execution |
| 72 | + # runs beyond time limits. |
| 73 | + signal (receive) set=(kill) peer=codejail_service, |
| 74 | + } |
| 75 | +} |
0 commit comments