@@ -71,6 +71,7 @@ var helmChartReadyConditions = summarize.Conditions{
71
71
sourcev1 .BuildFailedCondition ,
72
72
sourcev1 .FetchFailedCondition ,
73
73
sourcev1 .ArtifactOutdatedCondition ,
74
+ sourcev1 .SourceVerifiedCondition ,
74
75
meta .ReadyCondition ,
75
76
meta .ReconcilingCondition ,
76
77
meta .StalledCondition ,
@@ -79,6 +80,7 @@ var helmChartReadyConditions = summarize.Conditions{
79
80
sourcev1 .BuildFailedCondition ,
80
81
sourcev1 .FetchFailedCondition ,
81
82
sourcev1 .ArtifactOutdatedCondition ,
83
+ sourcev1 .SourceVerifiedCondition ,
82
84
meta .StalledCondition ,
83
85
meta .ReconcilingCondition ,
84
86
},
@@ -453,16 +455,20 @@ func (r *HelmChartReconciler) buildFromHelmRepository(ctx context.Context, obj *
453
455
opts .VersionMetadata = strconv .FormatInt (obj .Generation , 10 )
454
456
}
455
457
456
- var keyring []byte
457
- keyring , err = r .getProvenanceKeyring (ctx , obj )
458
+ keyring , err := r .getProvenanceKeyring (ctx , obj )
458
459
if err != nil {
459
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 .AuthenticationFailedReason , err .Error ())
460
- return sreconcile .ResultEmpty , err
460
+ e := & serror.Event {
461
+ Err : fmt .Errorf ("failed to get public key for chart signature verification: %w" , err ),
462
+ Reason : sourcev1 .SourceVerifiedCondition ,
463
+ }
464
+ conditions .MarkFalse (obj , sourcev1 .FetchFailedCondition , sourcev1 .SourceVerifiedCondition , e .Error ())
465
+ return sreconcile .ResultEmpty , e
461
466
}
467
+ opts .Keyring = keyring
462
468
463
469
// Build the chart
464
470
ref := chart.RemoteReference {Name : obj .Spec .Chart , Version : obj .Spec .Version }
465
- build , err := cb .Build (ctx , ref , util .TempPathForObj ("" , ".tgz" , obj ), opts , keyring )
471
+ build , err := cb .Build (ctx , ref , util .TempPathForObj ("" , ".tgz" , obj ), opts )
466
472
467
473
if err != nil {
468
474
return sreconcile .ResultEmpty , err
@@ -585,19 +591,23 @@ func (r *HelmChartReconciler) buildFromTarballArtifact(ctx context.Context, obj
585
591
}
586
592
opts .VersionMetadata += strconv .FormatInt (obj .Generation , 10 )
587
593
}
588
- var keyring []byte
589
- keyring , err = r .getProvenanceKeyring (ctx , obj )
594
+ keyring , err := r .getProvenanceKeyring (ctx , obj )
590
595
if err != nil {
591
- conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , sourcev1 .AuthenticationFailedReason , err .Error ())
592
- return sreconcile .ResultEmpty , err
596
+ e := & serror.Event {
597
+ Err : fmt .Errorf ("failed to get public key for chart signature verification: %w" , err ),
598
+ Reason : sourcev1 .SourceVerifiedCondition ,
599
+ }
600
+ conditions .MarkFalse (obj , sourcev1 .FetchFailedCondition , sourcev1 .SourceVerifiedCondition , e .Error ())
601
+ return sreconcile .ResultEmpty , e
593
602
}
603
+ opts .Keyring = keyring
594
604
595
605
// Build chart
596
606
cb := chart .NewLocalBuilder (dm )
597
607
build , err := cb .Build (ctx , chart.LocalReference {
598
608
WorkDir : sourceDir ,
599
609
Path : chartPath ,
600
- }, util .TempPathForObj ("" , ".tgz" , obj ), opts , keyring )
610
+ }, util .TempPathForObj ("" , ".tgz" , obj ), opts )
601
611
if err != nil {
602
612
return sreconcile .ResultEmpty , err
603
613
}
@@ -620,6 +630,14 @@ func (r *HelmChartReconciler) reconcileArtifact(ctx context.Context, obj *source
620
630
conditions .Delete (obj , sourcev1 .ArtifactOutdatedCondition )
621
631
conditions .MarkTrue (obj , meta .ReadyCondition , reasonForBuild (b ), b .Summary ())
622
632
}
633
+ if b .VerificationSignature != nil && b .ProvFilePath != "" && obj .GetArtifact () != nil {
634
+ var sigVerMsg strings.Builder
635
+ sigVerMsg .WriteString (fmt .Sprintf ("chart signed by: %v" , strings .Join (b .VerificationSignature .Identities [:], "," )))
636
+ sigVerMsg .WriteString (fmt .Sprintf (" using key with fingeprint: %X" , b .VerificationSignature .KeyFingerprint ))
637
+ sigVerMsg .WriteString (fmt .Sprintf (" and hash verified: %s" , b .VerificationSignature .FileHash ))
638
+
639
+ conditions .MarkTrue (obj , sourcev1 .SourceVerifiedCondition , reasonForBuild (b ), sigVerMsg .String ())
640
+ }
623
641
}()
624
642
625
643
// Create artifact from build data
@@ -759,15 +777,23 @@ func (r *HelmChartReconciler) garbageCollect(ctx context.Context, obj *sourcev1.
759
777
obj .Status .Artifact = nil
760
778
return nil
761
779
}
780
+
762
781
if obj .GetArtifact () != nil {
763
- if deleted , err := r .Storage .RemoveAllButCurrent (* obj .GetArtifact ()); err != nil {
782
+ localPath := r .Storage .LocalPath (* obj .GetArtifact ())
783
+ provFilePath := localPath + ".prov"
784
+ dir := filepath .Dir (localPath )
785
+ callbacks := make ([]func (path string , info os.FileInfo ) bool , 0 )
786
+ callbacks = append (callbacks , func (path string , info os.FileInfo ) bool {
787
+ if path != localPath && path != provFilePath && info .Mode ()& os .ModeSymlink != os .ModeSymlink {
788
+ return true
789
+ }
790
+ return false
791
+ })
792
+ if _ , err := r .Storage .RemoveConditionally (dir , callbacks ); err != nil {
764
793
return & serror.Event {
765
794
Err : fmt .Errorf ("garbage collection of old artifacts failed: %w" , err ),
766
795
Reason : "GarbageCollectionFailed" ,
767
796
}
768
- } else if len (deleted ) > 0 {
769
- r .eventLogf (ctx , obj , events .EventTypeTrace , "GarbageCollectionSucceeded" ,
770
- "garbage collected old artifacts" )
771
797
}
772
798
}
773
799
return nil
@@ -1037,20 +1063,12 @@ func (r *HelmChartReconciler) getProvenanceKeyring(ctx context.Context, chart *s
1037
1063
var secret corev1.Secret
1038
1064
err := r .Client .Get (ctx , name , & secret )
1039
1065
if err != nil {
1040
- e := & serror.Event {
1041
- Err : fmt .Errorf ("failed to get secret '%s': %w" , chart .Spec .VerificationKeyring .SecretRef .Name , err ),
1042
- Reason : sourcev1 .AuthenticationFailedReason ,
1043
- }
1044
- return nil , e
1066
+ return nil , err
1045
1067
}
1046
1068
key := chart .Spec .VerificationKeyring .Key
1047
1069
if val , ok := secret .Data [key ]; ! ok {
1048
1070
err = fmt .Errorf ("secret doesn't contain the advertised verification keyring name %s" , key )
1049
- e := & serror.Event {
1050
- Err : fmt .Errorf ("invalid secret '%s': %w" , secret .GetName (), err ),
1051
- Reason : sourcev1 .AuthenticationFailedReason ,
1052
- }
1053
- return nil , e
1071
+ return nil , err
1054
1072
} else {
1055
1073
return val , nil
1056
1074
}
0 commit comments