Skip to content

Commit 445d974

Browse files
tolbertamjoao-r-reis
authored andcommitted
Don't restrict server authenticator in PasswordAuthenticator
Currently gocql will only allow authenticating with authenticators defined in defaultApprovedAuthenticators in conn.go. There have been multiple occurrences of implementers needing to update this list, either when a vendor would like to add their authenticator, or a new authenticator being added. It would probably reduce friction to just accept any authenticator provided by the server. From what I know, other drivers behave in this way. If a user wanted to restrict this, they could use the existing configuration PasswordAuthenticator.AllowedAuthenticators. patch by Andy Tolbert; reviewed by Joao Reis, Lukasz Antoniak for CASSGO-19
1 parent 42755a5 commit 445d974

File tree

3 files changed

+36
-31
lines changed

3 files changed

+36
-31
lines changed

conn.go

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,11 @@ import (
4343
"github.com/gocql/gocql/internal/streams"
4444
)
4545

46-
var (
47-
defaultApprovedAuthenticators = []string{
48-
"org.apache.cassandra.auth.PasswordAuthenticator",
49-
"com.instaclustr.cassandra.auth.SharedSecretAuthenticator",
50-
"com.datastax.bdp.cassandra.auth.DseAuthenticator",
51-
"io.aiven.cassandra.auth.AivenAuthenticator",
52-
"com.ericsson.bss.cassandra.ecaudit.auth.AuditPasswordAuthenticator",
53-
"com.amazon.helenus.auth.HelenusAuthenticator",
54-
"com.ericsson.bss.cassandra.ecaudit.auth.AuditAuthenticator",
55-
"com.scylladb.auth.SaslauthdAuthenticator",
56-
"com.scylladb.auth.TransitionalAuthenticator",
57-
"com.instaclustr.cassandra.auth.InstaclustrPasswordAuthenticator",
58-
}
59-
)
60-
61-
// approve the authenticator with the list of allowed authenticators or default list if approvedAuthenticators is empty.
46+
// approve the authenticator with the list of allowed authenticators. If the provided list is empty,
47+
// the given authenticator is allowed.
6248
func approve(authenticator string, approvedAuthenticators []string) bool {
6349
if len(approvedAuthenticators) == 0 {
64-
approvedAuthenticators = defaultApprovedAuthenticators
50+
return true
6551
}
6652
for _, s := range approvedAuthenticators {
6753
if authenticator == s {
@@ -86,9 +72,15 @@ type Authenticator interface {
8672
Success(data []byte) error
8773
}
8874

75+
// PasswordAuthenticator specifies credentials to be used when authenticating.
76+
// It can be configured with an "allow list" of authenticator class names to avoid
77+
// attempting to authenticate with Cassandra if it doesn't provide an expected authenticator.
8978
type PasswordAuthenticator struct {
90-
Username string
91-
Password string
79+
Username string
80+
Password string
81+
// Setting this to nil or empty will allow authenticating with any authenticator
82+
// provided by the server. This is the default behavior of most other driver
83+
// implementations.
9284
AllowedAuthenticators []string
9385
}
9486

conn_test.go

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,18 +55,21 @@ const (
5555

5656
func TestApprove(t *testing.T) {
5757
tests := map[bool]bool{
58-
approve("org.apache.cassandra.auth.PasswordAuthenticator", []string{}): true,
59-
approve("com.instaclustr.cassandra.auth.SharedSecretAuthenticator", []string{}): true,
60-
approve("com.datastax.bdp.cassandra.auth.DseAuthenticator", []string{}): true,
61-
approve("io.aiven.cassandra.auth.AivenAuthenticator", []string{}): true,
62-
approve("com.amazon.helenus.auth.HelenusAuthenticator", []string{}): true,
63-
approve("com.ericsson.bss.cassandra.ecaudit.auth.AuditAuthenticator", []string{}): true,
64-
approve("com.scylladb.auth.SaslauthdAuthenticator", []string{}): true,
65-
approve("com.scylladb.auth.TransitionalAuthenticator", []string{}): true,
66-
approve("com.instaclustr.cassandra.auth.InstaclustrPasswordAuthenticator", []string{}): true,
67-
approve("com.apache.cassandra.auth.FakeAuthenticator", []string{}): false,
68-
approve("com.apache.cassandra.auth.FakeAuthenticator", nil): false,
69-
approve("com.apache.cassandra.auth.FakeAuthenticator", []string{"com.apache.cassandra.auth.FakeAuthenticator"}): true,
58+
approve("org.apache.cassandra.auth.PasswordAuthenticator", []string{}): true,
59+
approve("org.apache.cassandra.auth.MutualTlsWithPasswordFallbackAuthenticator", []string{}): true,
60+
approve("org.apache.cassandra.auth.MutualTlsAuthenticator", []string{}): true,
61+
approve("com.instaclustr.cassandra.auth.SharedSecretAuthenticator", []string{}): true,
62+
approve("com.datastax.bdp.cassandra.auth.DseAuthenticator", []string{}): true,
63+
approve("io.aiven.cassandra.auth.AivenAuthenticator", []string{}): true,
64+
approve("com.amazon.helenus.auth.HelenusAuthenticator", []string{}): true,
65+
approve("com.ericsson.bss.cassandra.ecaudit.auth.AuditAuthenticator", []string{}): true,
66+
approve("com.scylladb.auth.SaslauthdAuthenticator", []string{}): true,
67+
approve("com.scylladb.auth.TransitionalAuthenticator", []string{}): true,
68+
approve("com.instaclustr.cassandra.auth.InstaclustrPasswordAuthenticator", []string{}): true,
69+
approve("com.apache.cassandra.auth.FakeAuthenticator", []string{}): true,
70+
approve("com.apache.cassandra.auth.FakeAuthenticator", nil): true,
71+
approve("com.apache.cassandra.auth.FakeAuthenticator", []string{"com.apache.cassandra.auth.FakeAuthenticator"}): true,
72+
approve("com.apache.cassandra.auth.FakeAuthenticator", []string{"com.apache.cassandra.auth.NotFakeAuthenticator"}): false,
7073
}
7174
for k, v := range tests {
7275
if k != v {

doc.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@
8181
// }
8282
// defer session.Close()
8383
//
84+
// By default, PasswordAuthenticator will attempt to authenticate regardless of what implementation the server returns
85+
// in its AUTHENTICATE message as its authenticator, (e.g. org.apache.cassandra.auth.PasswordAuthenticator). If you
86+
// wish to restrict this you may use PasswordAuthenticator.AllowedAuthenticators:
87+
//
88+
// cluster.Authenticator = gocql.PasswordAuthenticator {
89+
// Username: "user",
90+
// Password: "password"
91+
// AllowedAuthenticators: []string{"org.apache.cassandra.auth.PasswordAuthenticator"},
92+
// }
93+
//
8494
// # Transport layer security
8595
//
8696
// It is possible to secure traffic between the client and server with TLS.

0 commit comments

Comments
 (0)