Skip to content

GitLab CI/CD

Scope: designing CI/CD pipelines on GitLab CI/CD, including CI/CD components, merge request pipelines, runners and deployments. Pipelines run with access to your code, secrets and cloud accounts, so many rules here are about keeping them secure. GitHub Actions covers the same concerns on GitHub. For general secrets and supply-chain rules, see Security; for building container images, see Docker.

Entries are sorted by score from 1 to 10 (criteria): 9โ€“10 start here or strongly recommended, 6โ€“8 recommended, 1โ€“5 further reading or conditional.

Adopted references

  • 8 Pipeline security (GitLab Docs): the baseline for pipeline security: where to store secrets, inputs instead of pipeline variables, and pinning images, dependencies, scripts and included configuration.
  • 8 Security for self-managed runners (GitLab Docs): the risks of each executor, privileged containers, image pull policies, shared Git working copies and network segmentation.
  • 8 Deployment safety (GitLab Docs): protected environments, one deployment at a time, outdated deployment jobs, deploy freezes, production secrets and a separate project for deployments.
  • 7 CI/CD components (GitLab Docs): reusable, versioned pipeline configuration, the CI/CD Catalog, and security best practices for component users and maintainers.
  • 7 OpenID Connect authentication using ID tokens (GitLab Docs): short-lived credentials for cloud providers and secret managers instead of stored secrets, with guides per cloud provider.
  • 7 CI/CD job token (GitLab Docs): what CI_JOB_TOKEN can access, and how the job token allowlist limits which projects can use it.
  • 6 Pipeline efficiency (GitLab Docs): finding bottlenecks, failing fast, needs, components, caching and Docker images.
  • 6 Pipeline architecture (GitLab Docs): when to use basic pipelines, needs, parent-child pipelines and multi-project pipelines.

Key rules

Security

Pipeline design

Deployments

How to enforce

Tools that check the key rules above automatically, in CI, the IDE or a commit hook. "Partly" means the tool covers only some of what the rule asks.

  • 7 CI Lint: GitLab's built-in validation of .gitlab-ci.yml, with its includes, which can also simulate pipeline creation. Run it in the pipeline editor, with glab ci lint or through the CI Lint API. Its pipeline warnings flag rules that can start duplicate pipelines. Partly checks GITLAB-11.
  • 7 GitLab CI/CD settings: setting "Minimum role to use pipeline variables" to no_one_allowed blocks pipeline variables. Other settings keep the job token allowlist on (administrators of self-managed instances can enforce it for every project), keep separate caches for protected branches, and turn on Prevent outdated deployment jobs. Partly checks GITLAB-6, GITLAB-7, GITLAB-9 and GITLAB-16.
  • 5 Plumber: a CI/CD security scanner for GitLab CI and GitHub Actions, run as a CLI or a GitLab CI/CD component. Its GitLab controls flag includes on forbidden versions such as latest, main or HEAD, images not pinned by digest, unprotected and unmasked variables, and pipelines that enable CI_DEBUG_TRACE. Partly checks GITLAB-1, GITLAB-2 and GITLAB-8.
  • 5 poutine: a build pipeline scanner for GitHub Actions and GitLab CI. For GitLab, it flags CI_DEBUG_TRACE, and its injection rule flags inputs interpolated with expand_vars into scripts. Partly checks GITLAB-7 and GITLAB-8.
  • 5 Checkov GitLab CI checks: CKV_GITLABCI_2 flags job rules that create duplicate pipelines. Partly checks GITLAB-11.

Tutorials and further reading