@@ -26,7 +26,6 @@ import (
26
26
"github.com/Masterminds/semver/v3"
27
27
securejoin "github.com/cyphar/filepath-securejoin"
28
28
"helm.sh/helm/v3/pkg/chart/loader"
29
- "helm.sh/helm/v3/pkg/provenance"
30
29
"sigs.k8s.io/yaml"
31
30
32
31
"github.com/fluxcd/pkg/runtime/transform"
@@ -107,21 +106,6 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
107
106
requiresPackaging := isChartDir || opts .VersionMetadata != "" || len (opts .GetValuesFiles ()) != 0
108
107
109
108
var provFilePath string
110
- verifyProvFile := func (chart , provFile string ) (* provenance.Verification , error ) {
111
- if opts .Keyring != nil {
112
- if _ , err := os .Stat (provFile ); err != nil {
113
- err = fmt .Errorf ("could not load provenance file %s: %w" , provFile , err )
114
- return nil , & BuildError {Reason : ErrProvenanceVerification , Err : err }
115
- }
116
- ver , err := verifyChartWithProvFile (bytes .NewReader (opts .Keyring ), chart , provFile )
117
- if err != nil {
118
- err = fmt .Errorf ("failed to verify helm chart using provenance file: %w" , err )
119
- return nil , & BuildError {Reason : ErrProvenanceVerification , Err : err }
120
- }
121
- return ver , nil
122
- }
123
- return nil , nil
124
- }
125
109
126
110
// If all the following is true, we do not need to package the chart:
127
111
// - Chart name from cached chart matches resolved name
@@ -135,16 +119,14 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
135
119
if result .Name == curMeta .Name && result .Version == curMeta .Version {
136
120
// We can only verify a cached chart with provenance file if we didn't
137
121
// package the chart ourselves, and instead stored it as is.
138
- if ! requiresPackaging {
122
+ if ! requiresPackaging && opts . Keyring != nil {
139
123
provFilePath = provenanceFilePath (opts .CachedChart )
140
- ver , err := verifyProvFile ( opts .CachedChart , provFilePath )
124
+ ver , err := verifyChartWithProvFile ( bytes . NewReader ( opts . Keyring ), opts .CachedChart , provFilePath )
141
125
if err != nil {
142
- return nil , err
143
- }
144
- if ver != nil {
145
- result .VerificationSignature = buildVerificationSig (ver )
146
- result .ProvFilePath = provFilePath
126
+ return nil , & BuildError {Reason : ErrProvenanceVerification , Err : err }
147
127
}
128
+ result .VerificationSignature = buildVerificationSig (ver )
129
+ result .ProvFilePath = provFilePath
148
130
}
149
131
result .Path = opts .CachedChart
150
132
result .ValuesFiles = opts .GetValuesFiles ()
@@ -158,18 +140,18 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
158
140
// If the chart at the path is already packaged and no custom values files
159
141
// options are set, we can copy the chart without making modifications
160
142
if ! requiresPackaging {
161
- provFilePath = provenanceFilePath (p )
162
143
if err = copyFileToPath (localRef .Path , p ); err != nil {
163
144
return result , & BuildError {Reason : ErrChartPull , Err : err }
164
145
}
165
- if err = copyFileToPath (provenanceFilePath (localRef .Path ), provFilePath ); err != nil {
166
- return result , & BuildError {Reason : ErrChartPull , Err : err }
167
- }
168
- ver , err := verifyProvFile (localRef .Path , provFilePath )
169
- if err != nil {
170
- return nil , err
171
- }
172
- if ver != nil {
146
+ if opts .Keyring != nil {
147
+ provFilePath = provenanceFilePath (p )
148
+ if err = copyFileToPath (provenanceFilePath (localRef .Path ), provFilePath ); err != nil {
149
+ return result , & BuildError {Reason : ErrChartPull , Err : err }
150
+ }
151
+ ver , err := verifyChartWithProvFile (bytes .NewReader (opts .Keyring ), localRef .Path , provFilePath )
152
+ if err != nil {
153
+ return nil , err
154
+ }
173
155
result .ProvFilePath = provFilePath
174
156
result .VerificationSignature = buildVerificationSig (ver )
175
157
}
0 commit comments