Interview Prep/CI/CD/GitHub Actions and GitLab CI in Production

How do you secure self-hosted runners?

AdvancedProductionGitHub Actions and GitLab CI in Production
Answer
  • Never attach self-hosted runners to public repos, since a fork PR can run arbitrary code on them.
  • Use ephemeral runners (--ephemeral, ARC scale sets) so each job starts clean.
  • Put them in a network segment without access to internal systems beyond what builds need.
  • Use runner groups and restrict which repos and workflows may use them.
  • Avoid mounting the Docker socket; run as non-root with rootless builders.
  • Grant cloud access via OIDC role bound to repo/environment, not instance profiles broad enough for every job.
  • Patch the runner image regularly; the runner application auto-updates, but the OS does not.
All CI/CD questions Roadmap: GitLab CI/CD

More on GitHub Actions and GitLab CI in Production