On this page
GitHub-hosted runners are fresh virtual machines that GitHub destroys after each job. Self-hosted runners are whatever you make them: often a long-lived VM or a Kubernetes pod inside your network, with cloud credentials attached, reused for job after job. That difference is the whole security story. Any code that a workflow runs on a self-hosted runner runs inside your infrastructure, and if the runner is persistent, it can leave something behind for the next job.
This guide covers when to use self-hosted runners, how to make them ephemeral, how to restrict which repositories and workflows can reach them, and how to isolate them on the network.
The threat model
Assume that any job on a runner can be fully controlled by an attacker. That is realistic: a script injection or pwn request, a compromised third-party action, or a malicious dependency install script all give code execution on the runner. From there, an attacker on a self-hosted runner can:
- Read secrets and tokens of the current job, and on a persistent runner, of later jobs, by planting a process, modifying the runner binary, poisoning tool caches or editing
~/.bashrc. - Use the machine's own identity: an instance profile, a Kubernetes service account, a mounted Docker socket, cached cloud CLI credentials.
- Reach internal networks: artifact registries, databases, metadata endpoints such as
169.254.169.254.
Every control below reduces one of these.
Never attach persistent runners to public repositories
GitHub's guidance is direct: self-hosted runners should almost never be used for public repositories, because any user can open a pull request that runs a workflow. Fork pull request approval settings help, but one approved run, or one workflow bug, is enough. Researchers have repeatedly shown compromises of major open source projects that started with a persistent self-hosted runner on a public repository.
If a public repository needs special hardware or network access, use ephemeral runners in an isolated network with no credentials, and require approval for all outside contributors.
Make runners ephemeral
An ephemeral runner takes exactly one job and is then removed. Persistence between jobs disappears:
./config.sh --url https://github.com/ACME \
--token "$REGISTRATION_TOKEN" \
--ephemeral \
--runnergroup production-builds \
--labels linux,x64,build \
--unattended
./run.sh
Pair --ephemeral with infrastructure that destroys the VM or container after the job and creates a fresh one from a known image. Merely restarting the runner process on the same host does not remove what a job left on disk.
Just-in-time runners
For autoscaling systems, just-in-time (JIT) configuration is better than registration tokens. Your orchestrator calls the API to create a single-use runner configuration and passes it to the runner, which never stores a reusable registration token:
gh api -X POST "/orgs/ACME/actions/runners/generate-jitconfig" \
-f name="build-$(uuidgen)" \
-F runner_group_id=3 \
-f 'labels[]=self-hosted' -f 'labels[]=linux' \
-f work_folder=_work \
--jq .encoded_jit_config > jitconfig
./run.sh --jitconfig "$(cat jitconfig)"
JIT runners are automatically ephemeral.
Actions Runner Controller
On Kubernetes, Actions Runner Controller (ARC) with runner scale sets creates a pod per job and deletes it afterwards. Harden the pods:
- Run the runner container as non-root, with
allowPrivilegeEscalation: falseand a read-only root filesystem where the build allows it. - Avoid Docker-in-Docker in privileged mode; if container builds are needed, prefer rootless builders such as BuildKit rootless or Kaniko, or the Kubernetes container mode.
- Give the runner pods a dedicated service account with no Kubernetes API permissions, and set
automountServiceAccountToken: falseif jobs do not need it. - Run ARC runners in a dedicated node pool or cluster, never alongside production workloads.
Restrict who can use a runner
Runners registered at the organization or enterprise level go into runner groups. A group controls which repositories, and optionally which workflows, can send jobs to its runners.
Under Settings > Actions > Runner groups:
- Do not use the Default group for anything sensitive; it is often open to all repositories.
- Set Repository access to Selected repositories.
- Leave Allow public repositories unchecked.
- Use Selected workflows to bind a group to specific workflow files at specific refs, for example
ACME/deploy-config/.github/workflows/deploy.yml@refs/heads/main. Only that workflow on that branch can use the runner, so a contributor who adds a new workflow in a feature branch cannot reach it.
# Inspect runner groups and what they allow
gh api "/orgs/ACME/actions/runner-groups" \
--jq '.runner_groups[] | [.id, .name, .visibility, .allows_public_repositories, .restricted_to_workflows] | @tsv'
Separate runners by trust level: one group for builds of untrusted pull requests (no credentials, no internal network), one for main-branch builds, one for deployments bound to specific workflows. Never share a runner between trust levels.
Repository-level runners are visible only to one repository, but anyone with admin on that repository can register them, which is one more reason to keep repository admin limited (see the organization baseline).
Credentials on the runner
Do not bake long-lived credentials into runner images or attach broad instance roles to runner hosts. Instead:
- Use OIDC from the workflow to get short-lived, per-job cloud credentials, restricted by repository, branch and environment.
- If the host itself needs an identity (to pull images, for example), make it minimal and separate from what jobs use.
- Block access to the cloud metadata service from job containers, or require IMDSv2 with a hop limit of 1 on AWS so containers cannot reach it.
- Do not mount the host Docker socket into jobs; it is root on the host.
Network isolation
Place runners in their own network segment and decide what they may reach:
- Egress: allow GitHub endpoints (
github.com,api.github.com,*.actions.githubusercontent.comand the other domains listed in GitHub's documentation), your package mirrors and artifact registry. Deny the rest, or at least log it. An egress allowlist is what turns a stolen secret into a failed exfiltration. - Ingress: runners connect out to GitHub over HTTPS long polling; they need no inbound access.
- Internal access: deployment runners may need to reach production APIs; build runners should not.
Larger GitHub-hosted runners with Azure private networking are an alternative when the only reason for self-hosting is private network access: you get GitHub-managed ephemeral VMs inside your own virtual network.
Keep the image and runner current
- Build runner images from code, scan them, and rebuild them regularly.
- Keep the runner application up to date. Runners update themselves by default; if you disable auto-update in immutable images, GitHub stops sending jobs to runner versions that are too old, so rebuild on each release.
- Remove tools the builds do not need, especially credential helpers and cloud CLIs with cached logins.
Monitor runners
Audit log events cover runner registration and removal (org.register_self_hosted_runner, org.remove_self_hosted_runner, repo.register_self_hosted_runner) and runner group changes (org.runner_group_updated, org.runner_group_runners_added). A runner registered on a repository nobody expected is a classic persistence technique; alert on it using the audit log guide.
On the host side, collect process and network telemetry from runner hosts like any production server, and keep the runner _diag logs. Legitify's runner_group namespace checks runner group exposure across an organization; see the organization audit guide.
Checklist
- No persistent self-hosted runners on public repositories.
- Runners are ephemeral (JIT or
--ephemeralwith destroy-after-job infrastructure). - Runner groups restricted to selected repositories and, for deployments, selected workflows.
- Separate runner pools per trust level.
- No long-lived credentials on runners; OIDC for cloud access; metadata service blocked from jobs.
- Egress allowlist; runner network segmented.
- Runner registration events alerted on.
References
- About self-hosted runners (GitHub Docs)
- Security hardening for GitHub Actions: hardening for self-hosted runners (GitHub Docs)
- Managing access to self-hosted runners using groups (GitHub Docs)
- REST API endpoints for self-hosted runners (GitHub Docs)
- About Actions Runner Controller (GitHub Docs)
- actions/runner (GitHub repository)
- Kubernetes Pod Security Standards
- Use IMDSv2 for EC2 instance metadata (AWS Documentation)
- MITRE ATT&CK T1195.002: Compromise Software Supply Chain
Tags:actionssupply-chain
Written by
Florian Amette, Security Engineer & EditorSecurity engineer writing practical hardening guides for GitHub organizations, repositories and CI/CD pipelines, with a focus on software supply-chain security.