Skip to content

Guardrails / gitlab

A required section covers everything ​

gitlab/codeowners-catch-all@v1

A section that requires approval declares a rule matching every path, so a file nobody thought about still has an owner who must approve it.

Idgitlab/codeowners-catch-all
Versionv1
Categorygitlab
Default severitywarning
Interpreterpython3
Timeout30 seconds
Violations tolerated0
Collectsgitlab

Collectors ​

This guardrail doesn't gather anything itself. It relies on the collectors below, which the CLI runs once per build before any check, and reads what they found from GUARDRAIL_FACTS. If a collector collects nothing, this guardrail is skipped, not failed.

CollectorGathersInputs it is given
gitlabWhat GitLab itself reads out of the repository: the .gitlab-ci.yml, read as GitLab writes it, and the CODEOWNERS file, read as sections of rules. For the pipeline, the stages it declares, what it includes, and for every job the stage it sits in, the image and runner tags it asks for, how long it may run, the rules that decide whether it runs at all, and each script section with the variables it interpolates. For CODEOWNERS, every section with whether it is optional and how many approvals it needs, the rules under each, and the owners that apply to the paths a guardrail asks about, resolved per section the way GitLab resolves them. Names and shapes only, never a secret, a variable value or an environment value.pipelines

The inputs above are this guardrail's own inputs, passed straight through to the collector. Setting one in buildnote.json changes what is collected, and two guardrails configured the same way share a single collection.

Configuration ​

json
{
  "guardrails": {
      "failOn": "error",
      "checks": [
          {
              "use": "gitlab/codeowners-catch-all@v1",
              "severity": "warning",
              "with": {
                  "pipelines": ".gitlab-ci.yml,.gitlab-ci.yaml",
                  "patterns": "*,**,/*"
              },
              "exemptions": []
          }
      ]
  }
}

Inputs ​

InputDescriptionDefaultEnvironment variable
pipelinesComma separated globs naming the GitLab CI files to read..gitlab-ci.yml,.gitlab-ci.yamlGUARDRAIL_INPUT_PIPELINES
patternsComma separated patterns, any one of which counts as matching every path.*,**,/*GUARDRAIL_INPUT_PATTERNS

How to fix ​

Make a catch-all the first rule of a required section, then narrow ownership below it:

* @company/platform

[Backend][2] @company/backend
/api/

GitLab resolves ownership separately for each section, so a catch-all only covers the section it sits in. A file that no section names has no owner, and you won't notice the gap until a merge request touches it.

A catch-all in an optional section doesn't close the gap. Optional sections are written ^[Name]. Their owners are shown on the merge request, but their approval is never required, so the change can merge without anyone having looked at it.

More in gitlab ​

  • gitlab/codeowners-no-unowned-rules. No rule in CODEOWNERS ends up with no owners, counting the default owners it inherits from its section header, so no section claims a path without naming someone for it.
  • gitlab/codeowners-owners-per-rule. Every rule in CODEOWNERS ends up with between the minimum and maximum number of owners, counting the default owners it inherits from its section header, so review depends neither on a single person nor on everyone.
  • gitlab/codeowners-parses. Every line of CODEOWNERS that isn't a comment is either a section header or a rule, so no ownership is silently lost to a line GitLab ignores.
  • gitlab/codeowners-present. The project has a CODEOWNERS file in one of the three places GitLab reads it from, and at least one section of it declares a rule, so every change has someone to review it.
  • gitlab/codeowners-team-owned. Every rule in CODEOWNERS ends up owned by at least one GitLab group, so ownership survives changes in who is on the team.
  • gitlab/job-timeout-set. Every job declares how long it may run, so a hung job is cut off rather than holding a runner until the project's own limit.

All 7 gitlab guardrails

Buildnote Limited
Registered in England and Wales, Reg: 16140412