Sub topic 3
Just-in-Time Runner Configuration Through the API
This chapter assumes you know GitHub Actions workflow syntax, Linux shell commands, pull requests, and the difference between containers and virtual machines.
Create a single-use runner
A just-in-time (JIT) runner is registered for one job. The REST API returns an encoded configuration. The runner uses that configuration without storing a long-lived registration token.
gh api --method POST /repos/OWNER/REPO/actions/runners/generate-jitconfig \
-f name="jit-runner-1" \
-F runner_group_id=1 \
-f 'labels[]=self-hosted' \
-f 'labels[]=linux' \
-f 'labels[]=x64' \
-f 'labels[]=ephemeral' \
--jq .encoded_jit_config > jitconfig.txt
./run.sh --jitconfig "$(cat jitconfig.txt)"After the job finishes, the runner becomes unavailable. The host or container must be discarded or rebuilt before another job.
Autoscale fresh runners
An autoscaler creates runners when queued jobs need them and removes them afterward. Actions Runner Controller (ARC) performs this work on Kubernetes. A runner resource starts a pod, registers it, runs one job, and then disappears.
Restrict access
Runner groups limit which repositories can use a runner. Combine groups with narrow labels and workflow permissions. Do not place sensitive deployment runners in a group available to every repository.
Choose isolation
A virtual machine provides a stronger boundary than a container because the kernel is separate from the workload. Containers start faster, but a compromised job may attack the shared host kernel. Use disposable VMs for hostile or sensitive workloads. Containers can fit trusted, controlled repositories when the host is hardened.
Use short-lived credentials
Use OpenID Connect (OIDC), a token exchange protocol, instead of storing cloud keys.
permissions:
id-token: write
contents: read
steps:
- uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::123456789012:role/example-deploy-role
aws-region: us-east-1The cloud provider validates the job identity and issues temporary credentials.
Operate the fleet
Bake runner software, tools, and security updates into a versioned image. Replace outdated images instead of modifying long-lived machines. Send runner and job logs to centralized storage, but remove secrets from output. Monitor queue time, startup failures, registration errors, and jobs that exceed their timeout.
Exercise
Why should a JIT runner be paired with a disposable host?
Show answer
JIT registration limits the runner to one job, while host disposal removes files, processes, and credentials left by that job.