feat: Implement SARIF output and add query metadata in engine #1042
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This pull request introduces
--output=sarif
feature that produces SARIF 2.1.0 logs from Conftest policy evaluations, without relying on an external SARIF library. Instead, SARIF objects are generated with a purpose-built implementation to better accommodate Conftest-specific logic, such as pass/fail/skipped/exception states, unique rule ID derivation, and multi-rule checks from single policy definitions.Implementation details
output/sarif.go
includes the core logic for a dedicated outputter that organizes policy evaluations into a SARIF run, defines rule metadata in the rules array, and emits each failure, warning, or exception as a separate SARIF result.engine.go
to inject "query" into each violation, enabling the new output to correlate results with the exactdata.main.deny
or other Rego query that triggered the violation.Documentation and Go tests with good amount of coverage included. Tested sample outputs with things like SARIF viewer and seems to work nicely.
Happy to hear feedback and make this merged in!
References
Fixes #885