Skip to content

Commit

Permalink
feat: filter k8s core components vuln results (#5713)
Browse files Browse the repository at this point in the history
Signed-off-by: chenk <hen.keinan@gmail.com>
  • Loading branch information
chen-keinan committed Dec 5, 2023
1 parent a54d1e9 commit 0ff5f96
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pkg/k8s/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func infraResource(misConfig Resource) bool {
}

func CreateResource(artifact *artifacts.Artifact, report types.Report, err error) Resource {
r := CreateK8sResource(artifact, report.Results)
r := createK8sResource(artifact, report.Results)

r.Metadata = report.Metadata
r.Report = report
Expand All @@ -234,7 +234,7 @@ func CreateResource(artifact *artifacts.Artifact, report types.Report, err error
return r
}

func CreateK8sResource(artifact *artifacts.Artifact, scanResults types.Results) Resource {
func createK8sResource(artifact *artifacts.Artifact, scanResults types.Results) Resource {
results := make([]types.Result, 0, len(scanResults))
// fix target name
for _, result := range scanResults {
Expand Down
27 changes: 24 additions & 3 deletions pkg/k8s/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,14 @@ func (s *Scanner) scanK8sVulns(ctx context.Context, artifactsData []*artifacts.A
return nil, err
}
if results != nil {
resources = append(resources, report.CreateK8sResource(artifact, results))
resource, err := s.filter(ctx, types.Report{
Results: results,
ArtifactName: artifact.Name,
}, artifact)
if err != nil {
return nil, err
}
resources = append(resources, resource)
}
case nodeComponents:
var nf bom.NodeInfo
Expand Down Expand Up @@ -301,7 +308,14 @@ func (s *Scanner) scanK8sVulns(ctx context.Context, artifactsData []*artifacts.A
return nil, err
}
if results != nil {
resources = append(resources, report.CreateK8sResource(artifact, results))
resource, err := s.filter(ctx, types.Report{
Results: results,
ArtifactName: artifact.Name,
}, artifact)
if err != nil {
return nil, err
}
resources = append(resources, resource)
}
case clusterInfo:
var cf bom.ClusterInfo
Expand Down Expand Up @@ -329,7 +343,14 @@ func (s *Scanner) scanK8sVulns(ctx context.Context, artifactsData []*artifacts.A
return nil, err
}
if results != nil {
resources = append(resources, report.CreateK8sResource(artifact, results))
resource, err := s.filter(ctx, types.Report{
Results: results,
ArtifactName: artifact.Name,
}, artifact)
if err != nil {
return nil, err
}
resources = append(resources, resource)
}
}
}
Expand Down

0 comments on commit 0ff5f96

Please sign in to comment.