Skip to content

Default rule engine to Rego v1#179

Merged
whitemerch merged 1 commit into
mainfrom
chakib.hamie/default_engine_rego_v1
Jun 11, 2026
Merged

Default rule engine to Rego v1#179
whitemerch merged 1 commit into
mainfrom
chakib.hamie/default_engine_rego_v1

Conversation

@whitemerch

@whitemerch whitemerch commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Motivation

Rego v1 is the current OPA syntax and is the syntax expected for future custom IaC rules. This PR updates the scanner engine and embedded rule assets so generated and authored rules can use Rego v1 directly.

Changes

Rule engine

The engine now prepares rules with Rego v1 enabled and parses coverage modules with Rego v1 parser options. The compatibility query shim was updated to v1 syntax while preserving support for the existing result contract.

Embedded Rego assets

Shared libraries, library tests, and scanner test fixtures were migrated to Rego v1 syntax. Removed builtins were replaced with equivalent rule logic where needed.

Author Checklist

  • I have reviewed my own PR.
  • I have added or updated relevant unit tests where necessary. If no tests are added, I've explained why.
  • All new and existing tests pass.
  • I have tested my changes on staging (if applicable).
  • I have updated any relevant documentation (if applicable).

QA Instruction

  1. opa test assets/libraries/
  2. go build ./...
  3. go test $(go list ./... | grep -v e2e) -count=1
  4. ./tool.sh test in the companion default-rules repo with a local workspace replacement pointing at this branch (PASS: 1397 rules).
  5. ./tool.sh test in the companion default-rules repo with the released scanner dependency (github.com/DataDog/datadog-iac-scanner v1.4.0) also passed (PASS: 1397 rules).

Deployment order

  1. Merge the companion default-rules PR (https://github.com/DataDog/datadog-iac-scanner-default-rules/pull/31) and push the rules to production. Wait for full prod propagation.
  2. Merge this PR and cut a release.
  3. Bump the scanner binary version in iac-scanning in dd-source and deploy.

Do not deploy this binary before step 1 is complete in production. The v1-default engine rejects v0-syntax rules, so all rules must be migrated first.

Blast Radius

This impacts scanner rule compilation and embedded Rego libraries. Existing default rules are covered by the companion rules migration, and custom rules are not yet released.

Additional Notes

Companion default-rules PR: https://github.com/DataDog/datadog-iac-scanner-default-rules/pull/31

I submit this contribution under the Apache-2.0 license.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jun 10, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 20.00%
Overall Coverage: 47.96% (-0.01%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: fdb17b0 | Docs | Datadog PR Page | Give us feedback!

@whitemerch
whitemerch force-pushed the chakib.hamie/default_engine_rego_v1 branch from 1e7832e to da7fb03 Compare June 10, 2026 12:10
@whitemerch
whitemerch force-pushed the chakib.hamie/default_engine_rego_v1 branch from da7fb03 to fdb17b0 Compare June 10, 2026 12:14
@whitemerch
whitemerch marked this pull request as ready for review June 10, 2026 12:45
@whitemerch
whitemerch requested a review from a team as a code owner June 10, 2026 12:45

@ChouraquiBen ChouraquiBen left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: it would've made the review easier if the PR had been split between the formatting, the changes in the regos to make them have the v1 syntax and one for the changes in the go code.

I left a comment that may be naive, correct me if I am wrong.

result.path == "spec"
result.spec.containers[0].name == "test"
test_get_spec_info_job_template if {
resource := {"spec": {"job_template": {"spec": {"template": {"spec": {"containers": [{"name": "test"}]}}}}}}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: imho, I preferred the previous formatting

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's less readable, but this is opa fmt output, overriding it manually would immediately cause the test-rego-libraries check to fail

Comment thread pkg/engine/inspector.go
rego.Module("Common", q.commonLibrary.LibraryCode),
rego.Module("Generic", platformGeneralQuery.LibraryCode),
rego.Module(query.Query, query.Content),
rego.Module("dd_iac_compat.rego", utils.RegoCompatShim),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Isn't it possible to just add the rego version here to declare it in the files just like you did with the regoshim? This would be convenient to write import rego.v1 only once here

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rules still need to use the v1 format, so no, it would not be enough

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I am planning on cleaning up afterwards

@whitemerch
whitemerch merged commit 3d4b57f into main Jun 11, 2026
20 checks passed
@whitemerch
whitemerch deleted the chakib.hamie/default_engine_rego_v1 branch June 11, 2026 08:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants