Add component detectors for Docker Compose, Helm, and Kubernetes#1759
Add component detectors for Docker Compose, Helm, and Kubernetes#1759
Conversation
|
👋 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
Adds new YAML-based detectors to Component Detection so Docker image references can be discovered from Docker Compose, Helm values, and Kubernetes manifests, plus updates orchestration wiring and expands detector test coverage.
Changes:
- Introduce new
DockerCompose,Helm, andKubernetesdetectors that parse YAML and registerDockerReferenceComponentusages. - Register the new detectors in Orchestrator DI and extend
DetectorClasswith new categories. - Add MSTest coverage for the new detectors and add/expand tests for the existing Dockerfile detector.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.Detectors.Tests/KubernetesComponentDetectorTests.cs | Adds unit tests for K8s YAML image extraction and non-K8s YAML ignoring behavior. |
| test/Microsoft.ComponentDetection.Detectors.Tests/HelmComponentDetectorTests.cs | Adds unit tests for Helm values.yaml image patterns (scalar, structured, digest, sequences). |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs | Adds Dockerfile detector tests for FROM, multi-stage, digests, COPY --from, and file patterns. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerComposeComponentDetectorTests.cs | Adds tests for Compose service images, overrides, digests, and build-only services. |
| src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs | Registers the three new detectors with DI so they can be executed by the orchestrator. |
| src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs | New detector implementation for parsing Kubernetes manifests and extracting container images. |
| src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs | New detector implementation for parsing Helm values.yaml and extracting image references. |
| src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs | New detector implementation for parsing Compose YAML and extracting service image: references. |
| src/Microsoft.ComponentDetection.Contracts/DetectorClass.cs | Adds new detector classes/categories for Docker Compose, Helm, and Kubernetes. |
Comments suppressed due to low confidence (5)
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs:104
- This file is compiled with nullable reference types enabled, but
apiVersion/kindare declared as non-nullablestringand initialized tonull, which will fail the build with warnings-as-errors. Make thesestring?(and similarly update any other locals/returns that can be null).
private bool IsKubernetesManifest(YamlMappingNode rootMapping)
{
string apiVersion = null;
string kind = null;
foreach (var entry in rootMapping.Children)
{
var key = (entry.Key as YamlScalarNode)?.Value;
if (string.Equals(key, "apiVersion", StringComparison.OrdinalIgnoreCase))
{
apiVersion = (entry.Value as YamlScalarNode)?.Value;
}
else if (string.Equals(key, "kind", StringComparison.OrdinalIgnoreCase))
{
kind = (entry.Value as YamlScalarNode)?.Value;
}
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs:217
GetMappingChildreturnsnullwhen the key isn't present, but the return type is non-nullableYamlMappingNode. With nullable enabled + warnings-as-errors this will fail compilation. Change the return type toYamlMappingNode?(and update call sites accordingly).
private static YamlMappingNode GetMappingChild(YamlMappingNode parent, string key)
{
foreach (var entry in parent.Children)
{
if (entry.Key is YamlScalarNode scalarKey && string.Equals(scalarKey.Value, key, StringComparison.OrdinalIgnoreCase))
{
return entry.Value as YamlMappingNode;
}
}
return null;
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs:230
GetSequenceChildreturnsnullwhen the key isn't present, but the return type is non-nullableYamlSequenceNode. With nullable enabled + warnings-as-errors this will fail compilation. Change the return type toYamlSequenceNode?(and update call sites accordingly).
private static YamlSequenceNode GetSequenceChild(YamlMappingNode parent, string key)
{
foreach (var entry in parent.Children)
{
if (entry.Key is YamlScalarNode scalarKey && string.Equals(scalarKey.Value, key, StringComparison.OrdinalIgnoreCase))
{
return entry.Value as YamlSequenceNode;
}
}
return null;
src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs:135
- This method initializes non-nullable
stringlocals (repository,tag,digest,registry) tonull. With nullable enabled + TreatWarningsAsErrors, this will fail the build. Usestring?for these locals (and keep the subsequent null/whitespace checks).
private void TryRegisterStructuredImageReference(YamlMappingNode imageMapping, ISingleFileComponentRecorder recorder, string fileLocation)
{
string repository = null;
string tag = null;
string digest = null;
string registry = null;
src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs:137
GetMappingChildreturnsnullwhen the key isn't present, but the return type is non-nullableYamlMappingNode. With nullable enabled + warnings-as-errors this will fail compilation. Change the return type toYamlMappingNode?and update call sites accordingly.
private static YamlMappingNode GetMappingChild(YamlMappingNode parent, string key)
{
foreach (var entry in parent.Children)
{
if (entry.Key is YamlScalarNode scalarKey && string.Equals(scalarKey.Value, key, StringComparison.OrdinalIgnoreCase))
{
return entry.Value as YamlMappingNode;
}
}
return null;
…d improve logging
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Comments suppressed due to low confidence (1)
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs:86
- The exception handler logs "Skipping non-Kubernetes YAML file" for any exception, but exceptions here primarily represent YAML parse/processing failures (a file can be a Kubernetes manifest but malformed). Consider adjusting the message to reflect parse errors (or splitting try/catch so non-Kubernetes vs parse-failure are distinguished) to avoid misleading diagnostics.
catch (Exception e)
{
// Not all YAML files are Kubernetes manifests; silently skip parse errors
this.Logger.LogDebug(e, "Skipping non-Kubernetes YAML file: {Location}", file.Location);
}
…prove error logging. And address SA1204
… and detectors introduced in the new scan
There was a problem hiding this comment.
Pull request overview
This PR extends Component Detection’s Docker image reference scanning by adding DefaultOff detectors for Docker Compose, Helm values, and Kubernetes manifests, plus consolidates “skip unresolved template variables” behavior into a shared Docker reference helper. It also wires the new detectors into DI, updates detector taxonomy, and adds unit + verification resources and workflow/script updates to exercise the new detectors.
Changes:
- Added new detectors:
DockerComposeComponentDetector,HelmComponentDetector,KubernetesComponentDetectorto discover Docker image references in YAML-based config formats. - Introduced
DockerReferenceUtility.HasUnresolvedVariables/TryParseImageReference/TryRegisterImageReferenceand updated Dockerfile detector to use the shared logic. - Added unit tests + verification resources and enabled the new detectors in verification scripts/workflows; updated
DetectorClassand DI registration.
Show a summary per file
| File | Description |
|---|---|
src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs |
New Docker Compose detector parsing compose YAML and registering image references. |
src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs |
New Helm detector that filters to values files co-located with a chart file and extracts image references. |
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs |
New Kubernetes detector that pre-filters YAML then parses manifests to extract container image references. |
src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs |
Adds shared “unresolved variable” detection and safe parse/register helpers used by Docker-related detectors. |
src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs |
Updates Dockerfile parsing to use shared Docker reference parsing + unresolved-variable skipping. |
src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs |
Registers the new detectors in DI. |
src/Microsoft.ComponentDetection.Contracts/DetectorClass.cs |
Adds DockerCompose, Helm, Kubernetes detector classes. |
test/Microsoft.ComponentDetection.Detectors.Tests/DockerComposeComponentDetectorTests.cs |
Unit tests for Docker Compose detection scenarios (tags/digests/overrides/variable skipping). |
test/Microsoft.ComponentDetection.Detectors.Tests/HelmComponentDetectorTests.cs |
Unit tests for Helm values parsing (structured/direct refs, co-location behavior, variable skipping). |
test/Microsoft.ComponentDetection.Detectors.Tests/KubernetesComponentDetectorTests.cs |
Unit tests for Kubernetes workload kinds + variable skipping and non-K8s YAML rejection. |
test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs |
Adds/updates Dockerfile tests including variable skipping, digests, stages. |
docs/detectors/dockercompose.md |
Documentation for Docker Compose detector behavior and limitations. |
docs/detectors/helm.md |
Documentation for Helm detector behavior and limitations. |
docs/detectors/kubernetes.md |
Documentation for Kubernetes detector behavior and limitations. |
docs/detectors/README.md |
Adds detector entries/links for the new docs. |
test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.yml |
Verification resource for Docker Compose detection. |
test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.override.yml |
Verification resource for Docker Compose override detection. |
test/Microsoft.ComponentDetection.VerificationTests/resources/helm/Chart.yaml |
Verification resource to mark Helm chart root. |
test/Microsoft.ComponentDetection.VerificationTests/resources/helm/values.yaml |
Verification resource for Helm values image extraction. |
test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/deployment.yaml |
Verification resource for Kubernetes detection (multiple images, digests). |
test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/statefulset.yaml |
Verification resource for Kubernetes detection (statefulset image). |
test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/cronjob.yaml |
Verification resource for Kubernetes detection (cronjob image). |
test/Microsoft.ComponentDetection.VerificationTests/resources/VerificationTest.ps1 |
Enables new detectors in local verification test script. |
.github/workflows/snapshot-verify.yml |
Enables new detectors during snapshot verification scans. |
.github/workflows/snapshot-publish.yml |
Enables new detectors during snapshot publish scans. |
.gitignore |
Ignores .nuget/. |
Copilot's findings
- Files reviewed: 25/26 changed files
- Comments generated: 3
There was a problem hiding this comment.
Pull request overview
Adds new Docker-image–focused detectors (Docker Compose, Helm values, Kubernetes manifests) to Component Detection, plus shared parsing/skip logic for variable-interpolated image references and accompanying docs/tests/resources.
Changes:
- Introduce
DockerComposeComponentDetector,HelmComponentDetector, andKubernetesComponentDetectorto detect Docker image references in YAML-based configs. - Add
DockerReferenceUtility.HasUnresolvedVariables+TryParseImageReference/TryRegisterImageReferenceand update Dockerfile detector to use the shared logic. - Expand
DetectorClass, wire detectors into DI, and add unit + verification-test resources and workflow enablement for snapshot runs.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/statefulset.yaml | Adds Kubernetes sample manifest with an image reference for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/deployment.yaml | Adds Kubernetes deployment samples covering tags and digests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/cronjob.yaml | Adds Kubernetes CronJob sample manifest for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/values.yaml | Adds Helm values sample with multiple image specification patterns for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/Chart.yaml | Adds Helm chart marker file for co-location verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.yml | Adds Docker Compose sample file for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.override.yml | Adds Compose override sample for verification tests. |
| test/Microsoft.ComponentDetection.Detectors.Tests/KubernetesComponentDetectorTests.cs | Adds unit tests for Kubernetes detector image extraction and filtering behavior. |
| test/Microsoft.ComponentDetection.Detectors.Tests/HelmComponentDetectorTests.cs | Adds unit tests for Helm values parsing and chart co-location behavior. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs | Adds/updates Dockerfile detector tests, including variable-interpolation skipping. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerComposeComponentDetectorTests.cs | Adds unit tests for Docker Compose detector image extraction and skipping. |
| src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs | Registers new detectors in orchestrator DI container. |
| src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs | Implements Kubernetes YAML parsing and image extraction logic. |
| src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs | Implements Helm values parsing with chart co-location pre-filtering. |
| src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs | Switches Dockerfile detector to shared image parsing + variable-skip helpers and nullable enablement. |
| src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs | Implements Docker Compose YAML parsing and image extraction logic. |
| src/Microsoft.ComponentDetection.Contracts/DetectorClass.cs | Adds detector categories for DockerCompose/Helm/Kubernetes. |
| src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs | Adds shared unresolved-variable detection and safe parse/register helpers. |
| docs/detectors/kubernetes.md | Documents Kubernetes detector behavior, patterns, and limitations. |
| docs/detectors/helm.md | Documents Helm detector behavior, patterns, and limitations. |
| docs/detectors/dockercompose.md | Documents Docker Compose detector behavior, patterns, and limitations. |
| docs/detectors/README.md | Adds the new detectors to detector documentation index. |
| .gitignore | Ignores local .nuget/ folder. |
| .github/workflows/snapshot-verify.yml | Enables new DefaultOff detectors during snapshot verification scans. |
| .github/workflows/snapshot-publish.yml | Enables new DefaultOff detectors during snapshot publish scans. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs:18
- This detector is described (in docs/workflows/PR description) as DefaultOff, but the class does not implement
IDefaultOffComponentDetector. As written, it will run by default and scan all*.yml/*.yamlfiles, which is a significant behavioral/perf change. ImplementIDefaultOffComponentDetector(or update the docs/registration if it is intended to be on by default).
public class KubernetesComponentDetector : FileComponentDetector
{
- Files reviewed: 24/25 changed files
- Comments generated: 1
There was a problem hiding this comment.
Pull request overview
Adds DefaultOff detectors that scan Docker-related configuration formats (Docker Compose, Helm values, Kubernetes manifests) to discover Docker image references and register them as DockerReference components, plus shared utility improvements and accompanying tests/docs.
Changes:
- Added new DefaultOff detectors:
DockerComposeComponentDetector,HelmComponentDetector,KubernetesComponentDetector. - Added shared helper APIs in
DockerReferenceUtilityto skip unresolved-variable image references and to safely parse/register references. - Added/updated unit tests, verification resources, docs, DI registration, and extended
DetectorClass.
Show a summary per file
| File | Description |
|---|---|
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/statefulset.yaml | Adds Kubernetes manifest sample for verification tests (image extraction). |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/deployment.yaml | Adds Kubernetes deployment sample covering multiple image reference forms. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/cronjob.yaml | Adds Kubernetes CronJob sample for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/values.yaml | Adds Helm values sample with multiple image patterns for verification tests. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/Chart.yaml | Adds minimal Helm chart metadata to qualify the values file as Helm. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.yml | Adds docker-compose sample for verification tests (multiple services/images). |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.override.yml | Adds compose override sample for verification tests. |
| test/Microsoft.ComponentDetection.Detectors.Tests/KubernetesComponentDetectorTests.cs | Unit tests for Kubernetes image extraction + skipping unresolved variables. |
| test/Microsoft.ComponentDetection.Detectors.Tests/HelmComponentDetectorTests.cs | Unit tests for Helm values parsing + chart co-location filtering. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs | Adds/updates tests for Dockerfile parsing and unresolved-variable skipping. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerComposeComponentDetectorTests.cs | Unit tests for Docker Compose parsing and unresolved-variable skipping. |
| src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs | Registers the new detectors in DI. |
| src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs | New Kubernetes YAML detector with fast pre-filter + YAML parsing for image: fields. |
| src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs | New Helm detector that filters values files to chart directories and walks YAML for image keys. |
| src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs | Updates Dockerfile detector to use shared “try-parse / skip unresolved variables” logic. |
| src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs | New Docker Compose detector that extracts service image references. |
| src/Microsoft.ComponentDetection.Contracts/DetectorClass.cs | Adds enum entries for DockerCompose/Helm/Kubernetes categories. |
| src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs | Adds shared unresolved-variable detection and safe parse/register helpers. |
| docs/detectors/kubernetes.md | New Kubernetes detector documentation. |
| docs/detectors/helm.md | New Helm detector documentation. |
| docs/detectors/dockercompose.md | New Docker Compose detector documentation. |
| docs/detectors/README.md | Links new detector docs and status tables. |
| .gitignore | Ignores .nuget/ directory. |
Copilot's findings
Comments suppressed due to low confidence (1)
src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs:56
processRequests.ToList()returns anIObservable<IList<ProcessRequest>>(Rx), soawait processRequests.ToList()won’t compile. Use the RxToTask(cancellationToken)pattern (as in other detectors) to materialize the observable, and add the neededSystem.Reactive.Threading.Tasksimport.
protected override async Task<IObservable<ProcessRequest>> OnPrepareDetectionAsync(
IObservable<ProcessRequest> processRequests,
IDictionary<string, string> detectorArgs,
CancellationToken cancellationToken = default)
{
var allRequests = await processRequests.ToList();
var chartDirectories = new HashSet<string>(
- Files reviewed: 22/23 changed files
- Comments generated: 2
Clarify supported chart metadata file names for Helm detection.
There was a problem hiding this comment.
Pull request overview
This PR adds new DefaultOff detectors to discover Docker image references in Docker Compose, Helm values, and Kubernetes manifests, and centralizes “skip unresolved variable placeholders” handling across Docker-related detectors.
Changes:
- Added
DockerComposeComponentDetector,HelmComponentDetector, andKubernetesComponentDetector, and registered them in the orchestrator. - Introduced
DockerReferenceUtility.HasUnresolvedVariables/TryParseImageReference/TryRegisterImageReference, and updated the Dockerfile detector to use the shared logic. - Added/updated unit tests, verification resources, and detector documentation pages.
Show a summary per file
| File | Description |
|---|---|
| src/Microsoft.ComponentDetection.Orchestrator/Extensions/ServiceCollectionExtensions.cs | Registers the new detectors in DI. |
| src/Microsoft.ComponentDetection.Detectors/dockercompose/DockerComposeComponentDetector.cs | New detector for extracting services.*.image from compose YAML. |
| src/Microsoft.ComponentDetection.Detectors/helm/HelmComponentDetector.cs | New detector for Helm chart values image extraction with chart co-location filtering. |
| src/Microsoft.ComponentDetection.Detectors/kubernetes/KubernetesComponentDetector.cs | New detector for extracting container images from supported Kubernetes workload kinds. |
| src/Microsoft.ComponentDetection.Detectors/dockerfile/DockerfileComponentDetector.cs | Refactors parsing to use shared Docker reference parsing/variable-skipping helpers. |
| src/Microsoft.ComponentDetection.Common/DockerReference/DockerReferenceUtility.cs | Adds shared unresolved-variable detection and safe parse/register helpers. |
| src/Microsoft.ComponentDetection.Contracts/DetectorClass.cs | Extends DetectorClass with DockerCompose/Helm/Kubernetes. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerComposeComponentDetectorTests.cs | New unit tests for docker-compose detection behavior. |
| test/Microsoft.ComponentDetection.Detectors.Tests/HelmComponentDetectorTests.cs | New unit tests for Helm values detection behavior and co-location logic. |
| test/Microsoft.ComponentDetection.Detectors.Tests/KubernetesComponentDetectorTests.cs | New unit tests for Kubernetes manifest detection and image extraction. |
| test/Microsoft.ComponentDetection.Detectors.Tests/DockerfileComponentDetectorTests.cs | Adds/updates tests for Dockerfile detector behavior (including unresolved variables). |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.yml | Verification resource for compose detection. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/dockercompose/docker-compose.override.yml | Verification resource for compose override detection. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/Chart.yaml | Verification resource for Helm chart co-location. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/helm/values.yaml | Verification resource for Helm values image discovery. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/deployment.yaml | Verification resource for Kubernetes workloads and image formats. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/statefulset.yaml | Verification resource for Kubernetes statefulset image discovery. |
| test/Microsoft.ComponentDetection.VerificationTests/resources/kubernetes/cronjob.yaml | Verification resource for Kubernetes cronjob image discovery. |
| docs/detectors/dockercompose.md | New detector documentation page. |
| docs/detectors/helm.md | New detector documentation page. |
| docs/detectors/kubernetes.md | New detector documentation page. |
| docs/detectors/README.md | Adds the new detectors to the detector docs index. |
| .gitignore | Ignores local .nuget/ folder. |
Copilot's findings
- Files reviewed: 22/23 changed files
- Comments generated: 2
| public override IList<string> SearchPatterns { get; } = | ||
| [ | ||
| "Chart.yaml", "Chart.yml", | ||
| "*values*.yaml", "*values*.yml", | ||
| ]; |
There was a problem hiding this comment.
SearchPatterns/IsChartFile treat Chart.yml as a valid chart indicator, but the unit tests only cover Chart.yml without a values file (expecting no components). Add a test that verifies a co-located Chart.yml + values file is actually processed (or drop Chart.yml support if it’s not intended).
| private void ExtractImageReferencesFromValues(YamlStream yaml, ISingleFileComponentRecorder recorder, string fileLocation) | ||
| { | ||
| foreach (var document in yaml.Documents) | ||
| { | ||
| if (document.RootNode is YamlMappingNode rootMapping) | ||
| { | ||
| this.WalkYamlForImages(rootMapping, recorder, fileLocation); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Walks the YAML tree looking for image references. Handles two common patterns: | ||
| /// 1. Direct image string: `image: nginx:1.21` | ||
| /// 2. Structured image object: `image: { repository: nginx, tag: "1.21" }`. | ||
| /// </summary> | ||
| private void WalkYamlForImages(YamlMappingNode mapping, ISingleFileComponentRecorder recorder, string fileLocation) | ||
| { |
There was a problem hiding this comment.
fileLocation is threaded through ExtractImageReferencesFromValues/WalkYamlForImages but never used. Consider removing the parameter (and corresponding call-site arguments) or using it for logging/context to avoid dead parameters being propagated through the recursion.
grvillic
left a comment
There was a problem hiding this comment.
There is no need to add all detectors in a single PR, break them up into separate PRs.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1759 +/- ##
============================
============================
☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This pull request adds new detectors for Docker Compose, Helm, and Kubernetes YAML files, enabling the system to automatically discover and register Docker image references found in these types of configuration files. It also updates the service registration and the
DetectorClassenum to support these new detectors.It also adds tests for the new detectors plus the Dockerfile one.
Image references containing unresolved variable placeholders (e.g.,
${REGISTRY}/app:${TAG},{{ .Values.image.tag }}) are silently skipped in all four Docker-related detectors (DockerCompose, Helm, Kubernetes, and Dockerfile) to avoid noisy warnings for otherwise-valid real-world manifests. A sharedDockerReferenceUtility.HasUnresolvedVariableshelper was added toMicrosoft.ComponentDetection.Commonto consolidate this logic, and all detectors—including the existingDockerfileComponentDetector—now use it.The Helm detector uses the combination of a
Chart.yaml/Chart.ymlfile and a*values*.(yaml|yml)file in the same directory to identify Helm charts. Values files found without a co-located Chart file are skipped, avoiding false positives from unrelatedvalues.yamlfiles in non-Helm projects.A bug in
DetectorRestrictionServicewas also fixed: when bothAllowedDetectorIdsandAllowedDetectorCategoriesare specified, DefaultOff detectors introduced via category expansion are now also constrained by the ID allow-list, producing an intersection rather than an unintended union.New Detector Checklist
ComponentType.csandDetectorClass.csComponent class created inTypedComponent/folder with proper validationFileComponentDetectorand implementingIDefaultOffComponentDetectorServiceCollectionExtensions.csSearchPatternsdefined for file discoveryOnFileFoundAsync()implemented with component registration logicDetectors.Tests/usingDetectorTestUtilityBuilderVerificationTests/resources/--DetectorArgs YourDetectorId=EnableIfDefaultOff