Add option to exclude base image components#1825
Draft
jasonpaulos wants to merge 1 commit into
Draft
Conversation
Contributor
There was a problem hiding this comment.
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
--FilterBaseImageComponentstoScanSettingsto enable base-image-only component filtering for container scans. - Implemented filtering logic in
DefaultGraphTranslationServiceto remove components whose referenced container layers are all markedIsBaseImage. - 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")); | ||
|
|
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.
Add a new option to exclude components which solely originate from the base image when scanning a container image.