Reactivate resolved vulnerability findings instead of duplicating rows - #212
Merged
Conversation
The upsert built its match lookup from active findings only, so an advisory that was resolved in an earlier run and reappeared was inserted as a new row while the old row stayed behind as a tombstone. The lookup now covers all findings of the image version and prefers the active row, falling back to the most recently resolved one. A matched resolved row is reactivated in place with a cleared resolution state and the current scan run, and the stale pass only considers rows that were already active when the run started. Closes #204.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Summary
UpsertVulnerabilityFindingsAsyncnow builds its match lookup from all findings of an image version instead of the active ones only. Where several rows share a finding identity, the active row wins; among resolved rows the most recently resolved one is picked. A match against a resolved row reactivates it in place —IsActive = true,ResolvedAtUtcandResolvedByScanRunIdcleared,ScanRunIdstamped with the current run and a freshDetectedAtUtcfor the new active period. The stale pass at the end of the upsert now iterates only over rows that were already active when the run started, so a row reactivated in the same run cannot be deactivated again.Why
The lookup was restricted to active findings, so an advisory that had been resolved in an earlier run and was reported again never matched. Each re-detection inserted a brand-new row while the old one stayed behind as a resolved tombstone. That grew the findings table by a full copy of the finding set per resolve/re-detect cycle — 1236 extra rows for an image with 1236 findings — until
ScanCleanupBackgroundServicepassed the retention cutoff, and it reported every re-detected CVE as brand new even though it was already known.Linked issues
Closes #204
Review notes
(ImageVersionId, AdvisoryId, AffectedPackage)only covers active rows, so reactivation cannot collide with an existing active row for the same identity.VulnerabilityEnrichmentServiceTests: reactivation instead of insert, a reactivated row surviving the stale pass of the same run, and a legacy active/resolved pair resolving to the active row.Follow-up work
None