git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "M. Buecher" <maddes+git@maddes.net>
To: Harley Paterson <harley.paterson@hotmail.co.nz>
Cc: git@vger.kernel.org
Subject: Re: False negative authentication with multiple accounts on a SSH-GIT server
Date: Tue, 19 Jan 2021 19:22:14 +0100	[thread overview]
Message-ID: <ddf34d963a57971c13d12d8f0c04a0fc@mailbox.org> (raw)
In-Reply-To: <DB8P189MB10460B9A3CA31ADF5C05A39FF9A30@DB8P189MB1046.EURP189.PROD.OUTLOOK.COM>

Hi there,

you can use GIT_SSH_COMMAND or config 'core.sshCommand'.
For more flexibility use wrappers like ssh-ident.

Recommended read: https://superuser.com/a/1616186/557798

Hope this helps
Kind regards
Maddes


On 2021-01-19 07:17, Harley Paterson wrote:
> Hello,
> 
> I've noticed an edge case in Git when a user has two Git accounts on a
> single server - as might be common for a personal account and a work
> account on a Git forge (Github, GitLab, Bitbucket...)
> 
> When attempting SSH login, `ssh` and Git will eagerly connect with the
> first matching key. This may or may not be the key right key for the
> repository the user needs. As a result, Git clones, pulls, and pushes
> will fail with the `Repository not found` if the wrong key is tried
> first.
> 
> For example, the user `alice` has two accounts on the host
> `git-server.com`. `alice`'s accounts are `alice-work`, and
> `alice-personal`. `alice-work` has access to the `foo` repository, and
> `alice-personal` has access to the `bar` repository.
> 
> `alice` attempts to clone `foo` with both her `alice-work` and
> `alice-personal` keys in her SSH Agent. SSH Agent does not define
> which key it will attempt first, so SSH may connect successfully to
> `git-server.com` with her `alice-personal` keys, which do not have
> access to the `foo` repository.
> 
> I'd be interested in your opinions for fixes to this. I am willing to
> make a patch, although my knowledge of the Git codebase isn't perfect.
> 
> - Should Git servers provide distinctly different error messages for
> `access denied`, and `repository does not exist`? Currently the server
> immediately closes the connection in this case, so
> `transport.c:handshake()` with fail when attempting to
> `discover_version()` because the reader hits the EOF. Perhaps the
> server could send a hypothetical access denied packet here, and a more
> appropriate error generated?
> 
> Can anyone point me to where in the Git codebase the daemon receives
> and responds to these requests? I haven't found it yet, if I wanted to
> patch this.
> 
> - Should Git provide a `-i` option to allow the user to choose an SSH
> key, which could be added to the SSH subprocess's command line?
> 
> - Should Git attempt to iterate over all keys in the SSH Agent when
> the connection is setup, testing the connection to check if each
> connected key has access to the target repository, before giving up
> and reporting an error? This may be difficult looking at the current
> behavior of `ssh` and `ssh-agent`. `ssh-add -l` no longer lists paths
> to files (which could be plugged into `ssh -i`), just the key
> signature. Does anyone know of any SSH/SSH-Agent tricks which might
> help with this?
> 
> All the best,
> 
> 
> 
> H Paterson.

  reply	other threads:[~2021-01-19 18:30 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19  6:17 False negative authentication with multiple accounts on a SSH-GIT server Harley Paterson
2021-01-19 18:22 ` M. Buecher [this message]
2021-01-19 23:11 ` brian m. carlson
2021-01-20 12:42   ` Ævar Arnfjörð Bjarmason
2021-01-20 14:35     ` Jeff King
2021-01-20 19:11       ` Harley Paterson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ddf34d963a57971c13d12d8f0c04a0fc@mailbox.org \
    --to=maddes+git@maddes.net \
    --cc=git@vger.kernel.org \
    --cc=harley.paterson@hotmail.co.nz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).