Skip to content

ssh: unable to ignore host key auth callback  #654

@aymanbagabas

Description

@aymanbagabas

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions