From f975c4104001e8d75127171b6d6043a81047c047 Mon Sep 17 00:00:00 2001 From: Ivan Liang Date: Tue, 17 Nov 2026 12:42:33 -0500 Subject: [PATCH 1/2] fix(build): give every build context entry to root createBuildContext writes each challenge file with tar.FileInfoHeader, which records the owner the file has on the build host. The classic builder ignored that: a Dockerfile COPY without --chown always produced files owned by root. BuildKit, selected explicitly since 07b9d6e, keeps the owner the context entry carries, so since then every plain COPY in a cork-built image has been owned by whoever owns the challenge tree where it was built, not by root. Found by the examples check that follows: the multi-container example installs a sudoers drop-in with a plain COPY, sudo refuses a drop-in not owned by root ("owned by uid 1000, should be 0"), and its solver waited at a password prompt until it timed out. Every context entry now says root, as artifact archives already do. Nothing hashes the context's headers, so this changes no build's identity: an image built since 07b9d6e keeps its owners until its challenge is rebuilt for another reason. --- cork/buildcontext_owner_test.go | 61 +++++++++++++++++++++++++++++++++ cork/filesystem.go | 3 ++ 2 files changed, 64 insertions(+) create mode 100644 cork/buildcontext_owner_test.go diff --git a/cork/buildcontext_owner_test.go b/cork/buildcontext_owner_test.go new file mode 100644 index 0000000..88bb65f --- /dev/null +++ b/cork/buildcontext_owner_test.go @@ -0,0 +1,61 @@ +package cork + +import ( + "archive/tar" + "io" + "os" + "path/filepath" + "testing" +) + +// BuildKit gives a COPY'd file the owner its context entry carries, so every +// entry must say root: anything else is whoever owns the challenge tree on the +// build host, in every image. Only meaningful when the test does not run as +// root, which is the case on CI and on a developer's machine. +func TestBuildContextEntriesAreOwnedByRoot(t *testing.T) { + chalDir := t.TempDir() + for rel, body := range map[string]string{ + "Dockerfile": "FROM busybox:1.36 AS base\nCOPY secret /secret\n", + "problem.md": "# chal\n", + "secret": "s3cr3t\n", + "app/sudoers.conf": "nobody ALL=(ALL) NOPASSWD: ALL\n", + } { + if err := os.MkdirAll(filepath.Dir(filepath.Join(chalDir, rel)), 0o755); err != nil { + t.Fatal(err) + } + if err := os.WriteFile(filepath.Join(chalDir, rel), []byte(body), 0o644); err != nil { + t.Fatal(err) + } + } + + m := &Manager{log: newLogger(DISABLED)} + ctxFile, err := m.createBuildContext(&ChallengeMetadata{Path: filepath.Join(chalDir, "problem.md")}, nil) + if err != nil { + t.Fatal(err) + } + defer os.Remove(ctxFile) + + f, err := os.Open(ctxFile) + if err != nil { + t.Fatal(err) + } + defer f.Close() + tr := tar.NewReader(f) + seen := 0 + for { + hdr, err := tr.Next() + if err == io.EOF { + break + } + if err != nil { + t.Fatal(err) + } + seen++ + if hdr.Uid != 0 || hdr.Gid != 0 || hdr.Uname != "" || hdr.Gname != "" { + t.Errorf("%s enters the context as %d:%d (%q:%q), not root", hdr.Name, hdr.Uid, hdr.Gid, hdr.Uname, hdr.Gname) + } + } + if seen == 0 { + t.Fatal("the context is empty") + } +} diff --git a/cork/filesystem.go b/cork/filesystem.go index 138a028..fde36d8 100644 --- a/cork/filesystem.go +++ b/cork/filesystem.go @@ -597,6 +597,9 @@ func (m *Manager) createBuildContext(cm *ChallengeMetadata, dockerfile []byte) ( if err != nil { return nil } + // Owned by root, as COPY always made them under the classic builder: + // BuildKit keeps the owner a context file arrives with. + hdr.Uid, hdr.Gid, hdr.Uname, hdr.Gname = 0, 0, "", "" archivePath := path[len(challengeDir)+1:] hdr.Name = strings.ReplaceAll(archivePath, `\`, `/`) From 80b05b74fe6bd436ee9e689a6c619eaed3a5d886 Mon Sep 17 00:00:00 2001 From: Ivan Liang Date: Tue, 17 Nov 2026 13:08:42 -0500 Subject: [PATCH 2/2] test(ci): build, deliver and solve every example on each pull request `cmgr test --require-solve examples` used to do this in CI. It went with the in-process CLI in 19e25e2, its CI step followed in 4c81a10, and since then nothing built most of the corpus: the e2e fleet builds four of the eight examples, by hand, and runs one solver. ci/examples/run.sh starts a corkd on the runner's own docker daemon (no registry, no workers) and, for every challenge it finds: - builds it through POST /challenges/ - checks the recorded flag, and that a build publishing artifacts left a readable archive in the artifact directory - for a service, launches it as the platform does (user_id and env), runs its solver on the instance's network, then stops it and checks its containers and network are gone - for artifact-only and flag-only, checks a launch is refused and runs the solver on the default network - destroys the build The solver runs the way examples/solvers.md describes, which this rewrites to match: solver/ plus the extracted artifacts and lookup values, in the default image ci/examples/solver.Dockerfile unless it brings its own, under cork's seccomp policy, and must write the build's flag within ten minutes. A challenge without a solver fails unless it is flag-only. It runs as a job of its own in go.yml, amd64 only, against a docker:$DOCKER_ENGINE-dind engine (29.10.0, what production runs, with overlay2 as production configures it) rather than the runner's own, which lags it: an engine before 29.6.0 cannot pull a base image for a build with no client session, which is how cork builds (moby/moby#48112; 29.4.3 and 29.5.3 fail, 29.6.0 to 29.10.0 build, the runner shipped 29.4.2). The e2e never met this because its builder is a pinned dind too. The disks example's base image is built through the Actions cache on the runner and handed to that engine. Checked on Docker Desktop 29.9.3 and on a cold docker:29.10.0-dind engine set up as the job sets it up (189 s): all eight examples pass with the ownership fix; without it the multi-container example's solver hangs at sudo's password prompt. --- .github/workflows/go.yml | 67 ++++++++++ ci/examples/run.sh | 242 ++++++++++++++++++++++++++++++++++ ci/examples/solver.Dockerfile | 21 +++ e2e/README.md | 10 +- examples/solvers.md | 44 ++++--- 5 files changed, 363 insertions(+), 21 deletions(-) create mode 100755 ci/examples/run.sh create mode 100644 ci/examples/solver.Dockerfile diff --git a/.github/workflows/go.yml b/.github/workflows/go.yml index 1df3c30..f1155e3 100644 --- a/.github/workflows/go.yml +++ b/.github/workflows/go.yml @@ -101,3 +101,70 @@ jobs: - name: Display Coverage run: go tool cover -func=coverage.out + + # Every example challenge, built and delivered by a corkd and solved by its + # own solver. One architecture: this checks the challenge corpus and the + # build path, not the toolchain. + examples: + name: Examples (build, deliver, solve) + runs-on: ubuntu-latest + timeout-minutes: 45 + env: + # The engine production runs, not the runner's own, which lags it: cork + # builds with no client session, and before 29.6.0 such a build cannot + # pull its base image (moby/moby#48112). Keep this in step with prod. + DOCKER_ENGINE: 29.10.0 + + steps: + - name: Check out code + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + fetch-depth: 0 # ci/version.sh describes from a tag + + - name: Set up Go + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e # v7.0.0 + with: + go-version: '1.26.x' + cache: true + + - name: Build + run: | + mkdir -p bin + LDFLAGS=$(sh ci/version.sh --ldflags) + go build -ldflags "$LDFLAGS" -o bin/ ./cmd/corkd ./cmd/cork + + # With overlay2, as production's daemons are configured (BUILDER.md). + - name: Start the docker engine production runs + run: | + docker run -d --privileged --name engine -e DOCKER_TLS_CERTDIR= \ + -p 127.0.0.1:2375:2375 "docker:${DOCKER_ENGINE}-dind" \ + dockerd --host=tcp://0.0.0.0:2375 --storage-driver=overlay2 + for _ in $(seq 60); do + docker -H tcp://127.0.0.1:2375 version >/dev/null 2>&1 && break + sleep 1 + done + docker -H tcp://127.0.0.1:2375 info --format '{{.ServerVersion}} {{.Driver}}' + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@bb05f3f5519dd87d3ba754cc423b652a5edd6d2c # v4.2.0 + + # The disks example builds FROM this image, which no registry holds. Cached + # across runs, so its libguestfs and kernel install only re-runs when the + # Dockerfile changes; built on the runner's daemon, then handed over. + - name: Build the shared example base image + uses: docker/build-push-action@53b7df96c91f9c12dcc8a07bcb9ccacbed38856a # v7.3.0 + with: + context: ci + file: ci/guestfish-base.Dockerfile + tags: cmgr/examples-guestfish-base:latest + load: true + cache-from: type=gha + cache-to: type=gha,mode=max + + - name: Hand the base image to the engine + run: docker save cmgr/examples-guestfish-base:latest | docker -H tcp://127.0.0.1:2375 load + + - name: Build, deliver and solve every example + env: + DOCKER_HOST: tcp://127.0.0.1:2375 + run: bash ci/examples/run.sh bin diff --git a/ci/examples/run.sh b/ci/examples/run.sh new file mode 100755 index 0000000..a30e50d --- /dev/null +++ b/ci/examples/run.sh @@ -0,0 +1,242 @@ +#!/usr/bin/env bash +# Every example challenge builds, is delivered the way its type says, and is +# solved by its own solver against the flag cork recorded for the build. +# +# usage: ci/examples/run.sh +# +# Starts a corkd of its own on the local docker daemon (no registry, no +# workers) unless CORK_SERVER names one already running, in which case +# CORK_DIR and CORK_ARTIFACT_DIR must be that daemon's. CORK_EXAMPLES limits +# the run to the challenge ids it lists. Needs docker, curl, jq and tar. +set -uo pipefail + +if [[ $# -ne 1 || ! -x "$1/corkd" || ! -x "$1/cork" ]]; then + echo "usage: $0 " >&2 + exit 2 +fi +BIN=$(cd "$1" && pwd) +HERE=$(cd "$(dirname "$0")" && pwd) +REPO=$(cd "$HERE/../.." && pwd) +WORK=$(mktemp -d) +SEED=1 +FORMAT='examples{%s}' +SOLVE_TIMEOUT=600 # what cmgr's solver framework allowed + +T0=$(date +%s) +since() { echo $(($(date +%s) - $1)); } +api() { # api [body]: the body on 2xx, else fails with it + curl -sS --fail-with-body --max-time 1800 -X "$1" -H 'Content-Type: application/json' \ + ${3:+-d "$3"} "$CORK_SERVER$2" +} +code() { # code [body]: the status alone + curl -sS -o /dev/null -w '%{http_code}' --max-time 1800 -X "$1" \ + -H 'Content-Type: application/json' ${3:+-d "$3"} "$CORK_SERVER$2" +} + +BUILDS=() +INSTANCES=() +SOLVES=0 +CORKD_PID="" +cleanup() { + local id + for id in "${INSTANCES[@]}"; do code DELETE "/instances/$id" >/dev/null; done + for id in "${BUILDS[@]}"; do code DELETE "/builds/$id" >/dev/null; done + docker ps -aq --filter 'name=^cork-examples-solver-' | xargs -r docker rm -f >/dev/null + docker images -q cork-examples-solver | sort -u | xargs -r docker rmi -f >/dev/null 2>&1 + if [[ -n "$CORKD_PID" ]]; then + kill "$CORKD_PID" 2>/dev/null + wait "$CORKD_PID" 2>/dev/null + fi + rm -rf "$WORK" +} +trap cleanup EXIT + +if [[ -z "${CORK_SERVER:-}" ]]; then + unset CORK_REGISTRY CMGR_REGISTRY CORK_BUILD_PLANE CMGR_BUILD_PLANE + export CORK_DIR=${CORK_DIR:-$REPO/examples} + export CORK_DB=$WORK/cork.db CORK_ARTIFACT_DIR=$WORK/artifacts + export CORK_SERVER=http://127.0.0.1:${CORK_EXAMPLES_PORT:-4290} + "$BIN/corkd" --address 127.0.0.1 --port "${CORK_SERVER##*:}" >"$WORK/corkd.log" 2>&1 & + CORKD_PID=$! + for _ in $(seq 60); do + curl -sSf --max-time 2 -o /dev/null "$CORK_SERVER/version" 2>/dev/null && break + kill -0 "$CORKD_PID" 2>/dev/null || break + sleep 1 + done + if ! curl -sSf --max-time 2 -o /dev/null "$CORK_SERVER/version" 2>/dev/null; then + echo "corkd did not come up on $CORK_SERVER:" >&2 + tail -30 "$WORK/corkd.log" >&2 + exit 2 + fi +fi +: "${CORK_DIR:?CORK_DIR must name the challenge tree the daemon serves}" +: "${CORK_ARTIFACT_DIR:?CORK_ARTIFACT_DIR must name the artifact directory of that daemon}" + +"$BIN/cork" update >"$WORK/update.log" 2>&1 || { + cat "$WORK/update.log" + exit 2 +} +if [[ -n "${CORK_EXAMPLES:-}" ]]; then + read -ra CHALLENGES <<<"$CORK_EXAMPLES" +else + mapfile -t CHALLENGES < <(api GET /challenges | jq -r '.[].id' | sort) +fi +[[ ${#CHALLENGES[@]} -gt 0 ]] || { echo "no challenges under $CORK_DIR" >&2; exit 2; } + +# solve : runs the +# challenge's solver the way examples/solvers.md promises and sets REASON +# when it does not write the build's flag. +solve() { + local dir=$1 bmeta=$2 net=$3 bid flag ctx img name got + bid=$(jq -r .id <<<"$bmeta") + flag=$(jq -r .flag <<<"$bmeta") + # Numbered per solve, not per build: cork hands a destroyed build's id to + # the next build. + SOLVES=$((SOLVES + 1)) + ctx=$WORK/solve-$SOLVES + img=cork-examples-solver:$SOLVES + name=cork-examples-solver-$SOLVES + mkdir -p "$ctx" + cp -a "$dir/solver/." "$ctx/" + [[ -f "$ctx/Dockerfile" ]] || cp "$HERE/solver.Dockerfile" "$ctx/Dockerfile" + if [[ "$(jq -r .has_artifacts <<<"$bmeta")" == true ]]; then + tar xzf "$CORK_ARTIFACT_DIR/$bid.tar.gz" -C "$ctx" || { + REASON="could not extract the artifacts of build $bid" + return 1 + } + fi + if [[ "$(jq -r '.lookup_data // {} | length' <<<"$bmeta")" != 0 ]]; then + jq -c .lookup_data <<<"$bmeta" >"$ctx/metadata.json" + fi + if ! docker build -q -t "$img" "$ctx" >"$WORK/solver-build-$bid.log" 2>&1; then + REASON="the solver image did not build: $(tail -5 "$WORK/solver-build-$bid.log")" + return 1 + fi + docker create --name "$name" --hostname solve -t \ + --security-opt "seccomp=$REPO/cork/seccomp.json" \ + ${net:+--network "$net" --network-alias solver} "$img" >/dev/null && + docker start "$name" >/dev/null || { + REASON="the solver container did not start" + return 1 + } + if ! timeout "$SOLVE_TIMEOUT" docker wait "$name" >/dev/null; then + REASON="the solver did not exit within ${SOLVE_TIMEOUT}s; its last output: $(docker logs --tail 10 "$name" 2>&1)" + return 1 + fi + got=$(docker cp "$name:/solve/flag" - 2>/dev/null | tar xO 2>/dev/null) + got=${got#"${got%%[![:space:]]*}"} + got=${got%"${got##*[![:space:]]}"} + if [[ "$got" != "$flag" ]]; then + REASON="the solver wrote '${got:-nothing}' and build $bid carries '$flag'; its last output: $(docker logs --tail 10 "$name" 2>&1)" + return 1 + fi + docker rm -f "$name" >/dev/null + docker rmi -f "$img" >/dev/null 2>&1 + return 0 +} + +# check : builds, delivers, solves and destroys one challenge, +# and sets REASON when any of it goes wrong. +check() { + local id=$1 cmeta type dir builds bid bmeta flag inst iid cid + cmeta=$(api GET "/challenges/$id") || { REASON="cork does not know it: $cmeta"; return 1; } + type=$(jq -r .delivery_type <<<"$cmeta") + dir=$(dirname "$(jq -r .path <<<"$cmeta")") + + # The disks example builds FROM a base image no registry holds; CI builds + # it with a layer cache first, and a local run gets it built here. + if grep -qs '^FROM cmgr/examples-guestfish-base' "$dir/Dockerfile" "$dir/solver/Dockerfile" && + ! docker image inspect cmgr/examples-guestfish-base >/dev/null 2>&1; then + echo " building cmgr/examples-guestfish-base first (slow; CI caches it)" + docker build -q -t cmgr/examples-guestfish-base -f "$REPO/ci/guestfish-base.Dockerfile" "$REPO/ci" >"$WORK/base.log" 2>&1 || { + REASON="its base image did not build: $(tail -5 "$WORK/base.log")" + return 1 + } + fi + + builds=$(api POST "/challenges/$id" "{\"flag_format\":\"$FORMAT\",\"seeds\":[$SEED]}") || { + REASON="it did not build: $(tail -c 600 <<<"$builds")" + return 1 + } + bid=$(jq -r '.[0].id' <<<"$builds") + BUILDS+=("$bid") + bmeta=$(api GET "/builds/$bid") || { REASON="build $bid cannot be read back: $bmeta"; return 1; } + # A flag-only challenge brings its own flag, so the format proves nothing; + # the solver is what checks the flag. + flag=$(jq -r '.flag // ""' <<<"$bmeta") + [[ -n "$flag" ]] || { REASON="build $bid carries no flag"; return 1; } + if [[ "$(jq -r .has_artifacts <<<"$bmeta")" == true ]] && ! tar tzf "$CORK_ARTIFACT_DIR/$bid.tar.gz" >/dev/null 2>&1; then + REASON="build $bid publishes artifacts, but $CORK_ARTIFACT_DIR/$bid.tar.gz is not a readable archive" + return 1 + fi + + case "$type" in + service) + # As the platform launches one: a user and runtime environment. + inst=$(api POST "/builds/$bid" '{"user_id":"examples","env":{"CUSTOM_VAR":"examples"}}') || { + REASON="build $bid did not launch: $inst" + return 1 + } + iid=$(jq -r .id <<<"$inst") + INSTANCES+=("$iid") + [[ "$(jq -r '.ports // {} | length' <<<"$inst")" != 0 ]] || { + REASON="instance $iid of a service challenge publishes no port: $inst" + return 1 + } + if [[ "$(jq -r .solve_script <<<"$cmeta")" != true ]]; then + REASON="it has no solver, and only a flag-only challenge may go without one" + return 1 + fi + solve "$dir" "$bmeta" "cmgr-$iid" || return 1 + [[ "$(code DELETE "/instances/$iid")" == 204 ]] || { REASON="instance $iid did not stop"; return 1; } + for cid in $(jq -r '.containers[]?' <<<"$inst"); do + ! docker container inspect "$cid" >/dev/null 2>&1 || { + REASON="container $cid of instance $iid is still there after the stop" + return 1 + } + done + ! docker network inspect "cmgr-$iid" >/dev/null 2>&1 || { + REASON="network cmgr-$iid is still there after the stop" + return 1 + } + ;; + artifact_only | flag_only) + [[ "$(code POST "/builds/$bid" '{}')" != 201 ]] || { + REASON="a launch of a $type build was answered with an instance" + return 1 + } + if [[ "$(jq -r .solve_script <<<"$cmeta")" == true ]]; then + solve "$dir" "$bmeta" "" || return 1 + elif [[ "$type" != flag_only ]]; then + REASON="it has no solver, and only a flag-only challenge may go without one" + return 1 + fi + ;; + *) + REASON="cork reports an unknown delivery type '$type'" + return 1 + ;; + esac + + [[ "$(code DELETE "/builds/$bid")" == 204 ]] || { REASON="build $bid was not destroyed"; return 1; } + return 0 +} + +echo "== ${#CHALLENGES[@]} challenges from $CORK_DIR, against $CORK_SERVER on docker $(docker version --format '{{.Server.Version}}') ($(docker info --format '{{.Driver}}'))" +failed=() +for id in "${CHALLENGES[@]}"; do + t=$(date +%s) + REASON="" + if check "$id"; then + echo "PASS $id ($(since "$t")s)" + else + echo "FAIL $id ($(since "$t")s): $REASON" + failed+=("$id") + fi +done + +echo "== ${#CHALLENGES[@]} challenges, ${#failed[@]} failed, in $(since "$T0")s" +if [[ ${#failed[@]} -ne 0 ]]; then + [[ -f "$WORK/corkd.log" ]] && { echo "-- last lines of corkd's log"; tail -40 "$WORK/corkd.log"; } + exit 1 +fi diff --git a/ci/examples/solver.Dockerfile b/ci/examples/solver.Dockerfile new file mode 100644 index 0000000..91917e7 --- /dev/null +++ b/ci/examples/solver.Dockerfile @@ -0,0 +1,21 @@ +# The image a solver runs in when its solver/ directory brings no Dockerfile +# of its own (examples/solvers.md describes the contract). +FROM ubuntu:24.04 +ENV DEBIAN_FRONTEND=noninteractive + +RUN apt-get update && apt-get install -y \ + python3-pip \ + socat \ + build-essential && \ + rm -rf /var/lib/apt/lists/* + +COPY Dockerfile packages.txt* ./ +RUN if [ -f packages.txt ]; then apt-get update && xargs -a packages.txt apt-get install -y && rm -rf /var/lib/apt/lists/*; fi + +COPY Dockerfile requirements.txt* ./ +RUN if [ -f requirements.txt ]; then pip3 install --break-system-packages -r requirements.txt; fi + +COPY . /solve +WORKDIR /solve + +CMD ["python3", "solve.py"] diff --git a/e2e/README.md b/e2e/README.md index e1e707c..90ac868 100644 --- a/e2e/README.md +++ b/e2e/README.md @@ -4,11 +4,11 @@ A compose project that runs the whole cork fleet on one machine and drives the real launch sequence through it: `corkd` built from this checkout, the docker daemon it builds on, a zot registry, and two docker workers with the telemetry agent, all wired with the PKI that `config-examples/gen-docker-certs.sh` -mints. It replaces nothing: the `cmgr test` suite that CI used to run built -and solved every example against one daemon and is gone since 4c81a10; this -exercises what that never could, placement across workers, the registry round -trip, worker health, rebuilds, and teardown across boxes, with four challenges -and no solvers. +mints. It does not cover the example corpus: every example is built, +delivered and solved against one daemon on each pull request by +`ci/examples/run.sh`. This exercises what that cannot, placement across +workers, the registry round trip, worker health, rebuilds, and teardown across +boxes, with four challenges and no solvers. ``` docker compose run --rm e2e (scenario.sh) diff --git a/examples/solvers.md b/examples/solvers.md index f13ae91..6da9873 100644 --- a/examples/solvers.md +++ b/examples/solvers.md @@ -1,24 +1,36 @@ # Automated Solvers -One of the goals for `cmgr` is to further improve the state of CI/CD for CTFs. -Part of this is creating a framework for automated solvescripts that can check -the status and solvability of deployed challenges. To enable this, we have -implemented a standardized mechanism for solve scripts that can be easily run -against individual challenge instances. +A challenge can carry a solve script that proves it is solvable. cork itself +runs no solvers; `ci/examples/run.sh` runs every example's on each pull +request, against a fresh build, and checks that it recovers the flag cork +recorded for that build. A challenge without a solver fails that check unless +it is `flag-only`. ## Usage -To create a solver, a challenge author only needs to create a `solver` directory -inside of their challenge directory and add a `solve.py` script (Python 3) that -implements the solution (both regular build tools and `pwntools` are installed by default). - -The `cmgr` interface will ensure any requested dependencies are installed prior to launching the script and will launch the script from a container in the same network as the challenge itself. This allows the challenge author to leverage the standardized DNS naming convention (`challenge` for the container hosting the challenge and `solver` for the solve script container) as well as the static ports in use (5000/tcp for `cmgr` challenge types and whatever was chosen for "custom" challenges). - -For artifact-only challenges (no published ports, e.g. `static-make`), there is no challenge container to connect to: the solver container runs on Docker's default network, so the `challenge` DNS name does not resolve and the flag must be recovered from the extracted artifacts in the working directory. Outbound network access (e.g. for downloading tooling at runtime) remains available as before. - -In addition to the files in the `solver` directory, `cmgr` will extract the artifacts given to competitors into the working directory of the solve script prior to launch. - -Once the flag has been retrieved, the solve script should write the flag to a file named `flag` in the working directory and exit. +To create a solver, add a `solver` directory to the challenge directory with a +`solve.py` script (Python 3) that implements the solution. Unless the +directory brings its own `Dockerfile`, the script runs in Ubuntu 24.04 with +`python3`, `pip3`, `socat` and `build-essential` installed +(`ci/examples/solver.Dockerfile`); anything else goes in the files below. + +For a challenge that runs a service, the solver container joins the +instance's network, so it reaches the challenge as `challenge` (and is itself +`solver`) on the port the container listens on, not the one published on the +host. + +For artifact-only challenges (no published ports, e.g. `static-make`), there is +no challenge container to connect to: the solver container runs on Docker's +default network, so the `challenge` DNS name does not resolve and the flag must +be recovered from the artifacts. Outbound network access (e.g. for downloading +tooling at runtime) remains available. + +The working directory holds the files of the `solver` directory, the artifacts +given to competitors (extracted), and, when the build has lookup values, +`metadata.json` with them. + +Once the flag has been retrieved, the solve script should write the flag to a +file named `flag` in the working directory and exit, within ten minutes. ## Installing Dependencies