Skip to content

feat(trivy_operator): add remediation, messages, category, and publishedDate mappings#14360

Open
SergK wants to merge 1 commit intoDefectDojo:devfrom
SergK:feat/trivy-operator-add-field-mappings
Open

feat(trivy_operator): add remediation, messages, category, and publishedDate mappings#14360
SergK wants to merge 1 commit intoDefectDojo:devfrom
SergK:feat/trivy-operator-add-field-mappings

Conversation

@SergK
Copy link

@SergK SergK commented Feb 21, 2026

Description

Add missing field mappings to the Trivy Operator parser.

1. Add remediation, messages, category to checks handler

The Trivy Operator Go source defines these fields on the Check struct:

type Check struct {
    ID          string   `json:"checkID"`
    Title       string   `json:"title,omitempty"`
    Description string   `json:"description,omitempty"`
    Severity    Severity `json:"severity"`
    Category    string   `json:"category,omitempty"`
    Messages    []string `json:"messages,omitempty"`
    Remediation string   `json:"remediation,omitempty"`
    Success     bool     `json:"success"`
}

The compliance_handler.py already maps remediationFinding.mitigation, messages, and category from the same Check struct, but checks_handler.py (used by ConfigAuditReport, RbacAssessmentReport, InfraAssessmentReport) does not. This PR brings parity:

  • check.remediationFinding.mitigation
  • check.messages → appended to Finding.description as **messages:**
  • check.category → appended to Finding.description as **category:**

2. Add publishedDate to vulnerability handler

Trivy provides publishedDate on vulnerability findings. The existing vulnerabilityreport_extended.json test fixture already contains this field:

{
    "vulnerabilityID": "CVE-2024-0553",
    "publishedDate": "2024-01-16T12:15:45Z",
    ...
}

This maps it to Finding.publish_date (existing nullable DateField), with graceful handling of empty strings and malformed dates via contextlib.suppress(ValueError).

Test results

  • Updated test_vulnerabilityreport_extended — verifies publish_date = date(2024, 1, 16) for first vuln, None for vulns with empty publishedDate
  • Added test_configauditreport_with_remediation — verifies mitigation, category, and messages extraction
  • All existing tests pass
  • ruff check passes

Documentation

No documentation changes needed — additional field mappings for an existing parser.

Checklist

  • Features/Changes should be submitted against the dev.
  • Give a meaningful name to your PR, as it may end up being used in the release notes.
  • Your code is flake8 compliant.
  • Your code is python 3.13 compliant.
  • Add applicable tests to the unit tests.
  • Add the proper label to categorize your PR.

@valentijnscholten
Copy link
Member

@SergK Thanks. Could you assess the possible impact on deduplication?

@SergK
Copy link
Author

SergK commented Feb 22, 2026

@valentijnscholten The Trivy Operator parser uses hash-code based deduplication. The hash is computed from title, severity, vulnerability_ids, description, and service.

For publishedDate and remediation — no dedup impact. Neither publish_date nor mitigation is part of the hash.

For messages and category appended to description — this does affect dedup, since description is part of the hash. ConfigAuditReport findings that have messages or category populated will get a richer description, which means a different hash on the next reimport. Those findings will show up as new, and the old ones will get auto-closed.

This is a one-time shift on the first reimport after upgrade. After that, the hashes stay stable. Worth noting that messages and category are already mapped the same way in compliance_handler.py — this PR just brings checks_handler.py to parity.

@valentijnscholten valentijnscholten added this to the 2.56.0 milestone Feb 25, 2026
Copy link
Contributor

@Maffooch Maffooch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are very sensitive about deduplication changes because we cannot guarantee that all users will read the release notes before upgrading. The least impacting breaking changes, the better. With that in mind, we should steer clear of updating the description when it is used in the dedupe hash codes

…hedDate mappings

Add missing field mappings to the Trivy Operator parser:

- checks_handler: extract remediation and messages → Finding.mitigation,
  category → Finding tag. These fields are defined on the Check struct
  (config_audit_types.go) and were already mapped in compliance_handler
  but missing from checks_handler. Messages and remediation are combined
  in the mitigation field since both provide actionable guidance. Category
  is stored as a tag for filterability rather than in description, to
  avoid affecting the deduplication hash.

- vulnerability_handler: extract publishedDate → Finding.publish_date.
  Trivy provides CVE publication dates in VulnerabilityReport; map them
  to the existing nullable DateField with graceful handling of empty
  strings and malformed dates.

Signed-off-by: Sergiy Kulanov <sergiy_kulanov@epam.com>
@SergK SergK force-pushed the feat/trivy-operator-add-field-mappings branch from 62ba09d to 0a8f05e Compare February 26, 2026 16:48
@SergK SergK requested a review from Maffooch February 27, 2026 07:20
Copy link
Contributor

@mtesauro mtesauro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants