git-up / GitUp

The Git interface you've been missing all your life has finally arrived.
http://gitup.co
GNU General Public License v3.0
11.5k stars 1.26k forks source link

GitUpKit ssh credentials callback does not handle username correctly if it is defined in ssh config #976

Open prostolyubo opened 8 months ago

prostolyubo commented 8 months ago

As mentioned in git-up/GitUp#35 the GitUp displays ambiguous error messages when there is an error related to ssh credentials. There may be many causes as @andreyz pointed out:

          I think the diagnosis of this error is incorrect. ssh agent and up and running and keychain is unlocked. Gitup still refuses to do a remote push.

Originally posted by @andreyz in https://github.com/git-up/GitUp/issues/35#issuecomment-239800880

I managed to isolate at least one that allowed me to create a workaround for myself, however fixing the issue is beyond my current scope of skills.

I simply changed the origin url from: ssh://git-codecommit.amazonaws.com/myproject to ssh://myusername@git-codecommit.amazonaws.com/myproject And now magically I can interact with the remote. The reason it worked in terminal is because the username is defined in my ssh config:

Host git-codecommit.*.amazonaws.com
  User myusername
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/mykey

Now here's what my investigation revealed:

  1. libgit2 detects there is no username and calls request_creds with GIT_CREDENTIAL_USERNAME as an auth method (Username-only authentication request, Used as a pre-authentication step if the underlying transport, (eg. SSH, with no username in its URL) does not know which username to use.)
  2. The process ends up calling the _CredentialsCallback method in GCRepository.m but it does not know how to handle GIT_CREDENTIAL_USERNAME as it only supports: GIT_CREDENTIAL_SSH_KEY and GIT_CREDENTIAL_USERPASS_PLAINTEXT so it immediatelly returns error -30: "A user-configured callback refused to act "