Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Implement SARIF output and add query metadata in engine #1042

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

thevilledev
Copy link
Contributor

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.
  • Minimal updates in engine.go to inject "query" into each violation, enabling the new output to correlate results with the exact data.main.deny or other Rego query that triggered the violation.
  • SARIF 2.1.0 support for the best tooling coverage. Version 2.2.0 could be supported later, but IMO brings no new functionality that would matter in this case, at least in the current engine state. Comments welcome.

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

Add Static Analysis Results Interchange Format (SARIF) v2.1.0 output support
to conftest. SARIF is a standard JSON format for static analysis tools.

- SARIF v2.1.0 schema compliance
- Includes file locations and rule metadata
- Tracks execution timing and status
- Test coverage
- Documentation

Signed-off-by: Ville Vesilehto <[email protected]>
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.

Sarif Format Support
1 participant