Sub topic 2
What Goes Wrong When a Runner Is Reused
Prerequisites: basic workflow syntax, Linux shell commands, containers or virtual machines, and Git pull requests.
Persistent Runner Risks
A self-hosted runner is a machine or container that runs GitHub Actions jobs. A persistent runner remains registered and accepts many jobs over time. Reuse is fast, but cleanup becomes your responsibility.
A job can leave behind:
- Source files, build outputs, or test data in the workspace.
- Package-manager and Docker caches containing private code.
- Background processes that affect later jobs.
- Cloud credentials, tokens, or copied secrets.
- A modified toolchain or runner configuration.
A later job may read this data. A malicious job may also intentionally search for it. Deleting the workspace after a job helps, but it does not reliably remove process state, filesystem artifacts outside the workspace, Docker volumes, or host-level access.
Untrusted Code and Fork Pull Requests
Pull requests from forks are untrusted because contributors can change workflow inputs and source code. If such a workflow runs on a persistent self-hosted runner, attacker-controlled commands may inspect the machine or attack the next job.
Secrets are usually withheld from ordinary pull_request workflows, but this does not make a self-hosted runner safe. The runner may already have credentials in files, environment variables, caches, or cloud metadata. Be especially careful with pull_request_target: it runs with the base repository's privileges, and checking out the fork's code can execute untrusted content with those privileges.
Use hosted runners for untrusted validation when possible. Otherwise, isolate the job and give it no sensitive access.
Ephemeral Runners: One Job, Then Gone
An ephemeral runner accepts one job and then removes its registration from GitHub. The machine or container should also be destroyed and recreated, so state does not cross job boundaries.
./config.sh \
--url https://github.com/OWNER/REPO \
--token REGISTRATION_TOKEN \
--name "runner-$(hostname)-$(date +%s)" \
--labels ephemeral \
--ephemeral \
--unattended
./run.shThe --ephemeral option does not clean the host by itself. Use a disposable virtual machine, container, or autoscaling system to provide that cleanup.
Exercise
Why is deleting only the workspace insufficient for a persistent runner?
Show answer
Credentials, processes, caches, Docker state, and files outside the workspace can remain available to later jobs.