Skip to content

Commit

Permalink
Fix: ssh connector closes failed connections
Browse files Browse the repository at this point in the history
  • Loading branch information
doodlesbykumbi authored Dec 16, 2021
1 parent b740617 commit 89c30f4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/plugin/connectors/ssh/proxy_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ func (proxy *proxyService) Start() error {
// https://godoc.org/golang.org/x/crypto/ssh#NewServerConn
conn, chans, reqs, err := ssh.NewServerConn(nConn, serverConfig)
if err != nil {
nConn.Close()
logger.Debugf("Failed to handshake: %s", err)
continue
}
Expand All @@ -149,6 +150,7 @@ func (proxy *proxyService) Start() error {
go func() {
if err := proxy.handleConnections(chans); err != nil {
logger.Errorf("Failed on handle connection: %s", err)
nConn.Close()
return
}

Expand Down
5 changes: 5 additions & 0 deletions internal/plugin/connectors/ssh/service_connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ func (h *ServiceConnector) Connect(
}

if server, err = ssh.Dial(serverConfig.Network, serverConfig.Address, &serverConfig.ClientConfig); err != nil {
for newChannel := range h.channels {
if err := newChannel.Reject(ssh.ConnectionFailed, "secretless unable to dial upstream"); err != nil {
h.logger.Errorf("Failed to send new channel rejection : %s", err)
}
}
return fmt.Errorf("failed to dial SSH backend '%s': %s", serverConfig.Address, err)
}

Expand Down

0 comments on commit 89c30f4

Please sign in to comment.