Skip to content

Commit 445cd2b

Browse files
simar7nikpivkin
andauthored
feat(misconf): Add support for configurable Rego error limit (#9657)
Signed-off-by: nikpivkin <nikita.pivkin@smartforce.io> Co-authored-by: nikpivkin <nikita.pivkin@smartforce.io>
1 parent 3fb8703 commit 445cd2b

21 files changed

Lines changed: 142 additions & 5 deletions

File tree

docs/docs/advanced/telemetry-flags.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
--pkg-types
2525
--quiet
2626
--redis-tls
27+
--rego-error-limit
2728
--removed-pkgs
2829
--report
2930
--scanners

docs/docs/references/configuration/cli/trivy_config.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ trivy config [flags] DIR
5858
--redis-key string redis key file location, if using redis as cache backend
5959
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
6060
--registry-token string registry token
61+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
6162
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)
6263
--report string specify a compliance report format for the output (allowed values: all,summary) (default "all")
6364
-s, --severity strings severities of security issues to be displayed

docs/docs/references/configuration/cli/trivy_filesystem.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ trivy filesystem [flags] PATH
106106
--redis-key string redis key file location, if using redis as cache backend
107107
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
108108
--registry-token string registry token
109+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
109110
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
110111
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)
111112
--report string specify a compliance report format for the output (allowed values: all,summary) (default "all")

docs/docs/references/configuration/cli/trivy_image.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ trivy image [flags] IMAGE_NAME
127127
--redis-key string redis key file location, if using redis as cache backend
128128
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
129129
--registry-token string registry token
130+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
130131
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
131132
--removed-pkgs detect vulnerabilities of removed packages (only for Alpine)
132133
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)

docs/docs/references/configuration/cli/trivy_kubernetes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ trivy kubernetes [flags] [CONTEXT]
118118
--redis-key string redis key file location, if using redis as cache backend
119119
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
120120
--registry-token string registry token
121+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
121122
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
122123
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)
123124
--report string specify a report format for the output (allowed values: all,summary) (default "all")

docs/docs/references/configuration/cli/trivy_repository.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
105105
--redis-key string redis key file location, if using redis as cache backend
106106
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
107107
--registry-token string registry token
108+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
108109
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
109110
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)
110111
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (allowed values: oci,rekor)

docs/docs/references/configuration/cli/trivy_rootfs.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ trivy rootfs [flags] ROOTDIR
108108
--redis-key string redis key file location, if using redis as cache backend
109109
--redis-tls enable redis TLS with public certificates, if using redis as cache backend
110110
--registry-token string registry token
111+
--rego-error-limit int maximum number of compile errors allowed during Rego policy evaluation (default 10)
111112
--rekor-url string [EXPERIMENTAL] address of rekor STL server (default "https://rekor.sigstore.dev")
112113
--render-cause strings specify configuration types for which the rendered causes will be shown in the table report (allowed values: terraform)
113114
--sbom-sources strings [EXPERIMENTAL] try to retrieve SBOM from the specified sources (allowed values: oci,rekor)

docs/docs/references/configuration/config-file.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,9 @@ rego:
495495
# Same as '--config-data'
496496
data: []
497497

498+
# Same as '--rego-error-limit'
499+
error-limit: 10
500+
498501
# Same as '--include-deprecated-checks'
499502
include-deprecated-checks: false
500503

docs/docs/scanner/misconfiguration/config/config.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,22 @@ This can be repeated for specifying multiple packages.
4646
trivy config --config-check ./my-check --namespaces main --namespaces user ./configs
4747
```
4848

49+
### Limiting Rego compile errors
50+
51+
By default, Trivy limits the number of compile errors allowed during Rego policy compilation.
52+
You can configure this limit using the `--rego-error-limit` flag.
53+
54+
```bash
55+
trivy config --rego-error-limit 20 ./configs
56+
```
57+
58+
This flag controls the maximum number of compile errors Trivy will tolerate before stopping the compilation.
59+
60+
If the number of compile errors exceeds this limit, Trivy will terminate the scan.
61+
You can set `--rego-error-limit 0` to enforce strict checking and disallow any compile errors.
62+
63+
The default value is defined internally via [CompileErrorLimit](https://github.com/aquasecurity/trivy/tree/{{ git.commit }}pkg/iac/rego/scanner.go).
64+
4965
### Private Terraform registries
5066
Trivy can download Terraform code from private registries.
5167
To pass credentials you must use the `TF_TOKEN_` environment variables.

pkg/commands/artifact/run.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,6 +750,7 @@ func initMisconfScannerOption(ctx context.Context, opts flag.Options) (misconf.S
750750
DisableEmbeddedPolicies: disableEmbedded,
751751
DisableEmbeddedLibraries: disableEmbedded,
752752
IncludeDeprecatedChecks: opts.IncludeDeprecatedChecks,
753+
RegoErrorLimit: opts.RegoOptions.ErrorLimit,
753754
TfExcludeDownloaded: opts.TfExcludeDownloaded,
754755
RawConfigScanners: opts.RawConfigScanners,
755756
FilePatterns: opts.FilePatterns,

0 commit comments

Comments
 (0)