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

Allow import DB from URL #2532

Merged
merged 1 commit into from
Mar 17, 2025
Merged

Allow import DB from URL #2532

merged 1 commit into from
Mar 17, 2025

Conversation

wagoodman
Copy link
Contributor

@wagoodman wagoodman commented Mar 17, 2025

Enables being able to import DBs from a URL (whereas today this must be a local file), so the user does not need to download them first:

$ grype db import https://grype.anchore.io/databases/v6/vulnerability-db_v6.0.2_2025-03-14T01:31:06Z_1741925227.tar.zst
 ⠴ Vulnerability DB                ━━━━━━━━━━━━━━━━━━━━  [62 MB / 66 MB]  

This means if you have a previous grype scan with a DB URL in it (added in #2529) you can quickly use that reference to import the DB:

$grype db import $(cat mygrype.json | jq '.descriptor.db.status.from')
 ✔ Vulnerability DB                [imported]  

The value in grype JSON documents has the checksum of the argument as a query parameter (https://grype.anchore.io/databases/v6/vulnerability-db_v6.0.2_2025-03-14T01:31:06Z_1741925227.tar.zst?checksum=sha256%3Ad4654e3b212f1d8a1aaab979599691099af541568d687c4a7c4e7c1da079b9b8), which allows for client side validation:

$ grype db import https://grype.anchore.io/databases/v6/vulnerability-db_v6.0.2_2025-03-14T01:31:06Z_1741925227.tar.zst?checksum=sha256%3Ad4654e3b212f1d8a1aaab979599691099af541568d687c4a7c4e7c1da079b9b7
 ✔ Vulnerability DB                [validating]  
[0004] ERROR unable to import vulnerability database: unable to update vulnerability database: unable to download db: Checksums did not match for /tmp/getter3555198916/archive.
Expected: d4654e3b212f1d8a1aaab979599691099af541568d687c4a7c4e7c1da079b9b7
Got:      8a179b9568141aad1092b899fe7c1da09af5a69d4654e3b21b97957c4a7c4d68

Closes #2134

PR Stack

@wagoodman wagoodman self-assigned this Mar 17, 2025
@wagoodman wagoodman changed the title Import DB from URL Allow import DB from URL Mar 17, 2025
Base automatically changed from db-provenance-improvements to main March 17, 2025 16:34
Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com>
@wagoodman wagoodman requested a review from a team March 17, 2025 17:40
@wagoodman wagoodman added this to OSS Mar 17, 2025
@wagoodman wagoodman moved this to In Review in OSS Mar 17, 2025
@wagoodman wagoodman marked this pull request as ready for review March 17, 2025 17:40
Copy link
Contributor

@kzantow kzantow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -443,6 +467,12 @@ func (c curator) Import(path string) error {
return nil
}

var urlPrefixPattern = regexp.MustCompile("^[a-zA-Z]+://")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this will match file://; I think this will end up working fine, since it's supported by go-getter, is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup yup -- it supports handling file:// 👍

@wagoodman wagoodman merged commit fc78167 into main Mar 17, 2025
10 checks passed
@wagoodman wagoodman deleted the import-from-url branch March 17, 2025 18:48
@github-project-automation github-project-automation bot moved this from In Review to Done in OSS Mar 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Allow DB import from a URL
2 participants