From 244b797a199458f504758c0e3a775572a021e629 Mon Sep 17 00:00:00 2001 From: Shane Dell <32347414+Shanedell@users.noreply.github.com> Date: Mon, 17 Apr 2023 12:26:07 -0400 Subject: [PATCH] Create consul binary classifier (#1738) * Create consul binary classifier Closes #1590 Signed-off-by: Shane Dell * Create test for consul binary classifier Signed-off-by: Shane Dell * Update version for consul. Add note that about consul version matcher is brittle Signed-off-by: Shane Dell --------- Signed-off-by: Shane Dell --- syft/pkg/cataloger/binary/cataloger_test.go | 12 ++++++++++++ syft/pkg/cataloger/binary/default_classifiers.go | 11 +++++++++++ syft/pkg/cataloger/binary/test-fixtures/Makefile | 10 +++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/syft/pkg/cataloger/binary/cataloger_test.go b/syft/pkg/cataloger/binary/cataloger_test.go index af31d4fa4..84771a16f 100644 --- a/syft/pkg/cataloger/binary/cataloger_test.go +++ b/syft/pkg/cataloger/binary/cataloger_test.go @@ -714,6 +714,18 @@ func Test_Cataloger_DefaultClassifiers_PositiveCases(t *testing.T) { Metadata: metadata("ruby-binary"), }, }, + { + name: "positive-consul-1.15.2", + fixtureDir: "test-fixtures/classifiers/dynamic/consul-1.15.2", + expected: pkg.Package{ + Name: "consul", + Version: "1.15.2", + Type: "binary", + PURL: "pkg:golang/github.com/hashicorp/consul@1.15.2", + Locations: locations("consul"), + Metadata: metadata("consul-binary"), + }, + }, } for _, test := range tests { diff --git a/syft/pkg/cataloger/binary/default_classifiers.go b/syft/pkg/cataloger/binary/default_classifiers.go index a80f9676f..8aa739b4b 100644 --- a/syft/pkg/cataloger/binary/default_classifiers.go +++ b/syft/pkg/cataloger/binary/default_classifiers.go @@ -270,6 +270,17 @@ var defaultClassifiers = []classifier{ PURL: mustPURL("pkg:generic/ruby@version"), CPEs: singleCPE("cpe:2.3:a:ruby-lang:ruby:*:*:*:*:*:*:*:*"), }, + { + Class: "consul-binary", + FileGlob: "**/consul", + EvidenceMatcher: fileContentsVersionMatcher( + // NOTE: This is brittle and may not work for past or future versions + `CONSUL_VERSION: (?P\d+\.\d+\.\d+)`, + ), + Package: "consul", + PURL: mustPURL("pkg:golang/github.com/hashicorp/consul@version"), + CPEs: singleCPE("cpe:2.3:a:hashicorp:consul:*:*:*:*:*:*:*:*"), + }, } // in both binaries and shared libraries, the version pattern is [NUL]3.11.2[NUL] diff --git a/syft/pkg/cataloger/binary/test-fixtures/Makefile b/syft/pkg/cataloger/binary/test-fixtures/Makefile index 863170125..afd160d8f 100644 --- a/syft/pkg/cataloger/binary/test-fixtures/Makefile +++ b/syft/pkg/cataloger/binary/test-fixtures/Makefile @@ -15,7 +15,9 @@ all: \ classifiers/dynamic/kubectl-1.25.7 \ classifiers/dynamic/kubectl-1.26.2 \ classifiers/dynamic/kustomize-4.5.7 \ - classifiers/dynamic/kustomize-5.0.0 + classifiers/dynamic/kustomize-5.0.0 \ + classifiers/dynamic/consul-1.15.2 + classifiers/dynamic/python-binary-shared-lib-3.11: @@ -141,6 +143,12 @@ classifiers/dynamic/kustomize-5.0.0: /usr/local/bin/kustomize \ $@/kustomize +classifiers/dynamic/consul-1.15.2: + $(eval $@_image := "hashicorp/consul:1.15.2@sha256:c2169f3bb18dd947ae8eb5f6766896695c71fb439f050a3343e0007d895615b8") + ./get-image-file.sh $($@_image) \ + /bin/consul \ + $@/consul + .PHONY: clean clean: rm -rf classifiers/dynamic