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

Add support for AstraAuthenticator #123

Merged
merged 2 commits into from
Jan 24, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Log if we see an unexpected authenticator but still return SASL as th…
…e default
  • Loading branch information
absurdfarce committed Jan 22, 2024
commit ec21a024fc60dd3355d2b1b8f93a2420406bdc48
19 changes: 12 additions & 7 deletions proxycore/auth.go
Original file line number Diff line number Diff line change
@@ -17,10 +17,12 @@ package proxycore
import (
"bytes"
"fmt"

"go.uber.org/zap"
)

type Authenticator interface {
InitialResponse(authenticator string) ([]byte, error)
InitialResponse(authenticator string, c *ClientConn) ([]byte, error)
EvaluateChallenge(token []byte) ([]byte, error)
Success(token []byte) error
}
@@ -35,14 +37,17 @@ const dseAuthenticator = "com.datastax.bdp.cassandra.auth.DseAuthenticator"
const passwordAuthenticator = "org.apache.cassandra.auth.PasswordAuthenticator"
const astraAuthenticator = "org.apache.cassandra.auth.AstraAuthenticator"

func (d *passwordAuth) InitialResponse(authenticator string) ([]byte, error) {
switch authenticator {
case dseAuthenticator:
func (d *passwordAuth) InitialResponse(authenticator string, c *ClientConn) ([]byte, error) {
if authenticator == dseAuthenticator {
return []byte("PLAIN"), nil
case passwordAuthenticator, astraAuthenticator:
return d.makeToken(), nil
}
return nil, fmt.Errorf("unknown authenticator: %v", authenticator)
// We'll return a SASL response but if we're seeing an authenticator we're unfamiliar with at least log
// that information here
if (authenticator != passwordAuthenticator) && (authenticator != astraAuthenticator) {
c.logger.Info("observed unknown authenticator, treating as SASL",
zap.String("authenticator", authenticator))
}
return d.makeToken(), nil
}

func (d *passwordAuth) EvaluateChallenge(token []byte) ([]byte, error) {
2 changes: 1 addition & 1 deletion proxycore/clientconn.go
Original file line number Diff line number Diff line change
@@ -152,7 +152,7 @@ func (c *ClientConn) registerForEvents(ctx context.Context, version primitive.Pr
}

func (c *ClientConn) authInitialResponse(ctx context.Context, version primitive.ProtocolVersion, auth Authenticator, authenticate *message.Authenticate) error {
token, err := auth.InitialResponse(authenticate.Authenticator)
token, err := auth.InitialResponse(authenticate.Authenticator, c)
if err != nil {
return err
}
Loading