Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: concurrent map write in trivy analyzer #1222

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
7 changes: 7 additions & 0 deletions pkg/integration/trivy/analyzer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package trivy
import (
"fmt"
"strings"
"sync"

ctrl "sigs.k8s.io/controller-runtime/pkg/client"

Expand All @@ -29,12 +30,16 @@ type TrivyAnalyzer struct {
configAuditReportAnalysis bool
}

var rwMutex sync.RWMutex

func (TrivyAnalyzer) analyzeVulnerabilityReports(a common.Analyzer) ([]common.Result, error) {
// Get all trivy VulnerabilityReports
result := &v1alpha1.VulnerabilityReportList{}

client := a.Client.CtrlClient
rwMutex.Lock()
err := v1alpha1.AddToScheme(client.Scheme())
rwMutex.Unlock()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -94,7 +99,9 @@ func (t TrivyAnalyzer) analyzeConfigAuditReports(a common.Analyzer) ([]common.Re
result := &v1alpha1.ConfigAuditReportList{}

client := a.Client.CtrlClient
rwMutex.Lock()
err := v1alpha1.AddToScheme(client.Scheme())
rwMutex.Unlock()
if err != nil {
return nil, err
}
Expand Down
Loading