Articles / Security

  • security
  • threat-modelling
  • ci-cd
  • github-actions
  • self-hosting
  • nftables

How to Threat Model a CI Runner That Builds Strangers' PRs

A CI runner that builds pull requests from strangers is a remote code execution service that you set up on purpose. Anyone who can open a PR can propose commands for your machine to run. So skip "could an attacker run code?" and start at "they are running code, now what?"

The examples use GitHub Actions with a self-hosted Linux runner, but the questions carry over to GitLab, Forgejo or a shell script behind a webhook. GitHub's own secure use reference says self-hosted runners should almost never be used for public repositories. If hosted runners will do the job, use them. If not, carry on.

Assume every file in the PR is a command

Reviewing the diff for a suspicious shell line is not enough. A normal build executes repository content in plenty of places:

  • Makefile targets and test files
  • build.rs and procedural macros in Rust
  • postinstall and other package manager scripts
  • a Dockerfile, or a changed dependency that brings its own hooks

Quick detour, because this one catches people. With the pull_request trigger, the PR can change the workflow file itself. A timeout, a container: line or a cautious cleanup step in YAML is therefore a request, which the author can edit. Controls that matter have to live somewhere the job cannot write.

Approval for runs from forks is worth turning on. It is a human checkpoint, though, and the human is often tired and looking at a 2,000 line diff. Model what happens when they click the button on something nasty.

List what you would hate to lose

Write the assets down before thinking about attacks. For a typical small project:

  • repository write access and release credentials
  • the integrity of what you publish: binaries, images, packages
  • other machines the runner can talk to
  • the credential that registers new runners
  • the runner's CPU, bandwidth and IP reputation
  • the truthfulness of the green tick

That last one is easy to miss. The job controls its own output and exit code, so a pass from untrusted code is only a claim. A PR can edit the tests, or the workflow, until everything succeeds. Branch protection still needs a person to read those changes.

Ask the runner what a job can reach

Architecture diagrams describe what you meant to build. To see what you did build, run a probe as an ordinary job from a test fork. Only do this on infrastructure you own or have permission to test.

id
sudo -n true 2>/dev/null && echo "FINDING: passwordless sudo"
[ -S /var/run/docker.sock ] && echo "FINDING: Docker socket present"
curl -s -m 2 -o /dev/null http://169.254.169.254/ && echo "FINDING: metadata address answers"
awk 'BEGIN { for (name in ENVIRON) print name }' | sort
ip route
[ -e "$HOME/canary" ] && echo "FINDING: an earlier job left state behind"
touch "$HOME/canary"

It prints environment variable names without their values, so the log does not become its own leak. Run it twice: the canary only means something on the second go. Then add a curl to your router, NAS or internal services and see which ones answer.

Hang on, what is that odd 169.254.169.254 address? On many cloud providers it is the instance metadata service, which can hand out temporary credentials for the machine's role to processes on it. Your carefully secret-free workflow may be sitting next to a vending machine for cloud access. Some configurations demand a token header first, so investigate an answer before you panic.

The Docker socket is the other big finding. A job that can drive a rootful Docker daemon can start a privileged container with the host filesystem mounted. Treat access to that socket as root on the host.

Give each job a machine you will destroy

On a persistent runner, one job can leave a background process, a poisoned tool or a modified shell profile for the next. The next job might be your release.

My preference is one fresh virtual machine per job, destroyed afterwards. A container shares the host kernel, which is a thinner wall than I want between a stranger and my kit. A VM can still be escaped, but it is a much better starting point.

GitHub offers ephemeral and just-in-time runners, which take at most one job. This controls the registration and leaves the disk underneath alone. --ephemeral does not wipe your machine; your tooling has to do that.

The loop belongs on the host:

  1. Clone a VM from a known image.
  2. Request a just-in-time runner configuration from the API.
  3. Pass only that configuration into the VM, and start the runner with ./run.sh --jitconfig.
  4. Wait for exit, with a hard deadline enforced by the host.
  5. Delete the VM and its disk.

The API credential used in step two stays on the host. If it leaks into the guest, an attacker may be able to register their own runner and receive your jobs.

Block the network from outside the VM

A job with sudo can remove any firewall inside its guest. Put the rules on the host instead. This nftables example assumes VMs sit behind a routed or NATed bridge called br-ci, with the host providing DHCP and DNS:

table inet ci {
  chain forward {
    type filter hook forward priority filter; policy accept;
    iifname "br-ci" ip daddr { 10.0.0.0/8, 100.64.0.0/10, 169.254.0.0/16, 172.16.0.0/12, 192.168.0.0/16 } drop
    iifname "br-ci" meta nfproto ipv6 drop
  }
  chain input {
    type filter hook input priority filter; policy accept;
    iifname "br-ci" ct state established,related accept
    iifname "br-ci" udp dport 67 accept
    iifname "br-ci" meta l4proto { tcp, udp } th dport 53 accept
    iifname "br-ci" drop
  }
}

This is a starting point with deliberate gaps. It drops forwarded IPv6 altogether, does not separate two VMs on the same bridge, and still allows the public internet. Your own services on public addresses remain reachable too. Rerun the network probes after loading it.

Open outbound access lets a build fetch dependencies. It also lets it mine cryptocurrency, send junk or scan other people from your address. Decide how much abuse you can absorb, then cap CPU, memory, disk, run time and concurrent VMs on the host. An egress allowlist is tighter, at the cost of maintaining it.

Follow anything that leaves the job

Destroying the VM does nothing about data that has already gone somewhere trusted. Trace each route out:

  • Caches: never let untrusted jobs write a cache that release jobs read. That includes your own shared volumes and package mirrors.
  • Artefacts: treat them as hostile input. A privileged workflow_run job must not execute them.
  • Logs and comments: a bot that parses job output is accepting input from the PR author.
  • Runner pools: release jobs need separate runners which fork PRs cannot select. A label alone is routing and grants no permission; use runner group restrictions where your plan and setup provide them.

GitHub's built-in cache scopes pull_request caches to the PR's merge ref. A home-made cache directory mounted into every VM has no such manners.

Keep secrets away from the triggers that have them

For public repositories, an ordinary pull_request run from a fork gets a read-only GITHUB_TOKEN and no repository secrets. That protects GitHub credentials. It does not protect anything already lying around on your runner.

pull_request_target runs in the base repository's trusted context. Checking out and building the PR's code there hands that context to its author. GitHub has announced that from 2 December 2026 the trigger is blocked by default in public repositories. If you explicitly allow it again, never execute the fork's code in that job.

Turn the answers into tests

For each asset, write one sentence: who can affect it, by what route, what stops them, and how you check. For example: "A fork author cannot reach the NAS because the host drops private destinations; the probe job must time out."

Anything without a "what stops them" is either work to do or a risk you are accepting out loud. Rerun the probe when you change the VM image, network, runner software or workflow triggers. The runner you modelled in spring has a habit of acquiring a helpful shared cache by autumn.