Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions internal/controller/gitrepository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/fluxcd/pkg/runtime/logger"
"github.com/fluxcd/pkg/runtime/secrets"
"github.com/go-git/go-git/v5/plumbing/transport"
ssh "golang.org/x/crypto/ssh"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand Down Expand Up @@ -651,6 +652,22 @@ func (r *GitRepositoryReconciler) getAuthOpts(ctx context.Context, obj *sourcev1
return nil, e
}

// Check if SSH identity key is encrypted but no password was provided.
if opts.Transport == git.SSH && len(opts.Identity) > 0 && opts.Password == "" {
if _, err := ssh.ParseRawPrivateKey(opts.Identity); err != nil {
var missingErr *ssh.PassphraseMissingError
if errors.As(err, &missingErr) {
e := serror.NewGeneric(
fmt.Errorf("SSH identity key is encrypted but no 'password' field was provided in the secret '%s/%s'",
obj.GetNamespace(), obj.Spec.SecretRef.Name),
sourcev1.AuthenticationFailedReason,
)
conditions.MarkTrue(obj, sourcev1.FetchFailedCondition, e.Reason, "%s", e)
return nil, e
}
}
}

// Configure provider authentication if specified.
var getCreds func() (*authutils.GitCredentials, error)
switch provider := obj.GetProvider(); provider {
Expand Down