ROX-17374: Change dependency discovery method#46
Merged
Conversation
connorgorman
approved these changes
Jun 2, 2023
|
@mtodor any plans to cut a new release with these latest changes? I think the current CI images are using a version of this repo without these changes |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
We have a problem that downstream builds are failing because Cachito is not storing the information required for
osslsto work.We are using
go list -mcommand to discover golang dependencies. This command requires*.infofiles, which are no longer persisted in Cachito.This PR is adding change to the method of how dependencies are discovered and fixing two additional problems.
Changes
Change 1 - filter packages without directory
This is a bug discovered with the previous functionality. We have a lot of modules like this:
Because of a bug in reading JSON, such records would keep
Dirfrom the last module withDirdefined. The outcome of such an operation is that we reported a license frompackage_1under thepackage_2name.Example:
You can see that
github.com/streadway/amqpwill have a license fromfd.fxlcf.dpdns.org/steveyen/gtreap.Change 2 - use go mod download to get modules
Based on the investigation made here: https://github.com/chmeliik/godeps/tree/main#module-identification-methods-vs-corner-cases - there are several methods how to get dependencies.
go mod downloadis problematic for replacements that are using local directories. I have checked stackrox and scanner, and we don't have such cases in these repositories.We don't have information about
Replacefromgo mod. We will simply get the package used as a replacement. And that is correct.Change 3 - report licenses for github.com/stackrox/ repos
This is mostly relevant for replacements. We had a problem in the previous solution. We would report the license from a
stackroxrepository as it is a license from areplacedrepository. This is incorrect. If we want to handle licenses properly - we should simply report them (also from our packages). And inside our packages, we should define the license accordingly.Now we will have at least licenses from stackrox repos because they are actually used to build products. And not replaced libraries.
Testing
Test on
stackrox/stackrox:ossls-go build -o osslsossls audit --export ./THIRD_PARTY_NOTICES_reportAlso, test PR for downstream is open:
https://gitlab.cee.redhat.com/stackrox/rhacs-midstream/-/merge_requests/1399
Made comparisons
Cmp 1 -
list -json -m allvsmod download -jsonGet
list -json -m allresults.Get
mod download -jsonresults.Step 1:
Remove all wrongly reported packages (packages that are not available - no
Dirfor them) fromlist -json -m allresults. There is still a difference betweenlist -json -m allandmod download -json.Step 2:
Get diff between step 1 version of
list -json -m allandmod download -json. All diff packages are dependencies used in tests of our dependency packages. They are not direct test dependencies. We are not shipping these libraries, and there is no need to report their licenses.Cmp 2 -
go-licensesvsmod download -jsonI used https://github.com/google/go-licenses - to get results. There have been some differences. Some libraries were not reported by
go-licenses. But some additional licenses have been reported.An example of a reported license by
go-licenses:sigs.k8s.io/kustomize/kyaml/internal/forked/github.com/go-yaml/yaml- this is a case where project has multiple licenses depending on used packages.We didn't report these with the previous solution, and it's not a regression introduced with this functionality.
An example of not reported license by
go-licenses:cloud.google.com/go/compute- this is used by some tools we are using in Makefile. So it does not hurt to list it if it's used during the build of the project.