Skip to content
Merged
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
16 changes: 4 additions & 12 deletions packages/gateway-v2/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,10 @@ func (g *Gateway) handleIncomingChannel(newChannel ssh.NewChannel) {
}
sessionCtx, sessionCancel := context.WithCancel(g.ctx)
touchSession := g.RegisterPAMSession(forwardConfig.PAMConfig.SessionId, sessionCancel, tlsConn)
defer func() {
sessionCancel()
g.DeregisterPAMSession(forwardConfig.PAMConfig.SessionId, tlsConn)
}()
forwardConfig.PAMConfig.OnActivity = touchSession
if err := pam.HandlePAMProxy(sessionCtx, tlsConn, &forwardConfig.PAMConfig, g.httpClient); err != nil {
if err.Error() == "unexpected EOF" {
Expand All @@ -882,18 +886,6 @@ func (g *Gateway) handleIncomingChannel(newChannel ssh.NewChannel) {
log.Error().Err(err).Msg("PAM proxy handler ended with error")
}
}
sessionCancel()
// RDP reconnects via a stable .rdp file within the session's validity
// window; terminating on disconnect would break that. Idle reaper /
// expiry / explicit cancel still end the session normally.
isRDP := forwardConfig.PAMConfig.ResourceType == session.ResourceTypeWindows
if lastConn := g.DeregisterPAMSession(forwardConfig.PAMConfig.SessionId, tlsConn); lastConn && !isRDP {
if err := forwardConfig.PAMConfig.SessionUploader.CleanupPAMSession(
forwardConfig.PAMConfig.SessionId, "connection_closed",
); err != nil {
log.Error().Err(err).Str("sessionId", forwardConfig.PAMConfig.SessionId).Msg("Failed to cleanup PAM session")
}
}
return
} else if forwardConfig.Mode == ForwardModePAMCancellation {
if err := pam.HandlePAMCancellation(g.ctx, tlsConn, &forwardConfig.PAMConfig, g.httpClient, g.CancelPAMSession); err != nil {
Expand Down
Loading