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

feat(misconf): Add support for --cf-params for CFT #5507

Merged
merged 33 commits into from
Nov 15, 2023
Merged
Show file tree
Hide file tree
Changes from 22 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c4021ff
refactor(misconf): Update refactored dependencies
simar7 Sep 25, 2023
c74f3ac
update deps
simar7 Sep 25, 2023
88b78fa
update go mod
simar7 Sep 25, 2023
1ff26d2
update trivy-* deps
simar7 Sep 27, 2023
a96a3b6
update policy bundle path
simar7 Sep 27, 2023
b86d14e
bump defsec
simar7 Oct 11, 2023
d9342b2
update go mod
simar7 Oct 12, 2023
97b85f5
update go mod
simar7 Oct 16, 2023
98864a7
Merge branch 'main' into defsec-refactor-update
simar7 Oct 16, 2023
be682e8
go mod tidy
simar7 Oct 28, 2023
e0b3e1b
Merge branch 'main' into defsec-refactor-update
simar7 Oct 30, 2023
dc0839a
go mod tidy
simar7 Oct 30, 2023
bfdac0b
update docs
simar7 Oct 30, 2023
6f45fae
fix trivy-iac import
simar7 Oct 31, 2023
569b141
update trivy-iac to v0.5.2
simar7 Nov 1, 2023
91f949b
Merge branch 'main' into defsec-refactor-update
simar7 Nov 1, 2023
09d1775
Merge branch 'main' into defsec-refactor-update
simar7 Nov 2, 2023
e2bb9fc
pin testcontainers@v0.23.0
simar7 Nov 2, 2023
998ca85
feat(misconf): Add support for `--cf-params` for CloudFormation param…
simar7 Nov 1, 2023
9165d11
update docs
simar7 Nov 1, 2023
2ca15d9
pin testcontainers@v0.23.0
simar7 Nov 2, 2023
e59f91d
update docs
simar7 Nov 2, 2023
73de07f
go mod update
simar7 Nov 4, 2023
689f60a
rename vars
simar7 Nov 4, 2023
8b6f7a3
go mod tidy
simar7 Nov 7, 2023
8d27d95
use .WithParameterFiles()
simar7 Nov 7, 2023
62dace8
Merge branch 'main' into support-cf-params-2
simar7 Nov 10, 2023
349d3a9
go mod tidy
simar7 Nov 10, 2023
05b9d9a
refactor: use a dedicated FS for tf and CF configs
nikpivkin Nov 14, 2023
cb21634
Merge branch 'main' into support-cf-params-2
nikpivkin Nov 14, 2023
a9275bf
fix docs
simar7 Nov 15, 2023
8ae3aca
fix usage help
simar7 Nov 15, 2023
8d8d834
disable cf/tf flag where not needed
simar7 Nov 15, 2023
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
14 changes: 11 additions & 3 deletions docs/docs/coverage/iac/cloudformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@
Trivy supports the scanners listed in the table below.

| Scanner | Supported |
| :----------------: | :-------: |
|:------------------:|:---------:|
| [Misconfiguration] | ✓ |
| [Secret] | ✓ |

It supports the following formats.

| Format | Supported |
| :----: | :-------: |
|:------:|:---------:|
| JSON | ✓ |
| YAML | ✓ |

## Misconfiguration
Trivy recursively searches directories and scans all found CloudFormation files.
It evaluates properties, functions, and other elements within CloudFormation files to detect misconfigurations.

### Value Overrides
You can provide `cf-params` with path to [CloudFormation Parameters] file to Trivy to scan your CloudFormation code with parameters.

```bash
trivy conf --cf-params params.json ./infrastructure/cf
```

## Secret
The secret scan is performed on plain text files, with no special treatment for CloudFormation.

[Misconfiguration]: ../../scanner/misconfiguration/index.md
[Secret]: ../../scanner/secret.md
[Secret]: ../../scanner/secret.md
[CloudFormation Params]: https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html
2 changes: 1 addition & 1 deletion docs/docs/coverage/iac/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Trivy scans Infrastructure as Code (IaC) files for
## Supported configurations

| Config type | File patterns |
| ----------------------------------- | ----------------------------- |
|-------------------------------------|-------------------------------|
| [Kubernetes](kubernetes.md) | *.yml, *.yaml, *.json |
| [Docker](docker.md) | Dockerfile, Containerfile |
| [Terraform](terraform.md) | *.tf, *.tf.json, *.tfvars, |
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/coverage/iac/terraform.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
Trivy supports the scanners listed in the table below.

| Scanner | Supported |
| :--------------: | :-------: |
|:----------------:|:---------:|
| Misconfiguration | ✓ |
| Secret | ✓ |

It supports the following formats:

| Format | Supported |
| :-------: | :-------: |
|:---------:|:---------:|
| JSON | ✓ |
| HCL | ✓ |
| Plan JSON | ✓ |
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Docs

In this section you can find the complete reference documentation for all of the different features and settings that Trivy has to offer.
In this section you can find the complete reference documentation for all the different features and settings that Trivy has to offer.

👈 Please use the side-navigation on the left in order to browse the different topics.
3 changes: 2 additions & 1 deletion docs/docs/references/configuration/cli/trivy_aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ trivy aws [flags]
```
--account string The AWS account to scan. It's useful to specify this when reviewing cached results for multiple accounts.
--arn string The AWS ARN to show results for. Useful to filter results once a scan is cached.
--cf-params strings specify paths to override the Cloudformation parameters files
--compliance string compliance report to generate (aws-cis-1.2,aws-cis-1.4)
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
--config-policy strings specify the paths to the Rego policy files or to the directories containing them, applying config files
Expand All @@ -85,7 +86,7 @@ trivy aws [flags]
--list-all-pkgs enabling the option will output all packages regardless of vulnerability
--max-cache-age duration The maximum age of the cloud cache. Cached data will be requeried from the cloud provider if it is older than this. (default 24h0m0s)
-o, --output string output file name
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--region string AWS Region to scan
--report string specify a report format for the output (all,summary) (default "all")
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/references/configuration/cli/trivy_config.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ trivy config [flags] DIR
```
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--compliance string compliance report to generate
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
Expand All @@ -31,7 +32,7 @@ trivy config [flags] DIR
--module-dir string specify directory to the wasm modules that will be loaded (default "$HOME/.trivy/modules")
-o, --output string output file name
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trivy filesystem [flags] PATH
```
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--compliance string compliance report to generate
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
Expand Down Expand Up @@ -55,7 +56,7 @@ trivy filesystem [flags] PATH
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/references/configuration/cli/trivy_image.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ trivy image [flags] IMAGE_NAME
```
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--compliance string compliance report to generate (docker-cis)
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
Expand Down Expand Up @@ -75,7 +76,7 @@ trivy image [flags] IMAGE_NAME
-o, --output string output file name
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--platform string set platform in the form os/arch if image is multi-platform capable
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
-A, --all-namespaces fetch resources from all cluster namespaces
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--compliance string compliance report to generate (k8s-nsa,k8s-cis,k8s-pss-baseline,k8s-pss-restricted)
--components strings specify which components to scan (workload,infra) (default [workload,infra])
Expand Down Expand Up @@ -67,7 +68,7 @@ trivy kubernetes [flags] { cluster | all | specific resources like kubectl. eg:
-o, --output string output file name
--parallel int number (between 1-20) of goroutines enabled for parallel scanning (default 5)
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
--branch string pass the branch name to be scanned
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--commit string pass the commit hash to be scanned
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
Expand Down Expand Up @@ -55,7 +56,7 @@ trivy repository [flags] (REPO_PATH | REPO_URL)
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/references/configuration/cli/trivy_rootfs.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ trivy rootfs [flags] ROOTDIR
```
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--config-data strings specify paths from which data for the Rego policies will be recursively loaded
--config-policy strings specify the paths to the Rego policy files or to the directories containing them, applying config files
Expand Down Expand Up @@ -57,7 +58,7 @@ trivy rootfs [flags] ROOTDIR
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--password strings password. Comma-separated passwords allowed. TRIVY_PASSWORD should be used for security reasons.
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--policy-namespaces strings Rego namespaces
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
Expand Down
3 changes: 2 additions & 1 deletion docs/docs/references/configuration/cli/trivy_vm.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ trivy vm [flags] VM_IMAGE
--aws-region string AWS region to scan
--cache-backend string cache backend (e.g. redis://localhost:6379) (default "fs")
--cache-ttl duration cache TTL when using redis as cache backend
--cf-params strings specify paths to override the Cloudformation parameters files
--clear-cache clear image caches without scanning
--compliance string compliance report to generate
--custom-headers strings custom headers in client mode
Expand Down Expand Up @@ -51,7 +52,7 @@ trivy vm [flags] VM_IMAGE
--no-progress suppress progress bar
--offline-scan do not issue API requests to identify dependencies
-o, --output string output file name
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/defsec:0")
--policy-bundle-repository string OCI registry URL to retrieve policy bundle from (default "ghcr.io/aquasecurity/trivy-policies:0")
--redis-ca string redis ca file location, if using redis as cache backend
--redis-cert string redis certificate file location, if using redis as cache backend
--redis-key string redis key file location, if using redis as cache backend
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/scanner/misconfiguration/custom/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ As for `--namespaces` option, the detail is described as below.
If a file name matches the following file patterns, Trivy will parse the file and pass it as input to your Rego policy.

| File format | File pattern |
| ------------- | --------------------------------------------------------- |
|---------------|-----------------------------------------------------------|
| JSON | `*.json` |
| YAML | `*.yaml` and `*.yml` |
| Dockerfile | `Dockerfile`, `Dockerfile.*`, and `*.Dockerfile` |
Expand Down Expand Up @@ -125,7 +125,7 @@ schema that will be used is based on the input document type. It is recommended
correct and do not reference incorrect properties/values.

| Field name | Allowed values | Default value | In table | In JSON |
| -------------------------- | ----------------------------------------------------------------- | :--------------------------: | :--------------: | :--------------: |
|----------------------------|-------------------------------------------------------------------|:----------------------------:|:----------------:|:----------------:|
| title | Any characters | N/A | :material-check: | :material-check: |
| description | Any characters | | :material-close: | :material-check: |
| schemas.input | `schema["kubernetes"]`, `schema["dockerfile"]`, `schema["cloud"]` | (applied to all input types) | :material-close: | :material-close: |
Expand Down
8 changes: 4 additions & 4 deletions docs/docs/scanner/misconfiguration/custom/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Policies can be defined with custom schemas that allow inputs to be verified against them. Adding a policy schema
enables Trivy to show more detailed error messages when an invalid input is encountered.

In Trivy we have been able to define a schema for a [Dockerfile](https://github.com/aquasecurity/defsec/blob/master/pkg/rego/schemas/dockerfile.json).
In Trivy we have been able to define a schema for a [Dockerfile](https://github.com/aquasecurity/trivy-iac/blob/main/pkg/rego/schemas/dockerfile.json)
Without input schemas, a policy would be as follows:

!!! example
Expand Down Expand Up @@ -50,9 +50,9 @@ Now if this policy is evaluated against, a more descriptive error will be availa

Currently, out of the box the following schemas are supported natively:

1. [Docker](https://github.com/aquasecurity/defsec/blob/master/pkg/rego/schemas/dockerfile.json)
2. [Kubernetes](https://github.com/aquasecurity/defsec/blob/master/pkg/rego/schemas/kubernetes.json)
3. [Cloud](https://github.com/aquasecurity/defsec/blob/master/pkg/rego/schemas/cloud.json)
1. [Docker](https://github.com/aquasecurity/trivy-iac/blob/main/pkg/rego/schemas/dockerfile.json)
2. [Kubernetes](https://github.com/aquasecurity/trivy-iac/blob/main/pkg/rego/schemas/kubernetes.json)
3. [Cloud](https://github.com/aquasecurity/trivy-iac/blob/main/pkg/rego/schemas/cloud.json)


## Custom Policies with Custom Schemas
Expand Down
4 changes: 2 additions & 2 deletions docs/docs/scanner/misconfiguration/custom/testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ For more details, see [Policy Testing][opa-testing].
}
```

To write tests for custom policies, you can refer to existing tests under [defsec][defsec].
To write tests for custom policies, you can refer to existing tests under [trivy-policies][trivy-policies].

## Go testing
[Fanal][fanal] which is a core library of Trivy can be imported as a Go library.
Expand Down Expand Up @@ -85,6 +85,6 @@ The following example stores allowed and denied configuration files in a directo
`Dockerfile.allowed` has one successful result in `Successes`, while `Dockerfile.denied` has one failure result in `Failures`.

[opa-testing]: https://www.openpolicyagent.org/docs/latest/policy-testing/
[defsec]: https://github.com/aquasecurity/defsec
[defsec]: https://github.com/aquasecurity/trivy-policies/tree/main
[table]: https://github.com/golang/go/wiki/TableDrivenTests
[fanal]: https://github.com/aquasecurity/fanal
Loading