-
Notifications
You must be signed in to change notification settings - Fork 35
fix(pam): fix SCP returning exit code 1 despite successful transfer #170
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -247,6 +247,9 @@ func (p *SSHProxy) handleChannel(ctx context.Context, newChannel ssh.NewChannel, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Client to Server | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| go func() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := p.proxyData(clientChannel, serverChannel, "client→server", sessionID, true, chState) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Signal the server that the client is done writing so the remote process | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // receives EOF and can exit, which triggers exit-status delivery. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverChannel.CloseWrite() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errChan <- err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -256,20 +259,29 @@ func (p *SSHProxy) handleChannel(ctx context.Context, newChannel ssh.NewChannel, | |||||||||||||||||||||||||||||||||||||||||||||||||||||
| errChan <- err | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for either direction to finish or context cancellation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case err := <-errChan: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil && err != io.EOF { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug().Err(err).Str("sessionID", sessionID).Msg("Channel proxy error") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for BOTH directions to finish (or context cancellation). | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Previously only one direction was awaited, which caused premature teardown | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // for SCP: the client→server copy would finish first (file data sent), but the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // server had not yet delivered exit-status. Waiting for both directions ensures | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // the server's data EOF (which follows exit-status) is observed before teardown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for i := 0; i < 2; i++ { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case err := <-errChan: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil && err != io.EOF { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug().Err(err).Str("sessionID", sessionID).Msg("Channel proxy error") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-ctx.Done(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Info().Str("sessionID", sessionID).Msg("Channel cancelled by context") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-ctx.Done(): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Info().Str("sessionID", sessionID).Msg("Channel cancelled by context") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+270
to
282
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
If
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point — added a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Brief window for exit-status to be forwarded before channel teardown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Wait for the server-side channel requests handler to finish so that any | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // remaining requests (exit-status, exit-signal) are forwarded to the client | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // before we tear down the channels. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| select { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-serverReqDone: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-time.After(500 * time.Millisecond): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| case <-time.After(3 * time.Second): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| log.Debug().Str("sessionID", sessionID).Msg("Timed out waiting for server requests to complete") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| clientChannel.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
| serverChannel.Close() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
CloseWrite()error silently droppedThe error returned by
serverChannel.CloseWrite()is discarded. If the channel is already half-closed or broken when this fires, the failure will be invisible in logs, making it harder to diagnose future issues.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.
Good catch — added error logging for
CloseWrite()in c619d69.