Skip to content

gosec findings do not block a merge, and the job that runs gosec cannot fail #415

Closed

Description

@scttfrdmn

What happened

PR #414 added a uint64 → int64 conversion in internal/distributed/cluster.go. gosec flagged it as G115 and reported 1 new alert including 1 error on the PR — and the PR was still mergeable, because gosec is not among main's 19 required status checks. It was noticed only because the checks were read by hand.

The finding was real, not noise: a negative CacheRequests reads as "nothing has asked yet" to the guard that decides whether a cache hit rate is reported, so an overflow would make the busiest cache in the cluster report hit=not measured. Fixed in #414 by clamping.

Two separate problems

  1. The Security Scan job runs gosec -no-fail (.github/workflows/security.yml:58), so the job passes regardless of findings. The gosec check that does go red is the code-scanning check produced by the SARIF upload, which is a different check from the job.

  2. The gosec check only appears on pull requests, never on main pushes. Measured across the last four commits on main: zero gosec check runs on each. So it cannot simply be added to the required-checks list — a required context that does not always report blocks every PR forever, which is the failure mode ci: give the modulefiles matrix legs names that can be required checks #413 was written to avoid for the modulefiles legs.

Why this is not just "add it to branch protection"

Requiring a context that reports on PRs but not on pushes needs verifying first; branch protection matches by exact string and has no notion of "required only when present". Options, in rough order of preference:

  • Have the Security Scan job itself fail on new findings — drop -no-fail, or gate on a severity threshold — so the job is the required check. A job name is stable and reports on both triggers.
  • Keep -no-fail for the SARIF upload and add a separate step that fails on findings above a threshold, so the historical backlog does not block every PR while new findings do.

The severity threshold matters: the repo has a pre-existing G115 backlog in sdks/c that the SARIF filter already works around (see the comments at security.yml:63-94), so failing on all findings would block everything. Failing on findings in code changed by the PR is the behavior the current check-run summary already reports ("New alerts in code changed by this pull request").

Acceptance

  • A new gosec finding in changed code blocks the merge without anyone reading the checks by hand.
  • The mechanism reports on both push: main and pull_request, verified by looking at check runs on a merge commit — not assumed.
  • The pre-existing backlog does not block unrelated PRs.

Activity

  1. added this to the Future Work milestone on Aug 9, 2026
  2. added
    type: security
    type: ci-cd
    priority: medium
    area: ci-cd
    on Aug 9, 2026
  3. scttfrdmn commented on Aug 14, 2026

    @scttfrdmn
    OwnerAuthor

    Measured the trigger question this issue flags as needing verification, since it decides which of the two options is available.

    Security Scan reports on push: main. On fb0ecbc (the merge of #431) the commit carries 45 check runs and Security Scan is among them. It is in security.yml's on: block for both push: branches: [main] and pull_request, and the workflow's run list confirms both event types firing.

    So the issue's second problem — "only appears on pull requests, never on main pushes" — is true of the gosec code-scanning check produced by the SARIF upload, and not of the Security Scan job. Those are two different contexts with two different names, which is exactly the confusion the issue body identifies; this just settles which side of it each one falls on.

    That makes option 1 the one to take: have the job fail on new findings and require Security Scan, which is a stable job name that reports on both triggers. No need for the "required only when present" behaviour branch protection cannot express.

    The severity/backlog constraint stands unchanged. gosec -no-fail must keep running for the SARIF upload — the sdks/c back-fill step depends on getting a complete report — so the gate has to be a separate step reading gosec.sarif, failing on findings outside the known backlog rather than on all of them. .github/workflows/security.yml:113-115 already counts total results and back-filled results, so the numbers a threshold would compare against are being printed today.

    One addition to the acceptance criteria, from a defect just fixed next door in #433: whatever the gate prints, verify the message is reachable on a failing run. install-script had three carefully worded ::error:: messages that a set -e command substitution killed the step before reaching, so a real failure's log held only bash's errno. A security gate whose explanation only appears when it passes has the same problem.

  4. scttfrdmn commented on Aug 14, 2026

    @scttfrdmn
    OwnerAuthor

    #435 is merged. The gate exists and is verified on both triggers; one step remains and it needs your say-so.

    What landed

    .github/scripts/gosec-gate.sh, run as the last step of Security Scan, diffing the report against .github/gosec-baseline.txt.

    -no-fail stays, deliberately. The SARIF upload needs the complete report, including the three sdks/c findings the format-fix 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 reads as a tightening and is a loosening: the job would end before either step ran.

    The severity-threshold option in this issue is not available

    Measured: 12 findings, all G115, all error level. There is no level that separates the backlog from a new finding, because gosec reports every G115 identically. So the baseline is what the acceptance criterion actually needs, not a threshold.

    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, a refactor inside one of those eight 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, because a slot kept after its finding was fixed is permanent headroom for the next conversion in that file.

    Acceptance, item by item

    • A new gosec finding in changed code blocks the merge without anyone reading the checks by hand — yes, via the job's exit status. One qualification worth stating rather than glossing: the mechanism is whole-file counts, not "code changed by this PR". A PR that adds a conversion to a baselined file fails because that file's count went 1→2, which is the same outcome by a different route; a PR that moves an existing conversion between files fails on both ends and needs both lines edited. That is a slightly wider net than the check-run summary's wording, and it errs toward failing.
    • Reports on both triggers, verified by looking at check runs on a merge commit rather than assumed — done. Security Scan on the push: main commit bb914cf printed:
      gosec-gate: 12 findings in gosec.sarif, 8 (rule, file) groups
      gosec-gate: matches .github/gosec-baseline.txt exactly
      
      Both the PR run and the push run agree with the local count, so the baseline is CI's measurement.
    • The pre-existing backlog does not block unrelated PRs — yes, that is what the baseline is.

    Verified by running the failure path, which found a bug in the gate itself

    Five mutated SARIF files: a second finding in an already-baselined file; a finding in a file not baselined; a baselined finding removed; a different rule in a baselined file; and zero results, which is the shape a failed scan leaves behind as easily as a clean one and now gets its own message instead of a bogus eight-fixed-findings diff.

    The first run caught a defect in the script: diff exits 1 on a difference, pipefail promotes that to the pipeline, and set -e ended the script at diff | tail — so the 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 and re-verified.

    internal/config/gosec_gate_test.go gates the two silent failure modes — a baselined path that no longer exists, and the workflow step deleted, -no-fail dropped, or the script not executable. All six branches mutation-verified.

    Outstanding: adding Security Scan to required checks

    That is the last step, and it is the one that makes this issue's headline true — until the context is required, a red Security Scan still does not block a merge, it just goes red where someone can see it.

    It is a persistent branch-protection change on main (19 contexts → 20), so I have not made it. Say the word and it is one API call:

    gh api repos/scttfrdmn/objectfs/branches/main/protection/required_status_checks \
      --method PATCH -f strict=true -f 'contexts[]=…' -f 'contexts[]=Security Scan'
    

    Note it must be the job name Security Scan, not gosec — that is the code-scanning check this issue identified as not reporting on push: main, and requiring it is the thing that would block every PR forever.

    Leaving this open until then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: ci-cdpriority: mediumtype: ci-cdtype: security

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions