Skip to content

Commit

Permalink
fix: unknown host key error in git functions (#967) (#968)
Browse files Browse the repository at this point in the history
(cherry picked from commit ad0c36a)

Co-authored-by: Tanmoy Sarkar <[email protected]>
  • Loading branch information
mergify[bot] and tanmoysrt authored Jul 31, 2024
1 parent 1fd78a0 commit ed6c6a1
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions git_manager/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ package gitmanager

import (
"errors"
"os"
"sort"
"strings"

"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/config"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/transport"
"github.com/go-git/go-git/v5/plumbing/transport/http"
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
"github.com/go-git/go-git/v5/storage/memory"
"os"
"sort"
"strings"
cryptoSSH "golang.org/x/crypto/ssh"
)

func FetchLatestCommitHash(gitUrl string, branch string, username string, password string, privateKey string) (string, error) {
Expand Down Expand Up @@ -146,13 +148,15 @@ func getAuthMethod(repoInfo *GitRepoInfo, username string, password string, priv
if err != nil {
return nil, err
}
privateKeyAuth.HostKeyCallback = cryptoSSH.InsecureIgnoreHostKey()
auth = privateKeyAuth
} else {
if isGitSSHAgentForwardingEnabled() {
sshAgentAuth, err := ssh.NewSSHAgentAuth(repoInfo.SshUser)
if err != nil {
return nil, err
}
sshAgentAuth.HostKeyCallback = cryptoSSH.InsecureIgnoreHostKey()
auth = sshAgentAuth
} else {
return nil, errors.New("please setup SSH Agent Forwarding in your server SSH config for git authentication. You can use integrated authentication mechanisms by providing a ssh git credential")
Expand Down

0 comments on commit ed6c6a1

Please sign in to comment.