Skip to content

Commit

Permalink
Create consul binary classifier (#1738)
Browse files Browse the repository at this point in the history
* Create consul binary classifier

Closes #1590

Signed-off-by: Shane Dell <shanedell100@gmail.com>

* Create test for consul binary classifier

Signed-off-by: Shane Dell <shanedell100@gmail.com>

* Update version for consul. Add note that about consul version matcher is brittle

Signed-off-by: Shane Dell <shanedell100@gmail.com>

---------

Signed-off-by: Shane Dell <shanedell100@gmail.com>
  • Loading branch information
shanedell authored Apr 17, 2023
1 parent 95176d7 commit 244b797
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
12 changes: 12 additions & 0 deletions syft/pkg/cataloger/binary/cataloger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions syft/pkg/cataloger/binary/default_classifiers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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<version>\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]
Expand Down
10 changes: 9 additions & 1 deletion syft/pkg/cataloger/binary/test-fixtures/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 244b797

Please # to comment.