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

fix: update paths to checks #52

Merged
merged 1 commit into from
Jan 10, 2024
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: 4 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ First of all, you should check if the provider your rule targets is supported by

Next up, you'll need to check if the properties you want to target are supported, and if not, add support for them. The guide on [Adding Support for a New Service](https://github.com/aquasecurity/defsec/blob/master/CONTRIBUTING.md#adding-support-for-a-new-service) covers adding new properties.

At last, it's time to write your rule code! Rules are defined using _OPA Rego_. You can find a number of examples in the `rules/cloud/policies` directory. The [OPA documentation](https://www.openpolicyagent.org/docs/latest/policy-language/) is a great place to start learning Rego. You can also check out the [Rego Playground](https://play.openpolicyagent.org/) to experiment with Rego, and [join the OPA Slack](https://slack.openpolicyagent.org/).
At last, it's time to write your rule code! Rules are defined using _OPA Rego_. You can find a number of examples in the `checks/cloud` directory. The [OPA documentation](https://www.openpolicyagent.org/docs/latest/policy-language/) is a great place to start learning Rego. You can also check out the [Rego Playground](https://play.openpolicyagent.org/) to experiment with Rego, and [join the OPA Slack](https://slack.openpolicyagent.org/).

Create a new file in `rules/cloud/policies` with the name of your rule. You should nest it in the existing directory structure as applicable. The package name should be in the format `builtin.PROVIDER.SERVICE.ID`, e.g. `builtin.aws.rds.aws0176`.
Create a new file in `checks/cloud` with the name of your rule. You should nest it in the existing directory structure as applicable. The package name should be in the format `builtin.PROVIDER.SERVICE.ID`, e.g. `builtin.aws.rds.aws0176`.

Running `make id` will provide you with the next available _ID_ for your rule. You can use this ID in your rule code to identify it.

Expand Down Expand Up @@ -53,7 +53,7 @@ deny[res] {
}
```

In fact, this is the code for an actual rule. You can find it in `rules/cloud/policies/aws/rds/enable_iam_auth.rego`.
In fact, this is the code for an actual rule. You can find it in `checks/cloud/aws/rds/enable_iam_auth.rego`.

The metadata is the top section that starts with `# METADATA`, and is fairly verbose. You can copy and paste from another rule as a starting point. This format is effectively _yaml_ within a Rego comment, and is [defined as part of Rego itself](https://www.openpolicyagent.org/docs/latest/policy-language/#metadata).

Expand Down Expand Up @@ -88,7 +88,7 @@ The rule should return a result, which can be created using `result.new` (this f

In the example above, you'll notice properties are being accessed from the `input.aws` object. The full set of schemas containing all of these properties is [available here](https://github.com/aquasecurity/defsec/tree/master/pkg/rego/schemas). You can match the schema name to the type of input you want to scan.

You should also write a test for your rule(s). There are many examples of these in the `rules/cloud/policies` directory.
You should also write a test for your rule(s). There are many examples of these in the `checks/cloud` directory.

Finally, you'll want to generate documentation for your newly added rule. Please run `make docs` to generate the documentation for your new policy and submit a PR for us to take a look at.

Expand Down
4 changes: 2 additions & 2 deletions checks/cloud/aws/rds/disable_public_access.rego
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
# - service: rds
# provider: aws
# terraform:
# good_examples: "rules/cloud/policies/aws/rds/disable_public_access.tf.go"
# good_examples: "checks/cloud/aws/rds/disable_public_access.tf.go"
# cloud_formation:
# good_examples: "rules/cloud/policies/aws/rds/disable_public_access.cf.go"
# good_examples: "checks/cloud/aws/rds/disable_public_access.cf.go"

package builtin.aws.rds.aws0180

Expand Down
4 changes: 2 additions & 2 deletions checks/cloud/aws/s3/enable_logging.rego
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
# - service: s3
# provider: aws
# terraform:
# good_examples: "rules/cloud/policies/aws/s3/enable_bucket_logging.tf.go"
# good_examples: "checks/cloud/aws/s3/enable_bucket_logging.tf.go"
# links: "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/s3_bucket"
# cloud_formation:
# good_examples: "rules/cloud/policies/aws/s3/enable_bucket_logging.cf.go"
# good_examples: "checks/cloud/aws/s3/enable_bucket_logging.cf.go"
package builtin.aws.s3.aws0089

deny[res] {
Expand Down