RuleType
Rule types define an evaluation (and remediation) process for an individual policy check. Rule types are evaluated as part of a profile, via multiple phases of evaluation:
- Ingest data about the entity.
- Evaluate state using the specified rule definition.
- Store output from the rule evaluation.
- Remediate failed evaluations, if enabled.
- Alert the user about failed evaluations, if enabled.
Rule types can be defined using YAML syntax. Additionally, rules which use the Rego evaluator can be written using Rego syntax with the additional rule type fields recorded as Rego package metadata.
YAML Example
version: v1
type: rule_type
name: github_branch_protection
display_name: GitHub branch protection
description: Ensure protected branches are enabled.
guidance: Enable branch protection on default branch.
severity:
value: high
def:
in_entity: repository
rule_schema: {}
ingest:
type: rest
rest:
endpoint: '/repos/{{.Entity.Owner}}/{{.Entity.Name}}/branches/{{.Entity.DefaultBranch}}/protection'
parse: json
eval:
type: rego
rego:
type: deny-by-default
def: |
package minder
input.ingested.required_pull_request_reviews.required_approving_review_count >= 1
input.ingested.enforce_admins.enabled == true
input.ingested.allow_force_pushes == false
input.ingested.allow_deletions == false
Rego Example
The Minder CLI will parse rego files and extract RuleType metadata from them. It will automatically fill certain fields (such as type and version), and will promote the following fields:
| Rego field | RuleType field |
|---|---|
name | populate from filename if not present |
display_name | populate from title if not present |
def.rule_schemad | defaults to empty-object |
# METADATA
#
# name: github_branch_protection
# title: GitHub branch protection
# description: Ensure protected branches are enabled.
# custom:
# guidance: Enable branch protection on default branch.
# severity:
# value: high
# def:
# in_entity: repository
# ingest:
# type: rest
# rest:
# endpoint: '/repos/{{.Entity.Owner}}/{{.Entity.Name}}/branches/{{.Entity.DefaultBranch}}/protection'
# parse: json
# eval:
# rego:
# type: deny-by-default
package minder
import rego.v1
input.ingested.required_pull_request_reviews.required_approving_review_count >= 1
input.ingested.enforce_admins.enabled == true
input.ingested.allow_force_pushes == false
input.ingested.allow_deletions == false
Fields
note
Note that the Minder CLI uses snake_case for field names, but the OpenAPI spec (shown here) uses camelCase for names like display_name, in_entity, etc.