Skip to content

Commit c33abab

Browse files
authored
Add Flag for Custom Authenticators in Cassandra Storage (jaegertracing#5628)
<!-- !! Please DELETE this comment before posting. We appreciate your contribution to the Jaeger project! πŸ‘‹πŸŽ‰ --> ## Which problem is this PR solving? - jaegertracing#5627 ## Description of the changes - added defaultApprovedAuthenticators ## How was this change tested? - ## Checklist - [ ] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [ ] I have signed all commits - [ ] I have added unit tests for the new functionality - [ ] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `yarn lint` and `yarn test` --------- Signed-off-by: mehul gautam <[email protected]>
1 parent 60c2efb commit c33abab

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

β€Žpkg/cassandra/config/config.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ type Authenticator struct {
5656

5757
// BasicAuthenticator holds the username and password for a password authenticator for a Cassandra cluster
5858
type BasicAuthenticator struct {
59-
Username string `yaml:"username" mapstructure:"username"`
60-
Password string `yaml:"password" mapstructure:"password" json:"-"`
59+
Username string `yaml:"username" mapstructure:"username"`
60+
Password string `yaml:"password" mapstructure:"password" json:"-"`
61+
AllowedAuthenticators []string `yaml:"allowed_authenticators" mapstructure:"allowed_authenticators"`
6162
}
6263

6364
// ApplyDefaults copies settings from source unless its own value is non-zero.
@@ -143,8 +144,9 @@ func (c *Configuration) NewCluster(logger *zap.Logger) (*gocql.ClusterConfig, er
143144

144145
if c.Authenticator.Basic.Username != "" && c.Authenticator.Basic.Password != "" {
145146
cluster.Authenticator = gocql.PasswordAuthenticator{
146-
Username: c.Authenticator.Basic.Username,
147-
Password: c.Authenticator.Basic.Password,
147+
Username: c.Authenticator.Basic.Username,
148+
Password: c.Authenticator.Basic.Password,
149+
AllowedAuthenticators: c.Authenticator.Basic.AllowedAuthenticators,
148150
}
149151
}
150152
tlsCfg, err := c.TLS.Config(logger)

β€Žplugin/storage/cassandra/options.go

+10-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
suffixSocketKeepAlive = ".socket-keep-alive"
4646
suffixUsername = ".username"
4747
suffixPassword = ".password"
48-
48+
suffixAuth = ".basic.allowed-authenticators"
4949
// common storage settings
5050
suffixSpanStoreWriteCacheTTL = ".span-store-write-cache-ttl"
5151
suffixIndexTagsBlacklist = ".index.tag-blacklist"
@@ -214,6 +214,13 @@ func addFlags(flagSet *flag.FlagSet, nsConfig namespaceConfig) {
214214
nsConfig.namespace+suffixPassword,
215215
nsConfig.Authenticator.Basic.Password,
216216
"Password for password authentication for Cassandra")
217+
flagSet.String(
218+
nsConfig.namespace+suffixAuth,
219+
"",
220+
"The comma-separated list of allowed password authenticators for Cassandra."+
221+
"If none are specified, there is a default 'approved' list that is used "+
222+
"(https://github.com/gocql/gocql/blob/34fdeebefcbf183ed7f916f931aa0586fdaa1b40/conn.go#L27). "+
223+
"If a non-empty list is provided, only specified authenticators are allowed.")
217224
}
218225

219226
// InitFromViper initializes Options with properties from viper
@@ -256,6 +263,8 @@ func (cfg *namespaceConfig) initFromViper(v *viper.Viper) {
256263
cfg.SocketKeepAlive = v.GetDuration(cfg.namespace + suffixSocketKeepAlive)
257264
cfg.Authenticator.Basic.Username = v.GetString(cfg.namespace + suffixUsername)
258265
cfg.Authenticator.Basic.Password = v.GetString(cfg.namespace + suffixPassword)
266+
authentication := stripWhiteSpace(v.GetString(cfg.namespace + suffixAuth))
267+
cfg.Authenticator.Basic.AllowedAuthenticators = strings.Split(authentication, ",")
259268
cfg.DisableCompression = v.GetBool(cfg.namespace + suffixDisableCompression)
260269
var err error
261270
cfg.TLS, err = tlsFlagsConfig.InitFromViper(v)

β€Žplugin/storage/cassandra/options_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,24 @@ func TestOptionsWithFlags(t *testing.T) {
6464
"--cas.index.tag-whitelist=flerg, flarg,florg ",
6565
"--cas.index.tags=true",
6666
"--cas.index.process-tags=false",
67+
"--cas.basic.allowed-authenticators=org.apache.cassandra.auth.PasswordAuthenticator,com.datastax.bdp.cassandra.auth.DseAuthenticator",
68+
"--cas.username=username",
69+
"--cas.password=password",
6770
// enable aux with a couple overrides
6871
"--cas-aux.enabled=true",
6972
"--cas-aux.keyspace=jaeger-archive",
7073
"--cas-aux.servers=3.3.3.3, 4.4.4.4",
74+
"--cas-aux.username=username",
75+
"--cas-aux.password=password",
76+
"--cas-aux.basic.allowed-authenticators=org.apache.cassandra.auth.PasswordAuthenticator,com.ericsson.bss.cassandra.ecaudit.auth.AuditAuthenticator",
7177
})
7278
opts.InitFromViper(v)
7379

7480
primary := opts.GetPrimary()
7581
assert.Equal(t, "jaeger", primary.Keyspace)
7682
assert.Equal(t, "mojave", primary.LocalDC)
7783
assert.Equal(t, []string{"1.1.1.1", "2.2.2.2"}, primary.Servers)
84+
assert.Equal(t, []string{"org.apache.cassandra.auth.PasswordAuthenticator", "com.datastax.bdp.cassandra.auth.DseAuthenticator"}, primary.Authenticator.Basic.AllowedAuthenticators)
7885
assert.Equal(t, "ONE", primary.Consistency)
7986
assert.Equal(t, []string{"blerg", "blarg", "blorg"}, opts.TagIndexBlacklist())
8087
assert.Equal(t, []string{"flerg", "flarg", "florg"}, opts.TagIndexWhitelist())
@@ -86,6 +93,7 @@ func TestOptionsWithFlags(t *testing.T) {
8693
require.NotNil(t, aux)
8794
assert.Equal(t, "jaeger-archive", aux.Keyspace)
8895
assert.Equal(t, []string{"3.3.3.3", "4.4.4.4"}, aux.Servers)
96+
assert.Equal(t, []string{"org.apache.cassandra.auth.PasswordAuthenticator", "com.ericsson.bss.cassandra.ecaudit.auth.AuditAuthenticator"}, aux.Authenticator.Basic.AllowedAuthenticators)
8997
assert.Equal(t, 42, aux.ConnectionsPerHost)
9098
assert.Equal(t, 42, aux.MaxRetryAttempts)
9199
assert.Equal(t, 42*time.Second, aux.Timeout)

β€Žplugin/storage/integration/cassandra_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,9 @@ func (*CassandraStorageIntegration) initializeCassandraFactory(t *testing.T, fla
6262

6363
func (s *CassandraStorageIntegration) initializeCassandra(t *testing.T) {
6464
f := s.initializeCassandraFactory(t, []string{
65+
"--cassandra.basic.allowed-authenticators=",
66+
"--cassandra.password=password",
67+
"--cassandra.username=username",
6568
"--cassandra.keyspace=jaeger_v1_dc1",
6669
"--cassandra-archive.keyspace=jaeger_v1_dc1_archive",
6770
"--cassandra-archive.enabled=true",

0 commit comments

Comments
Β (0)