-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix agent forwarding for multi-session connections #3613
Conversation
d74855a
to
655b7c0
Compare
retest this please |
f928384
to
7b1dcb3
Compare
retest this please |
7b1dcb3
to
d24e2ab
Compare
d24e2ab
to
b4bf099
Compare
c.RLock() | ||
defer c.RUnlock() | ||
return c.agent | ||
if c.Parent == nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should GetAgent
and GetAgentChannel
return an error? Because it could potentially segfault here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fact that agent
might be nil
seems to be well handled, so I've opted to update the method docs to indicate that it might be nil
rather than changing the method to return an error.
@awly Can you take a look as well? |
@@ -1265,11 +1265,11 @@ func (s *discardServer) Stop() { | |||
s.sshServer.Close() | |||
} | |||
|
|||
func (s *discardServer) HandleNewChan(conn net.Conn, sconn *ssh.ServerConn, newChannel ssh.NewChannel) { | |||
func (s *discardServer) HandleNewChan(ccx *sshutils.ConnectionContext, newChannel ssh.NewChannel) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: ctx
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I deliberately assumed the convention of referring to sshutils.ConnectionContext
as ccx
to handle the fact that it is frequently in-scope at the same time as srv.ServerContext
, which is already conventionally called ctx
.
if c.Parent == nil { | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't c.Parent
always be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed nil
checks for methods which modify state. All the getters on the zero value of srv.ConnectionContext
return zero values themselves instead of panicking (a fact that some tests rely on), so I kept the nil
checks on the getters in order to preserve this behavior.
// make sure the socket is gone after we closed the connection. | ||
err = s.clt.Close() | ||
c.Assert(err, IsNil) | ||
s.clt = nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't seem necessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nullifying clt
prevents test-failure due to double-close in the suite's cleanup function. Added comment to clarify.
// ConnectionContext manages connection-level state. | ||
type ConnectionContext struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Context
is overloaded in Go.
How about just ServerConn
or Conn
?
Changes the lifetime of agent forwarding to be scoped to the underlying ssh connection, instead of the specific ssh channel which initially passed the agent forwarding request.
b4bf099
to
33b8803
Compare
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
Changes agent channel setup behavior to be consistent openssh by having servers lazily request agent channels when they are needed, rather than immediately starting a single connection-wide channel as soon as forwarding is requested. Fixes an issue introduced in #3613 which caused openssh clients to hang on exit due to persistent agent channel.
This PR changes the lifetime of agent forwarding to be scoped to the underlying ssh connection, instead of the specific ssh channel which initially passed the agent forwarding request.
Previous behavior was inconsistent with how openssh handles agent forwarding, and was causing issues with applications which rely on creating multiple separate
exec
sessions on a single connection.Fixes #3471