Skip to content

Add option to exclude base image components#1825

Draft
jasonpaulos wants to merge 1 commit into
mainfrom
users/jasonpaulos/exclude-base-image
Draft

Add option to exclude base image components#1825
jasonpaulos wants to merge 1 commit into
mainfrom
users/jasonpaulos/exclude-base-image

Conversation

@jasonpaulos

Copy link
Copy Markdown
Member

Add a new option to exclude components which solely originate from the base image when scanning a container image.

Copilot AI review requested due to automatic review settings June 10, 2026 20:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new scan option to exclude components that originate exclusively from base image layers when scanning container images, integrating the filtering into scan result generation and validating behavior with new unit tests.

Changes:

  • Added --FilterBaseImageComponents to ScanSettings to enable base-image-only component filtering for container scans.
  • Implemented filtering logic in DefaultGraphTranslationService to remove components whose referenced container layers are all marked IsBaseImage.
  • Added orchestrator tests covering removal/retention scenarios for base-image-only, mixed-layer, and non-container components.
Show a summary per file
File Description
test/Microsoft.ComponentDetection.Orchestrator.Tests/Services/DefaultGraphTranslationServiceTests.cs Adds unit tests validating the new base-image component filtering behavior.
src/Microsoft.ComponentDetection.Orchestrator/Services/GraphTranslation/DefaultGraphTranslationService.cs Applies the new filtering option during scan result generation and introduces base-image-only detection logic.
src/Microsoft.ComponentDetection.Orchestrator/Commands/ScanSettings.cs Introduces the new CLI/settings flag FilterBaseImageComponents.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 6

Comment on lines +44 to +49
var componentsToOutput = mergedComponents;
if (settings.FilterBaseImageComponents)
{
componentsToOutput = FilterOutBaseImageComponents(componentsToOutput, detectorProcessingResult.ContainersDetailsMap);
}

Comment on lines +96 to +106
var layersList = containerDetails.Layers.ToList();

foreach (var layerIndex in layerIndices)
{
var layer = layersList.FirstOrDefault(l => l.LayerIndex == layerIndex);
if (layer == null || !layer.IsBaseImage)
{
// Layer not found or not from base image. Keep this component.
return false;
}
}
Comment on lines +571 to +572
var singleFileRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, "/file1"));

Comment on lines +601 to +602
var singleFileRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, "/file1"));

Comment on lines +633 to +634
var singleFileRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, "/file1"));

Comment on lines +664 to +665
var singleFileRecorder = this.componentRecorder.CreateSingleFileComponentRecorder(Path.Join(this.sourceDirectory.FullName, "/file1"));

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.

2 participants