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

BOM: Include full list of transient go dependencies #2085

Merged
merged 5 commits into from
May 31, 2021

Conversation

puerco
Copy link
Member

@puerco puerco commented May 26, 2021

What type of PR is this?

/kind bug
/kind cleanup
/kind feature
/kind design

What this PR does / why we need it:

Full List of Dependencies is now the Default
Based on the discussion on #2077 this PR modifies the way we determine dependencies when scanning directories that contain go modules. All modules pulled by go as transient dependencies will now be included in the SBOM. The dependencies are determined by running go -list --deps.

This PR also includes code to take advantage of the local go
module cache. When scanning go package licenses, bom will use any
packages already downloaded and determine the licensing information
from there before attempting to download the modules. This results in a considerable performance improvement.

A new flag is introduced to bom generate: --no-transient
When set, this flag will revert to the original behvaior where only direct go dependencies are included in the Bill of Materials.

Parallel Downloads
When bom has to download go dependencies, all downloads will now be done in parallel, also resulting in a considerable performance improvement.

License package bugfix
Finally, a bug in the license package has been fixed, avoiding an edge case where a division by zero would crash the program under certain cases. Also, the license output has been improved by shifting some of the output to log level debug.

Which issue(s) this PR fixes:

Part of #1837
Follow up to: #2077

Special notes for your reviewer:

Only the last 4 commits are relevant, needs a rebase once #2077 merges.

Hold until 2077 merged
/hold

Does this PR introduce a user-facing change?

- `bom generate` will now perform go package downloads in parallel
- When generating an sbom from a go module directory, `bom` will now list all transient dependencies by default. A new flag `--no-transient` can be used to only include direct dependencies in the document.
- Reduced the output of the license package by moving some of the output to Debug.
- FIxed a bug where the license package would sometimes crash due to a division by zero.  

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. kind/design Categorizes issue or PR as related to design. needs-priority cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 26, 2021
@k8s-ci-robot k8s-ci-robot requested review from hasheddan and xmudrii May 26, 2021 06:30
@k8s-ci-robot k8s-ci-robot added area/release-eng Issues or PRs related to the Release Engineering subproject sig/release Categorizes an issue or PR as relevant to SIG Release. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels May 26, 2021
@puerco
Copy link
Member Author

puerco commented May 26, 2021

/milestone v1.22

@k8s-ci-robot k8s-ci-robot added this to the v1.22 milestone May 26, 2021
@puerco puerco force-pushed the deep-mods branch 2 times, most recently from f4ad8e0 to dfa6cbc Compare May 26, 2021 22:22
Copy link
Member

@saschagrunert saschagrunert left a comment

Choose a reason for hiding this comment

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

Just a few nits, but generally LGTM :)

pkg/spdx/spdx.go Outdated Show resolved Hide resolved
pkg/spdx/spdx.go Outdated Show resolved Hide resolved
pkg/spdx/package.go Outdated Show resolved Hide resolved
@@ -189,6 +222,7 @@ func (p *Package) Render() (docFragment string, err error) {
}

// If files were analyzed, calculate the verification
filesTagList := map[string]*struct{}{}
Copy link
Member

Choose a reason for hiding this comment

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

Can we make this a []string?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done. One question: I use that map of empty structs a lot as a temp dict to look up things that have to be listed once instead of looping a slice over and over.

Is it more efficient to loop the slice?

Copy link
Member

Choose a reason for hiding this comment

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

Is it more efficient to loop the slice?

In theory yes, but practically I don't know.

pkg/spdx/implementation.go Outdated Show resolved Hide resolved
pkg/license/implementation.go Outdated Show resolved Hide resolved
pkg/license/implementation.go Outdated Show resolved Hide resolved
pkg/spdx/gomod.go Outdated Show resolved Hide resolved
pkg/spdx/gomod.go Outdated Show resolved Hide resolved
pkg/spdx/gomod.go Outdated Show resolved Hide resolved
puerco added 4 commits May 28, 2021 11:29
This commit makes the go module download code parallel.
It also fixes a bug where the temprary go downlaods were
not removed correctly.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commit reduces the verbosity of the license package
by shifting some of the output to the debug level.

It also fixes a bug where a division by zero may occur
when reporting the number of licenses found.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
This commit modofies the behaviour of bom when scanning go modules
to include all transient dependencies. All modules included in the
as transient dependencies as reported by go list will now be included
in the sbom.

This commit also includes new code to take advantage of the local go
module cache. When scanning gp package licenses, bom will use any
packages already downloaded and determine the licensins information
from there before attempting to download the modules.

This PR also includes a new flag to `bom generate`: `--no-transient`
When defined, this flag will revert to the original behvaiour where
only direct go dependencies are included in the Bill of Materials.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels May 28, 2021
This commit also simplifies the data structure used to determine
the LicenseInfoFromFiles entry in the PSDX package.

Signed-off-by: Adolfo García Veytia (Puerco) <[email protected]>
@puerco puerco mentioned this pull request May 29, 2021
@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label May 31, 2021
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: puerco, saschagrunert

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [puerco,saschagrunert]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@saschagrunert
Copy link
Member

#2077 is merged
/hold cancel

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label May 31, 2021
@k8s-ci-robot k8s-ci-robot merged commit c6c13d5 into kubernetes:master May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. area/release-eng Issues or PRs related to the Release Engineering subproject cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/design Categorizes issue or PR as related to design. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. needs-priority release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/release Categorizes an issue or PR as relevant to SIG Release. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants