Skip to content

Code to Production 03: CI Gates Before Review

A reviewer's time is the most expensive check you have, so in eShop six jobs of machine gates run before a human opens the diff, and they finish in a minute or two. Every gate is a script that runs the same on a laptop and in CI, and every exception to a gate is a line with a reason and an expiry date. This post is the pipeline, each gate with its real output, and the pitfalls each guard is there for.


One pipeline answers two questions, at two speeds

A pipeline has to answer "is this change safe to read and merge?" and "is the thing we built fit to run?". The first has a person waiting on it. The second doesn't.

So eShop splits them. A merge request runs only the checks that read source: lint, then sast, secrets, config, deps and commits side by side. The slow work (build the image, start it, load it, attack it, scan it, sign it) runs in one job, service-image, on main and release/* only. That job is post 04.

Diagram of the service pipeline: a merge request lane with lint and gates only, and a main lane that adds service-image and a deploy trigger into eshop-infra

Top lane: a merge request stops after gates. Bottom lane: main runs the same gates again (minus commits), then the long service-image job, then a trigger that waits for the deploy in eshop-infra.

The worked example through this series is issue #3, twelve lines in eshop-web. Its merge request pipeline, #66, took 40 seconds. The main pipeline after the merge, #68, took 7 minutes 4 seconds.

GitLab pipeline #66 of eshop-web, Passed, 3 jobs in 40 seconds across the stages lint and gates

Pipeline #66: two stages, lint then gates, and no image stage.

The trade is real, and ADR 0007 ("Release gates run in CI against a temporary copy; deploys are promotion PRs") accepts it. A change can merge and then fail the image job. Then no image is pushed, dev keeps the previous build, and the fix is another merge request. main can be red for a while. An environment can't receive the broken image.

Every service includes one shared gates file

eShop has five service projects and one eshop-infra. Five copies of a CI config drift within months, so there's one copy. A service's whole .gitlab-ci.yml is an include plus its own lint job:

include:
  - project: root/eshop-infra
    ref: main
    file: ci/service-image.gitlab-ci.yml
    inputs:
      images: "eshop-web|.|Dockerfile"

lint:
  stage: lint
  image: node:24-alpine@sha256:a34ab6d7f6f4813f4d0c5469d74685604b962fbdbf5793a7bc7b4998ecb867c8
  tags: [eshop-docker]
  timeout: 15m
  interruptible: true
  script:
    - npm ci --cache .npm --prefer-offline
    - npx oxlint --format gitlab > lint-codequality.json || true
    - npm run lint
    - npm run build
  # ... cache and artifacts

A service decides what it builds (the images input, its lint job), never how it's gated. That's ADR 0009, "One repository per service; release candidates promote the images dev tested". A change to a gate reaches all five services at their next pipeline, with no merge request in five repositories.

The shared file, eshop-infra/ci/service-image.gitlab-ci.yml, is 208 lines, mostly comments. Its core is the workflow rules1:

workflow:
  rules:
    - if: $CI_PIPELINE_SOURCE == "merge_request_event" && ($CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "main" || $CI_MERGE_REQUEST_TARGET_BRANCH_NAME =~ /^release\//)
    - if: $CI_PIPELINE_SOURCE =~ /^(push|web|api)$/ && ($CI_COMMIT_BRANCH == "main" || $CI_COMMIT_BRANCH =~ /^release\//)
  auto_cancel:
    on_new_commit: interruptible

stages: [lint, gates, image, deploy]

Anything that matches neither rule creates no pipeline at all: a push to a feature branch with no merge request, a schedule, a tag.

Each gate job has the same shape. Here's sast, complete:

.eshop-infra:
  tags: [eshop-shell]
  before_script:
    - INFRA=$(mktemp -d)/eshop-infra
    - git clone --quiet --depth 1 --branch "$ESHOP_INFRA_REF" "${CI_SERVER_PROTOCOL}://gitlab-ci-token:${CI_JOB_TOKEN}@${CI_SERVER_HOST}:${CI_SERVER_PORT}/${ESHOP_INFRA_PROJECT}.git" "$INFRA"

sast:
  extends: .eshop-infra
  stage: gates
  timeout: 15m
  interruptible: true
  script:
    - '[ -e .semgrepignore ] || cp "$INFRA/.semgrepignore" .semgrepignore'
    - GATES_SOURCE="$CI_PROJECT_DIR" REPORT_DIR="$CI_PROJECT_DIR/reports/sast" "$INFRA/scripts/gates/pins.sh"
    - GATES_SOURCE="$CI_PROJECT_DIR" REPORT_DIR="$CI_PROJECT_DIR/reports/sast" "$INFRA/scripts/gates/sast.sh"
  artifacts:
    when: always
    expire_in: 30 days
    expose_as: SAST report
    paths: [reports/sast/]
    reports:
      codequality: reports/sast/codequality.json

The CI file only decides when to run a gate. The gate itself is a script in eshop-infra/scripts/gates/. The job clones eshop-infra with its job token into a temp folder beside the checkout, never inside it, or Semgrep would scan the gate scripts as the service's code.

Two things to copy from this:

  • The job token allowlist. Every project must allow the others' job tokens (Settings > CI/CD > Job token permissions). A new project missing from it fails at the git clone with an auth error that never mentions the allowlist.
  • The cost of ref: main. A service pipeline can go from green to red with no change in the service. When that happens, read eshop-infra's recent merges first.

Pitfall: a source no rule matches creates no pipeline

A pipeline started through the REST API has the source api, not push or web. When no workflow rule matches a source, GitLab creates nothing. No error, no failed pipeline, only an absent one.

So the workflow rule and the rules of service-image and deploy all match push|web|api. A workflow rule fails silently, so list every source you intend to support.

The gates need a shell runner; lint gets a docker runner

One VM, <RUNNER> (Ubuntu 24.04, amd64), hosts three runners on GitLab Runner 19.5.3. Jobs pick one by tag.

GitLab Admin area Runners page listing three online runners: eshop-docker-amd64, eshop-shell and gitlab-runner docker

All three runners live on one machine. eshop-shell carries every gate; eshop-docker-amd64 carries every service's lint.

Runner Executor Tags Runs
eshop-shell shell, 2 jobs at a time eshop-shell every gate job, service-image, eshop-infra's jobs
eshop-docker-amd64 docker, privileged eshop-docker, amd64 every service's lint
gitlab-runner docker docker, linux untagged jobs; none of the services'

Lint is a pure function of the source and a pinned image, which is what the docker executor is good at.

The gates are different. Each gate script runs its tool in a container and mounts the job's folders into it, so the script and the Docker daemon must share one file system. With Docker-in-Docker the daemon can't see the job's folders. On the shell runner it can.

The shell runner's machine needs Docker with the compose plugin, bash, git, curl, jq, python3 and Node 24, the gitlab-runner user in the docker group, and the CA certificates of GitLab and Harbor in its trust store.

Pitfall: a hardened runner image breaks the gates' assumptions

A hardened base image for the runner VM breaks four things the gates take for granted:

  • Node.js is missing. The gates need Node 24. Install it from a tarball checked against its checksum.
  • /tmp is mounted noexec. Nothing written there can run. So the eshop-shell runner sets TMPDIR=/home/gitlab-runner/tmp in its config.toml.
  • Python 3.13 and later applies strict X.509 checks and rejects a private CA certificate that fails them.
  • A strict umask makes the job's files unreadable to other users, and jobs mount the checkout into containers that run as another user. So the gitlab-runner user sets umask 022 (post 04 has the image side of this one).

docs/rebuild-on-a-new-environment.md lists what the runner machine must have. Write yours down too, and expect a hardened base image to break at least one assumption.

Pitfall: two pipelines race on an empty cache

Two pipelines that start together on a runner with empty caches race on them. One job deletes the other's cosign download, and Trivy crashes reading a vulnerability database the other is still writing.

So on a fresh runner the first pipeline runs alone, and its jobs fill the caches.

The tool's exit code never decides

One rule holds for every scanner here. Each gate runs its tool to write a full report, then a small eShop script applies eShop's rule to that report. The rule stays in a few reviewed lines, independent of a tool's defaults, which change between versions.

That gives every gate the same last line, <gate> gate: passed: ... or <gate> gate: FAILED: ..., and the same exit codes: 1 means the gate judged and failed, 2 means it couldn't judge (a malformed accepted file, a scan that didn't run).

Every engine is a container image pinned by digest, so a verdict is repeatable.

Lint: warnings are failures

Lint is the one job each service owns, because it depends on the language.

Service What lint runs
eshop-api dotnet restore --locked-mode, dotnet format --verify-no-changes, dotnet build -c Release, dotnet test
eshop-web npm ci, npm run lint (oxlint --deny-warnings), npm run build (tsc -b, then vite build)
eshop-node-api npm ci, npm run lint (oxlint, then tsc --noEmit), npm test
thirdparty-mock npm ci, npm run lint, npm run typecheck
eshop-loadgen the locustfile's unit tests, then locust --config locust.conf --list

Two settings worth stealing. --deny-warnings makes a warning a failure, because a linter whose warnings are allowed collects them until nobody reads them. And dotnet restore --locked-mode fails when a package changed without its regenerated lockfile, so what the dependency scan reads is what the build uses.

A red lint stops the pipeline at the first stage. The gate jobs never start.

The pin check: every image by digest, every chart exact

scripts/gates/pins.sh runs first in the sast job. It needs only bash, find and grep, and it fails on:

  • a Dockerfile FROM without a digest (FROM build and scratch are fine);
  • a floating chart version (1.2.x, *, ^1.2, ~1.2, >=1) under deploy/ or clusters/;
  • an image without a digest in a manifest, a CI file or a script.

Strip the digest from a copy of eshop-web's Dockerfile and it says exactly where:

./Dockerfile:9: base image without a digest: caddy:2.11.7-alpine
pins: FAILED: 1 problem(s) above. Pin images by digest (tag@sha256:...) and charts to an exact version.

There's no accepted file for pins and no "reported only" level. Pinning moves every upstream change into a merge request, where the pipeline tests it. Renovate is the other half: without something moving the pins forward, "pinned" soon means "stale".

SAST: Semgrep with pinned rules, and no inline suppressions

scripts/gates/sast.sh runs Semgrep Community Edition, image semgrep/semgrep:1.183.0, against the public semgrep-rules repository at one pinned commit. A new rule arrives only through a merge request that moves that commit.

sast-verdict.py then decides: an ERROR that isn't accepted fails the job. WARNING and INFO are listed under "Reported only" and never fail.

Log of job #109, sast, in pipeline #66: the pin check passes, then Semgrep reports 0 ERROR, 3 WARNING, 5 INFO and the gate passes

Issue #3's sast job, 34 seconds. Line 21 is the pin verdict, line 23 the counts, line 33 the SAST verdict: two verdict lines in one job.

pins: passed: base images and the images named in manifests, CI files and scripts are pinned by digest, and every chart version is exact
Semgrep findings: 0 ERROR, 3 WARNING, 5 INFO; 106 files scanned, 0 parse/rule errors
# ... eight "Reported only" findings
sast gate: passed: no unaccepted ERROR findings

Semgrep supports an inline nosemgrep comment that silences a finding on its line2. The gate passes --disable-nosem, so those comments are ignored on purpose. An inline suppression is written by the person who wants the finding gone, with no reason, and it's easy to miss in a diff. The only way to accept a finding is a line in sast-accepted.txt, covered below.

Dependencies and licences: two Trivy runs over the lockfiles

scripts/gates/deps.sh runs Trivy 0.76.1 (trivy fs --scanners vuln --include-dev-deps) over the npm and NuGet lockfiles. Dev dependencies are in, because they run in the builds.

Finding Effect
CRITICAL vulnerability, fixed version or not fails the job
HIGH, MEDIUM, LOW, UNKNOWN reported, never fails
forbidden licence (for example AGPL), not accepted fails the job
restricted, reciprocal, unknown licence reported, never fails

"Fixed or not" is deliberate. Many teams fail only on vulnerabilities with a fix. eShop fails on every critical one, so an unfixable one becomes a recorded decision in .trivyignore (CVE-... exp:YYYY-MM-DD # reason, Trivy's own expiry syntax3) instead of a silent pass. No eShop repository has one.

Licences are a second Trivy run with --scanners license, using Trivy's own categories4 instead of a list we'd have to maintain. It's a separate run because in a combined report a forbidden licence counts as CRITICAL and would fail the vulnerability check even in report mode.

The check has two modes, from ADR 0013 ("Forbidden licences fail the dependency and image scans, after a report-only start; Code Quality carries them"). The shared CI file sets ESHOP_LICENCE_GATE: enforce, so a forbidden licence fails the job. In report mode, the scripts' default, the same check only lists. eshop-web in report mode:

Licences: 0 forbidden, 0 restricted, 12 reciprocal, 0 unknown, 81 notice, 0 permissive, 0 unencumbered
# ...
licence check (report only, ESHOP_LICENCE_GATE=report): passed: no forbidden licences

NuGet needs one more step: its packages.lock.json records no licence, so Trivy alone sees nothing for .NET. So eshop-api's lint job runs ci/nuget-licences.ps1, which reads each package's .nuspec from the NuGet cache and writes a CycloneDX SBOM that deps hands to Trivy.

Secrets: a secret you deleted still fails

scripts/gates/secrets.sh runs gitleaks v8.30.1 with its default rules and --redact5, twice: over the files at HEAD (a git archive, so only tracked files), and over the commits. In a merge request that's the commits it adds; on main, the branch's whole history. The job sets GIT_DEPTH: "0" for that.

A secret that exists only in a commit, removed by a later one, fails as hard as one in the files. It's still in every clone. A probe proves it: a merge request that adds a made-up GitLab token in one commit and deletes the file in the next. HEAD is clean. The secrets job fails anyway:

Log of the failed secrets job 248: gitleaks found 0 secrets in the files at HEAD and 1 in the commits scanned, marked "removed since"

The finding names the file, line, commit and rule, never the value. "removed since" is the part people don't expect.

gitleaks findings: 0 in the files at HEAD, 1 in the commits scanned

Blocking (not accepted):
  docs/zz-probe.txt:1 (commit a2d5796a, removed since)  gitlab-pat
          Identified a GitLab Personal Access Token, risking unauthorized access to GitLab repositories and codebase exposure.

secrets gate: FAILED: 1 finding(s). A real secret: revoke it, then remove it. Not a secret: accept it with a reason in secrets-accepted.txt

The order in that last line matters. Revoke first, where the secret was issued. A commit can't clean history.

gitleaks' inline allow comments and .gitleaksignore are switched off, same as nosemgrep. A value that only looks like a secret goes in secrets-accepted.txt. eShop has exactly one: a forged JWT in a test that checks the API refuses it.

Pitfall: without a range, gitleaks reads every ref in the clone

Given no range, gitleaks reads every ref of the clone, and a runner's clone keeps the refs of merge requests long closed. A probe like the one above, with its made-up token, then turns main red although main holds no secret.

So secrets.sh always passes --log-opts with a range: commits reachable from HEAD, or from the merge request's base to HEAD. Test a gate on a runner's real clone, not only on a fresh one.

Config: Trivy on what will run, kubeconform on whether it's valid

scripts/gates/config.sh does two jobs depending on the repository.

Where What it checks Tool
Every repository every Dockerfile trivy config
eshop-infra only what each overlay renders, plus the manifests applied by hand Trivy's Kubernetes checks
eshop-infra only every rendered resource is valid for Kubernetes 1.36.2 or its CRD schema kubeconform 0.8.0 with -strict6

config-verdict.py fails the job on a HIGH or CRITICAL misconfiguration that isn't accepted, or on any invalid resource. For a service it's short. eshop-web:

Misconfigurations: 0 CRITICAL, 0 HIGH, 0 MEDIUM, 1 LOW

Reported only (MEDIUM, LOW):
  LOW      DS-0026     Dockerfile  No HEALTHCHECK defined

config gate: passed: no unaccepted HIGH or CRITICAL misconfigurations, no invalid resources

The gate scans rendered manifests, the same text a deploy publishes, not the files in deploy/. A finding is named <overlay>/<Kind>/<name>. A probe branch that adds privileged: true and a made-up field notAField to a Deployment gets both caught, in each of the three overlays that render it:

Misconfigurations: 1 CRITICAL, 9 HIGH, 29 MEDIUM, 62 LOW
kubeconform: 75 resources valid, 3 invalid, 0 skipped (no schema)

Blocking (HIGH or CRITICAL, or invalid; not accepted):
  CRITICAL kubeconform dev/Deployment/eshop-web
          ... at '/spec/template/spec/containers/0/securityContext': additional properties 'notAField' not allowed
  # ...
  HIGH     KSV-0017    dev/Deployment/eshop-web
          Container 'eshop-web' of Deployment 'eshop-web' should set 'securityContext.privileged' to false

Pitfall: a role that can read every Secret

A role with rights on secrets and no names can read every Secret in its namespaces, and Trivy reports it as KSV-0041, CRITICAL. Accepting that finding as it stands hides a real excess when the job needs one Secret.

So eShop's roles name the Secret. The deployer (the identity Flux applies the manifests as) and CI's read-only role each hold get on one Secret by name, and only that narrower right is accepted.

KSV-0041 still fires on the narrowed rule, so each role that reads the Secret needs its own accepted line. A merge request that adds such a role without one is blocked:

Merge request pipeline #345 of eshop-infra, Failed: the config job has a red cross while commits, scripts, secrets and validate are green

eshop-infra's own pipeline has one stage, validate. One red job is enough to block the merge.

Log of the failed config job #756 showing a blocking CRITICAL KSV-0041 finding in eshop-ci-reader.yaml and, below it, the accepted findings with their reasons

Read it top down: counts (line 29), the one blocking finding (lines 32 and 33), then "Accepted", where the deployer's same right sits with its reason. That entry is the model for the fix.

The finding isn't a bug to fix but a decision to record: one line in config-accepted.txt with the reason and a date. With it, pipeline #346 passes in 1 minute 2 seconds.

Pipeline #346 of the same merge request, Passed, with five green jobs in the validate stage

After one accepted line with a reason: commits, config, scripts, secrets and validate all green.

Commits: one line

The sixth gate, commits, fails a merge request that adds an unsigned commit (ESHOP_COMMITS_GATE: enforce). It reads no code, and post 02 covers it.

The gates on one page

Gate Tool Script What blocks Where the finding shows
lint oxlint, tsc, dotnet format, tests the service's own .gitlab-ci.yml any finding, any failed test job log; Code Quality widget
pins bash, find, grep pins.sh (in the sast job) any unpinned image or floating chart sast job log only
sast Semgrep CE 1.183.0 sast.sh, sast-verdict.py ERROR not accepted reports/sast/summary.txt; widget
deps Trivy 0.76.1 deps.sh, trivy-verdict.py CRITICAL vulnerability; forbidden licence reports/deps/trivy.txt, licences.txt; widget
secrets gitleaks v8.30.1 secrets.sh, secrets-verdict.py any finding not accepted, in files or history reports/secrets/summary.txt; widget
config Trivy, kubeconform 0.8.0 config.sh, config-verdict.py HIGH or CRITICAL not accepted; invalid resource reports/config/summary.txt; widget
commits git commits.sh an unsigned commit job log only

All scripts live in eshop-infra/scripts/gates/.

Every accepted finding carries a reason and a last day

Scanners report code that only looks dangerous, so a gate needs a way to accept a finding. The quality of that way decides whether people keep trusting the gate.

eShop's way: one file per gate, one line per finding, fields separated by |. These are the only two accepted SAST findings in eShop, both test code in eshop-api/sast-accepted.txt:

csharp.lang.security.sqli.csharp-sqli | tests/Eshop.SyncMaster.Tests/EnterpriseDatabase.cs | Test helper: ExecuteAsync is private and only ever called with SQL literals; values go in as SqlParameters. | until 2027-05-20
csharp.lang.security.sqli.csharp-sqli | tests/Eshop.SyncMaster.Tests/SyncMasterFactory.cs | Test setup: CREATE DATABASE takes no parameters; the name is the constant EnterpriseDatabase ("enterprise_test"). | until 2027-05-20

And the line for CI's read-only role, in eshop-infra/scripts/gates/config-accepted.txt:

KSV-0041 | clusters/eshop-prd1/eshop-ci-reader.yaml | CI reads one Secret by name (resourceNames: eshop-api-staff, the Staff account the smoke test signs in with), get only, bound in eshop-dev, eshop-qa and eshop-prod; it cannot list Secrets or read any other | until 2027-05-20
File Fields
sast-accepted.txt rule id, path glob, reason, until YYYY-MM-DD
secrets-accepted.txt rule, path glob, reason, until YYYY-MM-DD
config-accepted.txt check id, where (<overlay>/<Kind>/<name> or a path), reason, until YYYY-MM-DD
licence-accepted.txt package glob, licence, reason, until YYYY-MM-DD
.trivyignore CVE-... exp:YYYY-MM-DD # reason

The date is ADR 0016, "Accepted findings expire". An acceptance is a decision made with what somebody knew then. The vulnerability gets a fix, the odd test is deleted, and an entry that stays for ever hides all of it.

One program, scripts/gates/accepted.py, applies the same rule in every gate:

  • Required, and at most a year ahead. A line without a date is malformed, and the gate fails with exit 2: no expiry: end the line with '| until YYYY-MM-DD' (at most a year ahead).
  • 30 days before, the summary lists it under "Entries expiring within 30 days".
  • The day after, the entry accepts nothing. The finding fails the gate again, listed under "Expired entries".

The ADR considered a scheduled job that reports old entries and rejected it: someone has to read a report, while a failing gate gets read. The cost is a pipeline that can turn red on a day nobody changed anything. The 30 days of notice are there so it isn't a surprise.

The verdict also lists entries that no longer match anything, so the files shrink when the code is fixed. One hole: accepted.py checks only exp: in .trivyignore, not that a reason follows. Review has to enforce that one.

Read a red job from the outside in

A red job is a message. Reading it takes a minute:

  • Stage and job. In Build > Pipelines, the stage icon tells you which stage; click through to the job with the red cross.
  • Verdict line. Type gate: in Search visible log output. Exit 1 is a finding in your code; exit 2 is a problem with the gate's inputs.
  • Summary file. Open the job's Job artifacts > Browse, then reports/<gate>/summary.txt. The JSON beside it is for tools.
  • Decide. Fix the cause, or accept it with a reason and a date. A secret is never accepted.
  • Don't retry. The code hasn't changed, so a SAST, pin or scan verdict won't either.

Artifacts exist for failed jobs only because of one line. GitLab keeps artifacts from successful jobs by default, which is the opposite of what a gate needs, so every job says when: always.

Artifacts browser of job #115, service-image, showing the reports folder with dast, deps, image-scan, perf, sast and sbom subfolders

The service-image job of pipeline #68. It inherits the earlier stages' artifacts, so one download holds every report of the pipeline, sast and deps included.

What GitLab CE shows in the merge request

A passing pipeline gives the reviewer one line: "Merge request pipeline #66 passed". Issue #3's eight reported-only Semgrep findings sit three clicks away in a job log, where in practice nobody looks.

GitLab's security and licence-compliance reports are paid-tier features. Code Quality is the report type the free tier shows in a merge request7, so every gate writes a codequality.json and vulnerabilities, licences, secrets and misconfigurations all travel as Code Quality findings. That's the second half of ADR 0013, and it costs one more file per gate and no extra service.

A draft merge request in eshop-web: pipeline #79 passed, and below it the widget "Code Quality scans found 20 new findings" with a View report button

A throwaway merge request. The pipeline passed; the widget still puts 20 findings in front of the reviewer.

The Reports tab of the same merge request listing Code Quality findings: Major Semgrep warnings with file and line, then Minor MPL-2.0 licence findings at package-lock.json line 1

The twenty: three Semgrep warnings (Major), twelve reciprocal licences (Minor) and five Semgrep infos. A dependency finding points at line 1 of the lockfile.

The severity mapping is the same in every gate, and Blocker means exactly "this fails a gate":

Severity SAST Dependencies Licences
Blocker ERROR, not accepted CRITICAL forbidden, enforced
Critical HIGH forbidden, report mode
Major WARNING MEDIUM restricted
Minor LOW reciprocal, unknown
Info INFO UNKNOWN

Three things will confuse you the first time:

  • "New" means compared with the target branch's report. When the target branch has no report, every finding counts as new, as all 20 do above.
  • A new vulnerability may not be your doing. Trivy's database updates daily, so a CVE published after main's pipeline shows as new in a merge request that touched no dependency.
  • The widget shows; it decides nothing. A job passes or fails as its gate script says.

Reproduce any gate on your laptop

Every gate needs only git and Docker. From a clone of eshop-infra with the service cloned beside it:

GATES_SOURCE=../eshop-web scripts/gates/pins.sh
GATES_SOURCE=../eshop-web scripts/gates/sast.sh
GATES_SOURCE=../eshop-web scripts/gates/deps.sh
GATES_SOURCE=../eshop-web scripts/gates/secrets.sh
GATES_SOURCE=../eshop-web scripts/gates/config.sh
GATES_SOURCE=../eshop-web COMMITS_BASE=origin/main scripts/gates/commits.sh

The scripts default to report for licences and signatures, so a local run only lists. This portability also means a move to another CI system rewrites CI files, not gates.

The gates have tests of their own, too. eshop-infra's scripts job runs ShellCheck 0.10.0, scripts/tests/release-scripts.sh (126 checks) and scripts/tests/gate-reports.sh whenever a script or CI file changes. They test the verdict scripts against made-up reports. They don't prove a scanner still finds a real fault: for that, plant one locally after every scanner upgrade, watch the gate fail, and revert.

What production would change

This is a lab, and three things here are lab-shaped:

  • The shell runner isn't isolated. Every job runs as the same user and sees the same Docker daemon. Production would use fresh, short-lived runners and keep the ones holding the registry login and signing key away from merge request code. Here, protected variables do that job.
  • Reports live 30 days. Artifacts and Code Quality reports expire together. Production would keep gate reports as long as the release they describe runs, in a store outside CI, and track findings across builds.
  • The thresholds are lenient by design. A HIGH vulnerability or a Semgrep WARNING never stops a merge. The widget shows them; only people act on them. And a legal team would review Trivy's licence classes against company policy.

Summary

  • Split the pipeline: source-only gates on merge requests, image gates on main. Accept that main can go red after a merge.
  • Keep one shared gates file; let each service own only its lint job and its list of images.
  • List every pipeline source (push, web, api) in workflow:rules. A missing one fails silently.
  • Write each gate as a script that runs its tool in a pinned container, so laptop and CI run the same thing.
  • Let your own verdict script decide from the tool's report, with one verdict line and exit 1 vs exit 2.
  • Fail on warnings in lint, on every unpinned image, on every CRITICAL fixed or not, and on secrets in history.
  • Always pass gitleaks a commit range, and test gates on the runner's real clone.
  • Switch off inline suppressions. Accept findings in one file per gate: finding, path, reason, until date at most a year ahead.
  • Start a new gate in report mode, read what it finds, then enforce.
  • Set artifacts: when: always, and upload codequality.json so GitLab CE shows findings in the merge request.
  • Document what the runner machine must have. A hardened image breaks at least one assumption.
  • On a fresh runner, run the first pipeline alone to fill the caches.

Next: Post 04: Image gates and the supply chain: what service-image does with the merged code, from the temporary copy, Locust and ZAP to the scan, the SBOM and a signed image in Harbor.


  1. GitLab Docs, CI/CD YAML syntax reference: workflow:rules and workflow:auto_cancel:on_new_commit. ↩

  2. Semgrep Docs, Ignore files, folders, and code: the nosemgrep inline comment. ↩

  3. Trivy Docs, Filtering: .trivyignore entries with an exp: expiry date. ↩

  4. Trivy Docs, License scanning: the forbidden, restricted, reciprocal, notice, permissive, unencumbered and unknown categories. ↩

  5. gitleaks README: --redact, --log-opts and .gitleaksignore. ↩

  6. kubeconform README: -strict disallows properties that are not in the schema. ↩

  7. GitLab Docs, Code Quality: the merge request widget and the report format with its fingerprint field. ↩

Discussion

Have thoughts on this post? Share them below — questions, corrections, or your own experience are all welcome.