Skip to content
This repository was archived by the owner on Sep 11, 2020. It is now read-only.

SSH connection without SSH-agent #206

Closed
skyflyer opened this issue Jan 10, 2017 · 5 comments
Closed

SSH connection without SSH-agent #206

skyflyer opened this issue Jan 10, 2017 · 5 comments
Labels

Comments

@skyflyer
Copy link

skyflyer commented Jan 10, 2017

I'm having an issue connecting to git repository over ssh on windows, where I don't have an SSH agent running.

In ssh/common.go, the command.connect method calls c.setAuthFromEndpoint() which in turn tries to connect with SSH agent and fails. The method's comments note:

connect connects to the SSH server, unless a AuthMethod was set with
SetAuth method...

but for me, that does not work. Here is a brief program that reproduces this issue:

func main() {
	repoURL := "ssh://git@hostname:portnum/testing.git"
	signer := getSSHSigner()
	r := git.NewMemoryRepository()
	err := r.Clone(&git.CloneOptions{
		URL:  repoURL,
		Auth: &gitssh.PublicKeys{User: "git", Signer: signer},
	})
	check(err)
}

The error returned is dial unix: missing address, which is correct (in a way), since there is no SSH agent environment variable available, so there's nowhere to connect to. The getSigner function above retrieves the ssh.Signer from a private key, supplied to the program.

I can prepare a pull request with a fix, if you'd like that; it seems to me, that we would need to reorganise some code, as currently, Auth does not get propagated down to the actual transport layer.

@mikkeloscar
Copy link

I have the same problem as @skyflyer (on linux where I don't want to use the ssh-agent but pass in a privatekey).

@mcuadros mcuadros added the bug label Jan 12, 2017
@mcuadros
Copy link
Contributor

Exactly the CloneOptions.Auth field is totally unused, the only viable method to provide an auth config right now is using the endpoint and this is not enough or valid. We will find a solution in the next days.

@amlweems
Copy link
Contributor

I've been trying to find a way to implement this and it seems tricky without changing the interfaces significantly.

The general flow for transport/http interface is: create the session using NewFetchPackSession (which basically initializes a struct with an http.Client), optionally call session.SetAuth(auth) if needed, and call FetchPack() to execute the actual network connections.

The above flow works great because the initialization doesn't perform any network activity and it follows the Session interface in transport/common.go. The general flow for the transport/ssh interface is: create the session and Dial the SSH server using SSH agent for authentication and call FetchPack() to read from stdin/stdout.

I think the SSH transport needs to be broken out so that network connectivity happens during FetchPack() instead of in the session init, however, this is a rather large modification to the architecture.

I'm keen to get this issue fixed (I've got a temporary hack locally because I need SSH keys). Happy to help with discussion / design / code if possible.

@smola
Copy link
Collaborator

smola commented Jan 17, 2017

This is fixed now, thanks to @amlweems!

mcuadros pushed a commit that referenced this issue Jan 31, 2017
* remove SetAuth functions, implement at NewUploadPackSession/NewReceivePackSession level.
* propagate transport.Auth from Fetch/Pull/Clone options to the transport API.
gsalingu-ovhus pushed a commit to gsalingu-ovhus/go-git that referenced this issue Mar 28, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants
@smola @amlweems @mikkeloscar @skyflyer @mcuadros and others