Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion integration/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7557,13 +7557,40 @@ func testAgentlessConnection(t *testing.T, suite *integrationTestSuite) {
// so closing it here will result in io.EOF if the test passes
_ = session.Close()
})
require.NoError(t, agent.ForwardToAgent(sshClient, tc.LocalAgent()))

// this is essentially what agent.ForwardToAgent does, but we're
// doing it manually so can take ownership of the opened SSH channel
// and check that it's closed correctly
channels := sshClient.HandleChannelOpen("auth-agent@openssh.com")
require.NotNil(t, channels)

doneServing := make(chan error)
go func() {
for ch := range channels {
channel, reqs, err := ch.Accept()
assert.NoError(t, err)
go ssh.DiscardRequests(reqs)
go func() {
doneServing <- agent.ServeAgent(tc.LocalAgent(), channel)
channel.Close()
}()
}
}()

require.NoError(t, agent.RequestAgentForwarding(session))

// run a command
err = session.Run("cmd")
require.NoError(t, err)

// test that SSH agent channel is closed properly
select {
case err := <-doneServing:
require.ErrorIs(t, err, io.EOF)
case <-time.After(3 * time.Second):
require.Fail(t, "timeout waiting for SSH agent channel to be closed")
}

require.NoError(t, nodeClient.Close())
}

Expand Down
1 change: 1 addition & 0 deletions lib/srv/forward/sshserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -1161,6 +1161,7 @@ func (s *Server) handleAgentForward(ch ssh.Channel, req *ssh.Request, ctx *srv.S
if err != nil {
return trace.Wrap(err)
}
ctx.AddCloser(userAgent)
Comment thread
capnspacehook marked this conversation as resolved.
Outdated
}

err = agent.ForwardToAgent(ctx.RemoteClient.Client, userAgent)
Expand Down