Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions docs/docs/configuration/reporting.md
Original file line number Diff line number Diff line change
Expand Up @@ -617,19 +617,15 @@ For more details, please check [here](../plugin/user-guide.md#output-mode-suppor
To generate multiple reports, you can generate the JSON report first and convert it to other formats with the `convert` subcommand.

```shell
$ trivy image --format json -o result.json --list-all-pkgs debian:11
$ trivy image --format json -o result.json debian:11
$ trivy convert --format cyclonedx --output result.cdx result.json
```

!!! note
Please note that if you want to convert to a format that requires a list of packages,
such as SBOM, you need to add the `--list-all-pkgs` flag when outputting in JSON.

[Filtering options](./filtering.md) such as `--severity` are also available with `convert`.

```shell
# Output all severities in JSON
$ trivy image --format json -o result.json --list-all-pkgs debian:11
$ trivy image --format json -o result.json debian:11

# Output only critical issues in table format
$ trivy convert --format table --severity CRITICAL result.json
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/references/configuration/cli/trivy_convert.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trivy convert [flags] RESULT_JSON

```
# report conversion
$ trivy image --format json --output result.json --list-all-pkgs debian:11
$ trivy image --format json --output result.json debian:11
$ trivy convert --format cyclonedx --output result.cdx result.json

```
Expand All @@ -37,7 +37,7 @@ trivy convert [flags] RESULT_JSON
-h, --help help for convert
--ignore-policy string specify the Rego file path to evaluate each vulnerability
--ignorefile string specify .trivyignore file (default ".trivyignore")
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
-o, --output string output file name
--output-plugin-arg string [EXPERIMENTAL] output plugin arguments
--report string specify a report format for the output (allowed values: all,summary) (default "all")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ trivy filesystem [flags] PATH
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--license-confidence-level float specify license classifier's confidence level (default 0.9)
--license-full eagerly look for licenses in source code headers and license files
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
--no-progress suppress progress bar
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/references/configuration/cli/trivy_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ trivy image [flags] IMAGE_NAME
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--license-confidence-level float specify license classifier's confidence level (default 0.9)
--license-full eagerly look for licenses in source code headers and license files
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--max-image-size string [EXPERIMENTAL] maximum image size to process, specified in a human-readable format (e.g., '44kB', '17MB'); an error will be returned if the image exceeds this size
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ trivy kubernetes [flags] [CONTEXT]
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--k8s-version string specify k8s version to validate outdated api by it (example: 1.21.0)
--kubeconfig string specify the kubeconfig file path to use
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--no-progress suppress progress bar
--node-collector-imageref string indicate the image reference for the node-collector scan job (default "ghcr.io/aquasecurity/node-collector:0.3.1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--license-confidence-level float specify license classifier's confidence level (default 0.9)
--license-full eagerly look for licenses in source code headers and license files
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
--no-progress suppress progress bar
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/references/configuration/cli/trivy_rootfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ trivy rootfs [flags] ROOTDIR
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--license-confidence-level float specify license classifier's confidence level (default 0.9)
--license-full eagerly look for licenses in source code headers and license files
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
--no-progress suppress progress bar
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/references/configuration/cli/trivy_sbom.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ trivy sbom [flags] SBOM_PATH
--ignored-licenses strings specify a list of license to ignore
--ignorefile string specify .trivyignore file (default ".trivyignore")
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--no-progress suppress progress bar
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/references/configuration/cli/trivy_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ trivy vm [flags] VM_IMAGE
--ignorefile string specify .trivyignore file (default ".trivyignore")
--include-non-failures include successes, available with '--scanners misconfig'
--java-db-repository strings OCI repository(ies) to retrieve trivy-java-db in order of priority (default [mirror.gcr.io/aquasec/trivy-java-db:1,ghcr.io/aquasecurity/trivy-java-db:1])
--list-all-pkgs output all packages in the JSON report regardless of vulnerability
--list-all-pkgs output all packages in the JSON report regardless of vulnerability (default true)
--misconfig-scanners strings comma-separated list of misconfig scanners to use for misconfiguration scanning (default [azure-arm,cloudformation,dockerfile,helm,kubernetes,terraform,terraformplan-json,terraformplan-snapshot])
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
--no-progress suppress progress bar
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/references/configuration/config-file.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ ignore-policy: ""
ignorefile: ".trivyignore"

# Same as '--list-all-pkgs'
list-all-pkgs: false
list-all-pkgs: true

# Same as '--output'
output: ""
Expand Down
6 changes: 3 additions & 3 deletions docs/docs/scanner/vulnerability.md
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ Total: 7 (UNKNOWN: 0, LOW: 1, MEDIUM: 1, HIGH: 3, CRITICAL: 2)
</details>

!!! info
This flag filters the packages themselves, so it also affects the `--list-all-pkgs` option and SBOM generation.
This flag filters the packages themselves, so it also affects the list of detected packages in JSON reports and SBOM generation.

### Filtering by Package Relationships

Expand All @@ -313,7 +313,7 @@ The available relationships may vary depending on the ecosystem.
To see which relationships are supported for a particular project, you can use the JSON output format and check the `Relationship` field:

```
$ trivy repo -f json --list-all-pkgs /path/to/project
$ trivy repo -f json /path/to/project
```

To scan only the root package and its direct dependencies, you can use the flag as follows:
Expand All @@ -325,7 +325,7 @@ $ trivy repo --pkg-relationships root,direct /path/to/project
By default, all relationships are included in the scan.

!!! info
This flag filters the packages themselves, so it also affects the `--list-all-pkgs` option and SBOM generation.
This flag filters the packages themselves, so it also affects the list of detected packages in JSON reports and SBOM generation.

!!! warning
As it may not provide a complete package list, `--pkg-relationships` cannot be used with `--dependency-tree`, `--vex` or SBOM generation.
Expand Down
4 changes: 2 additions & 2 deletions integration/client_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -679,8 +679,8 @@ func setupClient(t *testing.T, c csArgs, addr, cacheDir string) []string {
osArgs = append(osArgs, "--format", "json")
}

if c.ListAllPackages {
osArgs = append(osArgs, "--list-all-pkgs")
if !c.ListAllPackages {
osArgs = append(osArgs, "--list-all-pkgs=false")
}

if c.IgnoreUnfixed {
Expand Down
3 changes: 3 additions & 0 deletions integration/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ severity:
osArgs := []string{
"--format",
"json",
"--list-all-pkgs=false",
"--cache-dir",
cacheDir,
"--skip-db-update",
Expand All @@ -180,6 +181,7 @@ severity:

t.Setenv("TRIVY_OUTPUT", outputFile)
t.Setenv("TRIVY_FORMAT", "json")
t.Setenv("TRIVY_LIST_ALL_PKGS", "false")
t.Setenv("TRIVY_CACHE_DIR", cacheDir)
t.Setenv("TRIVY_SKIP_DB_UPDATE", "true")
t.Setenv("TRIVY_SKIP_POLICY_UPDATE", "true")
Expand All @@ -204,6 +206,7 @@ severity:
configFile := tt.args.configFile
configFile += fmt.Sprintf(`
format: json
list-all-pkgs: false
output: %s
cache:
dir: %s
Expand Down
4 changes: 2 additions & 2 deletions integration/convert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ func TestConvert(t *testing.T) {
osArgs = append(osArgs, "--show-suppressed")
}

if tt.args.listAllPkgs {
osArgs = append(osArgs, "--list-all-pkgs")
if !tt.args.listAllPkgs {
osArgs = append(osArgs, "--list-all-pkgs=false")
}

// Set up the output file
Expand Down
1 change: 1 addition & 0 deletions integration/docker_engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ func TestDockerEngine(t *testing.T) {
"image",
"--skip-update",
"--format=json",
"--list-all-pkgs=false",
}

if tt.ignoreUnfixed {
Expand Down
1 change: 1 addition & 0 deletions integration/module_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ func TestModule(t *testing.T) {
"--ignore-unfixed",
"--format",
"json",
"--list-all-pkgs=false",
"--skip-db-update",
"--offline-scan",
"--quiet",
Expand Down
1 change: 1 addition & 0 deletions integration/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ func scan(t *testing.T, imageRef name.Reference, baseDir string, opt registryOpt
"image",
"--format",
"json",
"--list-all-pkgs=false",
"--image-src",
"remote",
"--skip-db-update",
Expand Down
4 changes: 2 additions & 2 deletions integration/repo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -626,8 +626,8 @@ func buildArgs(t *testing.T, cacheDir, command string, format types.Format, test
"--vuln-severity-source", strings.Join(testArgs.vulnSeveritySources, ","),
)
}
if testArgs.listAllPkgs {
osArgs = append(osArgs, "--list-all-pkgs")
if !testArgs.listAllPkgs {
osArgs = append(osArgs, "--list-all-pkgs=false")
}
if testArgs.includeDevDeps {
osArgs = append(osArgs, "--include-dev-deps")
Expand Down
1 change: 1 addition & 0 deletions integration/sbom_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ func TestSBOM(t *testing.T) {
tt.args.format,
"--scanners",
scanners,
"--list-all-pkgs=false",
}

// Set up the output file
Expand Down
4 changes: 4 additions & 0 deletions integration/standalone_tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,7 @@ func TestTar(t *testing.T) {
"--format",
string(tt.args.Format),
"--skip-db-update",
"--list-all-pkgs=false",
}

if tt.args.IgnoreUnfixed {
Expand Down Expand Up @@ -518,6 +519,7 @@ func TestTarWithEnv(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Setenv("TRIVY_FORMAT", tt.testArgs.Format)
t.Setenv("TRIVY_LIST_ALL_PKGS", "false")
t.Setenv("TRIVY_CACHE_DIR", cacheDir)
t.Setenv("TRIVY_QUIET", "true")
t.Setenv("TRIVY_SKIP_UPDATE", "true")
Expand Down Expand Up @@ -554,6 +556,7 @@ func TestTarWithConfigFile(t *testing.T) {
input: "testdata/fixtures/images/alpine-39.tar.gz",
configFile: `quiet: true
format: json
list-all-pkgs: false
severity:
- HIGH
- CRITICAL
Expand All @@ -570,6 +573,7 @@ cache:
input: "testdata/fixtures/images/debian-buster.tar.gz",
configFile: `quiet: true
format: json
list-all-pkgs: false
vulnerability:
ignore-unfixed: true
cache:
Expand Down
1 change: 1 addition & 0 deletions integration/vm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ func TestVM(t *testing.T) {
"--skip-db-update",
"--format",
tt.args.format,
"--list-all-pkgs=false",
}

// Decompress the gzipped image file
Expand Down
2 changes: 1 addition & 1 deletion pkg/commands/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,7 @@ func NewConvertCommand(globalFlags *flag.GlobalFlagGroup) *cobra.Command {
GroupID: groupUtility,
Short: "Convert Trivy JSON report into a different format",
Example: ` # report conversion
$ trivy image --format json --output result.json --list-all-pkgs debian:11
$ trivy image --format json --output result.json debian:11
$ trivy convert --format cyclonedx --output result.cdx result.json
`,
PreRunE: func(cmd *cobra.Command, args []string) error {
Expand Down
6 changes: 4 additions & 2 deletions pkg/flag/report_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var (
ListAllPkgsFlag = Flag[bool]{
Name: "list-all-pkgs",
ConfigName: "list-all-pkgs",
Default: true,
Usage: "output all packages in the JSON report regardless of vulnerability",
TelemetrySafe: true,
}
Expand Down Expand Up @@ -228,8 +229,9 @@ func (f *ReportFlagGroup) ToOptions(opts *Options) error {
}

// "--list-all-pkgs" option is unavailable with other than "--format json".
// If user specifies "--list-all-pkgs" with "--format table" or other formats, we should warn it.
if listAllPkgs && format != types.FormatJSON {
// If user explicitly specifies "--list-all-pkgs" with "--format table" or other formats, we should warn it.
// We check if the flag was explicitly set by the user to avoid warning when using the default value.
if f.ListAllPkgs.IsSet() && listAllPkgs && format != types.FormatJSON {
log.Warn(`"--list-all-pkgs" is only valid for the JSON format, for other formats a list of packages is automatically included.`)
}

Expand Down
Loading