Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ssh: unable to ignore host key auth callback #654

Closed
aymanbagabas opened this issue Jan 9, 2023 · 1 comment · Fixed by #655 or 610lyn/go-git#1
Closed

ssh: unable to ignore host key auth callback #654

aymanbagabas opened this issue Jan 9, 2023 · 1 comment · Fixed by #655 or 610lyn/go-git#1

Comments

@aymanbagabas
Copy link
Contributor

aymanbagabas commented Jan 9, 2023

Hi,

The changes introduced in c35b808 breaks the ability to ignore the client host key check. In our case, we're using ssh.InsecureIgnoreHostKey() for integration testing where we don't care about validating the host key. The changes made in the commit deprecate the HostKeyCallbackHelper interface and don't provide any workaround.

Implementing a ssh.AuthMethod with a custom HostKeyCallback won't work either since the associated ssh.ClientConfig will be overwritten by ssh.SetConfigHostKeyFields() when establishing the connection.

Before these changes were introduced, you could pass a HostKeyCallbackHelper to any ssh AuthMethod and it will set the HostKeyCallback function to be used to validate the host key.

	pks, _ := ssht.NewPublicKeysFromFile("git", filepath, "")
	pks.HostKeyCallbackHelper = ssht.HostKeyCallbackHelper{
	 	HostKeyCallback: ssh.InsecureIgnoreHostKey(),
	}
	err = r.Push(&git.PushOptions{
		RemoteName: "origin",
		Auth:       pks,
	})

I tried wrapping the PublicKeys AuthMethod and modifying the HostKeyCallback, but it gets overwritten before the connection happens.

type pkAuthMethod struct {
	*ssht.PublicKeys
}

func (p *pkAuthMethod) ClientConfig() (*ssh.ClientConfig, error) {
	cc, err := p.PublicKeys.ClientConfig()
	if err != nil {
		return nil, err
	}
	cc.HostKeyCallback = ssh.InsecureIgnoreHostKey()
	return cc, nil
}

func main() {
	pks, _ := gssh.NewPublicKeysFromFile("git", pkPath, "")
	auth := &pkAuthMethod{pks}
	err = r.Push(&git.PushOptions{
		RemoteName: "origin",
		Auth:       auth,
	})
}

Related: #411
Related: #431

aymanbagabas added a commit to aymanbagabas/go-git that referenced this issue Jan 9, 2023
Don't overwrite HostKeyCallback if one is provided.

Fixes: c35b808 ("plumbing: transport/ssh, auto-populate ClientConfig.HostKeyAlgorithms. Fixes go-git#411")
Fixes: go-git#654
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@crenshaw-dev
Copy link

Argo CD also relies on the HostKeyCallback field. argoproj/argo-cd#11893

aymanbagabas added a commit to aymanbagabas/go-git that referenced this issue Mar 5, 2023
Don't overwrite HostKeyCallback if one is provided.

Fixes: c35b808 ("plumbing: transport/ssh, auto-populate ClientConfig.HostKeyAlgorithms. Fixes go-git#411")
Fixes: go-git#654
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
@pjbgf pjbgf closed this as completed in #655 Mar 6, 2023
durandj pushed a commit to durandj/go-git that referenced this issue Jul 1, 2023
Don't overwrite HostKeyCallback if one is provided.

Fixes: c35b808 ("plumbing: transport/ssh, auto-populate ClientConfig.HostKeyAlgorithms. Fixes go-git#411")
Fixes: go-git#654
Signed-off-by: Ayman Bagabas <ayman.bagabas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants