Skip to content

Commit

Permalink
fix(misconf): do not log scanners when misconfig scanning is disabled (
Browse files Browse the repository at this point in the history
…#8345)

Signed-off-by: nikpivkin <[email protected]>
  • Loading branch information
nikpivkin authored Feb 4, 2025
1 parent 3eb0b03 commit 5695eb2
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions pkg/commands/artifact/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,6 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
// Specified analyzers to be disabled depending on scanning modes
// e.g. The 'image' subcommand should disable the lock file scanning.
analyzers := opts.DisabledAnalyzers

// It doesn't analyze apk commands by default.
if !opts.ScanRemovedPkgs {
analyzers = append(analyzers, analyzer.TypeApkCommand)
Expand All @@ -434,18 +433,16 @@ func disabledAnalyzers(opts flag.Options) []analyzer.Type {
analyzers = append(analyzers, analyzer.TypeSecret)
}

// Filter only enabled misconfiguration scanners
ma, err := filterMisconfigAnalyzers(opts.MisconfigScanners, analyzer.TypeConfigFiles)
if err != nil {
log.Error("Invalid misconfiguration scanners specified, defaulting to use all misconfig scanners",
log.Any("scanners", opts.MisconfigScanners))
} else {
analyzers = append(analyzers, ma...)
}

// Do not perform misconfiguration scanning when it is not specified.
if !opts.Scanners.AnyEnabled(types.MisconfigScanner, types.RBACScanner) {
analyzers = append(analyzers, analyzer.TypeConfigFiles...)
} else {
// Filter only enabled misconfiguration scanners
ma := disabledMisconfigAnalyzers(opts.MisconfigScanners)
analyzers = append(analyzers, ma...)

log.Debug("Enabling misconfiguration scanners",
log.Any("scanners", lo.Without(analyzer.TypeConfigFiles, ma...)))
}

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

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

log.Debug("Enabling misconfiguration scanners", log.Any("scanners", included))
return lo.Without(all, included...), nil
return lo.Without(analyzer.TypeConfigFiles, included...)
}

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

0 comments on commit 5695eb2

Please sign in to comment.