Repository navigation
Implement Grype report ingestion adapter (closes #6) - #123
Conversation
rrskris
left a comment
There was a problem hiding this comment.
First — this sat ten days without a review, and that's on me, not on you. You opened the project's first-ever PR back on 2026-07-07 and this is your fourth; waiting a week and a half for a first response isn't the deal. I've since swept the queue and I'm fixing the process that let it happen.
Now the review. The adapter is well built and one thing needs changing before it lands.
What's right
I checked this against trivy_adapter.py (#106) as the precedent, since the whole value of a second adapter is that it behaves identically to the first.
- The finding shape matches exactly. Same dedup key
(cve_id, image, component), same-contextual_scoresort, same additivesource/imagefields, samecompute_contextual_score()→build_remediation()sequence. Ingested Grype findings will flow through scoring, the PDF builder and the dashboard with nothing downstream changed, which is the actual acceptance bar indocs/trivy-grype-integration.md. - Test coverage exceeds the precedent. Trivy's adapter has 15 tests; you wrote 17, and the two extra ones (
test_image_name_falls_back_to_image_id_when_no_user_input,test_image_name_defaults_to_unknown_when_source_missing) cover a real difference — Grype'ssource.targetis a dict for images and a bare string for directory scans, where Trivy just hasArtifactName. You found that yourself; it isn't in the design doc. - The scope call is correct. You built the adapter and stopped.
trivy_adapterisn't wired into any router either, so adapter-only is exactly parity with #106 rather than an omission. 17/17 pass on my machine too. - Title-case → UPPER severity normalization is the right Grype-specific catch.
Required: _best_cvss_score() ignores cvss[].version
docs/trivy-grype-integration.md:55 sets the contract for both adapters:
"cvss_score": highest v3 base score present, else None
Trivy honours it structurally — it reads the V3Score key, so a v2 score can't leak in. The Grype adapter takes max(metrics.baseScore) across every entry regardless of version. Your own docstring names the hazard:
Grype's cvss array can mix v2/v3 metrics from different sources; we take the max baseScore across all of them, same spirit as Trivy's "highest V3Score across vendors" rule.
It isn't the same spirit, though — Trivy's rule maxes across vendors within v3. Maxing across versions mixes two different scales. CVSS v2 and v3.1 are not interchangeable: v2 rates many CVEs higher, so the max is systematically biased toward the v2 number.
I ran the same CVE through both adapters, carrying an NVD v2 of 10.0 and a v3.1 of 7.5 — the shape real Grype output takes for older CVEs:
expected (per the doc) -> 7.5
trivy_adapter -> 7.5 OK
grype_adapter -> 10.0 took the v2 score
And because cvss_score feeds compute_contextual_score(), it doesn't stop at the raw number:
contextual_score via trivy -> 11.25
contextual_score via grype -> 15.0
Same CVE, same image, same package, same context — a third higher just because of which scanner produced the JSON. That defeats the point of a second adapter.
Your 17 tests pass because every cvss[] entry in grype_report_sample.json is either "version": "3.1" or has no version key at all. There's no v2 entry anywhere in the fixture, so nothing exercises the branch. That's the same blind spot #131 hit last week — the test suite is thorough about everything the fixture represents, and the fixture is missing the one case that matters.
The fix
version = str(entry.get("version") or "")
if version and not version.startswith("3"):
continueI applied exactly that to your branch and ran it: grype_adapter returns 7.5, contextual scores match Trivy at 11.25, and all 17 of your tests still pass — so this costs you no rework.
Two things to add with it:
- A fixture entry carrying both a v2 and a v3 score, with a test asserting the v3 wins. Without it the next person can undo this and CI stays green.
- Keep the missing-
versioncase included — that's why the condition isif version and not ...rather than requiring a v3 match. An entry with noversionkey should still count. Under-reporting a CVE score is worse than over-reporting it for a scanner, and it keeps the existing fixture entry on line 124 working. Worth a one-line comment saying that's deliberate, the same way you documented the Title-case severity difference.
Two nits, non-blocking
_title(vulnerability, cve_id, pkg_name)never readsvulnerability— the fallback is unconditional. Either drop the parameter or actually look up a title field, so it doesn't read as an unfinished lookup.grype_adapter.pyhas no trailing newline.
On the test-run note in your description
You reported "1 pre-existing DB-dependent failure (test_smoke.py, requires local Postgres)". That test passes for me on the default config with no Postgres and no Docker — the suite is 129 green on main. Two other contributors hit the same thing this month, so it's likely something shared in the setup docs rather than your machine; I'm looking into it. Nothing to change in this PR.
Make the CVSS change and add the fixture case and I'll merge this. The rest is ready as-is, and the extra image-name coverage is better than what the Trivy adapter shipped with.
What's next
You've now done SARIF output (#10), SARIF security-severity (#32/#56), Trivy ingestion (#106) and Grype ingestion here — you own the output-and-ingestion surface of this project more than anyone.
- #35 — Kyverno PolicyReport ingestion, admission results as a finding source. Third adapter, same
parse()contract, and you've now written two of them. - #94 — granted-vs-used reporting, if you'd rather move from ingestion into analysis.
Nothing is assigned to anyone else on either. Comment and I'll assign it same-day.
Signed-off-by: Diya Maheshwari <[email protected]>
… test Signed-off-by: Diya Maheshwari <[email protected]>
2ccc1ba to
8f2d534
Compare
|
Thanks for the thorough review @rrskris All changes from the review are done:
Ready for another look when you get a chance. |
|
Following up on the You were right, and our documentation was wrong. I owe you a correction.
This got written off earlier on the grounds that it "passes locally with no Postgres". That was my mistake: this machine runs a Postgres on There was a second trap underneath it: Fixed in #149: Thank you for reporting it, and sorry it took two of you saying the same thing before it was taken at face value. |
|
Thanks for tracking this down properly and fixing the docs and for the correction. |
Adds release-notes entries for the five contributor PRs merged today: Grype ingestion (#123, @Diyaaa-12), combo-escalation remediation and rule catalog (#133, @Maqbool61), the combination-takeover fixture (#152, @Maqbool61), the Postgres-unreachable test skip (#151, @HeaTTap — first contribution), and the CIS 5.1.6 acceptance check moving into CI (#124, @donkk11). Also records the fixture-comment correction from #157. Signed-off-by: Vamshi Krishna Santhapuri <[email protected]>
What this changes
Implements a pure adapter (
control-plane/app/grype_adapter.py) that convertsgrype -o jsonoutput into Kaaval's finding shape, mirroringtrivy_adapter.py(#106) exactly — sameparse(report_json, context)contract, same finding shape, so ingested findings flow throughcompute_contextual_score()/build_remediation()unmodified. Readsmatches[].vulnerability/.artifact/.fixper docs/trivy-grype-integration.md, adds additivesource: "grype"andimagefields, and dedups on(cve_id, image, component).Closes #6
Type
Checklist
make testpasses (full suite: 108 passed, 1 pre-existing DB-dependent failure unrelated to this change)hack/dev/rbac-fixtures.yamlif it's a new rule (N/A — CVE ingestion adapter, not an RBAC rule)How you verified it
Ran
python -m pytest tests/test_grype_adapter.py -v— 17/17 passed, mirroring the Trivy adapter's test coverage: core field mapping, dedup across duplicate matches, missing fix/CVSS handling, Title-case→UPPER severity normalization (Grype's severity casing differs from Trivy's), title fallback, description truncation, scoring/remediation attachment via the realcompute_contextual_score()/build_remediation(), context forwarding, and image-name fallback (userInput → imageID → "unknown").Also ran the full suite: 108 passed, 2 skipped, 1 failed (
test_smoke.py::test_login_and_self_scan— pre-existing, requires local Postgres at 127.0.0.1:5432, unrelated to this change).