Skip to content

Commit d28a1d7

Browse files
slntoppclaude
andcommitted
fix: add nolint:gosec annotations for new gosec rules
G117 (marshaling structs with secret-pattern fields) and G118 (stored cancel func) are false positives in these contexts — test fixtures, internal credential structs, and a debouncer that stores cancel for later use. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent dd43c27 commit d28a1d7

7 files changed

Lines changed: 7 additions & 7 deletions

File tree

controllers/integration/integration_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *IntegrationCheckInSuite) SetupSuite() {
8484

8585
testMondooServiceAccount.PrivateKey = credentials.MondooServiceAccount(s.T())
8686

87-
testMondooServiceAccountDataBytes, err = json.Marshal(testMondooServiceAccount)
87+
testMondooServiceAccountDataBytes, err = json.Marshal(testMondooServiceAccount) //nolint:gosec
8888
s.Require().NoError(err, "error converting sample service account data")
8989
}
9090

controllers/k8s_scan/deployment_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_Create_ConsoleIntegration() {
8585
s.NoError(d.KubeClient.Create(s.ctx, mondooAuditConfig))
8686

8787
integrationMrn := utils.RandString(20)
88-
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "test-mrn"})
88+
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "test-mrn"}) //nolint:gosec
8989
s.NoError(err)
9090
clientSecret := &corev1.Secret{
9191
ObjectMeta: metav1.ObjectMeta{

controllers/mondooauditconfig_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ func TestTokenRegistration(t *testing.T) {
8181
testMondooServiceAccount.PrivateKey = credentials.MondooServiceAccount(t)
8282

8383
var err error
84-
testMondooServiceAccountDataBytes, err = json.Marshal(testMondooServiceAccount)
84+
testMondooServiceAccountDataBytes, err = json.Marshal(testMondooServiceAccount) //nolint:gosec
8585
require.NoError(t, err, "error converting sample service account data")
8686

8787
tests := []struct {

controllers/nodes/deployment_handler_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func (s *DeploymentHandlerSuite) TestReconcile_CreateConfigMapWithIntegrationMRN
7979

8080
s.seedNodes()
8181

82-
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "test-mrn"})
82+
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "test-mrn"}) //nolint:gosec
8383
s.NoError(err)
8484

8585
s.auditConfig.Spec.ConsoleIntegration.Enable = true

controllers/resource_watcher/debouncer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (d *Debouncer) Add(key string, resource K8sResourceIdentifier) {
5959
// Start begins the debouncer's background processing. It should be called once
6060
// and will run until the context is cancelled.
6161
func (d *Debouncer) Start(ctx context.Context) error {
62-
d.ctx, d.cancel = context.WithCancel(ctx)
62+
d.ctx, d.cancel = context.WithCancel(ctx) //nolint:gosec
6363
debouncerLogger.Info("Debouncer started", "interval", d.interval, "minInterval", d.minInterval)
6464
<-d.ctx.Done()
6565
d.stop()

controllers/status/status_reporter_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (s *StatusReporterSuite) BeforeTest(suiteName, testName string) {
5151
s.auditConfig.Spec.ConsoleIntegration.Enable = true
5252

5353
key := credentials.MondooServiceAccount(s.T())
54-
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "mrn", PrivateKey: key})
54+
sa, err := json.Marshal(mondooclient.ServiceAccountCredentials{Mrn: "mrn", PrivateKey: key}) //nolint:gosec
5555
s.Require().NoError(err)
5656

5757
secret := &v1.Secret{

pkg/utils/mondoo/token_exchange.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func CreateServiceAccountFromToken(ctx context.Context, kubeClient client.Client
8383
}
8484

8585
integrationMrn := resp.Mrn
86-
credsBytes, err := json.Marshal(*resp.Creds)
86+
credsBytes, err := json.Marshal(*resp.Creds) //nolint:gosec
8787
if err != nil {
8888
log.Error(err, "failed to marshal service account creds from IntegrationRegister()")
8989
return err

0 commit comments

Comments
 (0)