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

Start to scan all distroless images with Trivy #6

Merged
merged 2 commits into from
Apr 14, 2022

Conversation

mattmoor
Copy link
Member

With 0.3.1 Trivy is able to recognize that we're an Alpine image:

2022-04-13T23:40:25.809Z	INFO	Need to update DB
2022-04-13T23:40:25.809Z	INFO	Downloading DB...
2022-04-13T23:40:27.895Z	INFO	Detected OS: alpine
2022-04-13T23:40:27.895Z	INFO	Detecting Alpine vulnerabilities...
2022-04-13T23:40:27.896Z	INFO	Number of language-specific files: 0

This change will make it so that all of the distroless releases will scan the image (you can control whether this is fatal with trivy-exit-code: '0'.

Signed-off-by: Matt Moore [email protected]

@mattmoor mattmoor requested review from kaniini and puerco April 13, 2022 23:43
format: 'table'
exit-code: ${{ inputs.trivy-exit-code }}
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH,MEDIUM,LOW,UNKNOWN'
Copy link
Member Author

Choose a reason for hiding this comment

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

@kaniini I YOLO'd all of them here, but we can tune this based on what we reasonable expect to be fixed quickly in the feeds.

@mattmoor
Copy link
Member Author

Actually, if I drop the os-release stanza I'd added I get:

2022-04-13T23:48:27.323Z	INFO	Need to update DB
2022-04-13T23:48:27.323Z	INFO	Downloading DB...
2022-04-13T23:48:29.299Z	INFO	Detected OS: alpine
2022-04-13T23:48:29.299Z	WARN	This OS version is not on the EOL list: alpine 3.16
2022-04-13T23:48:29.299Z	INFO	Detecting Alpine vulnerabilities...
2022-04-13T23:48:29.299Z	INFO	Number of language-specific files: 0
2022-04-13T23:48:29.299Z	WARN	This OS version is no longer supported by the distribution: alpine 3.16
2022-04-13T23:48:29.299Z	WARN	The vulnerability detection may be insufficient because security updates are not provided

I believe this is where @knqyf263 work will help? 🤞

@mattmoor
Copy link
Member Author

I think the way I want this to evolve is as follows:

  1. Start to have the Trivy stuff emit SARIF format findings,
  2. Start to upload the SARIF files to github codeql,
  3. Start to attest with --type vuln using the SARIF result,
  4. (once Ville's fixes land) Start to use cosign verify-attestation --type vuln with a Cue policy to determine the failure criteria we want.

@mattmoor
Copy link
Member Author

Ok, I added 1/2 here, and TODOs for the other bits.

@mattmoor mattmoor force-pushed the trivy-scan-images branch 3 times, most recently from 44ab871 to 5add2fe Compare April 14, 2022 01:57
@mattmoor
Copy link
Member Author

It looks like uploading CodeQL results need contents: write permission, so we should update those before landing this.

@mattmoor
Copy link
Member Author

Hmm, even with that is fails 🤔

@mattmoor
Copy link
Member Author

I'll back out the codeql stuff for now...

Only update :latest on a clean scan after all of the signatures and (eventually) attestations have been published.

Signed-off-by: Matt Moore <[email protected]>
@mattmoor mattmoor force-pushed the trivy-scan-images branch from 5add2fe to 3002e4a Compare April 14, 2022 02:10
@knqyf263
Copy link

I believe this is where @knqyf263 work will help? 🤞

Yes, we're trying to capture Alpine version from /etc/apk/repositories when /etc/os-version and /etc/alpine-version don't exist. As you can see in the following PR, it works in my local. We'll merge it and release a new version today if we don't see any issues.
aquasecurity/trivy#1987

Signed-off-by: Matt Moore <[email protected]>
@mattmoor mattmoor force-pushed the trivy-scan-images branch from caed1b4 to 91bc182 Compare April 14, 2022 03:55
@mattmoor
Copy link
Member Author

Alright, I have a basic form of this that will start publishing vulnerability attestations as well, I'm going to pull that in here as a second commit.

@mattmoor
Copy link
Member Author

@knqyf263 interesting, so @kaniini added support for emitting /etc/alpine-release as a workaround, but I think it's getting 3.16 not edge, so I suspect our workaround has unfortunately collided with your fix, and our current release may actually be incompatible 😅

@kaniini should we change things to emit edge here instead? I believe it's based on os-release.id so perhaps once the new trivy drop lands, I can try specifying edge there, but we should sort out the right way to do this longer term.

Thank you both for the quick fixes here 🙏

@knqyf263
Copy link

As I talked with @kaniini, I believe edge should be detected.
aquasecurity/trivy#1975 (comment)

Otherwise, we can not know which stream should be used since v3.16 doesn't exist yet in secdb.
https://secdb.alpinelinux.org/

@mattmoor
Copy link
Member Author

@knqyf263 Ok, I think the latest ghcr.io/distroless/git image was rebuilt with her latest changes this morning, so if those are detected properly then I think we are golden 🤩

@mattmoor
Copy link
Member Author

Here are some of the relevant files:

$ tar xf foo.tar -O etc/alpine-release
3.16

$ tar xf foo.tar -O etc/os-release
ID=alpine
NAME="apko-generated image"
PRETTY_NAME="apko-generated image"
VERSION_ID=3.16
HOME_URL="https://github.com/chainguard-dev/apko"

$ tar xf foo.tar -O etc/apk/repositories
https://dl-cdn.alpinelinux.org/alpine/edge/main
https://dl-cdn.alpinelinux.org/alpine/edge/community

# no /etc/secfixes.d yet

I defer to you two on the best course forward here, I just wanted to call out the (potential) inconsistency early, so we could sort it out if it were a problem.

@knqyf263
Copy link

knqyf263 commented Apr 14, 2022

We can't detect it now😄 As @mattmoor pointed out, we are inconsistent now.

ghcr.io/distroless/git (alpine 3.16)
====================================
Total: 0 (UNKNOWN: 0, LOW: 0, MEDIUM: 0, HIGH: 0, CRITICAL: 0)

Currently /etc/alpine-release is prioritized than /etc/apk/repositories. If @kaniini thinks /etc/alpine-release should be 3.16, I guess there are two approaches on my end.

  1. Prefer /etc/apk/repositories than /etc/os-release and /etc/apk-release
  2. Assume v3.16 is edge and use the edge stream in secdb.

Or, you can put edge to /etc/os-release and /etc/apk-release instead of v3.16. Which is the best?

@knqyf263
Copy link

After thinking about it for a while, I realized that it is better to use the version of the repository for vulnerability detection, regardless of the OS version. This is because packages are installed according to the repository settings and the secdb stream should be determined from where a package is installed. Please correct me if I'm wrong.

It might be problematic if user installs some packages from 3.14 and others from 3.15, for example. But I didn't find repository info in /lib/apk/db/installed for each package.

@kaniini
Copy link
Contributor

kaniini commented Apr 14, 2022

@kaniini should we change things to emit edge here instead? I believe it's based on os-release.id so perhaps once the new trivy drop lands, I can try specifying edge there, but we should sort out the right way to do this longer term.

No, /etc/alpine-release is derived from the alpine-base package version. 3.16 is right for edge at the moment.

@kaniini
Copy link
Contributor

kaniini commented Apr 14, 2022

After thinking about it for a while, I realized that it is better to use the version of the repository for vulnerability detection, regardless of the OS version. This is because packages are installed according to the repository settings and the secdb stream should be determined from where a package is installed. Please correct me if I'm wrong.

In the long term, the idea is that scanners would consume /etc/secfixes.d files to determine the feeds to use for scanning an image. I plan to write a reference implementation of this soon, but I am busy with the Alpine 3.16 release at the moment.

It might be problematic if user installs some packages from 3.14 and others from 3.15, for example. But I didn't find repository info in /lib/apk/db/installed for each package.

Mixing Alpine versions results in an unsupported configuration. I think Trivy should warn about this.

@kaniini kaniini merged commit 82f1909 into chainguard-images:main Apr 14, 2022
@mattmoor mattmoor deleted the trivy-scan-images branch April 14, 2022 16:27
@knqyf263
Copy link

Just FYI, v0.26.0 is out and /etc/os-release and /etc/alpine-release are no longer needed as a version is taken from /etc/apk/repositories. You can drop them off if you want.
aquasecurity/trivy#2001

Also, once @kaniini writes a reference about /etc/secfixes.d, we will follow it. Meanwhile, we will look into some examples to understand the concept.

@mattmoor
Copy link
Member Author

@knqyf263 when do you think this will land in the trivy action?

@knqyf263
Copy link

It would be in a few days if we don't see any issue.

@mattmoor
Copy link
Member Author

ok cool, I will circle back next week. I want to make sure this is WAI once that lands.

@knqyf263
Copy link

@mattmoor
Copy link
Member Author

Seems to work, thanks!

@tuananh-finx
Copy link

@mattmoor can we disable trivy ? i'm using private repo and it's unable to fetch the image.

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.

4 participants