C.W.K.
Stream
Lesson 04 of 13 · published

Self-Hosted Runner Security

~12 min · security, isolation, ephemeral

Level 0Apprentice
0 XP0/101 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

Self-hosted runners run untrusted code by default

If your repo accepts PRs from anyone, those PRs can include workflow changes. Without isolation, a malicious PR can: read your filesystem, dump env vars, install a backdoor, exfiltrate secrets cached on disk. The default setup is dangerous.

The hardening checklist

  1. Don't expose to public forks. Repo Settings → Actions → Require approval for outside collaborators (or all PRs).
  2. Use ephemeral runners. One job per VM lifecycle. After the job, the VM is destroyed. Tools: actions-runner-controller (k8s), runs-on (AWS), philips-labs/terraform-aws-github-runner.
  3. Run in a container or VM. Don't run the runner agent on the host OS directly.
  4. Strict network egress. Allow only outbound to GitHub + your intended targets. Block default-allow.
  5. Separate trust tiers. Public-PR runners and trusted deploy-runners must not share a host.
  6. Secrets at registration time, not on disk. Don't bake secrets into the runner image. Use OIDC and per-job secret injection.
  7. Patch and rotate. Runner agents are auto-updated; OS patches are your responsibility.

Code

Ephemeral runner via Docker·bash
# Run one ephemeral runner that picks up exactly one job
docker run --rm \
  -e RUNNER_TOKEN=$RUNNER_TOKEN \
  -e RUNNER_REPOSITORY_URL=https://github.com/my-org/my-repo \
  -e RUNNER_LABELS='self-hosted,linux-x64,ephemeral' \
  -e EPHEMERAL=true \
  --network=runner-net \
  --read-only --tmpfs /tmp --tmpfs /home/runner \
  ghcr.io/myrepo/runner:latest

External links

Exercise

If you have any self-hosted runner, run the 7-item hardening checklist on it. Convert any 'no' to a 'yes' or accept the risk in writing. Don't leave the audit half-done.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.