DONT MERGE: feat: add kosli attest sarif command#838
DONT MERGE: feat: add kosli attest sarif command#838AlexKantor87 wants to merge 4 commits intomainfrom
kosli attest sarif command#838Conversation
The package parses generic SARIF v2.1.0 (used by Snyk, Checkov, Trivy, Semgrep, etc.), not Snyk-specifically. Rename to reflect the actual scope ahead of adding a first-class `kosli attest sarif` command that will share this parser. No behaviour change: the snyk attestation wire format keeps the `snyk_results` JSON key, and the snyk command continues to invoke the shared parser via its new name (`sarif.ProcessSarifResultFile`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
A first-class SARIF attestation type, parallel to `attest snyk`, that:
- Accepts SARIF v2.1.0 from any compatible scanner (Checkov, Trivy,
Semgrep, Snyk, CodeQL, etc.) and reports the parsed findings to Kosli.
- Surfaces the tool name and version dynamically from the SARIF report's
`runs[0].tool.driver` fields rather than hardcoding a label.
- Adds a `-C, --compliant` flag (default true, mirroring `attest generic`)
so the caller controls whether the attestation is compliant. The CLI
does not derive compliance from the SARIF findings — that decision
is the caller's, expressed via the flag (and typically driven by their
own policy or rego rules).
POSTs to a new server endpoint `api/v2/attestations/{org}/{flow}/trail/{trail}/sarif`
which is added in a follow-up commit on the server side.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
Claude finished @AlexKantor87's task in 3m 38s —— View job PR Review:
|
Emit a debug line when SARIF parsing starts (with file path) and another once parsing succeeds with the tool name, severity counts, and the caller-supplied --compliant flag value. Useful when troubleshooting CI pipelines where the upload silently looks empty. The error path is unchanged — parse failures still surface via the wrapped error, consistent with `attest snyk`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- Drop trailing whitespace from attestSarifShortDesc (was two spaces before the closing backtick — copied from attestSnykShortDesc, but not load-bearing here). - Add an else branch on the SARIF debug log so a valid-but-empty SARIF file (zero scan runs) still emits a debug line with the tool name and the caller-supplied --compliant flag. No behaviour change. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Reviewer findings — actions taken (commit
|
| Path | Finding | Action |
|---|---|---|
internal/sarif/sarif.go:53 |
Long $schema validation line + non-Snyk SARIF may omit/vary $schema |
Line length is style — left as-is for parity with the snyk-era code. The substantive concern (Checkov / Trivy may be rejected) is captured in server#5554 — that work adds real fixtures and will exercise this path |
cmd/kosli/attestSarif.go:28 |
Trailing whitespace in attestSarifShortDesc |
Fixed in fbfc6e14 |
cmd/kosli/attestSarif.go:28 (re-flagged) |
Same as above | Same fix — fbfc6e14 |
cmd/kosli/attestSarif_test.go:37 |
Need command-level test with non-Snyk SARIF fixture | Captured in server#5554 — fixtures should come from real customer output (ADCB / Checkov), not synthesised |
cmd/kosli/attestSarif.go:192 |
Else branch on zero-runs SARIF | Fixed in fbfc6e14 — else now logs tool name + compliant flag |
Local verification on the new commit
go build ./...— cleango test ./internal/sarif/...— pass
The full integration test suite still depends on the server PR (server#5538) merging before the published image picks up the /sarif route. This PR remains DONT MERGE until that lands.
Summary
Adds a first-class
kosli attest sarifcommand, parallel tokosli attest snyk, that:runs[0].tool.driverfields, so the Kosli UI tile reads "Checkov 3.2.1" / "Trivy 0.52" / etc. depending on what was run.-C, --compliantflag (default true, mirroringattest generic) so the caller controls whether the attestation is compliant. The CLI does not derive compliance from the SARIF findings — that decision is the caller's, expressed via the flag (typically driven by their own policy or rego rules).Why
Customers currently map non-Snyk SARIF scans (notably Checkov) to the
snykattestation type because no native SARIF type exists. This works for parsing/display but bakes Snyk-specific compliance logic ("any high/medium/low → fail") into a generic SARIF flow, hardcodes "Snyk" as the tool label, and gives customers no way to express their own threshold. The newsariftype fixes all three.Changes
Slice 1 — refactor:
internal/snyk→internal/sarifThe existing snyk parser is genuinely a generic SARIF v2.1.0 parser — it just lives in a
snyk-named package. Renamed to reflect actual scope; theattest snykcommand keeps working unchanged via the renamed package. Wire format preserved (still postssnyk_resultsJSON key for backwards compatibility).Slice 2 — new
attest sarifcommandcmd/kosli/attestSarif.gowith--scan-results,--upload-results, and--compliantflagsapi/v2/attestations/{org}/{flow}/trail/{trail}/sarif(added in server#5538)is_compliant: booltaken from the flag verbatim--compliant=falseand explicit--compliant=truecasesLocal verification
End-to-end smoke-tested against a local demo running the server branch:
kosli attest sarif --scan-results sarif-iac.json→ 201, attestation stored with dynamic tool name "Snyk IaC" 1.1177.0 andis_compliant: truekosli attest sarif --scan-results sarif-helm.json --compliant=false→ 201,is_compliant: falsestored verbatim despite zero high-severity findingsgo test ./internal/sarif/...— passesgo test ./...) — would only pass against a server with the/sarifroute, hence the merge blockTest plan
--compliant=trueand--compliant=false, confirm both tiles render correctly🤖 Generated with Claude Code