Add the usaco site's code runner
usaco-runner compiles, runs and lints solutions for the usaco site's solve page. It runs submitted code, so it gets no environment, sits only on usaco-runner-net (internal: no internet, and only the site can reach it), and runs read-only apart from an exec-able /tmp tmpfs, with memory, CPU and pids limits, no capabilities and no-new-privileges. The site joins that network and finds it through RUNNER_URL. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
@@ -237,6 +237,10 @@ JOBS_IMAGE_TAG=
|
|||||||
# a commit sha to pin. Changing it needs
|
# a commit sha to pin. Changing it needs
|
||||||
# `docker compose pull usaco && docker compose up -d usaco`.
|
# `docker compose pull usaco && docker compose up -d usaco`.
|
||||||
USACO_IMAGE_TAG=
|
USACO_IMAGE_TAG=
|
||||||
|
# The same for its code runner (usaco-runner), which the usaco repo's CI
|
||||||
|
# publishes and rolls alongside it. It takes no other settings: it has no
|
||||||
|
# secrets by design.
|
||||||
|
USACO_RUNNER_IMAGE_TAG=
|
||||||
# Gitea access token (repository: read and write on adamf/usaco). The site
|
# Gitea access token (repository: read and write on adamf/usaco). The site
|
||||||
# clones with it and pushes the admin's edits back.
|
# clones with it and pushes the admin's edits back.
|
||||||
USACO_GIT_TOKEN=
|
USACO_GIT_TOKEN=
|
||||||
|
|||||||
@@ -51,6 +51,13 @@ networks:
|
|||||||
ipam:
|
ipam:
|
||||||
config:
|
config:
|
||||||
- subnet: 172.28.0.0/16
|
- subnet: 172.28.0.0/16
|
||||||
|
# The usaco site's code runner and nothing else but the site. internal:
|
||||||
|
# no route out, so code submitted to it cannot reach the internet, and
|
||||||
|
# being off app-network keeps it away from postgres, gitea, garage and the
|
||||||
|
# backend. Docker picks the subnet; nothing here pins an address on it.
|
||||||
|
usaco-runner-net:
|
||||||
|
driver: bridge
|
||||||
|
internal: true
|
||||||
|
|
||||||
# PERSISTENT vs EPHEMERAL state
|
# PERSISTENT vs EPHEMERAL state
|
||||||
# Named volumes below survive `docker compose down` and container rebuilds;
|
# Named volumes below survive `docker compose down` and container rebuilds;
|
||||||
@@ -574,8 +581,10 @@ services:
|
|||||||
restart: always
|
restart: always
|
||||||
depends_on:
|
depends_on:
|
||||||
- gitea
|
- gitea
|
||||||
|
- usaco-runner
|
||||||
networks:
|
networks:
|
||||||
- app-network
|
- app-network
|
||||||
|
- usaco-runner-net
|
||||||
environment:
|
environment:
|
||||||
- GIT_REMOTE_URL=http://${GITEA_HOST}:${GITEA_PORT}/adamf/usaco.git
|
- GIT_REMOTE_URL=http://${GITEA_HOST}:${GITEA_PORT}/adamf/usaco.git
|
||||||
- GIT_TOKEN=${USACO_GIT_TOKEN:-}
|
- GIT_TOKEN=${USACO_GIT_TOKEN:-}
|
||||||
@@ -589,9 +598,48 @@ services:
|
|||||||
- S3_ENDPOINT=${USACO_S3_ACCESS_KEY_ID:+http://garage:3900}
|
- S3_ENDPOINT=${USACO_S3_ACCESS_KEY_ID:+http://garage:3900}
|
||||||
- S3_REGION=${USACO_S3_ACCESS_KEY_ID:+garage}
|
- S3_REGION=${USACO_S3_ACCESS_KEY_ID:+garage}
|
||||||
- S3_BUCKET=${USACO_S3_ACCESS_KEY_ID:+usaco-audio}
|
- S3_BUCKET=${USACO_S3_ACCESS_KEY_ID:+usaco-audio}
|
||||||
|
- RUNNER_URL=http://usaco-runner:8081
|
||||||
volumes:
|
volumes:
|
||||||
- ./usaco-data:/data
|
- ./usaco-data:/data
|
||||||
|
|
||||||
|
# The usaco site's code runner (site/Dockerfile.runner in adamf/usaco):
|
||||||
|
# compiles and runs solutions against their tests, and lints them, for the
|
||||||
|
# admin's solve page. It runs submitted code, so it has no secrets (no
|
||||||
|
# environment at all) and is only on usaco-runner-net, which is internal:
|
||||||
|
# no internet, and nothing but the site can reach it. Published by
|
||||||
|
# adamf/usaco's CI, which rolls it before `usaco`; pin
|
||||||
|
# USACO_RUNNER_IMAGE_TAG to hold a version.
|
||||||
|
#
|
||||||
|
# The hardening is the point:
|
||||||
|
# read_only the image is not writable; only /tmp is
|
||||||
|
# tmpfs /tmp one directory per request, removed after. Must NOT be
|
||||||
|
# noexec: the compiled program runs from it. Its pages count
|
||||||
|
# against mem_limit.
|
||||||
|
# mem_limit, cpus
|
||||||
|
# on top of the runner's own per-program limits (512 MB
|
||||||
|
# address space, CPU time, 64 MB files, wall clock)
|
||||||
|
# pids_limit what stops a fork bomb: the runner does not set
|
||||||
|
# RLIMIT_NPROC (it counts the whole uid, the server's own
|
||||||
|
# threads included). The image's tini reaps the leftovers.
|
||||||
|
# cap_drop, no-new-privileges
|
||||||
|
# the runner needs no capabilities, and runs as uid 1000
|
||||||
|
usaco-runner:
|
||||||
|
image: adam-french.co.uk/adamf/usaco-runner:${USACO_RUNNER_IMAGE_TAG:-latest}
|
||||||
|
container_name: usaco-runner
|
||||||
|
restart: always
|
||||||
|
networks:
|
||||||
|
- usaco-runner-net
|
||||||
|
read_only: true
|
||||||
|
tmpfs:
|
||||||
|
- /tmp:size=256m,exec
|
||||||
|
mem_limit: 1g
|
||||||
|
cpus: 2
|
||||||
|
pids_limit: 128
|
||||||
|
cap_drop:
|
||||||
|
- ALL
|
||||||
|
security_opt:
|
||||||
|
- no-new-privileges:true
|
||||||
|
|
||||||
# The activity tracker (time spent per app, site, walk...), served at
|
# The activity tracker (time spent per app, site, walk...), served at
|
||||||
# /tracker/ with the prefix stripped. Built and published by its own repo
|
# /tracker/ with the prefix stripped. Built and published by its own repo
|
||||||
# (adamf/ccp on this Gitea), whose CI pulls :latest into this service on
|
# (adamf/ccp on this Gitea), whose CI pulls :latest into this service on
|
||||||
|
|||||||
Reference in New Issue
Block a user