Skip to content

chore(lint): scope goconst/gosec via .golangci.yml and fix gosec findings#700

Merged
QuentinBisson merged 11 commits into
mainfrom
chore/lint-debt-cleanup
May 19, 2026
Merged

chore(lint): scope goconst/gosec via .golangci.yml and fix gosec findings#700
QuentinBisson merged 11 commits into
mainfrom
chore/lint-debt-cleanup

Conversation

@QuentinBisson
Copy link
Copy Markdown
Contributor

Summary

Unblocks #629 (Align files) and resolves the lint debt tracked in #637.

.golangci.yml (new):

  • goconst: min-len: 5, min-occurrences: 5, ignore-tests: true, plus an ignore-functions list covering muster's logging helpers and fmt.Errorf so log/error format strings stop firing as duplicates.
  • gosec: excluded from _test.go files (test fixtures contain repeated dummy tokens by design); G101 excluded narrowly on internal/events/types.go where event-reason identifiers contain the word Token.

Source-level fixes (no nolint substitutes):

  • cmd/: lifted resource-type / MCP primitive identifiers to constants in cmd/mcp_types.go; the existing //nolint:goconst directives on those strings are now redundant.
  • internal/aggregator/: added constants.go with shared defaultValkeyKeyPrefix/httpReadHeaderTimeout; switched the default namespace to metav1.NamespaceDefault; replaced the running/connected string comparisons with api.IsActiveState and the corresponding api.HealthHealthy/api.HealthUnhealthy constants in the event handler; set ReadHeaderTimeout on every HTTP server construction (fixes G112).
  • internal/context/storage.go: filepath.Clean on the user-supplied config path; tightened directory/file permissions to 0o700/0o600 (G301/G306/G304).
  • internal/oauth/manager.go: filepath.Clean on the configurable CA-file path (G304).
  • internal/orchestrator/orchestrator.go: dropped a stale //nolint:gosec on a context.WithCancel call that gosec no longer flags.
  • internal/aggregator/server.go: dropped a stale //nolint:gosec on the SSO init goroutine spawn.
  • internal/events/types.go: dropped per-line //nolint:gosec on the MCPServerToken* event reasons; now covered by the file-level exclusion above.
  • Stripped 152 redundant //nolint:goconst,gosec directives from _test.go files (now covered by the config).

Result: golangci-lint run -E=gosec -E=goconst -E=govet reports a single residual category (workflow/cli/mcpserver JSON-schema vocabulary), which is addressed in the follow-up PRs in this stack (api.ArgType enum, shared resource-type constants, JSON-key constants).

References

- Add .golangci.yml: goconst min-occurrences=5, min-len=5, ignore-tests,
  ignore-functions for logging.* and fmt.Errorf; exclude gosec on tests and
  on internal/events/types.go (event reason identifiers, not credentials).
- cmd/: lift resource-type / MCP primitive strings to constants in
  mcp_types.go and reference them from check/create/events/get/list/
  start/stop.go.
- internal/aggregator/: add constants.go (defaultValkeyKeyPrefix,
  httpReadHeaderTimeout); switch namespace defaults to
  metav1.NamespaceDefault; replace string state/health checks with
  api.IsActiveState / api.Health* in event_handler.go; set
  ReadHeaderTimeout on http.Server constructions (G112).
- internal/context/storage.go: filepath.Clean + 0o600/0o700 perms
  (G304/G306).
- internal/oauth/manager.go: filepath.Clean on caFile path (G304).
- internal/orchestrator/orchestrator.go: drop stale nolint:gosec.
- internal/aggregator/server.go: drop stale nolint:gosec on
  initSSOForSession call.
- internal/events/types.go: drop nolint:gosec from event reason consts.
- Strip nolint:goconst,gosec from test files; covered by config.
The initial .golangci.yml relied on goconst.ignore-tests, which only
honours the standalone CLI flag; golangci-lint v2 requires a path-based
exclusion to suppress test-file goconst hits. Add the _test.go goconst
exclusion alongside the existing gosec one.

Add a stop-gap ignore-string-values list covering the JSON Schema,
muster response field, CLI table header, OAuth wire and stringly-typed
boolean vocabulary still inlined at this point in the stack. Each
follow-up PR (api.ArgType, shared resource types, JSON-key constants,
OAuth wire constants) shrinks this list; the final PR drops it.

Add narrow gosec/govet exclusions for findings whose source-level fixes
land in later commits in the stack (G118 on the SSO bootstrap
goroutine, G710 on the admin handler redirect and BDD mock, reflect.Ptr
in muster_manager.go).
@QuentinBisson QuentinBisson marked this pull request as ready for review May 18, 2026 18:11
@QuentinBisson QuentinBisson requested a review from a team as a code owner May 18, 2026 18:11
Copy link
Copy Markdown
Contributor Author

@QuentinBisson QuentinBisson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Light review (DDD / SOLID / YAGNI / DRY / don't-reinvent / tests).

0o644 → 0o600 on user config and 0o755 → 0o700 on dirs are correct G306 fixes. No new #nosec annotations in source — only ones removed — which is the right direction.

Non-blocking — scope creep beyond "lint fix"

  • event_handler.go swaps inline string equality (event.NewState == "running" || "connected") for api.IsActiveState(...), api.HealthHealthy, api.StateStarting, etc. That's a behavior refactor, not a gosec fix. Behavior-equivalent only if IsActiveState covers exactly {running, connected} and the typed-string conversions are loss-less. Either surface in the PR body or split into its own PR — the title says "fix gosec findings".

Non-blocking — wrong-layer constant

  • internal/aggregator/constants.go introduces defaultValkeyKeyPrefix, but the value originates in internal/config. PR #706 then moves it. The factoring here is at the wrong layer and gets reverted next PR — net churn.

Non-blocking — .golangci.yml

  • The file-level scoping (internal/aggregator/server.go, internal/admin/handlers.go) hides any new G118/G710 in those files until #706 narrows them. Add an issue link in the YAML comment so the exclusion has a sunset.
  • The 152 redundant //nolint cleanups in _test.go rely on the new path-based test exclusion — confirm in CI that goconst's ignore-tests setting alone wouldn't have sufficed (one source of truth instead of two).

Resolves conflicts in three aggregator test files where main refactored
RegisterPendingAuth to take a PendingAuthRegistration struct. The
//nolint:gosec annotations added in those refactors are now redundant —
the path-based gosec exclusion in .golangci.yml already covers _test.go.
paurosello added a commit that referenced this pull request May 19, 2026
Propagates the main-merge from #700 down the stack. The api_adapter.go
conflict (new family arg from #670 vs. constant extraction from #706)
is resolved by keeping the constant style and adapting the new family
schema to use api.SchemaKey* constants.
Copy link
Copy Markdown
Contributor

@paurosello paurosello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conflicts resolved by merging main into the branch — verified go build ./..., full go test ./internal/aggregator/... (4.4s, all green), and make lint (0 issues). The RegisterPendingAuth refactor on main was accommodated by adopting the new PendingAuthRegistration struct signature; the //nolint:gosec annotations from main's tests are now redundant given the _test.go path exclusion this PR adds to .golangci.yml.

QuentinBisson and others added 2 commits May 19, 2026 14:01
…st config

Drop defaultValkeyKeyPrefix from internal/aggregator/constants.go and
restore the inline "muster:" literal at the four call sites. The value
originates in operator-facing config and #706 lifts it to the right
layer; introducing the constant here at the aggregator layer is reverted
in the next PR, so this is net churn. With min-occurrences=5 (already
configured) four literal occurrences don't trip goconst — no
//nolint:goconst needed.

Annotate the sunset gosec/govet exclusions with a "tracked: #706"
marker so each one has a visible follow-up reference.

Spell out why goconst keeps both ignore-tests and the path-based
_test.go exclusion: ignore-tests skips test files when COUNTING
occurrences (so test-only string usage doesn't inflate the production
count past min-occurrences); the path exclusion separately silences
any goconst report on test files. Dropping ignore-tests alone produces
36 false-positive goconst hits in production files because test-file
usage pushes the count past the threshold.
@QuentinBisson QuentinBisson enabled auto-merge (squash) May 19, 2026 13:18
QuentinBisson and others added 3 commits May 19, 2026 15:27
Resolve test-file conflicts from #716 (test constants). Drop redundant
local serverURL/issuerURL aliases now that testMusterURL/testDexURL
package-level constants exist.
Co-authored-by: github-actions <action@github.com>
Co-authored-by: Timo Derstappen <timo@giantswarm.io>
Co-authored-by: Quentin Bisson <quentin.bisson@gmail.com>
@QuentinBisson QuentinBisson merged commit 7f85e6c into main May 19, 2026
4 checks passed
@QuentinBisson QuentinBisson deleted the chore/lint-debt-cleanup branch May 19, 2026 13:39
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.

3 participants