Reapply "Add OCI image support to Linux scanner (#1708)" (#1716)#1717
Reapply "Add OCI image support to Linux scanner (#1708)" (#1716)#1717jasonpaulos merged 6 commits intomainfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Reapplies OCI image support for the Linux container detector by allowing --DockerImagesToScan inputs to reference OCI layout directories and OCI archive tarballs, running Syft against those sources, and mapping detected packages back to image layers.
Changes:
- Add
ImageReferenceparsing (Docker image vsoci-dir:/oci-archive:) and updateLinuxContainerDetectorto resolve/scan local OCI inputs via Syft volume binds. - Extend
ILinuxScanner/LinuxScannerto support returning raw Syft output and processing it separately (needed to extract source metadata for OCI inputs). - Extend
IDockerService/DockerServiceto support additional bind mounts and to create emptyContainerDetailsfor non-Docker-inspect image sources; add/expand unit tests and docs.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Detectors.Tests/LinuxScannerTests.cs | Updates mocks for new DockerService overload and adds tests for raw Syft output + layer mapping behavior. |
| test/Microsoft.ComponentDetection.Detectors.Tests/LinuxContainerDetectorTests.cs | Adds comprehensive OCI layout/archive detector tests (path normalization, metadata presence/absence, mixed inputs). |
| test/Microsoft.ComponentDetection.Detectors.Tests/ImageReferenceTests.cs | Adds unit tests for parsing Docker vs OCI references and validating empty-path errors. |
| src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs | Refactors to support “run Syft” vs “process Syft output” paths; adds bind support and a safe fallback when no layers are provided. |
| src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs | Implements OCI scanning flow: validate local paths, bind-mount into Syft container, extract metadata, and record components. |
| src/Microsoft.ComponentDetection.Detectors/linux/ImageReference.cs | Introduces parsing and classification of image inputs (Docker vs OCI directory/archive). |
| src/Microsoft.ComponentDetection.Detectors/linux/ILinuxScanner.cs | Adds new public methods to return raw Syft output and process it separately. |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftSourceMetadata.cs | Adds typed model for Syft source.metadata (image ID, layers, tags, labels, etc.). |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftSourceLayer.cs | Adds typed model for Syft source layer entries. |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SourceClassExtensions.cs | Adds helper to deserialize the untyped SourceClass.Metadata into SyftSourceMetadata. |
| src/Microsoft.ComponentDetection.Contracts/IDockerService.cs | Adds container-run overload supporting bind mounts and adds GetEmptyContainerDetails(). |
| src/Microsoft.ComponentDetection.Common/DockerService.cs | Implements new IDockerService members and plumbs additional bind mounts into container creation. |
| docs/detectors/linux.md | Documents supported image input types including oci-dir: and oci-archive:. |
|
👋 Hi! It looks like you modified some files in the
If none of the above scenarios apply, feel free to ignore this comment 🙂 |
There was a problem hiding this comment.
Pull request overview
Reapplies OCI image support for the Linux container scanning detector by enabling Syft scans over OCI layout directories / OCI archives / Docker archives, and by adding parsing + metadata extraction paths to map detected components to layers.
Changes:
- Add
ImageReferenceparsing to distinguish Docker images vsoci-dir:,oci-archive:, anddocker-archive:inputs. - Extend
ILinuxScannerto support retrieving raw Syft output and processing it separately (needed for OCI metadata). - Update Docker service/container execution APIs to accept additional bind mounts; add tests and documentation for new input types.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Detectors.Tests/LinuxScannerTests.cs | Updates mocks for new Docker service signature; adds Syft-output-focused tests. |
| test/Microsoft.ComponentDetection.Detectors.Tests/LinuxContainerDetectorTests.cs | Adds extensive coverage for OCI layout/archive and mixed image inputs. |
| test/Microsoft.ComponentDetection.Detectors.Tests/ImageReferenceTests.cs | New unit tests for image reference parsing behavior. |
| src/Microsoft.ComponentDetection.Detectors/linux/LinuxScanner.cs | Refactors Syft invocation + processing; introduces raw output retrieval and layer mapping fallback behavior. |
| src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs | Adds OCI/local-image resolution + scanning flow and metadata extraction for container details. |
| src/Microsoft.ComponentDetection.Detectors/linux/ImageReference.cs | New parser for user-provided image references (docker vs OCI/docker archive schemes). |
| src/Microsoft.ComponentDetection.Detectors/linux/ILinuxScanner.cs | New APIs for “get raw Syft output” and “process Syft output”. |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftSourceMetadata.cs | Strongly-typed model for Syft source.metadata (image) data. |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SyftSourceLayer.cs | Strongly-typed model for Syft source layer metadata. |
| src/Microsoft.ComponentDetection.Detectors/linux/Contracts/SourceClassExtensions.cs | Adds helper to deserialize source.metadata into SyftSourceMetadata. |
| src/Microsoft.ComponentDetection.Contracts/IDockerService.cs | Adds overload to pass additional binds and a helper for empty ContainerDetails. |
| src/Microsoft.ComponentDetection.Common/DockerService.cs | Implements additional-binds overload and empty container details creation. |
| docs/detectors/linux.md | Documents supported image input types including OCI and docker archives. |
Comments suppressed due to low confidence (1)
src/Microsoft.ComponentDetection.Common/DockerService.cs:323
CreateContainerAsyncbuilds abindslist that includesadditionalBinds, butCreateContainerParameters.HostConfig.Bindsis still hard-coded to only the default two mounts. As a result, callers providingadditionalBinds(e.g., OCI directory/archive mounts) will be silently ignored and Syft won’t be able to access the local image path. Use the constructedbindslist when settingHostConfig.Binds.
var binds = new List<string>
{
$"{Path.GetTempPath()}:/tmp",
"/var/run/docker.sock:/var/run/docker.sock",
};
if (additionalBinds != null)
{
binds.AddRange(additionalBinds);
}
var parameters = new CreateContainerParameters
{
Image = image,
Cmd = command,
NetworkDisabled = true,
HostConfig = new HostConfig
{
CapDrop =
[
"all",
],
SecurityOpt =
[
"no-new-privileges",
],
Binds =
[
$"{Path.GetTempPath()}:/tmp",
"/var/run/docker.sock:/var/run/docker.sock",
],
},
src/Microsoft.ComponentDetection.Detectors/linux/LinuxContainerDetector.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 13 out of 13 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/Microsoft.ComponentDetection.Common/DockerService.cs:323
additionalBindsis currently ignored when creating the container.CreateContainerAsyncbuilds abindslist (includingadditionalBinds) but then setsHostConfig.Bindsto a hard-coded list instead of usingbinds. This both breaks OCI/archive scanning (Syft won't see the mounted image) and triggers a compiler warning/error becausebindsis assigned but never used (TreatWarningsAsErrors=true). Use the constructedbindslist forHostConfig.Binds(and avoid duplicating the default binds).
var binds = new List<string>
{
$"{Path.GetTempPath()}:/tmp",
"/var/run/docker.sock:/var/run/docker.sock",
};
if (additionalBinds != null)
{
binds.AddRange(additionalBinds);
}
var parameters = new CreateContainerParameters
{
Image = image,
Cmd = command,
NetworkDisabled = true,
HostConfig = new HostConfig
{
CapDrop =
[
"all",
],
SecurityOpt =
[
"no-new-privileges",
],
Binds =
[
$"{Path.GetTempPath()}:/tmp",
"/var/run/docker.sock:/var/run/docker.sock",
],
},
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1717 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Reapply #1708 and #1711 which were reverted in #1716 and #1715