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 the roles of the namespaces arc-systems and arc-runners. You should also be comfortable with Kubernetes RBAC, Secrets, and NetworkPolicy basics. It covers credentials, container-mode risk, network isolation, namespace hardening, and workflow-side practices.
The threat model
A workflow is code, and a runner pod executes it. Anyone who can change a workflow in a repository that can reach your scale set can run arbitrary commands inside your cluster. Ephemeral runners help, because each pod is deleted after one job and a compromise does not persist on the runner. They do not stop a malicious job from doing damage while it runs. A job can still:
- Read anything the pod can read, including mounted tokens and environment variables.
- Reach any network address the pod can reach, including the Kubernetes API, other pods, and the node's cloud metadata service.
- Abuse the container runtime if the pod is privileged.
- Mine cryptocurrency or exhaust the cluster's resources.
The defenses below limit each of these. They fall into layers, shown here.
Credentials
Prefer a GitHub App over a personal access token
Earlier chapters used a personal access token (PAT) because it is quick. A PAT belongs to a person. It carries that person's broad access, and it stops working if they leave the organization. A GitHub App has its own identity and only the permissions you grant. For repository-level scale sets, grant read-only Actions and Metadata, plus read and write Administration. For organization-level scale sets, grant read and write Self-hosted runners. Check the current ARC documentation for the exact list before you create the App.
Store the App credentials in a Secret in the runner namespace:
kubectl create secret generic arc-github-app \
--namespace arc-runners \
--from-literal=github_app_id='<APP_ID>' \
--from-literal=github_app_installation_id='<INSTALLATION_ID>' \
--from-file=github_app_private_key=./private-key.pemThen point the scale set at it with githubConfigSecret: arc-github-app. Delete the local .pem file after you create the Secret, or keep it in a vault.
If you must use a PAT, create a classic token with only the scopes ARC needs, and rotate it on a schedule. Never put the token in --set githubConfigToken=... on the Helm command line, because it ends up in shell history and in the Helm release Secret.
Restrict who can read the Secret
Anyone who can get Secrets in arc-runners can read your GitHub credentials. Grant namespace access only to the platform team. Avoid cluster-wide roles that allow reading Secrets, and check with kubectl auth can-i get secrets -n arc-runners --as=<user>.
Runner groups limit who can use your runners
A scale set registers into a GitHub runner group. Create a dedicated group, allow only the repositories that need it, and name it in your values file:
githubConfigUrl: "https://github.com/<your-org>"
githubConfigSecret: arc-github-app
runnerGroup: ci-trusted
minRunners: 0
maxRunners: 10Do not attach self-hosted runners to public repositories. A pull request from a fork can modify the workflow file and run code on your infrastructure. If you must support forks, keep those jobs on GitHub-hosted runners and require approval for workflow runs from outside collaborators.
Container mode is a security decision
The earlier chapter on container modes compared dind and kubernetes mode on function. Here is the same choice judged on risk.
| Property | `dind` | `kubernetes` |
|---|---|---|
| Privileged container | Yes, the Docker daemon sidecar runs privileged | No |
| Blast radius if a job escapes its container | Node-level access is possible | Limited to what the pod's security context allows |
| Pod Security Admission level it fits | `privileged` only | `baseline` or stricter, depending on your pod template |
| `docker build` and `docker run` in steps | Works | Not available; jobs run through container hooks |
| Extra requirements | None | A work volume (PersistentVolumeClaim) and a service account with pod permissions |
A privileged container shares much of the host's kernel capabilities. A job that breaks out of it can reach the node and every other pod on it. If your builds do not need a Docker daemon, choose kubernetes mode. If you need image builds, consider a daemonless builder such as Kaniko or BuildKit in rootless mode, running in kubernetes mode.
A kubernetes-mode scale set needs a work volume:
githubConfigUrl: "https://github.com/<your-org>"
githubConfigSecret: arc-github-app
runnerGroup: ci-trusted
containerMode:
type: "kubernetes"
kubernetesModeWorkVolumeClaim:
accessModes: ["ReadWriteOnce"]
storageClassName: "<your-storage-class>"
resources:
requests:
storage: 1GiKubernetes mode has its own risk. The chart creates a service account that can create and delete pods in the runner namespace. That is why the runner namespace must contain only CI workloads.
Isolate the namespace and the nodes
Put runners in their own namespace, separate from the controller and from application workloads. Then add controls to that namespace:
- Pod Security Admission. Label the namespace so the cluster rejects pods that exceed your chosen level:
``bash kubectl label namespace arc-runners \ pod-security.kubernetes.io/enforce=baseline \ pod-security.kubernetes.io/warn=restricted ``
Dind mode will be rejected under baseline, which is the intended effect if you decided to forbid privileged pods. If you keep dind, the namespace must allow privileged, and the other controls matter more.
- ResourceQuota and limits.
maxRunnersalready caps the pod count. Add a ResourceQuota on CPU and memory, and setlimitsin the pod template, so one runaway job cannot starve neighbors.
- Dedicated nodes. Use a node pool for runners, labeled and tainted. Then set
nodeSelectorandtolerationsin the pod template (covered in the scheduling chapter). Production pods will not share a kernel with untrusted builds.
- Service account tokens. Where a mode does not need the Kubernetes API, a mounted token is an unneeded credential. Check whether your pod template can disable automounting for your mode, and confirm that jobs still pass.
Network policy
By default, every pod can talk to every other pod and to anything routable from the node. A NetworkPolicy in the runner namespace can restrict egress to DNS and public HTTPS, and block private ranges and the cloud metadata address 169.254.169.254:
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: runner-egress
namespace: arc-runners
spec:
podSelector: {}
policyTypes:
- Egress
egress:
- to:
- namespaceSelector:
matchLabels:
kubernetes.io/metadata.name: kube-system
podSelector:
matchLabels:
k8s-app: kube-dns
ports:
- protocol: UDP
port: 53
- protocol: TCP
port: 53
- to:
- ipBlock:
cidr: 0.0.0.0/0
except:
- 10.0.0.0/8
- 172.16.0.0/12
- 192.168.0.0/16
- 169.254.0.0/16
ports:
- protocol: TCP
port: 443Apply it with kubectl apply -f runner-egress.yaml. Three caveats:
- The cluster's network plugin must enforce NetworkPolicy. Some do not, and the object is then silently ignored.
- If your pod or service CIDRs fall outside the RFC 1918 ranges, add them to
except. - Jobs that pull from an internal package mirror or registry need an extra
torule. In kubernetes mode, the runner pod must also reach the API server, so add a narrow rule for it.
On AWS, also set the instance metadata option HttpPutResponseHopLimit to 1 where your setup allows it. Pods then cannot fetch node credentials through IMDSv2.
Secrets and images used by workflows
- Store secrets in GitHub encrypted secrets, not in the pod template. Anything in the template is readable by every job on the scale set.
- Prefer OpenID Connect (OIDC) federation to your cloud provider over long-lived access keys. The job requests a short-lived token, so nothing durable sits in the cluster.
- Pin the runner image to a version tag or digest rather than
latest. GitHub deprecates old runner versions, so plan to update the pin regularly. Scan custom images before use. - Limit workflow
permissions:forGITHUB_TOKENto the minimum, for examplecontents: read.
Common mistakes
- Registering a scale set at organization level with the default runner group, which lets every repository use it.
- Leaving dind enabled out of habit when no step uses Docker.
- Sharing the runner namespace with other teams' workloads.
- Assuming a NetworkPolicy works without checking the network plugin.
- Granting the GitHub App more permissions than the list above.
Exercise
Your team runs a dind scale set in a namespace labeled pod-security.kubernetes.io/enforce=baseline. After you create the label, new runner pods fail to start. What is the cause, and what are two ways to resolve it?
Show answer
The dind sidecar runs as a privileged container, which baseline forbids, so the admission controller rejects the pod. You can either switch the scale set to kubernetes mode, which has no privileged container, if no step needs a Docker daemon, or relax the namespace to privileged and compensate with network policies, dedicated nodes, and a restricted runner group.
Exercise
Write the one change that stops a job from reaching the cloud metadata service at 169.254.169.254 using a NetworkPolicy, and name one situation where the policy has no effect.
Show answer
Keep 169.254.0.0/16 (or 169.254.169.254/32) in the except list of the ipBlock egress rule, and do not add any other rule that allows that address. The policy has no effect when the cluster's network plugin does not enforce NetworkPolicy.