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

feat: v6 database support, updated matcher interfaces #2311

Open
wants to merge 31 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
fe1eef5
feat: basic v6 database support
kzantow Dec 10, 2024
bb01798
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Dec 12, 2024
204fe85
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Dec 13, 2024
0a47e70
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Dec 16, 2024
f25083a
chore: move towards v6 interfaces
kzantow Dec 17, 2024
01bdb3e
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Dec 17, 2024
91c1f5a
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Dec 20, 2024
7b627c8
pull in changes from main
wagoodman Dec 24, 2024
8556722
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 1, 2025
d2e9b0d
Merge remote-tracking branch 'origin/feat/v6-query-api' into feat/v6-…
kzantow Jan 1, 2025
e298078
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 6, 2025
103ec5d
use v6 vuln status enum
wagoodman Jan 8, 2025
d984a23
chore: implement new vulnerability.Provider interface for v5 database
kzantow Jan 10, 2025
25082fa
Merge remote-tracking branch 'origin/feat/v6-query-api' into feat/v6-…
kzantow Jan 10, 2025
49da16c
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 10, 2025
eb4a554
chore: update tests
kzantow Jan 13, 2025
9eb7d45
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 14, 2025
1e75a9b
chore: cleanup
kzantow Jan 14, 2025
e55f716
chore: properly filter affected ranges
kzantow Jan 14, 2025
44b13ef
add v5 namespace adapter
wagoodman Jan 14, 2025
017b4e1
chore: add language to package specifier lookup
kzantow Jan 15, 2025
cf5d6c4
do not error when effective record lookup fails
wagoodman Jan 15, 2025
205a821
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
wagoodman Jan 15, 2025
d7fb5e4
use single v5 namespace helper
wagoodman Jan 15, 2025
ea5adac
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 15, 2025
0e9b313
chore: ignore fields during test compare
kzantow Jan 15, 2025
2c4f0bd
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 16, 2025
2b1f3f2
chore: add some v6 Provider tests
kzantow Jan 17, 2025
eed9a9d
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 17, 2025
9ad62d8
chore: update tests
kzantow Jan 17, 2025
3eb781b
Merge remote-tracking branch 'origin/main' into feat/v6-query-api
kzantow Jan 21, 2025
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
73 changes: 5 additions & 68 deletions cmd/grype/cli/commands/db_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
v6 "github.com/anchore/grype/grype/db/v6"
"github.com/anchore/grype/grype/db/v6/distribution"
"github.com/anchore/grype/grype/db/v6/installation"
"github.com/anchore/grype/grype/search"
"github.com/anchore/grype/grype/vulnerability"
"github.com/anchore/grype/internal/bus"
"github.com/anchore/grype/internal/log"
Expand Down Expand Up @@ -242,7 +243,7 @@ func legacyDBSearchPackages(opts dbSearchMatchOptions, vulnerabilityIDs []string

var vulnerabilities []vulnerability.Vulnerability
for _, vulnerabilityID := range vulnerabilityIDs {
vulns, err := str.Get(vulnerabilityID, "")
vulns, err := str.FindVulnerabilities(search.ByID(vulnerabilityID))
if err != nil {
return fmt.Errorf("unable to get vulnerability %q: %w", vulnerabilityID, err)
}
Expand Down Expand Up @@ -305,7 +306,7 @@ func renderDBSearchPackagesTableRows(structuredRows []dbsearch.AffectedPackage)
ranges = append(ranges, ra.Version.Constraint)
}
rangeStr := strings.Join(ranges, " || ")
rows = append(rows, []string{rr.Vulnerability.ID, pkgOrCPE, ecosystem, v5Namespace(rr), rangeStr})
rows = append(rows, []string{rr.Vulnerability.ID, pkgOrCPE, ecosystem, mimicV5Namespace(rr), rangeStr})
}

// sort rows by each column
Expand All @@ -321,70 +322,6 @@ func renderDBSearchPackagesTableRows(structuredRows []dbsearch.AffectedPackage)
return rows
}

// v5Namespace returns the namespace for a given affected package based on what schema v5 did.
func v5Namespace(row dbsearch.AffectedPackage) string {
switch row.Vulnerability.Provider {
case "nvd":
return "nvd:cpe"
case "github":
language := row.Package.Ecosystem
// normalize from purl type, github ecosystem types, and vunnel mappings
switch strings.ToLower(row.Package.Ecosystem) {
case "golang", "go-module":
language = "go"
case "composer", "php-composer":
language = "php"
case "cargo", "rust-crate":
language = "rust"
case "dart-pub", "pub":
language = "dart"
case "nuget":
language = "dotnet"
case "maven":
language = "java"
case "swifturl":
language = "swift"
case "npm", "node":
language = "javascript"
case "pypi", "pip":
language = "python"
case "rubygems", "gem":
language = "ruby"
}
return fmt.Sprintf("github:language:%s", language)
}
if row.OS != nil {
// distro family fixes
family := row.OS.Name
switch row.OS.Name {
case "amazon":
family = "amazonlinux"
case "mariner":
switch row.OS.Version {
case "1.0", "2.0":
family = "mariner"
default:
family = "azurelinux"
}
case "oracle":
family = "oraclelinux"
}

// provider fixes
pr := row.Vulnerability.Provider
if pr == "rhel" {
pr = "redhat"
}

// version fixes
ver := row.OS.Version
switch row.Vulnerability.Provider {
case "rhel", "oracle":
// ensure we only keep the major version
ver = strings.Split(row.OS.Version, ".")[0]
}

return fmt.Sprintf("%s:distro:%s:%s", pr, family, ver)
}
return row.Vulnerability.Provider
func mimicV5Namespace(row dbsearch.AffectedPackage) string {
return v6.MimicV5Namespace(&row.Vulnerability.Model, row.Model)
}
Loading
Loading