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

feat: add support for Wolfi Linux #3215

Merged
merged 11 commits into from
Dec 12, 2022
Merged

Conversation

luhring
Copy link
Contributor

@luhring luhring commented Nov 22, 2022

Description

This PR adds support for Wolfi Linux to Trivy, by adding support for detecting the Wolfi "OS" and mapping that to the Wolfi secdb data provided via aquasecurity/vuln-list-update#183 and aquasecurity/trivy-db#266.

(Note: I'm on the Wolfi team. 👋 Happy to answer any questions, including about what's similar/different from Alpine.)

Here's a look at Trivy's behavior before and after adding Wolfi support. These examples are scans of an intentionally old Wolfi image so that vulnerabilities are still present. (Wofli vulnerabilities are typically patched extremely quickly.) The image being scanned is cgr.dev/chainguard/wolfi-base:latest-20221001.

Before

2022-11-22T16:08:42.908-0500	INFO	Need to update DB
2022-11-22T16:08:42.908-0500	INFO	DB Repository: ghcr.io/aquasecurity/trivy-db
2022-11-22T16:08:42.908-0500	INFO	Downloading DB...
35.24 MiB / 35.24 MiB [-----------------------------------------------------------------------------------------------------] 100.00% 22.12 MiB p/s 1.8s
2022-11-22T16:08:45.239-0500	INFO	Vulnerability scanning is enabled
2022-11-22T16:08:45.239-0500	INFO	Secret scanning is enabled
2022-11-22T16:08:45.239-0500	INFO	If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
2022-11-22T16:08:45.239-0500	INFO	Please see also https://aquasecurity.github.io/trivy/v0.34/docs/secret/scanning/#recommendation for faster secret detection
2022-11-22T16:08:46.073-0500	INFO	Detected OS: none
2022-11-22T16:08:46.073-0500	WARN	unsupported os : none
2022-11-22T16:08:46.073-0500	INFO	Number of language-specific files: 0

After

2022-11-22T16:11:09.581-0500    INFO    Vulnerability scanning is enabled
2022-11-22T16:11:09.581-0500    INFO    Secret scanning is enabled
2022-11-22T16:11:09.581-0500    INFO    If your scanning is slow, please try '--security-checks vuln' to disable secret scanning
2022-11-22T16:11:09.581-0500    INFO    Please see also https://aquasecurity.github.io/trivy/dev/docs/secret/scanning/#recommendation for faster secret detection
2022-11-22T16:11:09.602-0500    INFO    Detected OS: wolfi
2022-11-22T16:11:09.602-0500    INFO    Detecting Wolfi vulnerabilities...
2022-11-22T16:11:09.603-0500    INFO    Number of language-specific files: 0

cgr.dev/chainguard/wolfi-base:latest-20221001 (wolfi 20220914)

Total: 5 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 3, CRITICAL: 1)

┌─────────┬────────────────┬──────────┬───────────────────┬───────────────┬─────────────────────────────────────────────────────────────┐
│ Library │ Vulnerability  │ Severity │ Installed Version │ Fixed Version │                            Title                            │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ busybox │ CVE-2022-28391 │ HIGH     │                   │ 1.35.0-r3     │ busybox: remote attackers may execute arbitrary code if     │
│         │                │          │                   │               │ netstat is used                                             │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-28391                  │
│         ├────────────────┤          ├───────────────────┤               ├─────────────────────────────────────────────────────────────┤
│         │ CVE-2022-30065 │          │                   │               │ busybox: A use-after-free in Busybox's awk applet leads to  │
│         │                │          │                   │               │ denial of service...                                        │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-30065                  │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ glibc   │ CVE-2022-39046 │ MEDIUM   │                   │ 2.36-r1       │ glibc: a crafted input may allow information disclosure     │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-39046                  │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ zlib    │ CVE-2022-37434 │ CRITICAL │                   │ 1.2.12-r3     │ zlib: heap-based buffer over-read and overflow in inflate() │
│         │                │          │                   │               │ in inflate.c via a...                                       │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-37434                  │
│         ├────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│         │ CVE-2018-25032 │ HIGH     │                   │ 1.2.12-r0     │ zlib: A flaw found in zlib when compressing (not            │
│         │                │          │                   │               │ decompressing) certain inputs...                            │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2018-25032                  │
└─────────┴────────────────┴──────────┴───────────────────┴───────────────┴─────────────────────────────────────────────────────────────┘

Related issues

Related PRs

Remove this section if you don't have related PRs.

Checklist

  • I've read the guidelines for contributing to this repository.
  • I've followed the conventions in the PR title.
  • I've added tests that prove my fix is effective or that my feature works.
  • I've updated the documentation with the relevant information (if needed).
  • I've added usage information (if the PR introduces new options)
  • I've included a "before" and "after" example to the description (if the PR is a user interface change).

Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@luhring luhring requested a review from knqyf263 as a code owner November 22, 2022 21:14
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@luhring
Copy link
Contributor Author

luhring commented Nov 23, 2022

(Compilation will fail until aquasecurity/trivy-db#266 is merged and we update this branch of trivy to use the new version of trivy-db.)

@afdesk
Copy link
Contributor

afdesk commented Dec 4, 2022

@luhring
Copy link
Contributor Author

luhring commented Dec 4, 2022

@luhring thanks for your efforts. could you say why we need a custom analyzer? https://github.com/luhring/trivy/tree/wolfi-support/pkg/fanal/analyzer/os/wolfi

You already handle family ID: https://github.com/luhring/trivy/blob/b7c961a65c08aa289a32659a412b550535688dd9/pkg/fanal/analyzer/os/release/release.go#L62-L63

We might not need it, actually! 😃 I'm still learning Trivy's architecture, but that's what I was hoping to learn here #3205 (comment):

I'm wondering if I can even delete what I added at pkg/fanal/analyzer/os/wolfi/..., relying instead on pkg/fanal/analyzer/os/release/release.go to detect the Wolfi OS. What do you think?

@afdesk
Copy link
Contributor

afdesk commented Dec 4, 2022

@luhring sorry, missed your thought.
yes, you can remove wolfi analyzer and rely on release package.

Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@luhring
Copy link
Contributor Author

luhring commented Dec 4, 2022

sorry, missed your thought.
yes, you can remove wolfi analyzer and rely on release package.

No worries! Removed in b0df2e5

@afdesk afdesk changed the title feat(wolfi): add support for Wolfi Linux feat: add support for Wolfi Linux Dec 4, 2022
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@luhring
Copy link
Contributor Author

luhring commented Dec 8, 2022

Now that aquasecurity/trivy-db#266 is merged, I've updated this branch to use the latest version of trivy-db.

@knqyf263 and @afdesk could you please take a look? I'm happy to make any other changes you'd like!

Also, in these situations do you typically wait for an updated Trivy DB to be published, in order to test Trivy without using a local cache of the DB?

@knqyf263
Copy link
Collaborator

knqyf263 commented Dec 8, 2022

The addition of Wolfi is causing the DB to fail to build (it is our fault), so let us fix that first.
https://github.com/aquasecurity/trivy-db/actions/runs/3648065794/jobs/6161044855

@luhring
Copy link
Contributor Author

luhring commented Dec 8, 2022

@knqyf263 The DB looks good to me now! Do you think this one is ready to merge?

Copy link
Collaborator

@knqyf263 knqyf263 left a comment

Choose a reason for hiding this comment

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

Looks almost good to me. I left some small comments.

pkg/detector/ospkg/wolfi/wolfi.go Outdated Show resolved Hide resolved
pkg/detector/ospkg/wolfi/wolfi.go Show resolved Hide resolved
pkg/detector/ospkg/wolfi/wolfi_test.go Outdated Show resolved Hide resolved
pkg/fanal/analyzer/const.go Outdated Show resolved Hide resolved
@knqyf263 knqyf263 mentioned this pull request Dec 11, 2022
8 tasks
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@knqyf263
Copy link
Collaborator

Hi, it looked good to me, but I found that the installed versions are empty. Do you know the reason? This analyzer should capture versions.
https://github.com/aquasecurity/trivy/blob/b944ac628616b892d2c1cb085c1bae63128de45d/pkg/fanal/analyzer/pkg/apk/apk.go

@knqyf263
Copy link
Collaborator

knqyf263 commented Dec 12, 2022

Doesn't Wolfi have origin package names/versions? If it is the case, we need to use FormatVersion instead.

installed := utils.FormatSrcVersion(pkg)

C:Q1LzfStMeff9oZ+09WB5Z5OR73s/Q=
P:binutils-dev
V:2.39-r4
A:x86_64
S:1052112
I:4209277
T:binutils development headers
U:
L:GPL-3.0-or-later
o:binutils
F:usr
F:usr/include

In the above example, can we assume binutils-dev is installed from binutils v2.39-r4? In other words, the origin package version and sub-package version are always the same?

Signed-off-by: Dan Luhring <dluhring@chainguard.dev>
@luhring
Copy link
Contributor Author

luhring commented Dec 12, 2022

In the above example, can we assume binutils-dev is installed from binutils v2.39-r4? In other words, the origin package version and sub-package version are always the same?

Yes, that's correct. Good to know about utils.FormatVersion, thanks! Updated.

@luhring
Copy link
Contributor Author

luhring commented Dec 12, 2022

Hi, it looked good to me, but I found that the installed versions are empty. Do you know the reason? This analyzer should capture versions.

Just so I understand this comment, where are you looking? I'm seeing installed versions in Trivy's output.

@knqyf263
Copy link
Collaborator

knqyf263 commented Dec 12, 2022

In your PR description, installed versions are empty in the table.
#3215 (comment)

image

@knqyf263
Copy link
Collaborator

It works now, though.

cgr.dev/chainguard/wolfi-base:latest-20221001 (wolfi 20220914)
==============================================================
Total: 4 (UNKNOWN: 0, LOW: 0, MEDIUM: 1, HIGH: 2, CRITICAL: 1)

┌─────────┬────────────────┬──────────┬───────────────────┬───────────────┬─────────────────────────────────────────────────────────────┐
│ Library │ Vulnerability  │ Severity │ Installed Version │ Fixed Version │                            Title                            │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ busybox │ CVE-2022-28391 │ HIGH     │ 1.35.0-r2         │ 1.35.0-r3     │ busybox: remote attackers may execute arbitrary code if     │
│         │                │          │                   │               │ netstat is used                                             │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-28391                  │
│         ├────────────────┤          │                   │               ├─────────────────────────────────────────────────────────────┤
│         │ CVE-2022-30065 │          │                   │               │ busybox: A use-after-free in Busybox's awk applet leads to  │
│         │                │          │                   │               │ denial of service...                                        │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-30065                  │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ glibc   │ CVE-2022-39046 │ MEDIUM   │ 2.36-r0           │ 2.36-r1       │ glibc: a crafted input may allow information disclosure     │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-39046                  │
├─────────┼────────────────┼──────────┼───────────────────┼───────────────┼─────────────────────────────────────────────────────────────┤
│ zlib    │ CVE-2022-37434 │ CRITICAL │ 1.2.12-r2         │ 1.2.12-r3     │ zlib: heap-based buffer over-read and overflow in inflate() │
│         │                │          │                   │               │ in inflate.c via a...                                       │
│         │                │          │                   │               │ https://avd.aquasec.com/nvd/cve-2022-37434                  │
└─────────┴────────────────┴──────────┴───────────────────┴───────────────┴─────────────────────────────────────────────────────────────┘

@luhring
Copy link
Contributor Author

luhring commented Dec 12, 2022

In your PR description, installed versions are empty in the table.

Got it! There have been a handful of changes in the past 3 weeks. I'm seeing installed versions locally — let me know if you see something different when you run it.

@knqyf263
Copy link
Collaborator

I didn't see installed versions before this commit 95568b5. It looks good now.

@knqyf263 knqyf263 merged commit 93c5d2d into aquasecurity:main Dec 12, 2022
@knqyf263
Copy link
Collaborator

Thanks for your contribution👍 It will be included in v0.36.0.

@luhring luhring deleted the wolfi-support branch December 12, 2022 20:50
@luhring
Copy link
Contributor Author

luhring commented Dec 12, 2022

Thanks for all your help @knqyf263 and @afdesk! 🙏 This was a great learning experience.

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.

Add support for Wolfi OS
3 participants