Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivy: disable more java analyzers #34064

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/util/trivy/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.

//go:build trivy

// Package trivy holds the scan components
package trivy

import (
trivylog "github.com/aquasecurity/trivy/pkg/log"
)

func init() {
trivylog.InitLogger(false, true)
}
53 changes: 52 additions & 1 deletion pkg/util/trivy/trivy.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ type Collector struct {

var globalCollector *Collector

var trivyDefaultSkipDirs = []string{
// already included in Trivy's defaultSkipDirs
// "**/.git",
// "proc",
// "sys",
// "dev",

"**/.cargo/git/**",
}

func getDefaultArtifactOption(opts sbom.ScanOptions) artifact.Option {
parallel := 1
if opts.Fast {
Expand All @@ -88,7 +98,9 @@ func getDefaultArtifactOption(opts sbom.ScanOptions) artifact.Option {
WalkerOption: walker.Option{},
}

if len(opts.Analyzers) == 1 && opts.Analyzers[0] == OSAnalyzers {
option.WalkerOption.SkipDirs = trivyDefaultSkipDirs

if slicesEqualOrderless(opts.Analyzers, []string{OSAnalyzers}) {
option.WalkerOption.OnlyDirs = []string{
"/etc/*",
"/lib/apk/db/*",
Expand All @@ -97,6 +109,31 @@ func getDefaultArtifactOption(opts sbom.ScanOptions) artifact.Option {
"/var/lib/dpkg/**",
"/var/lib/rpm/*",
}
} else if slicesEqualOrderless(opts.Analyzers, []string{OSAnalyzers, LanguagesAnalyzers}) {
option.WalkerOption.SkipDirs = append(
option.WalkerOption.SkipDirs,
"bin/**",
"boot/**",
"dev/**",
"media/**",
"mnt/**",
"proc/**",
"run/**",
"sbin/**",
"sys/**",
"tmp/**",
"usr/bin/**",
"usr/sbin/**",
"var/cache/**",
"var/lib/containerd/**",
"var/lib/containers/**",
"var/lib/docker/**",
"var/lib/libvirt/**",
"var/lib/snapd/**",
"var/log/**",
"var/run/**",
"var/tmp/**",
)
}

return option
Expand Down Expand Up @@ -313,3 +350,17 @@ func (c *Collector) scanImage(ctx context.Context, fanalImage ftypes.Image, imgM
marshaler: c.marshaler,
}, nil
}

func slicesEqualOrderless(a []string, b []string) bool {
if len(a) != len(b) {
return false
}

for _, ia := range a {
if !slices.Contains(b, ia) {
return false
}
}

return true
}
Loading