Skip to content

Commit 39a6832

Browse files
committed
Fix verification condition
Delete a failed verification condition at the beginning of the source reconciliation and set `SourceVerifiedCondition` to false approprietly. Set the `BuildOptions.Verify` to true as long as Verify is enabled in the API fields. Signed-off-by: Soule BA <soule@weave.works>
1 parent 96197f7 commit 39a6832

File tree

8 files changed

+21
-18
lines changed

8 files changed

+21
-18
lines changed

api/v1beta2/helmchart_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type HelmChartSpec struct {
9090
// Verify contains the secret name containing the trusted public keys
9191
// used to verify the signature and specifies which provider to use to check
9292
// whether OCI image is authentic.
93-
// This field is only supported for OCI sources.
93+
// This field is only supported when using HelmRepository source with spec.type 'oci'.
9494
// Chart dependencies, which are not bundled in the umbrella chart artifact, are not verified.
9595
// +optional
9696
Verify *OCIRepositoryVerification `json:"verify,omitempty"`

controllers/helmchart_controller.go

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ func (r *HelmChartReconciler) reconcileStorage(ctx context.Context, obj *sourcev
371371
}
372372

373373
func (r *HelmChartReconciler) reconcileSource(ctx context.Context, obj *sourcev1.HelmChart, build *chart.Build) (_ sreconcile.Result, retErr error) {
374+
// Remove any failed verification condition.
375+
// The reason is that a failing verification should be recalculated.
376+
if conditions.IsFalse(obj, sourcev1.SourceVerifiedCondition) {
377+
conditions.Delete(obj, sourcev1.SourceVerifiedCondition)
378+
}
379+
374380
// Retrieve the source
375381
s, err := r.getSource(ctx, obj)
376382
if err != nil {
@@ -649,15 +655,8 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
649655
Force: obj.Generation != obj.Status.ObservedGeneration,
650656
// The remote builder will not attempt to download the chart if
651657
// an artifact exists with the same name and version and `Force` is false.
652-
// It will try to verify the chart if:
653-
// - we are on the first reconciliation
654-
// - the HelmChart spec has changed (generation drift)
655-
// - the previous reconciliation resulted in a failed artifact verification
656-
// - there is no artifact in storage
657-
Verify: obj.Spec.Verify != nil && (obj.Generation <= 0 ||
658-
conditions.GetObservedGeneration(obj, sourcev1.SourceVerifiedCondition) != obj.Generation ||
659-
conditions.IsFalse(obj, sourcev1.SourceVerifiedCondition) ||
660-
obj.GetArtifact() == nil),
658+
// It will however try to verify the chart if `obj.Spec.Verify` is set, at every reconciliation.
659+
Verify: obj.Spec.Verify != nil && obj.Spec.Verify.Provider != "",
661660
}
662661
if artifact := obj.GetArtifact(); artifact != nil {
663662
opts.CachedChart = r.Storage.LocalPath(*artifact)
@@ -1292,9 +1291,13 @@ func observeChartBuild(obj *sourcev1.HelmChart, build *chart.Build, err error) {
12921291
}
12931292

12941293
switch buildErr.Reason {
1295-
case chart.ErrChartMetadataPatch, chart.ErrValuesFilesMerge, chart.ErrDependencyBuild, chart.ErrChartPackage, chart.ErrChartVerification:
1294+
case chart.ErrChartMetadataPatch, chart.ErrValuesFilesMerge, chart.ErrDependencyBuild, chart.ErrChartPackage:
1295+
conditions.Delete(obj, sourcev1.FetchFailedCondition)
1296+
conditions.MarkTrue(obj, sourcev1.BuildFailedCondition, buildErr.Reason.Reason, buildErr.Error())
1297+
case chart.ErrChartVerification:
12961298
conditions.Delete(obj, sourcev1.FetchFailedCondition)
12971299
conditions.MarkTrue(obj, sourcev1.BuildFailedCondition, buildErr.Reason.Reason, buildErr.Error())
1300+
conditions.MarkFalse(obj, sourcev1.SourceVerifiedCondition, buildErr.Reason.Reason, buildErr.Error())
12981301
default:
12991302
conditions.Delete(obj, sourcev1.BuildFailedCondition)
13001303
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, buildErr.Reason.Reason, buildErr.Error())

controllers/helmchart_controller_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2290,6 +2290,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
22902290
want: sreconcile.ResultEmpty,
22912291
assertConditions: []metav1.Condition{
22922292
*conditions.TrueCondition(sourcev1.BuildFailedCondition, "ChartVerificationError", "chart verification error: failed to verify <url>: no matching signatures:"),
2293+
*conditions.FalseCondition(sourcev1.SourceVerifiedCondition, "ChartVerificationError", "chart verification error: failed to verify <url>: no matching signatures:"),
22932294
},
22942295
},
22952296
{
@@ -2305,6 +2306,7 @@ func TestHelmChartReconciler_reconcileSourceFromOCI_verifySignature(t *testing.T
23052306
want: sreconcile.ResultEmpty,
23062307
assertConditions: []metav1.Condition{
23072308
*conditions.TrueCondition(sourcev1.BuildFailedCondition, "ChartVerificationError", "chart verification error: failed to verify <url>: no matching signatures:"),
2309+
*conditions.FalseCondition(sourcev1.SourceVerifiedCondition, "ChartVerificationError", "chart verification error: failed to verify <url>: no matching signatures:"),
23082310
},
23092311
},
23102312
{

docs/api/source.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -684,7 +684,7 @@ OCIRepositoryVerification
684684
<p>Verify contains the secret name containing the trusted public keys
685685
used to verify the signature and specifies which provider to use to check
686686
whether OCI image is authentic.
687-
This field is only supported for OCI sources.
687+
This field is only supported when using HelmRepository source with spec.type &lsquo;oci&rsquo;.
688688
Chart dependencies, which are not bundled in the umbrella chart artifact, are not verified.</p>
689689
</td>
690690
</tr>
@@ -2269,7 +2269,7 @@ OCIRepositoryVerification
22692269
<p>Verify contains the secret name containing the trusted public keys
22702270
used to verify the signature and specifies which provider to use to check
22712271
whether OCI image is authentic.
2272-
This field is only supported for OCI sources.
2272+
This field is only supported when using HelmRepository source with spec.type &lsquo;oci&rsquo;.
22732273
Chart dependencies, which are not bundled in the umbrella chart artifact, are not verified.</p>
22742274
</td>
22752275
</tr>

docs/spec/v1beta2/helmcharts.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ data:
290290

291291
Note that the keys must have the `.pub` extension for Flux to make use of them.
292292

293-
Flux will loop over the public keys and use them verify a HelmChart's signature.
293+
Flux will loop over the public keys and use them to verify a HelmChart's signature.
294294
This allows for older HelmCharts to be valid as long as the right key is in the secret.
295295

296296
#### Keyless verification

docs/spec/v1beta2/ocirepositories.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ data:
462462

463463
Note that the keys must have the `.pub` extension for Flux to make use of them.
464464

465-
Flux will loop over the public keys and use them verify an artifact's signature.
465+
Flux will loop over the public keys and use them to verify an artifact's signature.
466466
This allows for older artifacts to be valid as long as the right key is in the secret.
467467

468468
#### Keyless verification

internal/helm/registry/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func KeychainAdaptHelper(keyChain authn.Keychain) func(string) (registry.LoginOp
105105
}
106106

107107
// AuthAdaptHelper returns an ORAS credentials callback configured with the authorization data
108-
// from the given authn authenticator This allows for example to make use of credential helpers from
108+
// from the given authn authenticator. This allows for example to make use of credential helpers from
109109
// cloud providers.
110110
// Ref: https://github.com/google/go-containerregistry/tree/main/pkg/authn
111111
func AuthAdaptHelper(auth authn.Authenticator) (registry.LoginOption, error) {

internal/helm/repository/chart_repository.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,10 +523,8 @@ func (r *ChartRepository) RemoveCache() error {
523523
}
524524

525525
// VerifyChart verifies the chart against a signature.
526-
// If no signature is provided, a keyless verification is performed.
527526
// It returns an error on failure.
528527
func (r *ChartRepository) VerifyChart(_ context.Context, _ *repo.ChartVersion) error {
529-
// no-op
530528
// this is a no-op because this is not implemented yet.
531529
return fmt.Errorf("not implemented")
532530
}

0 commit comments

Comments
 (0)