Add option to exclude base image components#1825
Merged
Merged
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
32138d8 to
f97ff44
Compare
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
…rmine component to layer map
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1825 +/- ##
============================
============================
☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
JamieMagee
approved these changes
Jun 25, 2026
jpinz
approved these changes
Jun 25, 2026
jpinz
approved these changes
Jun 26, 2026
grvillic
approved these changes
Jun 26, 2026
grvillic
approved these changes
Jun 26, 2026
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.
This PR makes two changes:
Improve the way components from container images are mapped to layers
Prior to this, the Syft output's "Locations" field was the sole source of a component's file and layer information. This was undesirable because, for packages installed by the system package manager, the only location would be the system package manager database. As a result, any changes to system packages in later layers would result in every system package being mapped to the last layer where the database was modified.
Now, the Syft output's "Metadata.Files" field is used to augment the "Locations" data about files and layers associated with a component, and any known system package manager database files are ignored in favor of other file mappings, if present. This leads to more accurate mappings of components to image layers.
The expected result of this change is that some components which were previously mapped to layers above the base image may now be properly mapped to base image layers.
Add a new option to exclude components which solely originate from the base image when scanning a container image.
The flag
--ExcludeBaseImageComponentscan be specified to filter out components from the base image.