Repository navigation
ci(security): fail Security Scan on a gosec finding that is not baselined - #435
Merged
Merged
Conversation
…ined (#415) A gosec finding did not block a merge, and every part of the mechanism looked like it did. `Security Scan` runs `gosec -no-fail`, so the job passed on any number of findings. The check that went red was `gosec` — the code-scanning check derived from the SARIF upload, a different check with a different name — and that one reports on pull requests and not on `push: main`, measured across four commits. So it could not be added to the required contexts either: a required check that does not always report blocks every PR forever (#413). The result was that #414 added a `uint64 -> int64` conversion, gosec reported "1 new alert including 1 error", and the PR stayed mergeable. It was caught by someone reading the checks by hand. `-no-fail` stays. The upload needs the complete report, including the three `sdks/c` G115 findings that the "Fix Gosec SARIF format" step back-fills a path onto — and which golangci-lint discards for the same cgo reason, so they reach no other tool. Dropping the flag would end the job before either step ran, which reads as a tightening and is a loosening. The gate is instead a final step running .github/scripts/gosec-gate.sh, which diffs the report against .github/gosec-baseline.txt. `Security Scan` is a job name, so it reports on every trigger the workflow has, which is what lets it be required. Last in the job and `if: always()`, so a new conversion does not also cost the run its govulncheck result, Trivy upload and license check. The baseline is the twelve pre-existing findings across eight files, keyed by (rule, file, count). Not by line number, which moves whenever anything above it moves, so a line-keyed baseline goes stale on unrelated edits and reports on the wrong thing. A severity threshold was not available: all twelve are G115 at `error` level, identical to what a new finding reports, so there is nothing to threshold on. The ratchet is exact in both directions — fixing one of these fails too, until its line goes with it, because a slot kept after its finding was fixed is permanent headroom for the next conversion in that file. Two things are gated in Go, in internal/config/gosec_gate_test.go, because both failure modes are silent: every path in the baseline must exist (a renamed file leaves a standing allowance pointing at nothing, and the script would report it as a fixed finding, which is true said misleadingly), and the workflow must still invoke the script, still pass `-no-fail`, and the script must still be executable. All six branches were mutation-verified: each fails with its own message and the suite returns to green. The script's own failure path was verified by running it, not by reading it — and that caught a bug in it. `diff` exits 1 on a difference, `pipefail` promotes that to the pipeline, and `set -e` ended the script at `diff | tail`, so the first mutant printed the diff and then none of the three paragraphs explaining what to do about it. Which is the exact failure #433 had just fixed elsewhere, sitting directly below a comment describing it. Refs #415
This was referenced Aug 14, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #415.
The defect
A gosec finding did not block a merge, and every part of the mechanism looked like it did.
Security Scanrunsgosec -no-fail(security.yml:58), so the job passes on any number of findings. The check that did go red wasgosec— the code-scanning check derived from the SARIF upload, which is a different check with a different name. And that one reports on pull requests and not onpush: main, measured across four commits, so it could not simply be added to the required contexts either: a required check that does not always report blocks every PR forever, which is the failure mode #413 was written to avoid.The result: #414 added a
uint64 → int64conversion, gosec reported "1 new alert including 1 error", and the PR stayed mergeable. It was caught by someone reading the checks by hand.The fix
-no-failstays. The upload needs the complete report, including the threesdks/cG115 findings that the "Fix Gosec SARIF format" step back-fills a path onto — and which golangci-lint discards for the same cgo reason, so they reach no other tool. Dropping the flag would end the job before either step ran: it reads as a tightening and is a loosening.The gate is instead a final step running
.github/scripts/gosec-gate.sh, which diffs the report against.github/gosec-baseline.txt.Security Scanis a job name, so it reports on every trigger the workflow has — which is what lets it be required. It runs last, withif: always(), so one new conversion does not also cost the run its govulncheck result, Trivy upload and license check.Why a baseline and not a severity threshold
Measured locally: 12 findings, all G115, all
errorlevel.There is no level that separates the backlog from a new finding, because gosec reports every G115 identically. So the issue's severity-threshold option gates nothing, and the baseline is what the acceptance criterion actually needs.
Keyed by
(rule, file, count)— not by line number, which moves whenever anything above it moves, so a line-keyed baseline goes stale on unrelated edits and the failure it reports is always about the wrong thing. Keyed this way, an unrelated refactor inside one of these files is silent and a second conversion added to it is not.The ratchet is exact in both directions: fixing one of these fails too, until its line goes with it. A slot kept after its finding was fixed is permanent headroom for the next conversion in that file — the same hole as a coverage floor that only ever moves down.
Verification
The script's five failure paths were run, not reasoned about, against mutated SARIF:
index.go1→2)G401) in a baselined fileThat caught a bug in the script.
diffexits 1 on a difference,pipefailpromotes it to the pipeline, andset -eended the script atdiff | tail— so the first mutant printed the diff and then none of the three paragraphs explaining what to do about it. Which is precisely the failure #433 had just fixed in the install-script job, occurring directly beneath a comment describing it. Fixed with|| trueand re-verified; all four diff-path mutants now print their full guidance.internal/config/gosec_gate_test.gogates the two silent failure modes, and all six of its branches were mutation-verified (each fails with its own message; suite returns to green):-no-faildroppedLocal:
go build ./...,gofmt -l .,go vet ./...,golangci-lint run,go test -race ./internal/config/,shellcheck .github/scripts/gosec-gate.sh— all clean.Follow-up, deliberately not in this PR
Adding
Security Scantomain's 19 required contexts. It should be required only once this PR is onmainand the job has been observed green on apush: mainrun with the new step in it — the acceptance criterion says verified by looking at check runs on a merge commit, not assumed, and requiring a context whose new step has never run there is the same mistake in the other direction.