Self-hosted CI runners: persistence, network reach, and untrusted pull requests

Self-hosted runners execute pipeline code on your own machines, often with network access and cached credentials. Why persistent runners and public pull requests are a dangerous mix, and how ephemeral runners and job permissions fix it.

Lesson 22 of 26 · 10 min read · practice only with authorization

Diagram

Risk on a long-lived runner

Follow the path. One example at a time.

Step 1 of 4

Shared

One runner serves many repositories and stays up for months.

Illustration: Shared
# Shared
# One runner serves many repositories and stays up for
# months.

The example on the open step is one illustration, or the fix you can paste into an application you own.

What this page is made of

3 pieces. Each one says what fails, who is affected, what you would notice, and what you change.

  1. Public repositories

    What fails
    Anyone can open a pull request that runs code on a runner attached to a public repo.
    Who is affected
    The runner host and its network.
    What you would notice
    Self-hosted runners in public repositories.
    What you change
    Use GitHub-hosted runners for public repos.
  2. pull_request_target

    What fails
    This trigger runs with base repository secrets; checking out the PR head runs untrusted code with them.
    Who is affected
    Secrets and tokens.
    What you would notice
    pull_request_target workflows that check out head.sha.
    What you change
    Do not run PR code under pull_request_target; split into two workflows.
  3. Persistence

    What fails
    Long-lived runners keep state between jobs.
    Who is affected
    Later jobs and their secrets.
    What you would notice
    Runners up for weeks with shared work directories.
    What you change
    Use ephemeral or autoscaled runners such as Actions Runner Controller.

Network reach

Place runners in a segment that can reach only what builds need: the registry, artifact storage, and package mirrors. A runner on the flat corporate network turns any pipeline bug into internal access.

Check yourself

Recognition and the fix. Nothing here is a procedure.

1 / 3

Why should public repositories not use self-hosted runners?

Sibling techniques

Pages at the same depth, plus a lab and a glossary card for this one.

This page stands on its own. The lab and the glossary card are the next reading.

Practice

  1. LabControl benchA failure is described. Choose the control that changes the outcome.

Glossary

  1. CardOverprivileged self-hosted runnersThe runner is a production-adjacent machine that executes code from a pull request.