An online judge REST API which grades algorithmic task solutions automatically.
- Solve algorithmic problems in given time and memory limits
- Task and test case creation
- Support for task solutions in multiple programming languages
- Tags for tasks
- User profiles showing solved tasks
The operating system requirement for the server is Linux because of its nifty features. I have used Debian-based Ubuntu 18.04 for testing but it's probably possible to use other Linux distributions as well, with few to no changes.
- Install cgroup tools for manipulation of cgroups (cgcreate, cgset, cgget, cgexec, cgdelete)
$ sudo apt install cgroup-tools
- Create a non-privileged Linux user that will be used to run user programs (you will be prompted to select a password). We will also add him to a newly created Linux group with disabled network access. Execute the following commands:
$ sudo adduser coderunner
$ sudo addgroup no-network
$ sudo adduser coderunner no-network
$ sudo iptables -I OUTPUT 1 -m owner --gid-owner no-network -j DROP
- Allow some commands to be usable as sudo without a password in the /etc/sudoers file. This is a requirement for the system to be autonomous. Because user solutions will be executed by a non-privileged Linux user, as opposed to the privileged user <YOUR_LINUX_USERNAME> who will be starting the REST API service, this change does not pose a security threat. Execute the following command and insert the below line, with the username replaced, at the end of the file:
$ sudo visudo -f /etc/sudoers
<YOUR_LINUX_USERNAME> ALL = (root) NOPASSWD: /usr/bin/cgcreate,/usr/bin/cgset,/usr/bin/cgexec,/usr/bin/cgdelete,/usr/bin/timeout
- Make a directory executionroot in your Linux user's home directory (~) to serve as a chroot jail from which the task solutions will be executed. You can use a different directory for this, but be sure to update the reference in the project.
- Copy /bin/bash and its dependencies (using ldd and cp) into ~/executionroot/ with these commands:
$ chr=~/executionroot
$ cp -v --parents /bin/bash "${chr}"
$ list="$(ldd /bin/bash | egrep -o '/lib.*\.[0-9]')"
$ for i in $list; do cp -v --parents "$i" "${chr}"; done
- Run the two SQL scripts from the /database-scripts/ directory to create the project MySQL database schema and to populate it with initial data.
- The project back end assumes the following MySQL connection pairs: localhost for the server, root for the username and no password. If needed, change the connection string in the /OnlineJudgeApi/appsettings.json file.
ASP.NET Core Web API version used: 3.1
Authentication handled via JSON Web Tokens (JWT)
Versions used:
- .NET Core 3.1 SDK
- MySQL 8.0.11
Link to Angular front-end web app repository
To serve the REST API locally run the following command from the /OnlineJudgeApi/ directory:
dotnet run
- JSON Web Tokens - Authorization tokens for a RESTful API