@@ -25,8 +25,6 @@ import (
2525 "time"
2626
2727 "github.com/fluxcd/pkg/apis/meta"
28- "github.com/go-git/go-git/v5/plumbing/object"
29- "github.com/go-git/go-git/v5/plumbing/transport"
3028 "github.com/go-logr/logr"
3129 corev1 "k8s.io/api/core/v1"
3230 apimeta "k8s.io/apimachinery/pkg/api/meta"
@@ -46,6 +44,7 @@ import (
4644
4745 sourcev1 "github.com/fluxcd/source-controller/api/v1beta1"
4846 "github.com/fluxcd/source-controller/pkg/git"
47+ "github.com/fluxcd/source-controller/pkg/git/common"
4948)
5049
5150// GitRepositoryReconciler reconciles a GitRepository object
@@ -154,7 +153,6 @@ func (r *GitRepositoryReconciler) Reconcile(req ctrl.Request) (ctrl.Result, erro
154153 ))
155154
156155 return ctrl.Result {RequeueAfter : repository .GetInterval ().Duration }, nil
157-
158156}
159157
160158type GitRepositoryReconcilerOptions struct {
@@ -183,9 +181,9 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
183181 defer os .RemoveAll (tmpGit )
184182
185183 // determine auth method
186- var auth transport. AuthMethod
184+ auth := & common. Auth {}
187185 if repository .Spec .SecretRef != nil {
188- authStrategy , err := git .AuthSecretStrategyForURL (repository .Spec .URL )
186+ authStrategy , err := git .AuthSecretStrategyForURL (repository .Spec .URL , repository . Spec . GitImplementation )
189187 if err != nil {
190188 return sourcev1 .GitRepositoryNotReady (repository , sourcev1 .AuthenticationFailedReason , err .Error ()), err
191189 }
@@ -209,14 +207,17 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
209207 }
210208 }
211209
212- checkoutStrategy := git .CheckoutStrategyForRef (repository .Spec .Reference )
210+ checkoutStrategy , err := git .CheckoutStrategyForRef (repository .Spec .Reference , repository .Spec .GitImplementation )
211+ if err != nil {
212+ return sourcev1 .GitRepositoryNotReady (repository , sourcev1 .GitOperationFailedReason , err .Error ()), err
213+ }
213214 commit , revision , err := checkoutStrategy .Checkout (ctx , tmpGit , repository .Spec .URL , auth )
214215 if err != nil {
215216 return sourcev1 .GitRepositoryNotReady (repository , sourcev1 .GitOperationFailedReason , err .Error ()), err
216217 }
217218
218219 // return early on unchanged revision
219- artifact := r .Storage .NewArtifactFor (repository .Kind , repository .GetObjectMeta (), revision , fmt .Sprintf ("%s.tar.gz" , commit .Hash . String ()))
220+ artifact := r .Storage .NewArtifactFor (repository .Kind , repository .GetObjectMeta (), revision , fmt .Sprintf ("%s.tar.gz" , commit .Hash ()))
220221 if apimeta .IsStatusConditionTrue (repository .Status .Conditions , meta .ReadyCondition ) && repository .GetArtifact ().HasRevision (artifact .Revision ) {
221222 if artifact .URL != repository .GetArtifact ().URL {
222223 r .Storage .SetArtifactURL (repository .GetArtifact ())
@@ -227,10 +228,17 @@ func (r *GitRepositoryReconciler) reconcile(ctx context.Context, repository sour
227228
228229 // verify PGP signature
229230 if repository .Spec .Verification != nil {
230- err := r . verify ( ctx , types.NamespacedName {
231+ publicKeySecret := types.NamespacedName {
231232 Namespace : repository .Namespace ,
232233 Name : repository .Spec .Verification .SecretRef .Name ,
233- }, commit )
234+ }
235+ var secret corev1.Secret
236+ if err := r .Client .Get (ctx , publicKeySecret , & secret ); err != nil {
237+ err = fmt .Errorf ("PGP public keys secret error: %w" , err )
238+ return sourcev1 .GitRepositoryNotReady (repository , sourcev1 .VerificationFailedReason , err .Error ()), err
239+ }
240+
241+ err := commit .Verify (secret )
234242 if err != nil {
235243 return sourcev1 .GitRepositoryNotReady (repository , sourcev1 .VerificationFailedReason , err .Error ()), err
236244 }
@@ -288,30 +296,6 @@ func (r *GitRepositoryReconciler) reconcileDelete(ctx context.Context, repositor
288296 return ctrl.Result {}, nil
289297}
290298
291- // verify returns an error if the PGP signature can't be verified
292- func (r * GitRepositoryReconciler ) verify (ctx context.Context , publicKeySecret types.NamespacedName , commit * object.Commit ) error {
293- if commit .PGPSignature == "" {
294- return fmt .Errorf ("no PGP signature found for commit: %s" , commit .Hash )
295- }
296-
297- var secret corev1.Secret
298- if err := r .Client .Get (ctx , publicKeySecret , & secret ); err != nil {
299- return fmt .Errorf ("PGP public keys secret error: %w" , err )
300- }
301-
302- var verified bool
303- for _ , bytes := range secret .Data {
304- if _ , err := commit .Verify (string (bytes )); err == nil {
305- verified = true
306- break
307- }
308- }
309- if ! verified {
310- return fmt .Errorf ("PGP signature '%s' of '%s' can't be verified" , commit .PGPSignature , commit .Author )
311- }
312- return nil
313- }
314-
315299// resetStatus returns a modified v1beta1.GitRepository and a boolean indicating
316300// if the status field has been reset.
317301func (r * GitRepositoryReconciler ) resetStatus (repository sourcev1.GitRepository ) (sourcev1.GitRepository , bool ) {
0 commit comments