@@ -26,7 +26,6 @@ import (
2626 "github.com/Masterminds/semver/v3"
2727 securejoin "github.com/cyphar/filepath-securejoin"
2828 "helm.sh/helm/v3/pkg/chart/loader"
29- "helm.sh/helm/v3/pkg/provenance"
3029 "sigs.k8s.io/yaml"
3130
3231 "github.com/fluxcd/pkg/runtime/transform"
@@ -107,21 +106,6 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
107106 requiresPackaging := isChartDir || opts .VersionMetadata != "" || len (opts .GetValuesFiles ()) != 0
108107
109108 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- }
125109
126110 // If all the following is true, we do not need to package the chart:
127111 // - Chart name from cached chart matches resolved name
@@ -135,16 +119,14 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
135119 if result .Name == curMeta .Name && result .Version == curMeta .Version {
136120 // We can only verify a cached chart with provenance file if we didn't
137121 // package the chart ourselves, and instead stored it as is.
138- if ! requiresPackaging {
122+ if ! requiresPackaging && opts . Keyring != nil {
139123 provFilePath = provenanceFilePath (opts .CachedChart )
140- ver , err := verifyProvFile ( opts .CachedChart , provFilePath )
124+ ver , err := verifyChartWithProvFile ( bytes . NewReader ( opts . Keyring ), opts .CachedChart , provFilePath )
141125 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 }
147127 }
128+ result .VerificationSignature = buildVerificationSig (ver )
129+ result .ProvFilePath = provFilePath
148130 }
149131 result .Path = opts .CachedChart
150132 result .ValuesFiles = opts .GetValuesFiles ()
@@ -158,18 +140,18 @@ func (b *localChartBuilder) Build(ctx context.Context, ref Reference, p string,
158140 // If the chart at the path is already packaged and no custom values files
159141 // options are set, we can copy the chart without making modifications
160142 if ! requiresPackaging {
161- provFilePath = provenanceFilePath (p )
162143 if err = copyFileToPath (localRef .Path , p ); err != nil {
163144 return result , & BuildError {Reason : ErrChartPull , Err : err }
164145 }
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+ }
173155 result .ProvFilePath = provFilePath
174156 result .VerificationSignature = buildVerificationSig (ver )
175157 }
0 commit comments