Skip to content

Remove embedded Rego libraries and rely on backend delivery#231

Merged
whitemerch merged 1 commit into
mainfrom
chakib.hamie/remove_embedded_libraries
Jul 2, 2026
Merged

Remove embedded Rego libraries and rely on backend delivery#231
whitemerch merged 1 commit into
mainfrom
chakib.hamie/remove_embedded_libraries

Conversation

@whitemerch

@whitemerch whitemerch commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Motivation

Rego libraries were previously embedded in the scanner binary via go:embed and served as a fallback when the backend was unavailable. The libraries are now managed and pushed to the backen, making the embedded copy redundant and a source of drift. This PR removes the embedded libraries entirely and makes the backend the sole delivery path, with --libraries-path as an explicit local override for development or custom deployments.

Changes

Library delivery

Removed all files under assets/ (18 .rego files, common.json, and 4 *_test.rego files). The assets package no longer embeds anything. The OPA unit tests for library helper functions have been ported to the default-rules repository.

Backend source

DatadogSource.GetQueryLibrary now normalizes platform names to lowercase on both storage and lookup, fixing a case mismatch (cloudFormation vs cloudformation) that was previously masked by the embedded fallback. The auto-fallback to embedded libraries in NewDatadogSource is removed; the only library fallback path is when --libraries-path is explicitly set.

Filesystem source

FilesystemSource.GetQueryLibrary now reads .rego and .json files directly from disk instead of delegating to the embedded assets package.

Scan wiring

pkg/scan/scan.go only adds a local library fallback source when ChangedDefaultLibrariesPath is true (i.e. --libraries-path was explicitly passed). Without that flag, the scanner always fetches libraries from the backend.

CLI commands

list-queries, test-rules, and custom Rego evaluation (custom.go) all use DatadogSource for library access instead of the embedded filesystem.

E2E tests

Removed useLocalLibraries helper and the testdata/libraries/ snapshot. E2E tests now fetch libraries from the public backend endpoint (/api/v2/static-analysis/iac/libraries), which requires no authentication.

Tooling

Removed .github/scripts/update_versions/, the update_software_versions workflow, rules_generator/classes/CodeProcessor.py methods that read/wrote common.json now raise NotImplementedError (are they even used? Anyways if so they would need to be ported separetly, and in a different way)

Author Checklist

  • I have reviewed my own PR.
  • I have added or updated relevant unit tests where necessary.
  • 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

Build the binary and run a scan against any Terraform fixture, libraries are now fetched from the backend automatically:

go build -o bin/datadog-iac-scanner ./cmd/scanner
./bin/datadog-iac-scanner scan -p <path-to-terraform-dir>

Confirm no library not found errors appear. To test the explicit local override path:

./bin/datadog-iac-scanner serve --libraries-path <path-to-local-libraries>

Blast Radius

Affects the scanner binary only. The backend library endpoint is public and requires no authentication

Additional Notes

Companion PR in default-rules: https://github.com/DataDog/datadog-iac-scanner-default-rules/pull/71 (ports the OPA library tests, fixes tool.sh test to read libraries from disk, bumps scanner dependency to v1.7.0).

I submit this contribution under the Apache-2.0 license.

@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Jul 2, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 68.75%
Overall Coverage: 50.55% (-0.02%)

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

@whitemerch
whitemerch marked this pull request as ready for review July 2, 2026 08:54
@whitemerch
whitemerch requested a review from a team as a code owner July 2, 2026 08:54
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@whitemerch
whitemerch force-pushed the chakib.hamie/remove_embedded_libraries branch 3 times, most recently from 46a3bd5 to 06820e0 Compare July 2, 2026 09:08
@whitemerch
whitemerch marked this pull request as draft July 2, 2026 09:08
@whitemerch
whitemerch marked this pull request as ready for review July 2, 2026 09:11
@whitemerch
whitemerch force-pushed the chakib.hamie/remove_embedded_libraries branch from 06820e0 to c7c46a8 Compare July 2, 2026 09:11
chatgpt-codex-connector[bot]

This comment was marked as resolved.

@whitemerch
whitemerch force-pushed the chakib.hamie/remove_embedded_libraries branch from c7c46a8 to 87f325a Compare July 2, 2026 09:21
ChouraquiBen
ChouraquiBen previously approved these changes Jul 2, 2026

@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.

A few comments 🙏

Comment thread pkg/engine/source/datadog.go Outdated
}
}

func testLibSource() source.QueriesSource { return &stubLibSource{} }

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: Why not use the &stubLibSource directly in the functions' arguments

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.

Because it is called 24 times in the file

Comment thread rules_generator/classes/CodeProcessor.py
Comment thread pkg/engine/source/datadog.go Outdated
@whitemerch
whitemerch force-pushed the chakib.hamie/remove_embedded_libraries branch 3 times, most recently from 6026fe9 to 72c2727 Compare July 2, 2026 10:45
@whitemerch
whitemerch force-pushed the chakib.hamie/remove_embedded_libraries branch from 72c2727 to 49fb51a Compare July 2, 2026 11:01

@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.

LGTM

@whitemerch
whitemerch merged commit 9fae8e6 into main Jul 2, 2026
20 checks passed
@whitemerch
whitemerch deleted the chakib.hamie/remove_embedded_libraries branch July 2, 2026 11:12
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