Integrate SARIF and Dry-Run Remediation in CI¶
Read Reference Index before you start.
Prerequisites¶
- Make sure that Python
3.8+exists on the CI runner. - Confirm
security-events: writepermission for SARIF upload.
Safety Instructions¶
CAUTION: Review dry-run diffs and SQL before production runs. Unchecked edits can restart services or lock administrative accounts.
Procedure¶
- Run an audit with
--format sarif:
- Validate the SARIF v2.1.0 output:
python3 -c "import json, sarif_exporter as s; ok, m = s.validate_sarif_document(json.load(open('reports/rhel9.sarif'))); print(m); assert ok"
- Generate a JSON report for dry-run remediation:
- Generate deterministic dry-run remediation diffs or Ansible tasks:
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format diff --remediation-output reports/pg16.diff
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format ansible --remediation-output reports/pg16.yml
- Upload
reports/rhel9.sarifin GitHub Actions withgithub/codeql-action/upload-sarif.
NOTE: --remediate-dry-run runs zero OS commands and zero SQL queries.
Verification¶
- Confirm that
validate_sarif_documentprintsValid SARIF v2.1.0. - Confirm that JSON dry-run output sets
"dry_run": true:
python3 audit_cis.py --remediate-dry-run --from-report reports/pg16.json --remediation-format json | head -n 5
Rollback¶
- Disable the SARIF upload step.
- Delete stale
.sarifand.difffiles fromreports/. - Run
python3 -m unittest tests/test_sarif_exporter.py -v.