Securing Repositories and CI/CD — GitHub, GitHub Enterprise Server, GitLab and Azure DevOps

Merge controls, pipeline tokens and OIDC, fork and injection risks, deployment gates and build runners on GitHub, GHES, GitLab and Azure DevOps, with the plan each feature needs and how to recover from mistakes.

Overview

A repository and its pipeline together hold the keys to production. Whoever can merge to the default branch, edit a workflow file, or run a job on a privileged runner can usually ship code or read deployment credentials. Most real incidents are not exotic: an admin merges past a failing check, a workflow runs a fork's code with secrets in scope, a third-party action tag is moved to a malicious commit, a token can reach every repository in the organization, or a cloud key sits in a secret for years.

This page covers four platforms and is careful about which feature exists where: GitHub.com (Free, Pro, Team, Enterprise Cloud), GitHub Enterprise Server (GHES, self-hosted), GitLab (Free, Premium, Ultimate) and Azure DevOps (Services and Server). The same ideas repeat on each: gate the merge, give the pipeline the least identity it needs, keep untrusted code away from secrets, gate the deploy, and treat build machines as hostile.

> [!IMPORTANT] Plan and version matter. Rulesets, environments on private repositories, push protection, GitLab approval settings and protected environments all depend on the plan or tier. Each section names the plan the vendor documents.

Where the controls sit

A change travels through four stages on its way to production, and each stage has its own gate. The merge gate (reviews, checks and rules) decides what reaches the branch. The pipeline run holds a token and secrets. The deploy gate (environment approvals) decides what reaches the cloud or cluster. A gap at any one stage lets a change or a credential through, and each stage has a typical gap: an admin bypass or a force push at the merge gate, fork code with secrets in scope or a shared, persistent self-hosted runner in the pipeline, and long-lived keys with broad trust at the cloud.

Key concepts

  • Branch protection rule
  • Ruleset
  • Most recent push approval
  • Job authorization scope
  • OIDC federation
  • pull_request_target
  • Script injection
  • SHA pinning
  • JIT runner
  • Protected environment

Interview questions

  • Securing the git repo and CICD pipelines for ADO, gitlab, GitHub and GitHub enterprise server
  • How to secure merges and pull requests so anyone cannot merge it - GitHub Security
  • Best practices in GitHub workflow
  • Managing build agents, and what's the experience around that area
  • A developer pushed a cloud access key to the default branch an hour ago. Walk me through your response.
  • What is a pwn request in GitHub Actions, and how do you safely run automation on pull requests from forks?
  • How do you replace long-lived cloud credentials in CI with OIDC, and what do you restrict in the trust policy?
  • In Azure DevOps, a pipeline in one project was able to clone repositories from other projects. Why, and how do you fix it?
  • What happened in the tj-actions/changed-files compromise, and which controls limit the damage from a compromised third-party action?
  • A self-hosted runner's registration or authentication token was posted in a chat channel. What do you do?

Sign up free to read the full topic

More DevOps topics

Start free on Cariara · Coding problems · System design studio