fix(helm): Make Helm template detection less aggressive #7288
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.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
Description
This change addresses an issue where the Helm parser was too aggressive in its detection of Helm templates, causing it to incorrectly identify and skip valid, rendered Kubernetes manifests that contained other templating languages (like HashiCorp Vault) in their annotations.
Motivation and Context
When scanning a Helm chart,
checkov
first renders the chart usinghelm template
and then scans the resulting Kubernetes YAML. However, a regex-based check was in place to prevent the scanning of un-rendered Helm templates. This check was too broad and was incorrectly triggered by the syntax of other templating languages, such as the{{- with secret ... }}
syntax used by HashiCorp Vault in annotations.This resulted in
checkov
producing empty results for Helm charts that used these other templating languages, as it would incorrectly identify the rendered YAML as an un-rendered template and skip it.Description of the Change
This PR modifies the
helm_template_patterns
incheckov/kubernetes/parser/k8_yaml.py
to be more specific to Helm templates. It removes the generic checks forif
,end
, andwith
statements, and relies only on the presence of.Release.
and.Values.
to identify un-rendered Helm templates.This change ensures that
checkov
can correctly scan rendered Helm charts that include other templating languages in their annotations, without affecting its ability to handle standard Helm charts.Checklist: