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

proposal: x/crypto/ssh: allow to change allowed authentication methods #66815

Open
drakkan opened this issue Apr 14, 2024 · 5 comments
Open

proposal: x/crypto/ssh: allow to change allowed authentication methods #66815

drakkan opened this issue Apr 14, 2024 · 5 comments
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Milestone

Comments

@drakkan
Copy link
Member

drakkan commented Apr 14, 2024

Proposal Details

Now that CL 516355 has been merged a server can dynamically change allowed authentication methods for a given user by returning a PartialSuccessError.

When a PartialSuccessError is returned, the "partial success" boolean field in SSH_MSG_USERAUTH_FAILURE is set to true.

I propose adding a new error that allows to change authentication methods without returning a partial success error

// ChangeAuthMethodsError can be returned by any of the [ServerConfig]
// authentication callbacks to change the allowed authentication methods.
type ChangeAuthMethodsError struct {
	Next ServerAuthCallbacks
}

func (e *ChangeAuthMethodsError) Error() string {
	// We return a generic error string.
	return "ssh: authentication failed"
}

This is a cleaner approach to allowing modification of authentication methods and will reuse the logic already implemented for PartialSuccessError.

@gopherbot gopherbot added this to the Proposal milestone Apr 14, 2024
@gopherbot
Copy link

Change https://go.dev/cl/578735 mentions this issue: ssh: allow to dynamically change authentication methods

@ianlancetaylor ianlancetaylor added the Proposal-Crypto Proposal related to crypto packages or other security issues label Apr 14, 2024
@ianlancetaylor
Copy link
Contributor

CC @golang/security

@awly
Copy link
Contributor

awly commented Apr 17, 2024

The idea behind the proposal is sound: having a way to switch auth methods without returning PartialSuccess.

I suggest creating an interface (internal or exported) that both PartialSuccessError and ChangeAuthMethodsError implement to use in the type assertion here.

// ChangeAuthMethods can be implemented by any error returned from auth callbacks to 
// change the set of auth callbacks used for further attempts on this connection.
type ChangeAuthMethods interface {
    NextAuthMethods() ServerAuthCallbacks
}

func (e *PartialSuccessError) NextAuthMethods() ServerAuthCallbacks { return e.Next }
func (e *ChangeAuthMethodsError) NextAuthMethods() ServerAuthCallbacks { return e.Next }

An exported interface has the benefit of using error values to affect other behaviors, like sending banner messages.

@FiloSottile
Copy link
Contributor

I don't think a ChangeAuthMethods interface composes well with BannerError for example, because we'd have to add NextAuthMethods to BannerError ourselves.

Instead, we already have a mechanism to nest error types, which is Unwrap.

We can document that we check for both BannerError, PartialSuccessError, and ChangeAuthMethodsError with errors.As, and then implementations can just compose them by nesting a ChangeAuthMethodsError in a BannerError (or more complex custom nesting by using their own type which Unwraps to all of those).

@awly
Copy link
Contributor

awly commented May 3, 2024

Good point, Unwrap is a better way to combine errors. Should we implement Unwrap for all 3 proposed error types, so they can be combined in an arbitrary order?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Proposal Proposal-Crypto Proposal related to crypto packages or other security issues
Projects
Status: Incoming
Development

No branches or pull requests

5 participants