For the complete documentation index, see llms.txt. This page is also available as Markdown.

Custom Rules Quickstart

ORL Rules are YAML-like files that drive the orl engine to modify files within a workspace.

Step 1. Clone Rattleback

Rattleback includes some sample code that can be used to run checks against. We will use it for this example.

git clone git@github.com:Gomboc-AI/rattleback.git

Step 2. Create a Rule

Next, let's create a simple rule that ensures aws_s3_bucket Terraform resources are tagged. Don't worry too much about the details at this point, we'll explain it below.

Create a ./rules directory and write the following as ./rules/enforce_aws_s3_bucket_tagging.orl.

type: Ruleset
version: v1
metadata:
  annotations:
    purpose: tagging
  priority: 100
  name: ensure-s3-buckets-are-tagged
  display_name: Ensure S3 Buckets are tagged
  description: |
    ## Description

    All buckets have to be tagged according to the source of truth.
spec:
  template:
    language: terraform
    audit_language: ast
  rules:
    - name: ensure-tag-exists
      audit: |
        {{ aResource("aws_s3_bucket", aMissingAttribute("tags")) }}
      remediation:
        - command: insert_after
          path: body
          flags:
            prefix: "\n\n"
            indent: "  "
          value: |
            tags = {
              source = "rattleback"
            }

Step 3: Remediate

The ORL engine is provided as a Docker container. It can be executed with the appropriate mount points to load the rules and remediate files.

After running the command, main.tf is modified to include a tags attribute for the uut resource with source = "rattleback", just as specified by the rule. The resulting git diff would look like this:

orl remediate supports a --dry-run option which will write the changed files to the terminal instead of disk. This can help in developing rules as you don't need to run git restore to undo the changes and try again.

The Rule Explained

Here is a fully annotated version of the Rule.

Further Reading

Last updated