Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 430908

Summary: Pushing to a non-default remote sends wrong host info
Product: [ECD] Orion Reporter: Mark Macdonald <mamacdon>
Component: GitAssignee: Bartosz Grabski <bartosz.grabski>
Status: RESOLVED FIXED QA Contact: Maciej Bendkowski <maciej.bendkowski>
Severity: normal    
Priority: P3 CC: elijahe, maciej.bendkowski
Version: 5.0Flags: maciej.bendkowski: review+
Target Milestone: 6.0 M2   
Hardware: PC   
OS: Windows 7   
Whiteboard:
Attachments:
Description Flags
knownHosts while in problematic state
none
HAR showing the problem
none
HAR showing the problem none

Description Mark Macdonald CLA 2014-03-21 15:07:20 EDT
Elijah ran into a case where the SSH 'add key' prompt dialog kept coming up forever after he clicked OK the first time.

1. He had an existing git remote "origin" pointing to the public Orion repo URL:
> remote.origin.url=http://git.eclipse.org/gitroot/orion/org.eclipse.orion.client.git

2. He edited the repo config to change the URL to his committer-specific URL:
> remote.origin.url=ssh://eelhaddad@dev.eclipse.org/gitroot/orion/org.eclipse.orion.client.git

3. He tried to push. At this point a prompt appeared:
"Would you like to add ssh-rsa key for host dev.eclipse.org to continue operation? Key fingerpt is 68:d8:ed:a9:c2:d8:7b:b8:90:56:0c:9e:d9:8a:17:6c"

4. Clicked OK. He was *not* prompted for a password. The "add key" dialog immediately returned. This continued to happen till he cancelled it.

Forcibly clearing the setting with localStorage.removeItem("elijahe/knownHosts") made the repeated dialogs go away. He was then able to reach the password prompt.
Comment 1 Mark Macdonald CLA 2014-03-21 15:29:43 EDT
Created attachment 241119 [details]
knownHosts while in problematic state

We didn't capture any network traffic while in the endless-dialogs state. 

However we did capture the state of his knownHosts storage after he had clicked OK to the 'add key' dialog (note the entry for dev.eclipse.org).
Comment 2 Mark Macdonald CLA 2014-03-26 13:28:28 EDT
Created attachment 241279 [details]
HAR showing the problem

Just hit this problem myself. I captured a network log this time. In this case I have 2 remotes: 'origin' (the default) and 'github'. I was trying to push my local master branch to github/master.

From the Git Status page
1. Click Push > Push Branch.
2. Branch prompt appears. Click more, then expand github and select github/master. Click OK
3. "Would you like to add ssh-rsa key for host github.com ...?" -- Click OK.
4. Repeat step 3 forever, or until you get tired of clicking OK.

Attaching Chrome header archive (HAR) log.
Comment 3 Mark Macdonald CLA 2014-03-26 13:40:36 EDT
Created attachment 241280 [details]
HAR showing the problem

Previous HAR was incomplete-- this is the correct version.
Comment 4 Mark Macdonald CLA 2014-03-26 14:18:33 EDT
What causes this bug is pushing to a remote that is not the current value of 'branch.master.remote'. In my case, it failed because my repo had branch.master.remote=origin and I was trying to push to 'github'. This put me in endless-dialog world.

The good news is, when you get into endless-dialog world, you can reload the page and try again, and it will work.. That's because behind the scenes, the Push dialog sets 'branch.master.remote' equal to whatever remote you're trying to push to. But it doesn't seem to take effect until you reload the page.

After a reload, since you're now pushing to the current value of branch.master.remote, it works OK.
Comment 5 Maciej Bendkowski CLA 2014-03-27 05:58:49 EDT
Mark, have you captured your local storage contents at the time the issue occurred? I'd guess that while pushing to a non-default remote we're sending the wrong known hosts content, hence getting rejected. After that, we're prompting for the known hosts again (even though we already have them stored), and so on. Probably the default remote's known hosts are used even though you're pushing to a different remote.
Comment 6 Mark Macdonald CLA 2014-03-27 10:03:30 EDT
(In reply to Maciej Bendkowski from comment #5)
> I'd guess that while pushing to a non-default remote we're sending
> the wrong known hosts content, hence getting rejected. After that, we're
> prompting for the known hosts again (even though we already have them
> stored), and so on. Probably the default remote's known hosts are used even
> though you're pushing to a different remote.

Yeah, I think you're right. My localStorage looks like this:

> > localStorage.getItem("mamacdon/knownHosts")
> [{"host":"github.com","port":22,"keyType":"ssh-rsa","hostKey":"AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ=="}]

... But this is what the push request actually sends to the server:

> POST https://hub.jazz.net/code/gitapi/remote/github/master/file/Gc/mamacdon%20%7C%20unicrud/
> {
>   Force: false,
>   GitSshKnownHost: "",   // !
>   GitSshPassphrase: "",
>   GitSshPassword: "",
>   GitSshPrivateKey: "",
>   GitSshUsername: "",
>   PushSrcRef: "HEAD",
>   PushTags: false
> }

If I craft a knownHosts entry for the default remote, it gets sent in the request.
Comment 7 Maciej Bendkowski CLA 2014-04-10 06:00:39 EDT
Bartek, I think you could take a look at it.
Comment 8 Bartosz Grabski CLA 2014-05-26 08:10:34 EDT
Proposed fix

https://git.eclipse.org/r/#/c/27282/

I additionally introduced a fix for a similar issue with fetch command on status page. I had two remotes (origin, remote1). While fetching from another remote it kept displaying the "would you like to add..." prompt forever.
Comment 9 Maciej Bendkowski CLA 2014-05-26 09:48:44 EDT
Pushed to master. Thanks Bartek!