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

chore: Merge V2 back into main #1434

Merged
merged 17 commits into from
Dec 10, 2024
Merged

chore: Merge V2 back into main #1434

merged 17 commits into from
Dec 10, 2024

Conversation

another-rex
Copy link
Collaborator

Now that the last release is out, the main branch should be the v2 branch, and we can continue developing on main.

One caveat, scorecard github action has not updated yet to support the new ignore file format.

another-rex and others added 14 commits November 29, 2024 12:21
… our osv-scanner.toml in fixtures (#1337)

Uses the new feature landed in #1214
…ncy resolution (#1331)

Part of #1330

No functional change is made compared to the version in
`internal/manifest`, just switched to use the osv-scalibr interface.

Extractors moved to lockfilescalibr as a temporary staging ground before
moving to osv-scalibr.
Turns out we don't need most of the functionality of the third party
tire library. Built a simple and focused library pathtree which is just
a tree with insert and get functions to allow us to implement a virtual
filesystem easily.
Add/migrate osv-scanner.json extractor to use the scalibr format. This
is intended to replace the current extractor located here:
pkg/lockfile/osv-vuln-results.go

This is extractor is intended to stay in osv-scanner and not moved to
osv-scalibr as it is very osv-scanner specific.
Ideally, node package extracts can be done with packagejson extractor
directly (As every dir inside a node_modules directory has a
package.json file), but that changes the image scanning snapshots too
much to be part of this initial PR, and introduces new OS findings that
are difficult to filter out.

This keeps the existing solution of extracting directly with
node_modules by implementing an extractor that wraps the
`packagejsonlock` extractor to minimise snapshot changes.
Resolves #1316 

Update the --docker flag to:
- Only accept one image to scan at a time (to make displaying results
easier)
- Call new image scanning function internally.
- Acts like a convenience function for 
```
docker save <image-name> > img-name.tar && osv-scanner --experimental-oci-image=img.name.tar
```

TODO: 
- [x] Add an ACCEPTANCE test which uses docker to pull down a stable
image.
- [x] Include a docker pull first, as docker save only saves images
already on device and does not pull images online.
This PR contains all the code required to move to osv-scalibr while
making the existing code compile and pass all tests (container tests not
passing because of a bug in the scalibr alpine extractor).

Changes not mentioned in the following list will be split off in
separate PRs which should land before this PR.

Those are:
- [x] #1337
- [x] #1331
- [x] #1338
- [x] #1341
- [x] #1345

Changes in this PR:
- Fixture changes:
- Scalibr Python requirements.txt extractor currently doesn't support
packages without versions, so added some version strings to the test
files
- Image package required quite a bit of reworking to successfully
update.
- Add the ability to iterate through a directory via the pathtree
library
  - Support scalibr FS interface for Layers
- Add conversion code to convert inventories from osv-scalibr back to
v1's lockfile and Inventory
- This is done to minimize snapshot changes. Followup PRs should remove
this conversion
- Add `internal/lockfilescalibr` package:
  - `errors.go` adds common extraction errors we want to translate.
- `translation.go` adds helper functions and translation logic between
osv-scanner v1 extractor names, and osv-scalibr extractor names.

Changes in followup PRs:
- Delete lockfiles package and migrate everything to use osv-scalibr
extractors
- Remove conversion code in image

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: Gareth Jones <Jones258@Gmail.com>
Co-authored-by: Xueqin Cui <72771658+cuixq@users.noreply.github.com>
Co-authored-by: Michael Kedar <michaelkedar@google.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Using a separate branch to resolve the merge conflicts, but other than
that this is a straightforward update of the v2 branch up to the latest
main branch.

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Xueqin Cui <72771658+cuixq@users.noreply.github.com>
Co-authored-by: Michael Kedar <michaelkedar@google.com>
Co-authored-by: Gareth Jones <Jones258@Gmail.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Emmanuel Ferdman <emmanuelferdman@gmail.com>
Co-authored-by: Ignacio Vazquez <ivaz@meta.com>
Follow up to #1309

BREAKING CHANGE: these packages are no longer public

Co-authored-by: Rex P <106129829+another-rex@users.noreply.github.com>
Added support to automatically open the HTML file in users' default
browser after a scan finishes.

If the serve flag is enabled, the HTML file will be saved in a temporary
directory and then served on localhost.

If only specified the `--format html`, open the generated HTML file by
using the right `open` command for each OS (like `xdg-open` for Linux,
`start` for Windows, and `open` for macOS). Simultaneously, the file is
served on localhost for easy remote access.

---------

Co-authored-by: Rex P <106129829+another-rex@users.noreply.github.com>
The current v2 container scanning doesn't report any Debian-related
vulnerabilities. The reason is that the extractor takes the package name
and package version to match against OSV records. But OSV records store
records with the source name. Debian packages may have a different
source name than their package name (also source version). For example:

![image](https://github.com/user-attachments/assets/6c5cf9c9-7381-4f29-a887-5035b40c0efd)

The new change will convert the given package information to its
corresponding source information for matching, if the source information
is specified.
When `serve` is enabled, set the `format` to html (regardless of the
`output` flag).
@codecov-commenter
Copy link

codecov-commenter commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 72.89586% with 190 lines in your changes missing coverage. Please review.

Project coverage is 69.75%. Comparing base (152731f) to head (459ca69).

Files with missing lines Patch % Lines
cmd/osv-scanner/scan/main.go 21.05% 43 Missing and 2 partials ⚠️
internal/image/layer.go 48.38% 29 Missing and 3 partials ⚠️
...ckfilescalibr/language/java/pomxmlnet/extractor.go 75.63% 24 Missing and 5 partials ⚠️
pkg/osvscanner/osvscanner.go 81.81% 15 Missing and 7 partials ⚠️
internal/image/pathtree/pathtree.go 84.21% 8 Missing and 4 partials ⚠️
internal/lockfilescalibr/translation.go 82.35% 8 Missing and 4 partials ⚠️
internal/image/scan.go 87.20% 8 Missing and 3 partials ⚠️
...lescalibr/language/osv/osvscannerjson/extractor.go 73.68% 10 Missing ⚠️
internal/image/extractor.go 82.50% 6 Missing and 1 partial ⚠️
...alibr/language/javascript/nodemodules/extractor.go 50.00% 7 Missing ⚠️
... and 1 more
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1434      +/-   ##
==========================================
+ Coverage   69.08%   69.75%   +0.66%     
==========================================
  Files         186      186              
  Lines       18326    18576     +250     
==========================================
+ Hits        12661    12958     +297     
+ Misses       4998     4921      -77     
- Partials      667      697      +30     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@cuixq cuixq left a comment

Choose a reason for hiding this comment

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

🎉

@another-rex another-rex merged commit dc9a332 into main Dec 10, 2024
14 checks passed
@another-rex another-rex deleted the v2 branch December 10, 2024 00:26
@another-rex another-rex restored the v2 branch December 10, 2024 00:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants