Skip to content

Commit

Permalink
feat(graph): add support for guideline field to custom graph checks (#…
Browse files Browse the repository at this point in the history
…3600)

* add support for guideline to graph checks

* add docs
  • Loading branch information
gruebel authored Oct 3, 2022
1 parent 162651d commit 62e5346
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions checkov/common/checks_infra/checks_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ def parse_raw_check(self, raw_check: Dict[str, Dict[str, Any]], **kwargs: Any) -
check.name = raw_check.get("metadata", {}).get("name", "")
check.category = raw_check.get("metadata", {}).get("category", "")
check.frameworks = raw_check.get("metadata", {}).get("frameworks", [])
check.guideline = raw_check.get("metadata", {}).get("guideline")
solver = self.get_check_solver(check)
check.set_solver(solver)

Expand Down
14 changes: 13 additions & 1 deletion docs/3.Custom Policies/YAML Custom Policies.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ The Metadata includes:
* Policy Name
* ID - `CKV2_<provider>_<number>`
* Category
* Guideline (optional)

The possible values for category are:

Expand All @@ -32,14 +33,25 @@ The possible values for category are:
* CONVENTION
* SECRETS
* KUBERNETES
* APPLICATION_SECURITY
* SUPPLY_CHAIN
* API_SECURITY

```yaml
metadata:
id: "CKV2_CUSTOM_1"
name: "Ensure bucket has versioning and owner tag"
category: "BACKUP_AND_RECOVERY"
guideline: "https://docs.bridgecrew.io/docs/ckv2_custom_1"
```
## Policy Definition
The policy definition consists of:
* **Definition Block(s)** - either *Attribute Block(s)* or *Connection State Block(s)* or both
* **Logical Operator(s)** (optional)
* **Filter**(optional)
* **Filter** (optional)
The top level object under `definition` must be a single object (not a list). It can be an attribute block, a connection block, or a logical operator (`and`, `or`, `not`).

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ metadata:
id: "CKV2_CUSTOM_1"
name: "Ensure bucket has versioning and owner tag"
category: "BACKUP_AND_RECOVERY"
guideline: "https://docs.bridgecrew.io/docs/ckv2_custom_1"
definition:
and:
- cond_type: "attribute"
Expand Down
4 changes: 4 additions & 0 deletions tests/terraform/runner/test_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ def test_runner_extra_yaml_check(self):

self.assertEqual(passing_custom, 0)
self.assertEqual(failed_custom, 3)

graph_record = next(record for record in report.failed_checks if record.check_id == "CKV2_CUSTOM_1")
self.assertEqual(graph_record.guideline, "https://docs.bridgecrew.io/docs/ckv2_custom_1")

# Remove external checks from registry.
runner.graph_registry.checks[:] = [check for check in runner.graph_registry.checks if "CUSTOM" not in check.id]

Expand Down

0 comments on commit 62e5346

Please sign in to comment.