Skip to content
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

Don't retry SSH connection when auth fails #818

Merged
merged 2 commits into from
Jan 11, 2024
Merged

Conversation

djjuhasz
Copy link
Collaborator

@djjuhasz djjuhasz commented Jan 4, 2024

Authentication failures can not be resolved by retrying the connection with the same credentials.

Authentication failures can not be resolved by retrying the connection
with the same credentials.
@djjuhasz djjuhasz requested a review from sevein January 4, 2024 23:38
Copy link
Contributor

@sevein sevein left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, only one minor suggestion.

Comment on lines 8 to 22
type AuthError struct {
err error
}

func (e *AuthError) Error() string {
return e.err.Error()
}

func (e *AuthError) Unwrap() error {
return e.err
}

func NewAuthError(e error) *AuthError {
return &AuthError{err: e}
}
Copy link
Contributor

@sevein sevein Jan 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A possible alternative:

type AuthError struct {
	Reason string
}

func (e *AuthError) Error() string {
	return fmt.Sprintf("auth: %s", e.Reason)
}

func NewAuthError(err error) error {
	return &AuthError{Reason: err.Error()}
}

This version:

  • Doesn't use Unwrap because we don't need to give access to the underlying error.
  • Uses the error type in the constructor signature, see https://go.dev/doc/faq#nil_error:

    It's a good idea for functions that return errors always to use the error type in their signature rather than a concrete type such as *MyError, to help guarantee the error is created correctly. As an example, os.Open returns an error even though, if not nil, it's always of concrete type *os.PathError.

I think that we'd want the function to return a concrete type (*AuthError) if we were doing some performance-focused work, e.g. https://github.com/connectrpc/connect-go/blob/d88758dc0e89170db922ecd20f16cec57662ec23/error.go#L117-L128 could be a good example where the design was driven by performance objectives, like avoiding memory allocations. This is a guess though, not entirely sure.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sevein does Reason need to be exported?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exporting the Reason field does have the nice benefit of being able to set an arbitrary string without having to create an error first, e.g.

e := &sftp.AuthError{Reason: "bad password"}

vs.

e := sftp.NewAuthError(errors.New("bad password"))

@djjuhasz djjuhasz force-pushed the dev/no-ssh-auth-retry branch from a4db585 to fdb128b Compare January 10, 2024 20:09
@djjuhasz djjuhasz merged commit 7324d03 into main Jan 11, 2024
10 checks passed
@djjuhasz djjuhasz deleted the dev/no-ssh-auth-retry branch January 11, 2024 17:20
@@ -17,32 +18,32 @@ import (
// returns a client connection.
//
// Only private key authentication is currently supported, with or without a
// passphrase.
// passphrase.SSH: %v",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this was accidentally changed!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops! 🤦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants