Skip to content

Commit 5695eb2

Browse files
authored
fix(misconf): do not log scanners when misconfig scanning is disabled (#8345)
Signed-off-by: nikpivkin <[email protected]>
1 parent 3eb0b03 commit 5695eb2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

pkg/commands/artifact/run.go

+15-15
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
418418
// Specified analyzers to be disabled depending on scanning modes
419419
// e.g. The 'image' subcommand should disable the lock file scanning.
420420
analyzers := opts.DisabledAnalyzers
421-
422421
// It doesn't analyze apk commands by default.
423422
if !opts.ScanRemovedPkgs {
424423
analyzers = append(analyzers, analyzer.TypeApkCommand)
@@ -434,18 +433,16 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
434433
analyzers = append(analyzers, analyzer.TypeSecret)
435434
}
436435

437-
// Filter only enabled misconfiguration scanners
438-
ma, err := filterMisconfigAnalyzers(opts.MisconfigScanners, analyzer.TypeConfigFiles)
439-
if err != nil {
440-
log.Error("Invalid misconfiguration scanners specified, defaulting to use all misconfig scanners",
441-
log.Any("scanners", opts.MisconfigScanners))
442-
} else {
443-
analyzers = append(analyzers, ma...)
444-
}
445-
446436
// Do not perform misconfiguration scanning when it is not specified.
447437
if !opts.Scanners.AnyEnabled(types.MisconfigScanner, types.RBACScanner) {
448438
analyzers = append(analyzers, analyzer.TypeConfigFiles...)
439+
} else {
440+
// Filter only enabled misconfiguration scanners
441+
ma := disabledMisconfigAnalyzers(opts.MisconfigScanners)
442+
analyzers = append(analyzers, ma...)
443+
444+
log.Debug("Enabling misconfiguration scanners",
445+
log.Any("scanners", lo.Without(analyzer.TypeConfigFiles, ma...)))
449446
}
450447

451448
// Scanning file headers and license files is expensive.
@@ -482,14 +479,17 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
482479
return analyzers
483480
}
484481

485-
func filterMisconfigAnalyzers(included, all []analyzer.Type) ([]analyzer.Type, error) {
486-
_, missing := lo.Difference(all, included)
482+
func disabledMisconfigAnalyzers(included []analyzer.Type) []analyzer.Type {
483+
_, missing := lo.Difference(analyzer.TypeConfigFiles, included)
487484
if len(missing) > 0 {
488-
return nil, xerrors.Errorf("invalid misconfiguration scanner specified %s valid scanners: %s", missing, all)
485+
log.Error(
486+
"Invalid misconfiguration scanners provided, using default scanners",
487+
log.Any("invalid_scanners", missing), log.Any("default_scanners", analyzer.TypeConfigFiles),
488+
)
489+
return nil
489490
}
490491

491-
log.Debug("Enabling misconfiguration scanners", log.Any("scanners", included))
492-
return lo.Without(all, included...), nil
492+
return lo.Without(analyzer.TypeConfigFiles, included...)
493493
}
494494

495495
func (r *runner) initScannerConfig(ctx context.Context, opts flag.Options) (ScannerConfig, types.ScanOptions, error) {

0 commit comments

Comments
 (0)