Skip to content

Scope vulnerability data to live images and add manual rescan - #235

Merged
LarsLaskowski merged 3 commits into
mainfrom
enhancement/vulnerability
Aug 15, 2026
Merged

Scope vulnerability data to live images and add manual rescan#235
LarsLaskowski merged 3 commits into
mainfrom
enhancement/vulnerability

Conversation

@LarsLaskowski

Copy link
Copy Markdown
Owner

Pull Request

📖 Description

The dashboard previously counted active vulnerability findings for every image version that had ever been scanned, including image versions no longer backing any running container. Digging into the scan pipeline showed the same gap one level deeper: the batch vulnerability scan kept rescanning (and thus kept alive) any image version with so much as a historical container snapshot, so retired image versions and their findings never aged out of the database.

This PR:

  • Aligns the batch vulnerability scan's eligibility with the same "live" definition already used elsewhere (observed images' current version, currently running containers, and their base-image dependencies), so retired image versions stop being rescanned and their findings get deactivated on the next cycle.
  • Extends the cleanup job to purge deactivated findings of non-live image versions immediately, while keeping the existing 30-day retention for findings resolved on still-live images (e.g. a genuinely patched CVE).
  • Adds a "last vulnerability scan" timestamp to the Runtime Containers, Observed Images, and My Images tables.
  • Adds a per-row manual rescan trigger (per running container or per image) via a new reusable VulnerabilityRescanControl component and a new IVulnerabilityEnrichmentService.RefreshImageVersionAsync method that rescans a single image version without touching findings elsewhere in the fleet.

🎫 Issues

N/A

👩‍💻 Reviewer Notes

  • VulnerabilityEnrichmentService.RefreshAsync and ScanCleanupBackgroundService.ExecuteCoreAsync are the core behavior changes; the rest is UI plumbing (new DTO fields, a new shared component, wiring into three pages).
  • Three existing tests in VulnerabilityEnrichmentServiceTests.cs relied on a retired image version staying scan-eligible solely because of a stale container snapshot; they were updated to use setups that stay legitimately live, and one was repurposed into a direct regression test for the eligibility fix.
  • A smoke test worth doing manually: open Runtime Containers / Observed Images / My Images, confirm the "Checked " line and rescan button render per row, and that clicking rescan updates just that row.

📑 Test Plan

Added/updated unit and component tests covering: the scan-eligibility fix and its regression case, the new single-image rescan method, the cleanup job's immediate purge for non-live image versions vs. the retained 30-day window for still-live ones, the new DTO fields on the runtime-container and observed-image projections, and the new VulnerabilityRescanControl component (success, failure, and never-scanned states).

✅ Checklist

General

  • I have added tests for my changes.
  • I have tested my changes.
  • I have updated the project documentation to reflect my changes.
  • I have read the CONTRIBUTING documentation and followed the project's code style guidelines.

UI-specific

  • I have added a new Blazor page/component.
  • I have added Unit Tests for the new page/component.
  • I have modified an existing Blazor page/component.
  • I have updated the Unit Tests for the modified page/component.

⏭ Next Steps

  • The /vulnerabilities fleet-wide overview page intentionally remains unscoped (shows all active findings, including ones not currently backing a running container); worth revisiting if the dashboard's narrower scope should extend there too.
  • SharedBaseImages was left read-only; the same VulnerabilityRescanControl could be added there later if a manual rescan trigger is wanted for base images as well.

Introduce VulnerabilityRescanControl for image/container tables to allow manual rescans and display last scan timestamps. Update ApplicationViewService and view models to expose image version IDs and scan times. Adjust dashboard to count vulnerabilities only for images backing running containers, excluding retired images. Refine ScanCleanupBackgroundService to purge findings for deactivated, non-live images immediately. Extend IVulnerabilityEnrichmentService for single-image rescans. Improve logging for rescans targeting missing images. Add and update unit tests for new features and logic. Enhance UI hints and styling for scan status and rescans. Update project configuration and copyright.
The images parameter in RunRefreshAsync now requires a List<ImageVersion> instead of IReadOnlyList<ImageVersion>. This narrows the accepted argument type and requires callers to provide a List, not just any IReadOnlyList implementation.
@sonarqubecloud

Copy link
Copy Markdown

@LarsLaskowski
LarsLaskowski merged commit cbfa961 into main Aug 15, 2026
4 checks passed
@LarsLaskowski
LarsLaskowski deleted the enhancement/vulnerability branch August 15, 2026 13:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant