Skip to content

Conversation

@bk2204
Copy link
Member

@bk2204 bk2204 commented Oct 5, 2022

Right now, we try to spawn multiple SSH connections using ControlMaster when making multiple requests. However, if multiplexing is not enabled, we can spawn multiple actual connections, which can be expensive and require lots of authentication requests.

Instead, let's make sure we don't enable multiple connections if multiplexing is not enabled, since this may cause the user to be prompted for multiple SSH key connection attempts (say, if they're using a security key) and is substantially more heavyweight than simply spawning a new process over the same connection.

Fixes #5064

@bk2204 bk2204 requested a review from a team as a code owner October 5, 2022 15:05
@bk2204 bk2204 marked this pull request as draft October 5, 2022 15:44
@bk2204 bk2204 marked this pull request as ready for review October 5, 2022 17:36
@bk2204 bk2204 marked this pull request as draft October 5, 2022 19:21
Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only had a few notes, and I notice the Windows CI jobs seems to be failing, so maybe that's something worth review as well (but perhaps it's not related to this PR)?

In our SSH code, we check if the error is non-nil and then enable
multiplexing.  However, this is backwards: only if the error is nil do
we have a valid path and can we enable multiplexing.  Fix this condition
properly.

Since our tests will now often get additional arguments, update
lfs-ssh-echo to handle them gracefully.
Right now, we try to spawn multiple SSH connections using ControlMaster
when making multiple requests.  However, if multiplexing is not enabled,
we can spawn multiple actual connections, which can be expensive and
require lots of authentication requests.

Instead, let's make sure we don't enable multiple connections if
multiplexing is not enabled, since this may cause the user to be
prompted for multiple SSH key connection attempts (say, if they're
using a security key) and is substantially more heavyweight than simply
spawning a new process over the same connection.

Since the code has different behaviour if `XDG_RUNTIME_DIR` is set, make
sure to unset it for the tests so that we always try to create a
temporary directory and don't otherwise fail because that environment
variable points somewhere unexpected.
@bk2204 bk2204 marked this pull request as ready for review October 14, 2022 18:14
@bk2204
Copy link
Member Author

bk2204 commented Oct 14, 2022

Okay, the test failure has magically disappeared, I've added tests (and some additional commits since I discovered a bug), and this should be ready for another review when that's convenient.

Copy link
Member

@chrisd8088 chrisd8088 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

@bk2204 bk2204 merged commit b28f0c5 into git-lfs:main Oct 17, 2022
@bk2204 bk2204 deleted the ssh-multiplex branch October 17, 2022 12:54
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Oct 22, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Oct 23, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Oct 29, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Nov 1, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Nov 3, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
chrisd8088 added a commit to chrisd8088/git-lfs that referenced this pull request Nov 4, 2024
In commit b44cbe4 of PR git-lfs#5136 the
"multiplex" argument was added to the FormatArgs() function in our
ssh/ssh.go source file.  Later, the "controlPath" argument was also
added, in commit 448b0c4 of PR git-lfs#5537.

Neither of these arguments is used in the function's body, though,
so we can remove them now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Avoid issuing multiple SSH connections with pure SSH protocol if multiplexing is not enabled

2 participants