Sub topic 13
Securing runners on Kubernetes
This chapter assumes you have installed the ARC controller and a runner scale set with Helm, and that you know Kubernetes namespaces, secrets, and RBAC (role-based access control). Self-hosted runners execute code from your workflows inside your cluster, so a weak setup can expose credentials, nodes, and internal networks.
Where the risks come from
A runner pod runs whatever a workflow tells it to run. Anyone who can change a workflow, or open a pull request that triggers one, can run commands in that pod. Three things decide how much damage they can do:
- What the pod can reach: the network, the node, and the Kubernetes API.
- What credentials the pod holds or can read.
- How much the pod is isolated from the host and from other jobs.
Keep controller and runners apart
You installed the controller in arc-systems and the runners in arc-runners. Keep that split. Runner pods then have no access to the controller's service account or its secrets.
Add a few more controls:
- Use a dedicated namespace per trust level, for example one for public repositories and one for private ones.
- Do not mount a service account token into runner pods unless a job needs the Kubernetes API.
- Apply a NetworkPolicy that denies traffic to internal services the jobs do not need.
Here is a NetworkPolicy that allows only DNS and outbound HTTPS from runner pods. Your CNI plugin (the cluster's network plugin) must enforce NetworkPolicy for it to take effect.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: runner-egress
namespace: arc-runners
spec:
podSelector: {}
policyTypes:
- Egress
egress:
- ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
- ports:
- protocol: TCP
port: 443This rule allows port 443 to any address, including internal ones. To block internal ranges, add to blocks with ipBlock and except entries for your private CIDRs.
Protect the GitHub credentials
ARC needs a credential to register runners. A personal access token (PAT) is tied to a person and often has broad scope. A GitHub App can be limited to the permissions ARC needs and installed on chosen repositories. Prefer a GitHub App for production.
Whichever you use:
- Store it as a Kubernetes secret in the namespace where the scale set lives, as shown earlier with
pre-defined-secret. - Restrict who can read secrets in that namespace with RBAC.
- Never pass the token on the Helm command line, where it lands in shell history.
- Rotate it on a schedule, and immediately if you suspect exposure.
Choose the container mode with security in mind
Container mode changes your exposure.
| Mode | Security trade-off |
|---|---|
| `dind` | The Docker daemon runs in a privileged sidecar container. A job that escapes it can reach the node. |
| `kubernetes` | No privileged container is needed. Each container step runs as its own pod, with less node exposure. |
If your jobs do not build images, prefer kubernetes mode. If you need dind, run those pods on dedicated nodes (using the node selection and tolerations from the previous chapter) so a compromised job does not share a node with sensitive workloads.
Use the ephemeral model
ARC runner pods are ephemeral, so each job starts clean and the pod is deleted afterward. This prevents one job from leaving files or tokens for the next. Do not weaken it by mounting shared writable volumes across runners, which recreates the persistence problem you moved away from.
Also set resource limits, as in the customization chapter. A job without limits can exhaust a node's memory and affect other pods.
Keep the software current
Update the runner image regularly so it carries OS and runner-agent fixes. Pin images by version or digest instead of latest in production, so changes arrive when you choose.
Exercise
Your team runs jobs for a public repository and builds Docker images in them. Name two controls you would apply to the runner setup.
Show answer
Any two of: put the scale set in its own namespace with a restrictive NetworkPolicy; use a runner group limited to specific repositories and require approval for fork workflows; run dind pods on dedicated nodes (or switch to kubernetes mode with a daemonless builder); authenticate with a GitHub App instead of a PAT; set resource limits.