Skip to main content

The three build gates

Before the image exists
A failed gate means no image — not a red badge on an image that already shipped

The build Job of an application is generated from its component. Its gates run as init containers in front of the builder, on the exact commit the builder will build. When a gate enforces and fails, the builder never starts: there is nothing to roll back, because nothing was pushed.

The build Job, in order​

Every application component of type external_source_code renders k8s/build/base/<app>/ with one Job (BuildKit or Kaniko, by the stack's build_type). The containers run in this order:

#ContainerRuns whenWhat it does
1source-gatebuild_gate is enforce or reportClones the branch, scans the build context for secrets and for CRITICAL vulnerabilities that already have a fix in the dependency manifests (Trivy)
2sast-gatesast_gate is enforce or reportClones the branch, runs your pattern rules (Opengrep) over the exact tree
3sonar-gatethe sonarqube-<app> link has enforce_quality_gate: trueAnalyses the exact commit in SonarQube and waits for the quality gate
4builderalwaysBuilds and pushes <registry>/<app>:<version>
5rolloutpush_and_deploy is not falseWrites the pushed digest onto the Deployment and waits for the roll
source-gatebuild_gatesast-gatesast_gate · sast_rulessonar-gatelink: enforce_quality_gatebuilderpush by digestrolloutpush_and_deploysource-gate: passedsast-gate: FAILED - 2 finding(s) in 1 file(s); the image is not built. To build without this gate, set sast_gate to report or off on <app>.sonar-gate: NOT ENFORCED - SonarQube has not set this project up yet (no token): no analysisrollout: Deployment <ns>/<app> sha256:… -> sha256:…The verdict lines are what the stack agent reads back from the Job's pods.
One Job, four verdict lines. The builder is an init container too when the rollout step exists, so the roll only starts once the image is pushed.

Gate 1 — the source scan (build_gate)​

ValueBehaviour
enforceAny finding, or a scanner that could not run, fails the Job: the image is not built (fail closed)
reportThe same findings are printed; the build always continues
offThe container is not rendered

Two scans run: trivy fs --scanners secret over the build context, and trivy fs --scanners vuln --severity CRITICAL --ignore-unfixed over the dependency manifests. The secret scan needs no registry and cannot be stopped by a rate limit; the vulnerability scan resolves manifests online, and when the registry refuses, that part is reported as a warning rather than a block — the running image is still scanned by the Trivy operator. A finding exits with code 3; any other non-zero exit is a scanner error and is never reported as a finding.

Gate 2 — your own rules (sast_gate, sast_rules, sast_version)​

The pattern gate runs Opengrep (LGPL-2.1) with a baseline rule set shipped in the gate image (sast_version, a full image reference you can pin) plus the rules you type into sast_rules — Semgrep-syntax YAML, one textarea on the application. A .opengrep/ directory in the repository is picked up too. This is where a team writes the rule nobody else can write for them: "no permitAll() in our Spring security config", "no unescaped th:utext", "this internal client must not be called from a controller".

ExitMeaningJob behaviour
0passedcontinues
2findings, or rules that do not loadfails at once, no retry (a retry would rescan the same commit)
1clone or scanner failureretried like any build failure

report prints the same lines and always continues. The gate's own message tells you the attribute to change if you must build without it.

The sonarqube component provisions one project and one analysis token per linked application (its bootstrap Job, on every apply). With scan_enabled only, a separate <app>-sonar-scan Job analyses the code after the build and reports. With enforce_quality_gate: true on the link, the analysis becomes the sonar-gate init container: it analyses the exact commit the builder will build and waits for the quality gate. Once SonarQube has taken the project over (gate stacktic-managed, new code counted from the first gated analysis), new bugs or vulnerabilities on new code push nothing.

Verdict lineMeaning
sonar-gate: passedthe quality gate is OK for this commit
sonar-gate: FAILEDthe gate failed; nothing built or pushed; no retry
sonar-gate: NO VERDICTclone, compile or SonarQube unavailable; the Job retries
sonar-gate: NOT ENFORCEDthe project is not set up yet (first build) or not managed yet; the build continues

Java sources with a pom.xml are compiled for the analysis (mvn clean compile), so the gate sees bytecode, not just text.

What the stack agent keeps​

The Job is removed after its TTL; its log would be the only record of a gate's verdict. The agent's Builds & Gates scan (/build_scan, the tab of the same name) turns it into a durable one:

  • Configured, from stack-metadata only: which gates each application switched on, with the attribute that did it — enforce, report, off, or not available for a type without that gate.
  • Runtime, from the cluster: the build Jobs of the build namespace, their init containers, and in full mode the verdict line each gate printed.
  • Findings first: a blocked build, a retry loop, a gate image that cannot be pulled, findings that were only printed (report) — each naming the component and the attribute to change.

A gate switched on but never run shows as not started, not as passed.

What is deliberately not here​

  • Production never builds. An image_base component runs a prebuilt image named by its version; it has a deploy directory and no build Job, so there is no gate — promotion is a change of that attribute, from an image a gated build pushed.
  • No external CI. The build Job is the pipeline. Branch protection, code review rules and signing live where your repository host puts them; the platform does not pretend to replace them.

→ Next: DAST as a design fact · Which control reads what