Skip to content

fix: enable gosec G402 (TLS MinVersion) linter rule - #19588

Closed
raajheshkannaa wants to merge 2 commits into
stackrox:masterfrom
raajheshkannaa:fix/enable-gosec-g402
Closed

fix: enable gosec G402 (TLS MinVersion) linter rule#19588
raajheshkannaa wants to merge 2 commits into
stackrox:masterfrom
raajheshkannaa:fix/enable-gosec-g402

Conversation

@raajheshkannaa

@raajheshkannaa raajheshkannaa commented Mar 25, 2026

Copy link
Copy Markdown

Part of #3545

Why G402?

The gosec G402 rule flags any tls.Config literal that omits MinVersion. While Go 1.18+ defaults to TLS 1.2 at runtime, gosec performs static analysis and cannot infer runtime defaults. Without an explicit MinVersion, G402 fires on every tls.Config{} in the codebase. Setting it explicitly satisfies the linter and makes the security intent visible in code, so future readers do not have to know about Go's runtime behavior to confirm TLS 1.2 is enforced.

This also aligns with the broader #3545 effort to enable all security-relevant gosec rules across the repo.

Summary

  • Enables gosec G402 in .golangci.yml to enforce TLS minimum version settings
  • Adds MinVersion: tls.VersionTLS12 to 15 tls.Config structs missing it
  • Adds #nosec G402 annotations to 28 intentional InsecureSkipVerify usages with explanatory comments

Categories of nosec annotations

  • User-configurable TLS skip: notifiers (email, syslog, splunk, sumologic), scanners (quay, clair), registries
  • mTLS-authenticated connections: sensor-to-central, compliance indexer
  • Design intent: cosign fetcher, scanner transports
  • Test code: self-signed certs, test utilities

Changes

43 files changed, 59 insertions, 46 deletions

Test plan

  • golangci-lint passes with G402 enabled
  • All existing tests unaffected
  • Every nosec annotation includes a justification comment

Add G402 to the gosec includes list in .golangci.yml and fix all
violations across the codebase:

- Add MinVersion: tls.VersionTLS12 to tls.Config structs that were
  missing it (production code, test helpers, test servers)
- Add #nosec G402 annotations to intentional InsecureSkipVerify usages
  where TLS verification is user-configurable (notifiers, scanners,
  registries) or where mTLS provides authentication (sensor-to-central)
- Add #nosec G402 annotations to test code that uses self-signed certs

Fixes part of stackrox#3545
@openshift-ci

openshift-ci Bot commented Mar 25, 2026

Copy link
Copy Markdown

Hi @raajheshkannaa. Thanks for your PR.

I'm waiting for a stackrox member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@vikin91 vikin91 added external-contributor To put on issues and PRs from external contributors ok-to-test and removed ok-to-test labels Mar 26, 2026
@vikin91

vikin91 commented Mar 26, 2026

Copy link
Copy Markdown
Contributor

/ok-to-test

@janisz janisz left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Since Go 1.18+ defaults to TLS 1.2, this change might be redundant. Could you clarify the use case in the PR description?

@janisz janisz self-assigned this Mar 26, 2026

@raajheshkannaa raajheshkannaa left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right that Go 1.18+ defaults to TLS 1.2 at runtime, so the MinVersion additions don't change behavior. The driver here is enabling the gosec G402 rule (part of #3545), which flags any tls.Config without an explicit MinVersion regardless of Go's runtime default. Without setting it explicitly, the linter fires on every struct literal. I'll update the PR description to make that motivation clearer.

@raajheshkannaa

Copy link
Copy Markdown
Author

/retest-required

@openshift-ci

openshift-ci Bot commented Mar 30, 2026

Copy link
Copy Markdown

@raajheshkannaa: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/gke-nongroovy-e2e-tests fc3e9b7 link true /test gke-nongroovy-e2e-tests
ci/prow/gke-ui-e2e-tests fc3e9b7 link true /test gke-ui-e2e-tests
ci/prow/gke-operator-e2e-tests fc3e9b7 link false /test gke-operator-e2e-tests
ci/prow/gke-qa-e2e-tests fc3e9b7 link false /test gke-qa-e2e-tests
ci/prow/gke-upgrade-tests fc3e9b7 link false /test gke-upgrade-tests
ci/prow/gke-scanner-v4-install-tests fc3e9b7 link false /test gke-scanner-v4-install-tests
ci/prow/ocp-4-12-scanner-v4-install-tests fc3e9b7 link false /test ocp-4-12-scanner-v4-install-tests
ci/prow/ocp-4-21-ui-e2e-tests fc3e9b7 link false /test ocp-4-21-ui-e2e-tests
ci/prow/ocp-4-12-compliance-e2e-tests fc3e9b7 link false /test ocp-4-12-compliance-e2e-tests
ci/prow/ocp-4-12-nongroovy-e2e-tests fc3e9b7 link false /test ocp-4-12-nongroovy-e2e-tests
ci/prow/ocp-4-21-compliance-e2e-tests fc3e9b7 link false /test ocp-4-21-compliance-e2e-tests
ci/prow/ocp-4-21-operator-e2e-tests fc3e9b7 link false /test ocp-4-21-operator-e2e-tests
ci/prow/ocp-4-21-scanner-v4-install-tests fc3e9b7 link false /test ocp-4-21-scanner-v4-install-tests
ci/prow/ocp-4-12-qa-e2e-tests fc3e9b7 link false /test ocp-4-12-qa-e2e-tests
ci/prow/ocp-4-12-operator-e2e-tests fc3e9b7 link false /test ocp-4-12-operator-e2e-tests
ci/prow/ocp-4-21-qa-e2e-tests fc3e9b7 link false /test ocp-4-21-qa-e2e-tests
ci/prow/ocp-4-21-nongroovy-e2e-tests fc3e9b7 link false /test ocp-4-21-nongroovy-e2e-tests

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@raajheshkannaa

Copy link
Copy Markdown
Author

Updated the description with the G402 motivation. The short version: gosec does static analysis and can't infer Go's runtime TLS defaults, so explicit MinVersion is needed to satisfy the linter. Let me know if that covers it.

@janisz

janisz commented Apr 1, 2026

Copy link
Copy Markdown
Contributor

I created issue for gosec: securego/gosec#1627
I think we should not enable it until the issues is resolved as it generates a lot of noise.

@raajheshkannaa

Copy link
Copy Markdown
Author

Good call, and thanks for filing the upstream issue. You're right that Go 1.18+ defaults to TLS 1.2, so G402 firing on safe defaults is just noise. Happy to keep this PR open but on hold until securego/gosec#1627 is resolved. Once gosec handles this properly, we can revisit whether G402 is worth enabling here.

@raajheshkannaa raajheshkannaa left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

You're right that Go 1.18+ defaults to TLS 1.2 at runtime. The change is for gosec's static analysis, which can't infer runtime defaults. Without an explicit MinVersion, G402 fires on every tls.Config{} in the codebase. Setting it explicitly satisfies the linter and makes the security posture visible in code without relying on runtime knowledge. This is part of the broader #3545 effort to enable all security-relevant gosec rules.

@vladbologa vladbologa left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hi @raajheshkannaa, thanks for the contribution! Unfortunately OpenShift TLS profile consistency requires us not to hardcode TLS settings in the application.

Instead they will be propagated from the Operator (which in turn retrieves them from apiserver.config.openshift.io/cluster).

You can also force the configuration on the deployments manually by setting ROX_TLS_MIN_VERSION and ROX_TLS_CIPHER_SUITES (ROX_TLS_OPENSSL_CIPHERS for the Postgres services).

See these PRs for more context:

These changes will be available in the next ACS minor release (4.11).

@raajheshkannaa

Copy link
Copy Markdown
Author

Thanks for the context, @vladbologa. The OpenShift TLS profile + ROX_TLS_MIN_VERSION/CIPHER_SUITES approach makes sense for ensuring cluster-wide consistency, and hardcoding MinVersion in code would conflict with the Operator-propagated config path. Combined with @janisz's earlier point about gosec G402 firing noisily on Go's safe TLS 1.2 defaults (securego/gosec#1627 still open), the architectural direction here is clear. Closing this PR. Appreciate the review and the pointers to #19110 and #18864.

@vladbologa

Copy link
Copy Markdown
Contributor

Thanks for the context, @vladbologa. The OpenShift TLS profile + ROX_TLS_MIN_VERSION/CIPHER_SUITES approach makes sense for ensuring cluster-wide consistency, and hardcoding MinVersion in code would conflict with the Operator-propagated config path. Combined with @janisz's earlier point about gosec G402 firing noisily on Go's safe TLS 1.2 defaults (securego/gosec#1627 still open), the architectural direction here is clear. Closing this PR. Appreciate the review and the pointers to #19110 and #18864.

btw @raajheshkannaa the cluster-wide consistency feature is not available yet in OpenShift. But if you're using ACS 4.11, you will still be able to tell ACS to follow the profile from apiserver.config.openshift.io/cluster, by setting FORCE_OPENSHIFT_TLS_PROFILE=true on the ACS Operator deployment.

In the future, it will work automatically by checking the TLSAdherence field.

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

Labels

external-contributor To put on issues and PRs from external contributors ok-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants