Skip to content

Commit 59957d4

Browse files
authored
feat(scan): support --offline-scan option (#1511)
1 parent da8b72d commit 59957d4

File tree

13 files changed

+53
-16
lines changed

13 files changed

+53
-16
lines changed

docs/advanced/air-gap.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,12 @@ $ rm trivy-offline.db.tgz
5050

5151
In an air-gapped environment it is your responsibility to update the Trivy database on a regular basis, so that the scanner can detect recently-identified vulnerabilities.
5252

53-
### Run Trivy with --skip-update option
53+
### Run Trivy with --skip-update and --offline-scan option
5454
In an air-gapped environment, specify `--skip-update` so that Trivy doesn't attempt to download the latest database file.
55+
In addition, if you want to scan Java dependencies such as JAR and pom.xml, you need to specify `--offline-scan` since Trivy tries to issue API requests for scanning Java applications by default.
5556

5657
```
57-
$ trivy image --skip-update alpine:3.12
58+
$ trivy image --skip-update --offline-scan alpine:3.12
5859
```
5960

6061
## Air-Gapped Environment for misconfigurations

docs/getting-started/cli/client.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ OPTIONS:
2222
--timeout value timeout (default: 5m0s) [$TRIVY_TIMEOUT]
2323
--ignore-policy value specify the Rego file to evaluate each vulnerability [$TRIVY_IGNORE_POLICY]
2424
--list-all-pkgs enabling the option will output all packages regardless of vulnerability (default: false) [$TRIVY_LIST_ALL_PKGS]
25+
--offline-scan do not issue API requests to identify dependencies (default: false) [$TRIVY_OFFLINE_SCAN]
2526
--token value for authentication [$TRIVY_TOKEN]
2627
--token-header value specify a header name for token (default: "Trivy-Token") [$TRIVY_TOKEN_HEADER]
2728
--remote value server address (default: "http://localhost:4954") [$TRIVY_REMOTE]

docs/getting-started/cli/fs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OPTIONS:
2525
--no-progress suppress progress bar (default: false) [$TRIVY_NO_PROGRESS]
2626
--ignore-policy value specify the Rego file to evaluate each vulnerability [$TRIVY_IGNORE_POLICY]
2727
--list-all-pkgs enabling the option will output all packages regardless of vulnerability (default: false) [$TRIVY_LIST_ALL_PKGS]
28+
--offline-scan do not issue API requests to identify dependencies (default: false) [$TRIVY_OFFLINE_SCAN]
2829
--skip-files value specify the file paths to skip traversal [$TRIVY_SKIP_FILES]
2930
--skip-dirs value specify the directories where the traversal is skipped [$TRIVY_SKIP_DIRS]
3031
--config-policy value specify paths to the Rego policy files directory, applying config files [$TRIVY_CONFIG_POLICY]

docs/getting-started/cli/image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ OPTIONS:
2727
--light light mode: it's faster, but vulnerability descriptions and references are not displayed (default: false) [$TRIVY_LIGHT]
2828
--ignore-policy value specify the Rego file to evaluate each vulnerability [$TRIVY_IGNORE_POLICY]
2929
--list-all-pkgs enabling the option will output all packages regardless of vulnerability (default: false) [$TRIVY_LIST_ALL_PKGS]
30+
--offline-scan do not issue API requests to identify dependencies (default: false) [$TRIVY_OFFLINE_SCAN]
3031
--skip-files value specify the file path to skip traversal [$TRIVY_SKIP_FILES]
3132
--skip-dirs value specify the directory where the traversal is skipped [$TRIVY_SKIP_DIRS]
3233
--cache-backend value cache backend (e.g. redis://localhost:6379) (default: "fs") [$TRIVY_CACHE_BACKEND]

docs/getting-started/cli/repo.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OPTIONS:
2525
--no-progress suppress progress bar (default: false) [$TRIVY_NO_PROGRESS]
2626
--ignore-policy value specify the Rego file to evaluate each vulnerability [$TRIVY_IGNORE_POLICY]
2727
--list-all-pkgs enabling the option will output all packages regardless of vulnerability (default: false) [$TRIVY_LIST_ALL_PKGS]
28+
--offline-scan do not issue API requests to identify dependencies (default: false) [$TRIVY_OFFLINE_SCAN]
2829
--skip-files value specify the file path to skip traversal [$TRIVY_SKIP_FILES]
2930
--skip-dirs value specify the directory where the traversal is skipped [$TRIVY_SKIP_DIRS]
3031
--help, -h show help (default: false)

docs/getting-started/cli/rootfs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ OPTIONS:
2525
--no-progress suppress progress bar (default: false) [$TRIVY_NO_PROGRESS]
2626
--ignore-policy value specify the Rego file to evaluate each vulnerability [$TRIVY_IGNORE_POLICY]
2727
--list-all-pkgs enabling the option will output all packages regardless of vulnerability (default: false) [$TRIVY_LIST_ALL_PKGS]
28+
--offline-scan do not issue API requests to identify dependencies (default: false) [$TRIVY_OFFLINE_SCAN]
2829
--skip-files value specify the file paths to skip traversal [$TRIVY_SKIP_FILES]
2930
--skip-dirs value specify the directories where the traversal is skipped [$TRIVY_SKIP_DIRS]
3031
--config-policy value specify paths to the Rego policy files directory, applying config files [$TRIVY_CONFIG_POLICY]

docs/getting-started/troubleshooting.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@ https://developer.github.com/v3/#rate-limiting
3939
$ GITHUB_TOKEN=XXXXXXXXXX trivy alpine:3.10
4040
```
4141

42+
### Maven rate limiting
43+
44+
!!! error
45+
``` bash
46+
$ trivy image ...
47+
...
48+
status 403 Forbidden from http://search.maven.org/solrsearch/select
49+
```
50+
51+
Trivy calls Maven API for better detection of JAR files, but many requests may exceed rate limiting.
52+
If it happens frequently, try the `--offline-scan` option to stop Trivy from making API requests.
53+
This option affects only vulnerability scanning. The vulnerability database and builtin policies are downloaded as usual.
54+
If you want to skip them as well, you can try `--skip-update` and `--skip-policy-update`.
55+
56+
Note that a number of vulnerabilities might be fewer than without the `--offline-scan` option.
57+
4258
### Running in parallel takes same time as series run
4359
When running trivy on multiple images simultaneously, it will take same time as running trivy in series.
4460
This is because of a limitation of boltdb.

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ require (
77
github.com/Masterminds/sprig v2.22.0+incompatible
88
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46
99
github.com/aquasecurity/bolt-fixtures v0.0.0-20200903104109-d34e7f983986
10-
github.com/aquasecurity/fanal v0.0.0-20211223181536-672696605858
11-
github.com/aquasecurity/go-dep-parser v0.0.0-20211223152202-b497b40cd9d2
10+
github.com/aquasecurity/fanal v0.0.0-20211224062610-102e2bce2240
11+
github.com/aquasecurity/go-dep-parser v0.0.0-20211224061556-d0e33761a8ab
1212
github.com/aquasecurity/go-gem-version v0.0.0-20201115065557-8eed6fe000ce
1313
github.com/aquasecurity/go-npm-version v0.0.0-20201110091526-0b796d180798
1414
github.com/aquasecurity/go-pep440-version v0.0.0-20210121094942-22b2f8951d46

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,10 +207,10 @@ github.com/aquasecurity/cfsec v0.2.2 h1:hq6MZlg7XFZsrerCv297N4HRlnJM7K6LLd/l/xCz
207207
github.com/aquasecurity/cfsec v0.2.2/go.mod h1:sUELRJqIPXTOZiHUx7TzyyFFzuk0W22IG6IWAoV8T6U=
208208
github.com/aquasecurity/defsec v0.0.37 h1:zdZndlKrW257b8VLK1UwfmXiyPuDrNA+wzBilHRk1LA=
209209
github.com/aquasecurity/defsec v0.0.37/go.mod h1:csaBEcJ3AKy44expnW0dCANEZcS/c1vcJjwBCbnKWBM=
210-
github.com/aquasecurity/fanal v0.0.0-20211223181536-672696605858 h1:K+OhavtHOe6weJpCvSDDiObrJDBk4hXtcqBBJ0mTzjE=
211-
github.com/aquasecurity/fanal v0.0.0-20211223181536-672696605858/go.mod h1:cLmcWHV2gIXcwNEOVVVoas/5wSyhIvMHJACbenvGUCg=
212-
github.com/aquasecurity/go-dep-parser v0.0.0-20211223152202-b497b40cd9d2 h1:B+lL7tKxen+aWygRCv5YRjwq08YokAEHMrTsrujURrc=
213-
github.com/aquasecurity/go-dep-parser v0.0.0-20211223152202-b497b40cd9d2/go.mod h1:mYbm6nW+oy1o7gGYngbki6y2VPUf6BPt5U7+O9C78sI=
210+
github.com/aquasecurity/fanal v0.0.0-20211224062610-102e2bce2240 h1:wxeId0nDv3i3Ih98oFZE7Q6OeNY1R+itxOpkmpbaiek=
211+
github.com/aquasecurity/fanal v0.0.0-20211224062610-102e2bce2240/go.mod h1:Uj+SCSOPxrU4xrxu9fFVvRWimkktPXv/VWzSfMx/dog=
212+
github.com/aquasecurity/go-dep-parser v0.0.0-20211224061556-d0e33761a8ab h1:/i0NsV3rYRcW0hkcCCrHmppX5rAr3rlWVIGKdeKBThU=
213+
github.com/aquasecurity/go-dep-parser v0.0.0-20211224061556-d0e33761a8ab/go.mod h1:mYbm6nW+oy1o7gGYngbki6y2VPUf6BPt5U7+O9C78sI=
214214
github.com/aquasecurity/go-gem-version v0.0.0-20201115065557-8eed6fe000ce h1:QgBRgJvtEOBtUXilDb1MLi1p1MWoyFDXAu5DEUl5nwM=
215215
github.com/aquasecurity/go-gem-version v0.0.0-20201115065557-8eed6fe000ce/go.mod h1:HXgVzOPvXhVGLJs4ZKO817idqr/xhwsTcj17CLYY74s=
216216
github.com/aquasecurity/go-npm-version v0.0.0-20201110091526-0b796d180798 h1:eveqE9ivrt30CJ7dOajOfBavhZ4zPqHcZe/4tKp0alc=

pkg/commands/app.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,12 @@ var (
225225
EnvVars: []string{"TRIVY_SKIP_DIRS"},
226226
}
227227

228+
offlineScan = cli.BoolFlag{
229+
Name: "offline-scan",
230+
Usage: "do not issue API requests to identify dependencies",
231+
EnvVars: []string{"TRIVY_OFFLINE_SCAN"},
232+
}
233+
228234
// For misconfigurations
229235
configPolicy = cli.StringSliceFlag{
230236
Name: "config-policy",
@@ -309,6 +315,7 @@ var (
309315
&ignorePolicy,
310316
&listAllPackages,
311317
&cacheBackendFlag,
318+
&offlineScan,
312319
stringSliceFlag(skipFiles),
313320
stringSliceFlag(skipDirs),
314321
}
@@ -465,6 +472,7 @@ func NewFilesystemCommand() *cli.Command {
465472
&noProgressFlag,
466473
&ignorePolicy,
467474
&listAllPackages,
475+
&offlineScan,
468476
stringSliceFlag(skipFiles),
469477
stringSliceFlag(skipDirs),
470478
stringSliceFlag(configPolicy),
@@ -499,6 +507,7 @@ func NewRootfsCommand() *cli.Command {
499507
&noProgressFlag,
500508
&ignorePolicy,
501509
&listAllPackages,
510+
&offlineScan,
502511
stringSliceFlag(skipFiles),
503512
stringSliceFlag(skipDirs),
504513
stringSliceFlag(configPolicy),
@@ -536,6 +545,7 @@ func NewRepositoryCommand() *cli.Command {
536545
&noProgressFlag,
537546
&ignorePolicy,
538547
&listAllPackages,
548+
&offlineScan,
539549
stringSliceFlag(skipFiles),
540550
stringSliceFlag(skipDirs),
541551
},
@@ -569,6 +579,7 @@ func NewClientCommand() *cli.Command {
569579
stringSliceFlag(skipDirs),
570580
stringSliceFlag(configPolicy),
571581
&listAllPackages,
582+
&offlineScan,
572583

573584
// original flags
574585
&token,

0 commit comments

Comments
 (0)