Sub topic 10
Limiting which repositories and workflows can use a runner
This chapter assumes you can read workflow YAML, know how runs-on labels route jobs, and understand why a persistent runner is risky. Labels decide which runner a job prefers. They do not decide which jobs are allowed. Runner groups do that.
Labels are routing, not access control
Any job whose runs-on list is a subset of a runner's labels can be sent to that runner. Labels are free text in the workflow file, so anyone who can edit a workflow can copy them. If a runner is reachable by a repository, a workflow in that repository can ask for it.
Access control therefore has to live on the GitHub side, in runner groups.
Runner groups
A runner group is a named set of runners with an access policy. In an organization or enterprise, every runner belongs to exactly one group. New runners go into the Default group unless you choose another.
A group policy controls two things:
- Which repositories can use the group's runners. You can allow all repositories, or select specific ones.
- Which workflows can use them, through an optional workflow allow-list. Each entry is a reference to a workflow file at a specific branch, tag, or commit SHA, such as
my-org/ci-templates/.github/workflows/build.yml@refs/heads/main.
Repository-level runners have no groups. They are visible only to the repository they are registered to. This is the narrowest scope but does not scale.
| Scope | Who can use it | Groups available |
|---|---|---|
| Repository | That repository only | No |
| Organization | Repositories you select in a group | Yes |
| Enterprise | Organizations you select in a group | Yes |
Designing groups
Split groups by trust level and by what the runners can reach, not by team name. A practical layout:
- A
public-safegroup with no network access to internal systems, for low-risk jobs. - An
internal-buildgroup for private repositories that only build and test. - A
deploy-prodgroup, limited to one or two repositories and to a pinned deployment workflow.
Keep the Default group empty, or restrict it. An open default group is the usual way a sensitive runner ends up reachable by repositories nobody reviewed.
Public repositories
Runner groups for organizations on some plans do not allow public repositories by default. If you enable this, a pull request from a fork can start a job on your hardware, and that job runs code you have not reviewed. Leave public repositories disallowed for any group that has internal network access. If you must serve a public repository, use a separate group of ephemeral runners with no credentials and no internal routes.
Assigning a runner to a group
When you register a runner, name the group at configuration time:
./config.sh \
--url https://github.com/OWNER \
--token REGISTRATION_TOKEN \
--runnergroup internal-build \
--labels ephemeral \
--ephemeral \
--unattended
./run.shWith just-in-time configuration, the runner_group_id field in the API call does the same job. Putting it in your provisioning code means a new runner can never land in a more permissive group by mistake.
Minimal workflow permissions
Group policy controls where a job runs. The permissions block controls what the job's GITHUB_TOKEN can do once it is running. Set it explicitly:
name: test
on: pull_request
permissions:
contents: read
jobs:
test:
runs-on: [self-hosted, linux, x64, ephemeral]
steps:
- uses: actions/checkout@v4
- run: make testWhen you declare permissions, every scope you do not list is set to none. Grant id-token: write or contents: write only in the workflows that need them.
Common errors
- A job waits in the queue forever because the repository is not in the group's allow-list. The runner is online, but GitHub never offers it the job.
- A workflow allow-list pinned to
@refs/heads/mainrejects the same workflow when it is called from a feature branch. - Labels were tightened but the group stayed open, which gives a false sense of control.
Exercise
A repository named docs-site is not in the deploy-prod group's allow-list. A workflow in docs-site sets runs-on: [self-hosted, linux, x64, ephemeral], and an idle runner in deploy-prod has all of those labels. What happens to the job, and which setting would you change to make the runner unreachable even if the repository were later added to the group?
Show answer
The job stays queued, because GitHub only offers it to runners in groups that allow docs-site. To keep the runner unreachable even after a repository is added, add a workflow allow-list entry that names only the approved deployment workflow, so other workflows in an allowed repository still cannot use the group.