Skip to content

Commit ed6c6a1

Browse files
fix: unknown host key error in git functions (#967) (#968)
(cherry picked from commit ad0c36a) Co-authored-by: Tanmoy Sarkar <57363826+tanmoysrt@users.noreply.github.com>
1 parent 1fd78a0 commit ed6c6a1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

git_manager/repo.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@ package gitmanager
22

33
import (
44
"errors"
5+
"os"
6+
"sort"
7+
"strings"
8+
59
"github.com/go-git/go-git/v5"
610
"github.com/go-git/go-git/v5/config"
711
"github.com/go-git/go-git/v5/plumbing"
812
"github.com/go-git/go-git/v5/plumbing/transport"
913
"github.com/go-git/go-git/v5/plumbing/transport/http"
1014
"github.com/go-git/go-git/v5/plumbing/transport/ssh"
1115
"github.com/go-git/go-git/v5/storage/memory"
12-
"os"
13-
"sort"
14-
"strings"
16+
cryptoSSH "golang.org/x/crypto/ssh"
1517
)
1618

1719
func FetchLatestCommitHash(gitUrl string, branch string, username string, password string, privateKey string) (string, error) {
@@ -146,13 +148,15 @@ func getAuthMethod(repoInfo *GitRepoInfo, username string, password string, priv
146148
if err != nil {
147149
return nil, err
148150
}
151+
privateKeyAuth.HostKeyCallback = cryptoSSH.InsecureIgnoreHostKey()
149152
auth = privateKeyAuth
150153
} else {
151154
if isGitSSHAgentForwardingEnabled() {
152155
sshAgentAuth, err := ssh.NewSSHAgentAuth(repoInfo.SshUser)
153156
if err != nil {
154157
return nil, err
155158
}
159+
sshAgentAuth.HostKeyCallback = cryptoSSH.InsecureIgnoreHostKey()
156160
auth = sshAgentAuth
157161
} else {
158162
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")

0 commit comments

Comments
 (0)