Skip to content

Commit 5e06e78

Browse files
authored
fix(helm-chart): allow empty values (#2491)
Signed-off-by: Sylwester Piskozub <sylwesterpiskozub@gmail.com>
1 parent 8936e8d commit 5e06e78

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pkg/attestation/crafter/materials/helmchart.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"archive/tar"
2020
"compress/gzip"
2121
"context"
22+
"errors"
2223
"fmt"
2324
"io"
2425
"os"
@@ -121,12 +122,12 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
121122
// it was compressed from. So, we can check if the file name contains the required file names
122123
// Ex: helm-chart/Chart.yaml, helm-chart/values.yaml
123124
if strings.Contains(header.Name, chartFileName) {
124-
if err := c.validateYamlFile(tarReader); err != nil {
125+
if err := c.validateYamlFile(tarReader, false); err != nil {
125126
return nil, fmt.Errorf("invalid Chart.yaml file: %w", err)
126127
}
127128
chartFileValid = true
128129
} else if strings.Contains(header.Name, chartValuesYamlFileName) {
129-
if err := c.validateYamlFile(tarReader); err != nil {
130+
if err := c.validateYamlFile(tarReader, true); err != nil {
130131
return nil, fmt.Errorf("invalid values.yaml file: %w", err)
131132
}
132133
chartValuesValid = true
@@ -148,9 +149,14 @@ func (c *HelmChartCrafter) craftLocalHelmChart(ctx context.Context, filepath str
148149
}
149150

150151
// validateYamlFile validates the YAML file just by trying to unmarshal it
151-
func (c *HelmChartCrafter) validateYamlFile(r io.Reader) error {
152+
func (c *HelmChartCrafter) validateYamlFile(r io.Reader, allowEmpty bool) error {
152153
v := make(map[string]interface{})
153154
if err := yaml.NewDecoder(r).Decode(v); err != nil {
155+
// io.EOF means the file is empty or contains only comments
156+
// This is valid for values.yaml
157+
if errors.Is(err, io.EOF) && allowEmpty {
158+
return nil
159+
}
154160
return fmt.Errorf("failed to unmarshal YAML file: %w", err)
155161
}
156162

pkg/attestation/crafter/materials/helmchart_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ func TestHelmChartCraft(t *testing.T) {
102102
wantDigest: "sha256:08a46a850789938ede61d6a53552f48cb8ba74c4e17dcf30c9c50e5783ca6a13",
103103
wantFilename: "valid-chart.tgz",
104104
},
105+
{
106+
name: "chart with empty values.yaml",
107+
filePath: "./testdata/empty-values.tgz",
108+
wantDigest: "sha256:6c5bc910da7ecb00aa1c7be70e51db237d129e3f41ff6ada1d11ea402ff7082e",
109+
wantFilename: "empty-values.tgz",
110+
},
105111
}
106112

107113
assert := assert.New(t)
273 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)