Skip to content

Commit

Permalink
fix(redhat): check usr/share/buildinfo/ dir to detect content sets (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitriyLewen authored Jan 9, 2025
1 parent f9a6a71 commit f352f6b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
8 changes: 7 additions & 1 deletion pkg/fanal/analyzer/buildinfo/content_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,18 @@ import (

"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/types"
"github.com/aquasecurity/trivy/pkg/set"
)

func init() {
analyzer.RegisterAnalyzer(&contentManifestAnalyzer{})
}

var contentSetsDirs = set.New[string](
"root/buildinfo/content_manifests/",
"usr/share/buildinfo/", // for RHCOS
)

const contentManifestAnalyzerVersion = 1

type contentManifest struct {
Expand Down Expand Up @@ -44,7 +50,7 @@ func (a contentManifestAnalyzer) Analyze(_ context.Context, target analyzer.Anal

func (a contentManifestAnalyzer) Required(filePath string, _ os.FileInfo) bool {
dir, file := filepath.Split(filepath.ToSlash(filePath))
if dir != "root/buildinfo/content_manifests/" {
if !contentSetsDirs.Contains(dir) {
return false
}
return filepath.Ext(file) == ".json"
Expand Down
14 changes: 12 additions & 2 deletions pkg/fanal/analyzer/buildinfo/content_manifest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,22 @@ func Test_contentManifestAnalyzer_Required(t *testing.T) {
want bool
}{
{
name: "happy path",
name: "happy path root dir",
filePath: "root/buildinfo/content_manifests/nodejs-12-container-1-66.json",
want: true,
},
{
name: "sad path",
name: "happy path usr dir",
filePath: "usr/share/buildinfo/nodejs-12-container-1-66.json",
want: true,
},
{
name: "sad path wrong dir",
filePath: "foo/bar/nodejs-12-container-1-66.json",
want: false,
},
{
name: "sad path wrong extension",
filePath: "root/buildinfo/content_manifests/nodejs-12-container-1-66.xml",
want: false,
},
Expand Down

0 comments on commit f352f6b

Please sign in to comment.