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

fix(redhat): check usr/share/buildinfo/ dir to detect content sets #8222

Merged
merged 1 commit into from
Jan 9, 2025
Merged
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
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
Loading