Skip to content

ci(lint): path-scope gosec G304 to non-test code (#499)#507

Merged
trilamsr merged 1 commit into
mainfrom
chore/expand-lint-gate-499
Jun 3, 2026
Merged

ci(lint): path-scope gosec G304 to non-test code (#499)#507
trilamsr merged 1 commit into
mainfrom
chore/expand-lint-gate-499

Conversation

@trilamsr

@trilamsr trilamsr commented Jun 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Issue #499 lane A. Collapses ~22 inline gosec G304 waivers across the test tree into one path-scoped exclusion in .golangci.yml, plus a shared jsonschematest.Compile helper for the load-parse-compile dance every detector schema test was open-coding.

Root cause. gosec G304 flags variable-path os.ReadFile. Detector schema tests by construction use filepath.Join("testdata", "<pattern>_verdict.schema.json") — a variable path — and each carried a per-site //nolint:gosec rationale comment. The linter rule does not fit test code; the right scope is non-test code. Path-scoped exclusion + helper extraction is the structural fix, not a workaround.

Changes

  • .golangci.yml: linters.exclusions.rules waives gosec G304 on _test.go, with inline rationale referencing the inline waivers it replaces.
  • module/pkg/testutil/jsonschematest/: new helper package + its own unit test (TestCompile_ValidSchema, TestCompile_FailsOnMissingFile) + fixture.
  • module/pkg/patterns/*_test.go (12 files): 22 schema-compile blocks reduced to one-liners via jsonschematest.Compile(t, …).
  • All //nolint:gosec directives stripped from *_test.go across the module (path exclusion now covers them).
  • Production-code waivers preserved with their inline rationale: module/pkg/replay/runner.go:80,95,108 (hermetic fixture loader) and module/receiver/ncclfrreceiver/nccl_fr.go:225 (operator-configured dump dir).

Net: -274 / +86 lines.

ci(lint): centralize 22 inline `gosec G304` waivers in `module/pkg/patterns/**` and the broader test tree into a single path-scoped exclusion (`gosec G304` on `_test.go`) in `.golangci.yml`. Adds `module/pkg/testutil/jsonschematest.Compile` so detector schema tests share one load-parse-compile path. Production-code G304 coverage is unchanged.

Test plan

  • grep -rn 'nolint:gosec' module/ --include='*_test.go' | wc -l returns 0
  • cd module && go test ./pkg/... ./processor/rankjoinprocessor/... ./receiver/... ./sdk/... green
  • cd module && go test ./pkg/testutil/jsonschematest/... green (helper has unit test)
  • make lint green (0 issues)
  • make lint-module-full green (0 issues)
  • CI: full module test matrix

Note: module/processor/patterndetectorprocessor.TestPatternDetector_NegativeFixturesEmitNoVerdicts/synthetic-2026-06-multi-rank-disk-pressure fails on this branch AND on main at de5b201 — pre-existing, unrelated to this PR (verified via git stash + re-run on main HEAD).

@trilamsr trilamsr enabled auto-merge (squash) June 3, 2026 22:57
trilamsr added a commit that referenced this pull request Jun 3, 2026
## Summary

Bumps the Go toolchain pin from **1.26.3 -> 1.26.4** to pick up the
stdlib fix for [GO-2026-5037](https://pkg.go.dev/vuln/GO-2026-5037)
(`crypto/x509.HostnameError.Error`), which `govulncheck` flags via
`tools/pyspy-lint/main.go:106:14` (reachable through `fmt.Fprintln` on
an error path). This was failing the `verify-static` job on every
recent PR.

## Root cause

`crypto/x509.HostnameError.Error` shipped vulnerable in Go 1.26.3.
Patched in Go 1.26.4. There is no in-repo workaround — the call site
in `tools/pyspy-lint` is legitimate error formatting; the only correct
fix is bumping the toolchain pin. Confirmed locally:

```
$ govulncheck ./tools/pyspy-lint/...   # with GOTOOLCHAIN=go1.26.4
No vulnerabilities found.
```

## Files touched (5)

- `go.mod` — `go 1.26.3` -> `go 1.26.4`
- `go.work` — `go 1.26.3` -> `go 1.26.4` (+ updated header comments)
- `.go-version` — `1.26.3` -> `1.26.4` (drives `actions/setup-go` via
  `go-version-file`)
- `install/kubernetes/tracecore/Dockerfile` — base image bumped to
  `golang:1.26.4-alpine` with refreshed sha256 digest
  (`f23e8b22…2a17f`, fetched via `crane digest`)
- `docs/SUPPORT-MATRIX.md` — Go-toolchain row updated to `1.26.4`

`module/go.mod` is intentionally untouched — it pins `go 1.22.0` to
track the OTel collector v0.110.0 OCB-distribution baseline (see
existing comment), and the workspace `go` directive (`1.26.4`)
remains `>=` the member-module floor (`1.22.0`), so workspace mode is
unaffected.

## Test plan

- [x] `govulncheck ./tools/pyspy-lint/...` -> No vulnerabilities found
- [x] `go build ./...` (root, GOTOOLCHAIN=go1.26.4) -> clean
- [x] `go test ./tools/... ./internal/...` -> all green (incl.
  `tools/pyspy-lint`, the file containing the flagged call site)
- [x] `module/` `go test ./...` -> matches `main` (one pre-existing
  failure in `processor/patterndetectorprocessor`

`TestPatternDetector_NegativeFixturesEmitNoVerdicts/synthetic-2026-06-multi-rank-disk-pressure`,
  reproducible on `main` at the same SHA — unrelated to this bump,
  out-of-scope here)
- [x] `make lint` -> 0 issues
- [ ] CI `verify-static` job passes (the gate this PR exists to fix)
- [ ] CI `build` / kind install bench builds against new pinned-digest
  golang base image

## Unblocks

Should clear `verify-static` for PRs #504, #505, #507 (and #506 once
its own `action.yml` fix lands).

```release-notes
chore: bump Go toolchain pin to 1.26.4 to pick up the stdlib fix for
GO-2026-5037 (crypto/x509.HostnameError.Error). No behavior change.
```

Signed-off-by: Tri Lam <tree@lumalabs.ai>
Collapses ~22 inline gosec G304 waivers across the test tree into one
path-scoped exclusion in .golangci.yml plus a shared jsonschematest.Compile
helper for the load-parse-compile dance every detector schema test was
open-coding.

- .golangci.yml: linters.exclusions.rules waives gosec G304 on _test.go
- module/pkg/testutil/jsonschematest: new helper + its own unit test
- module/pkg/patterns/*_test.go: 22 schema-compile blocks => one-liner
- Strips redundant gosec waivers from all *_test.go (path exclusion
  now covers them)
- Keeps the 4 non-test waivers (runner.go + nccl_fr.go) with their
  inline rationale; production code still gets gosec G304 coverage

Net: -274 / +86 lines.

Signed-off-by: Tri Lam <tree@lumalabs.ai>
@trilamsr trilamsr force-pushed the chore/expand-lint-gate-499 branch from ba44555 to a1bb3fa Compare June 3, 2026 23:20
@trilamsr trilamsr merged commit 43b6f5a into main Jun 3, 2026
27 checks passed
@trilamsr trilamsr deleted the chore/expand-lint-gate-499 branch June 3, 2026 23:30
trilamsr added a commit that referenced this pull request Jun 4, 2026
## Summary

Centralize the remaining structural `nolint` patterns into
`.golangci.yml` path-scoped exclude-rules. Builds on PR #507 (lane A:
`_test.go` G304) by covering the next four structural classes that were
each generating multiple inline waivers.

**Inline `nolint:` waivers: 35 → 13 (-63%).** Untouched:
`module/processor/patterndetectorprocessor/` (lane J overlap; deferred
to next wave) and 11 point-specific load-bearing keepers.

## Before / after by category

| Category | Before | After | Mechanism |
| --------------------------------------- | -----: | ----: |
------------------------------------------------------------------------
|
| `gosec` (G304 in `_test.go`) | 8 | 0 | already covered by PR #507's
existing exclude-rule (redundant comments) |
| `gosec` (G204 / G107 integration tests) | 3 | 0 | new path scope
`internal/integration/.*_test\.go`,
`components/.*/integration_helper_test\.go` |
| `gosec` (G304 hermetic replay loader) | 3 | 0 | new path scope
`module/pkg/replay/runner\.go` |
| `gosec` (G304 jsonschematest helper) | 1 | 0 | new path scope
`module/pkg/testutil/jsonschematest/.*\.go` |
| `gosec` (G306 / G304 / G404 dev tools) | 5 | 0 | new path scopes for
`tools/genfixtures`, `tools/coverage-check`, `tools/failure-inject` |
| `goconst` (patterns test vocabularies) | 2 | 0 | new path scope
`module/pkg/patterns/.*_test\.go` |
| **Centralized subtotal** | **22** | **0** | |
| `gocyclo` (kept inline, load-bearing) | 7 | 7 | flat-table dispatch /
pattern-match rationale; point-specific |
| `gosec` (G103 / G304 prod, load-bearing)| 2 | 2 | `xid_correlation.go`
unsafe aliasing; `nccl_fr.go` operator-config path |
| `unused` (doc / export refs) | 2 | 2 | `pyspy.go`,
`steady_state_linux_test.go` — referenced from doc.go |
| `wrapcheck` (stutter rationale) | 1 | 1 |
`tools/coverage-check/main.go` os.Open already includes path |
| `staticcheck` (SA1019 parity assert) | 1 | 1 |
`xid_correlation_test.go` — issue #277 pre-deprecation parity |
| **Inline keepers subtotal** | **13** |**13** | |
| **TOTAL inline** | **35** |**13** | **-22 (-63%)** |

## Root cause

Each inline waiver was treating a *class* of safe-by-design call sites
as a point exception. The class-level fixes (path-scoped exclude-rules)
move the rationale into one searchable location so future reviewers grep
`.golangci.yml` instead of `git log`-archaeologying 22 scattered
comments.

## What's NOT in this PR

- `module/processor/patterndetectorprocessor/config.go` (2 gocyclo
waivers) and `xid_correlation_test.go` (1 staticcheck) — lane J (#497)
touches `patterndetectorprocessor/`; deferred to the next wave to avoid
merge conflicts.
- The 11 load-bearing inline keepers above — each carries a
point-specific rationale that does not generalize to a path scope
(unsafe aliasing site, weak-RNG-for-chaos-repro, pre-deprecation parity
asserts, etc.).

## Test plan

- [x] `make lint` green pre-change (baseline: 0 issues).
- [x] `make lint` green post-change (0 issues).
- [x] Pre-commit hook ran root `golangci-lint` + `module/`
`golangci-lint` + `go vet` + `go mod verify` + attribute-namespace-check
— all green.
- [x] `git diff --stat` confirms no `patterndetectorprocessor/` files
touched.

Closes #499.

```release-notes
ci(lint): centralize 22 inline `nolint` waivers (gosec G204/G107/G304/G306/G404, goconst) into `.golangci.yml` path-scoped exclude-rules. 13 load-bearing point-specific waivers remain inline.
```

---------

Signed-off-by: Tri Lam <tree@lumalabs.ai>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant