diff --git a/cmd/clair/main.go b/cmd/clair/main.go index bdd97dc81..58cf533bd 100644 --- a/cmd/clair/main.go +++ b/cmd/clair/main.go @@ -62,7 +62,6 @@ import ( _ "github.com/stackrox/scanner/ext/featurefmt/dpkg" _ "github.com/stackrox/scanner/ext/featurefmt/rpm" _ "github.com/stackrox/scanner/ext/featurens/alpinerelease" - _ "github.com/stackrox/scanner/ext/featurens/aptsources" _ "github.com/stackrox/scanner/ext/featurens/busybox" _ "github.com/stackrox/scanner/ext/featurens/lsbrelease" _ "github.com/stackrox/scanner/ext/featurens/osrelease" diff --git a/ext/featurens/aptsources/aptsources.go b/ext/featurens/aptsources/aptsources.go deleted file mode 100644 index 55bb3ea39..000000000 --- a/ext/featurens/aptsources/aptsources.go +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2017 clair authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -// Package aptsources implements a featurens.Detector for apt based container -// image layers. -// -// This detector is necessary to determine the precise Debian version when it -// is an unstable version for instance. -package aptsources - -import ( - "bufio" - "strings" - - "github.com/stackrox/scanner/database" - "github.com/stackrox/scanner/ext/featurens" - "github.com/stackrox/scanner/ext/versionfmt/dpkg" - "github.com/stackrox/scanner/pkg/analyzer" -) - -type detector struct{} - -func init() { - featurens.RegisterDetector("apt-sources", &detector{}) -} - -func (d detector) Detect(files analyzer.Files, _ *featurens.DetectorOptions) *database.Namespace { - f, hasFile := files.Get("etc/apt/sources.list") - if !hasFile { - return nil - } - - var OS, version string - - scanner := bufio.NewScanner(strings.NewReader(string(f.Contents))) - for scanner.Scan() { - // Format: man sources.list | https://wiki.debian.org/SourcesList) - // deb uri distribution component1 component2 component3 - // deb-src uri distribution component1 component2 component3 - line := strings.Split(scanner.Text(), " ") - if len(line) > 3 { - // Only consider main component - isMainComponent := false - for _, component := range line[3:] { - if component == "main" { - isMainComponent = true - break - } - } - if !isMainComponent { - continue - } - - var found bool - version, found = database.DebianReleasesMapping[line[2]] - if found { - OS = "debian" - break - } - - line[2] = strings.Split(line[2], "/")[0] - version, found = database.UbuntuReleasesMapping[line[2]] - if found { - OS = "ubuntu" - break - } - } - } - - if OS != "" && version != "" { - return &database.Namespace{ - Name: OS + ":" + version, - VersionFormat: dpkg.ParserName, - } - } - return nil -} - -func (d detector) RequiredFilenames() []string { - return []string{"etc/apt/sources.list"} -} diff --git a/ext/featurens/aptsources/aptsources_test.go b/ext/featurens/aptsources/aptsources_test.go deleted file mode 100644 index 94fc00f71..000000000 --- a/ext/featurens/aptsources/aptsources_test.go +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright 2017 clair authors -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - -package aptsources - -import ( - "testing" - - "github.com/stackrox/scanner/database" - "github.com/stackrox/scanner/ext/featurens" - "github.com/stackrox/scanner/ext/versionfmt/dpkg" - "github.com/stackrox/scanner/pkg/analyzer" - "github.com/stackrox/scanner/pkg/tarutil" -) - -func TestDetector(t *testing.T) { - testData := []featurens.TestData{ - { - ExpectedNamespace: &database.Namespace{Name: "debian:unstable", VersionFormat: dpkg.ParserName}, - Files: tarutil.CreateNewLayerFiles(map[string]analyzer.FileData{ - "etc/os-release": {Contents: []byte( - `PRETTY_NAME="Debian GNU/Linux stretch/sid" -NAME="Debian GNU/Linux" -ID=debian -HOME_URL="https://www.debian.org/" -SUPPORT_URL="https://www.debian.org/support/" -BUG_REPORT_URL="https://bugs.debian.org/"`)}, - "etc/apt/sources.list": {Contents: []byte(`deb http://httpredir.debian.org/debian unstable main`)}}), - }, - { - ExpectedNamespace: nil, - Files: tarutil.CreateNewLayerFiles(nil), - }, - } - - featurens.TestDetector(t, &detector{}, testData) -} diff --git a/localdev/main.go b/localdev/main.go index af50b7d70..e03a8397a 100644 --- a/localdev/main.go +++ b/localdev/main.go @@ -33,7 +33,6 @@ import ( _ "github.com/stackrox/scanner/ext/featurefmt/dpkg" _ "github.com/stackrox/scanner/ext/featurefmt/rpm" _ "github.com/stackrox/scanner/ext/featurens/alpinerelease" - _ "github.com/stackrox/scanner/ext/featurens/aptsources" _ "github.com/stackrox/scanner/ext/featurens/busybox" _ "github.com/stackrox/scanner/ext/featurens/lsbrelease" _ "github.com/stackrox/scanner/ext/featurens/osrelease" diff --git a/worker_test.go b/worker_test.go index eb2d2ce85..be2103c34 100644 --- a/worker_test.go +++ b/worker_test.go @@ -30,7 +30,6 @@ import ( // Register the required detectors. _ "github.com/stackrox/scanner/ext/featurefmt/dpkg" - _ "github.com/stackrox/scanner/ext/featurens/aptsources" _ "github.com/stackrox/scanner/ext/featurens/osrelease" _ "github.com/stackrox/scanner/ext/imagefmt/docker" )