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

FATAL DB error: failed to download vulnerability DB: OCI artifact error: OCI artifact error: OCI repository error: #1877

Closed
eoraita opened this issue Mar 24, 2022 · 18 comments
Assignees
Labels
triage/support Indicates an issue that is a support question.

Comments

@eoraita
Copy link

eoraita commented Mar 24, 2022

We upgraded to trviy version 0.24.4 and when running the trivy Scan we are getting the following error:

FATAL DB error: failed to download vulnerability DB: OCI artifact error: OCI artifact error: OCI repository error: Get "https://ghcr.io/v2/": x509: certificate signed by unknown authority

We where using release 0.21.3 prior and had now issues and then yesterday afternoon we started getting 👍

FATAL DB error: failed to download vulnerability DB: failed to download vulnerability DB: failed to list releases: Get "https://api.github.com/repos/aquasecurity/trivy-db/releases": x509: certificate signed by unknown authority

@DmitriyLewen
Copy link
Contributor

Hello @eoraita
Thank you for your report!

If trivy is running behind corporate firewall, you have to add the following urls to your allowlist.:

  • ghcr.io
  • pkg-containers.githubusercontent.com

Read more about some of the issues here

Regards, Dmitriy

@eoraita
Copy link
Author

eoraita commented Mar 25, 2022 via email

@github-actions
Copy link

github-actions bot commented Jun 4, 2022

This issue is stale because it has been labeled with inactivity.

@github-actions github-actions bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. label Jun 4, 2022
@ghost
Copy link

ghost commented Jun 23, 2022

I have the same error, but in my case I'm using a private oci registry for the trivy-db. The solution offered here to open firewalls to allow ghcr.io doesn't apply. Also worth noting that if I use a custom trivy image that includes my internal CA, everything works fine; however I would prefer to use the public aquasec/trivy: images. I should be able to pass something like the --insecure option when downloading the DB as well as images.

@afdesk
Copy link
Contributor

afdesk commented Jun 23, 2022

@flngen could you take a look at #2373?

@ghost
Copy link

ghost commented Jun 23, 2022

@flngen could you take a look at #2373?

I have seen that discussion. My local registry does not require authentication. As I mentioned above, there probably isn't an option to bypass ssl verification when downloading the DB. Granted I haven't taken the time to read the code. Pure guess.

@afdesk
Copy link
Contributor

afdesk commented Jun 23, 2022

@flngen do you use the latest trivy with --insecure?

@ghost
Copy link

ghost commented Jun 23, 2022

yes

@ghost
Copy link

ghost commented Jun 23, 2022

I tried using the public trivy docker image and mounted the node certs path to the docker container on /etc/ssl/certs, and was able to download the db from my private repo. So that's probably an acceptable workaround, provided your docker nodes contain your local CA certs/chain.

@github-actions github-actions bot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and will be auto-closed. label Jun 24, 2022
@DmitriyLewen
Copy link
Contributor

DmitriyLewen commented Jun 24, 2022

Hello @flngen

We added insecure skip to download Trivy-db earlier: #2140

To investigate your problem, can you send me:

  1. Trivy installed version (command trivy -v );
  2. Trivy result using -debug and --insecure flags(when you have error);

Regards, Dmitriy

@cathex-matt
Copy link

cathex-matt commented Aug 17, 2022

@DmitriyLewen
Hi,
For what it's worth, I run trivy --debug --insecure image --severity HIGH,CRITICAL,MEDIUM --exit-code 1 and got the logs below:

trivy 0.31.2 is already installed
2022-08-18T00:33:59.929+0100    DEBUG   Severities: ["HIGH" "CRITICAL" "MEDIUM"]
2022-08-18T00:33:59.970+0100    DEBUG   cache dir:  /Users/cathex-matt/Library/Caches/trivy
2022-08-18T00:33:59.970+0100    DEBUG   There is no valid metadata file: unable to open a file: open /Users/cathex-matt/Library/Caches/trivy/db/metadata.json: no such file or directory
2022-08-18T00:33:59.970+0100    INFO    Need to update DB
2022-08-18T00:33:59.970+0100    INFO    DB Repository: ghcr.io/aquasecurity/trivy-db
2022-08-18T00:33:59.970+0100    INFO    Downloading DB...
2022-08-18T00:33:59.970+0100    DEBUG   no metadata file
2022-08-18T00:34:00.330+0100    FATAL   init error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.Run
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:362
  - DB error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.NewRunner
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:121
  - failed to download vulnerability DB:
    github.com/aquasecurity/trivy/pkg/commands/operation.DownloadDB
        /home/runner/work/trivy/trivy/pkg/commands/operation/operation.go:117
  - OCI artifact error:
    github.com/aquasecurity/trivy/pkg/db.(*Client).Download
        /home/runner/work/trivy/trivy/pkg/db/db.go:154
  - OCI artifact error:
    github.com/aquasecurity/trivy/pkg/db.(*Client).initOCIArtifact
        /home/runner/work/trivy/trivy/pkg/db/db.go:194
  - OCI repository error:
    github.com/aquasecurity/trivy/pkg/oci.NewArtifact
        /home/runner/work/trivy/trivy/pkg/oci/artifact.go:69
  - GET https://ghcr.io/token?scope=repository%3Aaquasecurity%2Ftrivy-db%3Apull&service=ghcr.io: DENIED: denied
task: Failed to run task "docker:security:trivy": exit status 1

@DmitriyLewen
Copy link
Contributor

hm... it looks like a problem with authorization.
Can you try logging into docker as written here?

@cathex-matt
Copy link

cathex-matt commented Aug 18, 2022

hm... it looks like a problem with authorization. Can you try logging into docker as written here?

Thanks! It worked simply with authenticating to ghcr. I wasn't aware it was a requirement, was wrongly assuming it was all public. The problem occured when bumping from trivy 0.22.0 to 0.31.2.

@knqyf263
Copy link
Collaborator

I think you had an expired token in local. You re-logged in ghcr.io and the expired token was overwritten. I suppose docker logout ghcr.io also addressed your issue.
#2689 (reply in thread)

@iSeiryu
Copy link

iSeiryu commented Nov 24, 2022

I just installed trivy on a pretty empty Ubuntu without any firewalls, ran this command

trivy k8s --report summary cluster --debug

and got this error

2022-11-23T22:52:05.060-0500    DEBUG   Severities: ["UNKNOWN" "LOW" "MEDIUM" "HIGH" "CRITICAL"]
2022-11-23T22:52:17.322-0500    DEBUG   cache dir:  /home/iseiryu/.cache/trivy
2022-11-23T22:52:17.323-0500    DEBUG   There is no valid metadata file: unable to open a file: open /home/iseiryu/.cache/trivy/db/metadata.json: no such file or directory
2022-11-23T22:52:17.323-0500    INFO    Need to update DB
2022-11-23T22:52:17.323-0500    INFO    DB Repository: ghcr.io/aquasecurity/trivy-db
2022-11-23T22:52:17.323-0500    INFO    Downloading DB...
2022-11-23T22:52:17.323-0500    DEBUG   no metadata file
2022-11-23T22:52:49.935-0500    FATAL   init error:
    github.com/aquasecurity/trivy/pkg/k8s/commands.(*runner).run
        /home/runner/work/trivy/trivy/pkg/k8s/commands/run.go:74
  - DB error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.NewRunner
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:121
  - failed to download vulnerability DB:
    github.com/aquasecurity/trivy/pkg/commands/operation.DownloadDB
        /home/runner/work/trivy/trivy/pkg/commands/operation/operation.go:117
  - OCI artifact error:
    github.com/aquasecurity/trivy/pkg/db.(*Client).Download
        /home/runner/work/trivy/trivy/pkg/db/db.go:154
  - OCI artifact error:
    github.com/aquasecurity/trivy/pkg/db.(*Client).initOCIArtifact
        /home/runner/work/trivy/trivy/pkg/db/db.go:194
  - OCI repository error:
    github.com/aquasecurity/trivy/pkg/oci.NewArtifact
        /home/runner/work/trivy/trivy/pkg/oci/artifact.go:69
  - Get "https://ghcr.io/v2/": dial tcp: lookup ghcr.io: i/o timeout

@afdesk
Copy link
Contributor

afdesk commented Nov 24, 2022

@iSeiryu thanks for your report!
it looks like a duplicate of known issue #3146
we're working to fix it.
as a workaround you can try to use --insecure flag. is it ok for you?

@iSeiryu
Copy link

iSeiryu commented Nov 28, 2022

Not like this

trivy k8s --report summary cluster --debug --insecure

2022-11-28T16:39:57.865-0500    DEBUG   Severities: ["UNKNOWN" "LOW" "MEDIUM" "HIGH" "CRITICAL"]
2022-11-28T16:40:09.890-0500    DEBUG   cache dir:  /home/iseiryu/.cache/trivy
2022-11-28T16:40:09.892-0500    DEBUG   There is no valid metadata file: unable to open a file: open /home/iseiryu/.cache/trivy/db/metadata.json: no such file or directory
2022-11-28T16:40:09.892-0500    INFO    Need to update DB
2022-11-28T16:40:09.892-0500    INFO    DB Repository: ghcr.io/aquasecurity/trivy-db
2022-11-28T16:40:09.892-0500    INFO    Downloading DB...
2022-11-28T16:40:09.892-0500    DEBUG   no metadata file
35.34 MiB / 35.34 MiB [------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 4.34 MiB p/s 8.3s
2022-11-28T16:40:33.917-0500    DEBUG   Updating database metadata...
2022-11-28T16:40:33.917-0500    DEBUG   DB Schema: 2, UpdatedAt: 2022-11-28 18:07:09.629105676 +0000 UTC, NextUpdate: 2022-11-29 00:07:09.629105376 +0000 UTC, DownloadedAt: 2022-11-28 21:40:33.9176202 +0000 UTC
16 / 198 [------------->_______________________________________________________________________________________________________________________________________________________] 8.08% 0 p/s
2022-11-28T16:45:11.955-0500    WARN    Increase --timeout value
2022-11-28T16:45:11.958-0500    FATAL   k8s scan error:
    github.com/aquasecurity/trivy/pkg/k8s/commands.(*runner).run
        /home/runner/work/trivy/trivy/pkg/k8s/commands/run.go:101
  - scanning misconfigurations error:
    github.com/aquasecurity/trivy/pkg/k8s/scanner.(*Scanner).Scan
        /home/runner/work/trivy/trivy/pkg/k8s/scanner/scanner.go:73
  - scan error:
    github.com/aquasecurity/trivy/pkg/commands/artifact.(*runner).scanArtifact
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:230
  - scan failed:
    github.com/aquasecurity/trivy/pkg/commands/artifact.scan
        /home/runner/work/trivy/trivy/pkg/commands/artifact/run.go:555
  - failed analysis:
    github.com/aquasecurity/trivy/pkg/scanner.Scanner.ScanArtifact
        /home/runner/work/trivy/trivy/pkg/scanner/scan.go:127
  - failed to call hooks:
    github.com/aquasecurity/trivy/pkg/fanal/artifact/local.Artifact.Inspect
        /home/runner/work/trivy/trivy/pkg/fanal/artifact/local/fs.go:126
  - post handler error:
    github.com/aquasecurity/trivy/pkg/fanal/handler.Manager.PostHandle
        /home/runner/work/trivy/trivy/pkg/fanal/handler/handler.go:75
  - scan config error:
    github.com/aquasecurity/trivy/pkg/fanal/handler/misconf.misconfPostHandler.Handle
        /home/runner/work/trivy/trivy/pkg/fanal/handler/misconf/misconf.go:293
  - context deadline exceeded

But it worked like this

trivy k8s --report summary cluster --debug --insecure --timeout 60m0s

2022-11-28T16:46:45.011-0500    DEBUG   Severities: ["UNKNOWN" "LOW" "MEDIUM" "HIGH" "CRITICAL"]
2022-11-28T16:46:57.666-0500    DEBUG   cache dir:  /home/iseiryu/.cache/trivy
2022-11-28T16:46:57.667-0500    DEBUG   DB update was skipped because the local DB is the latest
2022-11-28T16:46:57.667-0500    DEBUG   DB Schema: 2, UpdatedAt: 2022-11-28 18:07:09.629105676 +0000 UTC, NextUpdate: 2022-11-29 00:07:09.629105376 +0000 UTC, DownloadedAt: 2022-11-28 21:40:33.9176202 +0000 UTC
198 / 198 [------------------------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 1 p/s
2022-11-28T16:52:10.072-0500    ERROR   Error during vulnerabilities scan: scan error: unable to initialize a scanner: unable to initialize a docker scanner: 4 errors occurred:
        * <redacted>
        * unable to initialize Podman client: no podman socket found: stat /mnt/wslg/runtime-dir/podman/podman.sock: no such file or directory
        * containerd socket not found: /run/containerd/containerd.sock
        * <redacted>

What is that DB for? Cannot the process be simplified?
Do I need to install Podman as well?
I'm using AKS which should use containerd underneath. Why would it complain about it?

@iSeiryu
Copy link

iSeiryu commented Nov 28, 2022

A subsequent run causes it to download the DB again...why?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage/support Indicates an issue that is a support question.
Projects
None yet
Development

No branches or pull requests

6 participants