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

Add RPM image scanner #342

Merged
merged 1 commit into from
Sep 14, 2023
Merged

Conversation

micahhausler
Copy link
Member

What type of PR is this?

/kind feature

What this PR does / why we need it:

Adds support for scanning RPM databases

Which issue(s) this PR fixes:

None

Special notes for your reviewer:

I split layer scanning tests into separate files

Does this PR introduce a user-facing change?

Added support for scanning images with RPM package managers

@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Sep 13, 2023
@k8s-ci-robot k8s-ci-robot added the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Sep 13, 2023
@micahhausler micahhausler force-pushed the rpm-scanner branch 2 times, most recently from 86418a7 to e1d5855 Compare September 13, 2023 17:15
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.

That's pretty cool, thank you for the contribution!

@puerco PTAL
/hold

@k8s-ci-robot k8s-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 14, 2023
@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Sep 14, 2023
@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 14, 2023
@micahhausler
Copy link
Member Author

I rebased to include the fix in #343

Copy link
Member

@puerco puerco left a comment

Choose a reason for hiding this comment

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

This is awesome @micahhausler !

The oldest branch I had on my machine was work in progress to implement this. It has finally happened, thank you Micah 🥲

I left a question there, but in it goes! I think it is time to cut a new relase 🚀

Type: "rpm",
// Namespace is set later
MaintainerName: p.Vendor,
// Most RPM pacakges don't have SPDX-valid license names
Copy link
Member

Choose a reason for hiding this comment

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

Curious: Is this true for all distros? Are they using an alternative naming scheme that could be translated later?

Copy link
Member Author

Choose a reason for hiding this comment

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

This potentially affects other distros, I haven't looked at APK or DEB for validation. I spent a lot of time digging into this and found that basically the story is not great:

  • If you stuff a SPDX-invalid license name into the field, the SPDX doc fails to verify
  • Some distros like Fedora are working to migrate license names to SPDX license strings. This effort is not complete yet for Fedora. Fedora has a license-fedora2spdx package (Python scripts/ config) that tries to do convert license name strings, but fails pretty hard in a lot of cases. Ex: BSD was Fedora-valid, but the tool spits out something like "BSD": "Warning: more options on how to interpret BSD. Possible options: ['BSD-1-Clause', 'BSD-2-Clause-FreeBSD', 'BSD-2-Clause-Views', 'BSD-2-Clause', 'BSD-3-Clause-Modification', 'BSD-3-Clause'] which requires more info.
  • There isn't a documented way to parse the RPM database to produce the equivalent of rpm -q --licensefiles $PACKAGE and get the list of license files in the image.
    • Most distros seem to put license files in /usr/share/licenses/$PACKAGE with multiple different filenames (Try running find /usr/share/licenses -type f -exec basename {} \; | sort |uniq | wc -l in any RPM-based container distro, you'll get >40 different names). Even if you ran rpm -qL $PKG, or just searched in the directory and tried to analyze the license files, you wouldn't know if there's an AND vs an OR for a given package. (AND typically indicating valid SPDX license vs and being a legacy license name. Try rpm -qa --queryformat '%{name} %{license}\n' | grep -E ' (and|or) ' to find those legacy ones. )

We could try calling Reader.LicenseFromLabel() and only including valid ones, but for now I just mirrored what DEB and APK parsers do.

@@ -56,6 +56,8 @@ func ReadOSPackages(layers []string) (
cs = newDebianScanner()
case OSAlpine, OSWolfi:
cs = newAlpineScanner()
case OSAmazonLinux, OSFedora, OSRHEL:
Copy link
Member

Choose a reason for hiding this comment

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

nit for later: we can also add opensuse ! 🦎
(Not actual chameleon emoji, but close :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Sep 14, 2023
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: micahhausler, 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

@puerco
Copy link
Member

puerco commented Sep 14, 2023

/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 Sep 14, 2023
@k8s-ci-robot k8s-ci-robot merged commit 69afd10 into kubernetes-sigs:main Sep 14, 2023
7 checks passed
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. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants