Skip to content

Commit aaf845d

Browse files
authored
chore: display the troubleshooting URL for the DB denial error (aquasecurity#3474)
1 parent ed5bb0b commit aaf845d

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

docs/docs/references/troubleshooting.md

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ Reference : [boltdb: Opening a database][boltdb].
9191

9292
[boltdb]: https://github.com/boltdb/bolt#opening-a-database
9393

94-
### Error downloading vulnerability DB
95-
96-
!!! error
97-
FATAL failed to download vulnerability DB
98-
99-
If trivy is running behind corporate firewall, you have to add the following urls to your allowlist.
100-
101-
- ghcr.io
102-
- pkg-containers.githubusercontent.com
103-
104-
### Old DB schema
105-
106-
!!! error
107-
--skip-update cannot be specified with the old DB schema.
108-
109-
Trivy v0.23.0 or later requires Trivy DB v2. Please update your local database or follow [the instruction of air-gapped environment][air-gapped].
110-
11194
### Multiple Trivy servers
11295

11396
!!! error
@@ -150,6 +133,37 @@ Try:
150133
$ TMPDIR=/my/custom/path trivy image ...
151134
```
152135

136+
## DB
137+
### Old DB schema
138+
139+
!!! error
140+
--skip-update cannot be specified with the old DB schema.
141+
142+
Trivy v0.23.0 or later requires Trivy DB v2. Please update your local database or follow [the instruction of air-gapped environment][air-gapped].
143+
144+
### Error downloading vulnerability DB
145+
146+
!!! error
147+
FATAL failed to download vulnerability DB
148+
149+
If trivy is running behind corporate firewall, you have to add the following urls to your allowlist.
150+
151+
- ghcr.io
152+
- pkg-containers.githubusercontent.com
153+
154+
### Denied
155+
156+
!!! error
157+
GET https://ghcr.io/token?scope=repository%3Aaquasecurity%2Ftrivy-db%3Apull&service=ghcr.io: DENIED: denied
158+
159+
Your local GHCR (GitHub Container Registry) token might be expired.
160+
Please remove the token and try downloading the DB again.
161+
162+
```shell
163+
docker logout ghcr.io
164+
```
165+
166+
153167
## Homebrew
154168
### Scope error
155169
!!! error

pkg/db/db.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,18 @@ package db
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"time"
78

8-
"github.com/aquasecurity/trivy/pkg/oci"
9-
9+
"github.com/google/go-containerregistry/pkg/v1/remote/transport"
1010
"golang.org/x/xerrors"
1111
"k8s.io/utils/clock"
1212

1313
"github.com/aquasecurity/trivy-db/pkg/db"
1414
"github.com/aquasecurity/trivy-db/pkg/metadata"
1515
"github.com/aquasecurity/trivy/pkg/log"
16+
"github.com/aquasecurity/trivy/pkg/oci"
1617
)
1718

1819
const (
@@ -191,6 +192,16 @@ func (c *Client) initOCIArtifact() (*oci.Artifact, error) {
191192
repo := fmt.Sprintf("%s:%d", c.dbRepository, db.SchemaVersion)
192193
art, err := oci.NewArtifact(repo, dbMediaType, c.quiet, c.insecureSkipTLSVerify)
193194
if err != nil {
195+
var terr *transport.Error
196+
if errors.As(err, &terr) {
197+
for _, diagnostic := range terr.Errors {
198+
// For better user experience
199+
if diagnostic.Code == transport.DeniedErrorCode || diagnostic.Code == transport.UnauthorizedErrorCode {
200+
log.Logger.Warn("See https://aquasecurity.github.io/trivy/latest/docs/references/troubleshooting/#db")
201+
break
202+
}
203+
}
204+
}
194205
return nil, xerrors.Errorf("OCI artifact error: %w", err)
195206
}
196207
return art, nil

0 commit comments

Comments
 (0)