Skip to content
This repository has been archived by the owner on Oct 14, 2024. It is now read-only.

Commit

Permalink
fix(vul-scanner): Get layer commands by image id and not image name
Browse files Browse the repository at this point in the history
  • Loading branch information
FrimIdan committed Apr 14, 2022
1 parent 0111dd5 commit 263ceb3
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions runtime_k8s_scanner/pkg/scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ func Run() {
}
}

// nolint: cyclop
func run(ctx context.Context, conf *_config.Config) {
logger := createLogger(conf)
reporter := report.CreateReporter(ctx, conf)
Expand All @@ -79,8 +80,6 @@ func run(ctx context.Context, conf *_config.Config) {
sbomBytes = nil
}

layerCommands := getLayerCommands(conf)

// If SBOM does not exist
if sbomBytes == nil {
// Run analyzers
Expand Down Expand Up @@ -132,6 +131,12 @@ func run(ctx context.Context, conf *_config.Config) {
logger.Infof("Image was scanned.")
logger.Debugf("scanResults=%+v", scanResults)

layerCommands, err := getLayerCommands(conf)
if err != nil {
logger.Errorf("Failed to get layer commands: %v", err)
// we should continue even if failed to get layer commands
}

// Send results
if err = reporter.ReportScanResults(scanResults, layerCommands); err != nil {
reportError(reporter, logger, fmt.Errorf("failed to report on successful scan: %v", err))
Expand All @@ -157,12 +162,11 @@ func createLogger(conf *_config.Config) *log.Entry {
return logger.WithFields(log.Fields{"scan-uuid": conf.ScanUUID, "image-id": conf.ImageIDToScan})
}

func getLayerCommands(conf *_config.Config) []*image_helper.FsLayerCommand {
logger := createLogger(conf)
layerCommands, err := image_helper.GetImageLayerCommands(conf.ImageNameToScan, conf.SharedConfig)
func getLayerCommands(conf *_config.Config) ([]*image_helper.FsLayerCommand, error) {
layerCommands, err := image_helper.GetImageLayerCommands(conf.ImageIDToScan, conf.SharedConfig)
if err != nil {
logger.Errorf("failed to get commands from image=%s: %v", conf.ImageIDToScan, err)
return nil, fmt.Errorf("failed to get commands from image=%s: %v", conf.ImageIDToScan, err)
}

return layerCommands
return layerCommands, nil
}

0 comments on commit 263ceb3

Please sign in to comment.