Skip to content

Commit 508d09e

Browse files
authored
Add support for AstraAuthenticator (#123)
1 parent 769499e commit 508d09e

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

proxycore/auth.go

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ package proxycore
1717
import (
1818
"bytes"
1919
"fmt"
20+
21+
"go.uber.org/zap"
2022
)
2123

2224
type Authenticator interface {
23-
InitialResponse(authenticator string) ([]byte, error)
25+
InitialResponse(authenticator string, c *ClientConn) ([]byte, error)
2426
EvaluateChallenge(token []byte) ([]byte, error)
2527
Success(token []byte) error
2628
}
@@ -31,14 +33,21 @@ type passwordAuth struct {
3133
password string
3234
}
3335

34-
func (d *passwordAuth) InitialResponse(authenticator string) ([]byte, error) {
35-
switch authenticator {
36-
case "com.datastax.bdp.cassandra.auth.DseAuthenticator":
36+
const dseAuthenticator = "com.datastax.bdp.cassandra.auth.DseAuthenticator"
37+
const passwordAuthenticator = "org.apache.cassandra.auth.PasswordAuthenticator"
38+
const astraAuthenticator = "org.apache.cassandra.auth.AstraAuthenticator"
39+
40+
func (d *passwordAuth) InitialResponse(authenticator string, c *ClientConn) ([]byte, error) {
41+
if authenticator == dseAuthenticator {
3742
return []byte("PLAIN"), nil
38-
case "org.apache.cassandra.auth.PasswordAuthenticator":
39-
return d.makeToken(), nil
4043
}
41-
return nil, fmt.Errorf("unknown authenticator: %v", authenticator)
44+
// We'll return a SASL response but if we're seeing an authenticator we're unfamiliar with at least log
45+
// that information here
46+
if (authenticator != passwordAuthenticator) && (authenticator != astraAuthenticator) {
47+
c.logger.Info("observed unknown authenticator, treating as SASL",
48+
zap.String("authenticator", authenticator))
49+
}
50+
return d.makeToken(), nil
4251
}
4352

4453
func (d *passwordAuth) EvaluateChallenge(token []byte) ([]byte, error) {

proxycore/clientconn.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (c *ClientConn) registerForEvents(ctx context.Context, version primitive.Pr
152152
}
153153

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

0 commit comments

Comments
 (0)