mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-12 07:40:48 -08:00
fix(misconf): do not log scanners when misconfig scanning is disabled [backport: release/v0.59] (#8349)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io> Co-authored-by: Nikita Pivkin <nikita.pivkin@smartforce.io>
This commit is contained in:
committed by
GitHub
parent
98f9ba295a
commit
412c690924
@@ -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)
|
||||
@@ -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.
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user