Sub topic 3
Registering a Runner and Choosing Its Scope
This chapter assumes you can read GitHub Actions workflow syntax (on, jobs, steps, runs-on), work in a Linux shell, and understand pull requests. The previous chapters covered what a runner is and why teams self-host. Here you will see how a runner gets connected to GitHub and who can send it jobs.
What registration does
Registration is the step that tells GitHub "this machine may run jobs for me." You download the runner application, then run config.sh with a URL and a token. The script contacts GitHub, creates a runner record, and saves credentials in files in the runner directory. After that, run.sh starts the listener. The listener polls GitHub for jobs and runs the ones that match.
./config.sh \
--url https://github.com/OWNER/REPO \
--token REGISTRATION_TOKEN \
--name "runner-$(hostname)-$(date +%s)" \
--labels ephemeral \
--unattended
./run.shThe flags do the following:
--urlsets the scope, which is covered below.--tokenis a registration token. It is short-lived (about one hour) and is used only to create the runner.--nameidentifies the runner in the GitHub UI. Using the hostname plus a timestamp keeps names unique.--labelsadds custom labels, which the next chapter uses for routing.--unattendedskips the interactive prompts, so scripts can run it.
The --ephemeral flag is deliberately missing here. Without it, this runner stays registered and takes job after job. A later chapter explains why that is risky.
Where the token comes from
You get a registration token from the repository, organization, or enterprise settings page under Actions, Runners. You can also request one from the REST API with a credential that has admin rights over that scope. Treat the token as a secret until it expires. Anyone holding a valid token can register a runner into your scope.
Choosing a scope
A runner belongs to exactly one level. The --url you pass decides which.
| Scope | `--url` example | Who can send jobs |
|---|---|---|
| Repository | `https://github.com/OWNER/REPO` | Only that repository |
| Organization | `https://github.com/ORG` | Repositories in the organization, subject to runner group settings |
| Enterprise | `https://github.com/enterprises/NAME` | Organizations in the enterprise, subject to runner group settings |
Pick the narrowest scope that works. A repository-scoped runner limits damage if a workflow is abused, because only one repository's code can ever run on it. Organization scope saves effort when many repositories share a fleet. It also widens the set of workflows that can reach the machine, so you should pair it with runner groups, which a later chapter covers.
Organization and enterprise runners are placed in a runner group. New runners go into the default group unless you pass --runnergroup. The default group is often open to every repository, so check it before registering.
Common errors
- Token expired.
config.shfails with an authentication error if you wait too long. Request a new token and retry. - Name collision. Registering a second runner with an existing name replaces the first only if you pass
--replace. Otherwise it errors. Unique names avoid the problem. - Wrong scope. A job in repository B never reaches a runner registered to repository A. The job stays queued and shows "Waiting for a runner."
- Reusing a configured directory. Running
config.shagain in a directory that already holds a registration fails until you run./config.sh removefirst.
Exercise
A team registers one runner with --url https://github.com/ORG. Which repositories can use it, and which setting should they check first?
Show answer
Repositories in the organization ORG can use it, limited by the runner group it joined. They should check the access settings of that group, which is the default group unless --runnergroup was passed and is often open to all repositories.