@@ -33,6 +33,7 @@ import (
3333 "github.com/fluxcd/pkg/runtime/logger"
3434 "github.com/fluxcd/pkg/runtime/secrets"
3535 "github.com/go-git/go-git/v5/plumbing/transport"
36+ ssh "golang.org/x/crypto/ssh"
3637 corev1 "k8s.io/api/core/v1"
3738 "k8s.io/apimachinery/pkg/runtime"
3839 "k8s.io/apimachinery/pkg/types"
@@ -651,6 +652,21 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
651652 return nil , e
652653 }
653654
655+ // Check if SSH identity key is encrypted but no password was provided.
656+ if opts .Transport == git .SSH && len (opts .Identity ) > 0 && opts .Password == "" {
657+ _ , err := ssh .ParseRawPrivateKey (opts .Identity )
658+ var missingErr * ssh.PassphraseMissingError
659+ if errors .As (err , & missingErr ) {
660+ e := serror .NewGeneric (
661+ fmt .Errorf ("SSH identity key is encrypted but no 'password' field was provided in the secret '%s/%s'" ,
662+ obj .GetNamespace (), obj .Spec .SecretRef .Name ),
663+ sourcev1 .AuthenticationFailedReason ,
664+ )
665+ conditions .MarkTrue (obj , sourcev1 .FetchFailedCondition , e .Reason , "%s" , e )
666+ return nil , e
667+ }
668+ }
669+
654670 // Configure provider authentication if specified.
655671 var getCreds func () (* authutils.GitCredentials , error )
656672 switch provider := obj .GetProvider (); provider {
0 commit comments