Self-Hosted Runners Setup
Earn 25 points (50 with Pro) in two steps
- ① Read through the lesson — each section gets a ✓ as you scroll through it.
- ② When every section has a ✓, tap Complete lesson.
0 of 10 read · keep scrolling
✦ See fewer ads and earn double points — 50 a lesson instead of 25 — with Pro
Lesson: Mastering Self-Hosted Runners at Scale
Introduction: Why Self-Hosted Runners Matter
In the modern software development lifecycle, automation is the backbone of efficiency. GitHub Actions has revolutionized how teams build, test, and deploy applications by providing a deeply integrated CI/CD platform. While GitHub-hosted runners offer a convenient, "zero-configuration" experience for many teams, they are not always the right fit for every enterprise environment. As organizations grow, they often encounter specific requirements—such as strict network security, specialized hardware dependencies, or the need to manage massive build volumes cost-effectively—that necessitate the use of self-hosted runners.
A self-hosted runner is a system that you manage and maintain, which executes jobs from GitHub Actions. By deploying your own infrastructure, you gain full control over the operating system, the installed software, and the network environment where your code is processed. This is particularly important for enterprises that operate within private networks (VPCs), require access to internal databases that should not be exposed to the public internet, or have high-performance computing needs that standard virtual machines cannot satisfy.
Mastering the deployment and management of self-hosted runners is not just about getting a build to pass; it is about building a scalable, secure, and observable infrastructure. This lesson will guide you through the architecture, configuration, and operational best practices required to manage self-hosted runners at an enterprise scale. We will move beyond the basic "getting started" guide and look at how to handle thousands of jobs, ensure security in multi-tenant environments, and automate the lifecycle of your runner fleet.
Not read yet
The Architecture of Self-Hosted Runners
At its core, a self-hosted runner is a lightweight agent that runs as a service on your local machine, virtual machine, or container. It communicates with GitHub via HTTPS, polling for new jobs. This pull-based architecture is a significant security benefit because it eliminates the need for inbound firewall rules. The runner initiates the connection to GitHub, downloads the workflow instructions, executes the steps, and reports the results back.
The Runner Lifecycle
- Registration: The runner agent authenticates with GitHub using a registration token or a JIT (Just-In-Time) configuration.
- Polling: Once active, the runner constantly checks the GitHub API for assigned jobs.
- Execution: When a job is assigned, the runner creates a dedicated work directory, clones the repository, and executes the workflow steps one by one.
- Cleanup: After the job finishes, the runner cleans up the work directory and reports the status (success/failure) back to GitHub.
- Idle State: The runner returns to a waiting state, ready for the next job.
Callout: Pull vs. Push Architecture Unlike traditional CI/CD systems that require an external server to push commands to your build nodes, GitHub's self-hosted runners use a "pull" model. This is a critical distinction for security teams. Because the runner initiates the connection, you do not need to open inbound ports on your corporate firewall. The runner only needs outbound HTTPS access to GitHub's API and relevant artifact storage endpoints.
Not read yet
Planning Your Runner Infrastructure
Before deploying a fleet of runners, you must determine the scope and scale of your requirements. Scaling runners is not just about adding more machines; it is about organizing them in a way that is manageable and secure.
Scope Levels
GitHub allows you to register runners at three different levels:
- Repository Level: Runners are exclusive to a single repository. This is useful for projects with unique hardware requirements or highly sensitive code.
- Organization Level: Runners are available to all repositories within the organization. This is the most common setup for enterprise teams.
- Enterprise Level: Runners are available to all organizations under an enterprise account. This is ideal for shared infrastructure teams that manage runners for the entire company.
Choosing the Right Compute Strategy
You have several options for where your runners live. The choice depends on your organization's existing cloud footprint and operational maturity.
- Virtual Machines (VMs): Running the agent on a persistent VM is the simplest approach. It is easy to debug but requires patch management for the underlying OS.
- Auto-scaling Groups: Using tools like AWS Auto Scaling or Azure Virtual Machine Scale Sets allows you to dynamically increase or decrease the number of runners based on job demand.
- Containers (Kubernetes): This is the gold standard for high-scale environments. By using the Actions Runner Controller (ARC), you can deploy runners as pods in a Kubernetes cluster, allowing for near-instant scaling and isolated environments for each job.
Not read yet
Setting Up a Standard Self-Hosted Runner (Step-by-Step)
For those just starting or managing smaller workloads, a standard persistent runner is the first step. Here is the process for setting up a Linux-based runner.
Step 1: Generate the Token
Navigate to your organization settings in GitHub, go to Actions -> Runners, and click New self-hosted runner. GitHub will provide you with a unique registration token.
Step 2: Download the Runner Package
On your target server, download the latest version of the runner software:
# Create a folder for the runner
mkdir actions-runner && cd actions-runner
# Download the latest runner package
curl -o actions-runner-linux-x64-2.316.0.tar.gz -L https://github.com/actions/runner/releases/download/v2.316.0/actions-runner-linux-x64-2.316.0.tar.gz
# Extract the package
tar xzf ./actions-runner-linux-x64-2.316.0.tar.gz
Step 3: Configure the Runner
Run the configuration script provided in the package. This script will prompt you for the GitHub URL and the registration token.
./config.sh --url https://github.com/your-org --token YOUR_TOKEN_HERE
Step 4: Install as a Service
You don't want the runner to stop when you close your terminal. Install it as a systemd service:
sudo ./svc.sh install
sudo ./svc.sh start
Warning: Persistent Runners and Security If you run a persistent runner as a service, the machine remains active even when no jobs are running. While this is convenient, it also means the machine is constantly "on." Ensure that you have automated patching and security scanning (e.g., OS-level vulnerability scanners) running on these machines, as they are essentially long-lived servers inside your network.
Not read yet
Scaling with Actions Runner Controller (ARC)
For enterprise-scale, manual VM management is unsustainable. The Actions Runner Controller (ARC) is a Kubernetes operator that automates the deployment and scaling of self-hosted runners. It watches the GitHub API and automatically creates or destroys pods based on the number of pending jobs.
Why Use ARC?
- Dynamic Scaling: Automatically scale to zero when no jobs are running, saving significant costs.
- Ephemeral Runners: Each pod runs a single job and is then destroyed. This prevents "configuration drift" where a runner becomes unreliable because of lingering files from previous builds.
- Declarative Configuration: Define your runner fleet using Kubernetes YAML files, making it easy to version control your infrastructure.
Basic ARC Deployment Example
You define a RunnerDeployment custom resource in Kubernetes:
apiVersion: actions.github.com/v1alpha1
kind: RunnerDeployment
metadata:
name: example-runner
spec:
replicas: 2
template:
spec:
organization: my-org
labels:
- self-hosted
- kubernetes
When you apply this to your cluster, ARC will ensure two pods are always available to pick up jobs. If you need more, you can configure a HorizontalRunnerAutoscaler to scale based on the number of queued jobs in your organization.
Not read yet
Security Best Practices for Self-Hosted Runners
When you host your own runners, you are responsible for the security of the build environment. GitHub-hosted runners are ephemeral and isolated; self-hosted runners, if mismanaged, can become a vector for lateral movement within your network.
1. Use Ephemeral Runners
Whenever possible, configure your runners to be "ephemeral." This means the runner will process exactly one job and then shut down. This is the default behavior for ARC and can be enabled on VMs by passing the --ephemeral flag during configuration. This ensures that any malicious code executed during a build cannot persist and affect the next job.
2. Network Isolation
Runners should live in a restricted network segment. They should not have broad access to your internal corporate resources. Use Security Groups or Network Policies to restrict the runner's access to only the specific internal services it needs to reach (like a private artifact repository or a database).
3. Principle of Least Privilege
Do not run the runner service as root. Create a dedicated system user (e.g., github-runner) with limited permissions. This prevents a compromised build script from gaining full control over the host operating system.
4. Secret Management
Never hardcode secrets in your workflow files. Even though self-hosted runners are "internal," the code that runs on them might be contributed by developers who should not have access to production credentials. Rely on GitHub Secrets or an external secret manager (like HashiCorp Vault) that integrates with your runners.
Tip: Monitoring and Observability Treat your runners like production services. Use tools like Prometheus and Grafana to monitor the CPU and memory utilization of your runner fleet. If you see a consistent spike in memory usage, it might indicate that your builds are not cleaning up properly or that you need to provision larger instances.
Not read yet
Comparison: Hosted vs. Self-Hosted
| Feature | GitHub-Hosted | Self-Hosted |
|---|---|---|
| Maintenance | None (Managed by GitHub) | High (OS, patching, updates) |
| Security | Isolated, ephemeral VMs | User-managed, potential persistence |
| Networking | Public access only | Private network (VPC) access |
| Hardware | Fixed specs | Customizable (GPU, high RAM) |
| Cost | Per-minute usage | Infrastructure + compute costs |
| Scalability | On-demand (no limits) | Requires scaling logic (e.g., ARC) |
Common Pitfalls and How to Avoid Them
Pitfall 1: "Dirty" Runners
If you use persistent runners, build artifacts, temporary files, and cached dependencies can accumulate over time. This leads to "flaky" builds where a job passes on one machine but fails on another.
- The Fix: Use ephemeral runners. If you must use persistent runners, implement a cleanup script that runs after every job or use a cron job to restart the runner service periodically to ensure a clean state.
Pitfall 2: Relying on the Default User
Running the runner process as root is a security disaster waiting to happen.
- The Fix: Always create a non-privileged user. Grant this user only the permissions required to execute the build tools. If your build needs to perform
dockeroperations, ensure the user is in thedockergroup, but be aware that this gives the user effective root access to the host.
Pitfall 3: Ignoring Runner Updates
GitHub frequently updates the runner software to support new features and security patches. An outdated runner can lead to unexpected errors.
- The Fix: Configure your runners to auto-update. By default, the runner service checks for updates and installs them automatically. Do not disable this feature unless you have a strictly controlled manual update process.
Pitfall 4: Misconfigured Labels
Labels are how GitHub determines which runner should pick up a job. If your labels are inconsistent, your jobs will stay queued indefinitely.
- The Fix: Create a naming convention for labels (e.g.,
os-linux,arch-arm64,env-production). Use these labels consistently across all your runner deployments so developers know exactly what to put in theirruns-onblock.
Not read yet
Advanced Configuration: Custom Runner Images
For large enterprises, installing software on every runner manually is not scalable. Instead, use "Golden Images" or container images.
Using Packer for VM Images
If you are using VMs, use a tool like Packer to create pre-configured machine images. Your Packer configuration should:
- Install the OS (e.g., Ubuntu 22.04).
- Install required build tools (Java, Node.js, Docker, etc.).
- Install the GitHub Actions runner binary.
- Configure the runner as a systemd service.
By baking the runner into the image, you ensure that every new runner you spin up is identical to the last, eliminating "snowflake" servers.
Using Dockerfiles for ARC
If you are using Kubernetes, define a custom Dockerfile that installs all necessary dependencies.
FROM ghcr.io/actions/actions-runner:latest
# Install custom tools
RUN sudo apt-get update && sudo apt-get install -y \
maven \
python3-pip \
&& sudo rm -rf /var/lib/apt/lists/*
Building your own images allows you to keep your build environment consistent across the entire organization. It also reduces build times, as tools are already present on the runner rather than being downloaded at the start of every job.
Not read yet
Managing Capacity: The Queue Strategy
When you have multiple teams sharing a pool of runners, you will eventually face contention. Team A might trigger a massive build that consumes all available runners, leaving Team B waiting.
Job Priority
GitHub Actions does not natively support "job priority" in the traditional sense, but you can achieve this by using different runner groups.
- Create a "High Priority" runner group for production deployments.
- Create a "Standard" runner group for feature branch builds.
- Use labels to route jobs to the appropriate group.
Scaling to Zero
One of the biggest advantages of self-hosted runners in the cloud is the ability to scale to zero. If you are using ARC or a cloud-native auto-scaler, ensure your scaling policies are aggressive. You should not be paying for idle compute power. Configure your auto-scaler to terminate instances after a period of inactivity (e.g., 5-10 minutes).
Note: Monitoring Queued Jobs Use the GitHub API to monitor the
total_countof queued jobs in your organization. If this number grows beyond a certain threshold, it is a clear signal that your auto-scaler is not aggressive enough or that your runner pool is undersized. You can even set up alerts that notify your SRE team when queue times exceed your internal SLAs.
Not read yet
Key Takeaways
- Understand the Architecture: Self-hosted runners use a pull-based model, which simplifies network security by removing the need for inbound firewall ports.
- Choose the Right Strategy: Use persistent VMs for simple, small-scale needs, but transition to the Actions Runner Controller (ARC) on Kubernetes for enterprise-scale, dynamic environments.
- Prioritize Security: Always treat runners as untrusted environments. Use ephemeral runners to prevent cross-job contamination, avoid running as root, and isolate runners within restricted network segments.
- Consistency is Key: Use infrastructure-as-code (Packer, Docker, or Kubernetes manifests) to ensure your runner fleet is reproducible and free from "configuration drift."
- Observe and Automate: Treat your runner infrastructure like any other production service. Monitor resource usage, set up auto-scaling to manage costs, and establish clear labeling conventions to ensure jobs reach the correct hardware.
- Plan for Contention: Use runner groups and distinct labels to manage capacity and ensure that critical production builds are not blocked by non-essential developer workflows.
- Maintenance Matters: Even with automation, runners require lifecycle management. Stay updated with the latest runner releases and ensure your host operating systems are patched regularly.
By following these principles, you can build a robust, scalable, and secure CI/CD infrastructure that empowers your developers to move fast without compromising the integrity of your enterprise environment. Managing runners at scale is a journey of continuous improvement, and the tools provided by GitHub—when combined with smart infrastructure practices—provide everything you need to succeed.
Not read yet
Each section gets a ✓ as you scroll through it. Tap the button to jump to the next one.
- Scheduled Event Triggers
- Scheduled Event Triggers Quiz5q
- Manual Workflow Dispatch
- Manual Workflow Dispatch Quiz5q
- Webhook Event Triggers
- Webhook Event Triggers Quiz5q
- Repository Events Configuration
- Repository Events Configuration Quiz5q
- Workflow Dispatch Inputs
- Workflow Dispatch Inputs Quiz5q
- Reusable Workflows with workflow_call
- Reusable Workflows with workflow_call Quiz5q
- Jobs and Steps Fundamentals
- Jobs and Steps Fundamentals Quiz5q
- Conditional Logic in Workflows
- Conditional Logic in Workflows Quiz5q
- Job Dependencies with needs
- Job Dependencies with needs Quiz5q
- Service Containers Configuration
- Service Containers Configuration Quiz5q
- Matrix Strategy Configuration
- Matrix Strategy Configuration Quiz5q
- YAML Anchors and Aliases
- YAML Anchors and Aliases Quiz5q
- Predefined Contexts Usage
- Predefined Contexts Usage Quiz5q
- Azure Integration Patterns
- Azure Integration Patterns Quiz5q
- AWS Integration Patterns
- AWS Integration Patterns Quiz5q
- Kubernetes Deployments
- Kubernetes Deployments Quiz5q
- Notification Integrations
- Notification Integrations Quiz5q
- Code Quality Integrations
- Code Quality Integrations Quiz5q
- Third-Party Service Integration
- Third-Party Service Integration Quiz5q
- Workflow Orchestration Patterns
- Workflow Orchestration Patterns Quiz5q
- Multi-Environment Workflows
- Multi-Environment Workflows Quiz5q
- Blue-Green and Canary Deployments
- Blue-Green and Canary Deployments Quiz5q
- GitHub-Hosted Runners Configuration
- GitHub-Hosted Runners Configuration Quiz5q
- Self-Hosted Runners Setup
- Self-Hosted Runners Setup Quiz5q
- Runner Groups Management
- Runner Groups Management Quiz5q
- IP Allow Lists and Networking
- IP Allow Lists and Networking Quiz5q
- Runner Troubleshooting
- Runner Troubleshooting Quiz5q
- Environment Protections
- Environment Protections Quiz5q
- Trustworthy Marketplace Actions
- Trustworthy Marketplace Actions Quiz5q
- Script Injection Mitigation
- Script Injection Mitigation Quiz5q
- GITHUB_TOKEN Permissions
- GITHUB_TOKEN Permissions Quiz5q
- OIDC Token for Cloud Federation
- OIDC Token for Cloud Federation Quiz5q
- Action Version Pinning
- Action Version Pinning Quiz5q
- Artifact Attestations and Provenance
- Artifact Attestations and Provenance Quiz5q
Spend your points to unlock exam-style practice questions
Spend points to unlock GH-200 exam-style practice questions.
Practice for GH-200