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(graph): add support for guideline field to custom graph checks #3600

Merged
merged 2 commits into from
Oct 3, 2022
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
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