forked from cadence-workflow/cadence
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cassandra TLS support (cadence-workflow#2769)
* Consolidate duplicate Cassandra setup and config into a new common/cassandra package * Add TLS support for Cassandra * Add TLS flags to cadence-cassandra-tool * Combine TLS config structs into new common auth.TLS * Add more TLS options: - CaFile - EnableHostVerification - Remove TLS bundleFile option in favor of caFile option
- Loading branch information
Showing
26 changed files
with
368 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package auth | ||
|
||
type ( | ||
// TLS describe TLS configuration (for Kafka, Cassandra) | ||
TLS struct { | ||
Enabled bool `yaml:"enabled"` | ||
|
||
// CertPath and KeyPath are optional depending on server | ||
// config, but both fields must be omitted to avoid using a | ||
// client certificate | ||
CertFile string `yaml:"certFile"` | ||
KeyFile string `yaml:"keyFile"` | ||
|
||
CaFile string `yaml:"caFile"` //optional depending on server config | ||
// If you want to verify the hostname and server cert (like a wildcard for cass cluster) then you should turn this on | ||
// This option is basically the inverse of InSecureSkipVerify | ||
// See InSecureSkipVerify in http://golang.org/pkg/crypto/tls/ for more info | ||
EnableHostVerification bool `yaml:"enableHostVerification"` | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright (c) 2017 Uber Technologies, Inc. | ||
// | ||
// Permission is hereby granted, free of charge, to any person obtaining a copy | ||
// of this software and associated documentation files (the "Software"), to deal | ||
// in the Software without restriction, including without limitation the rights | ||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the Software is | ||
// furnished to do so, subject to the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be included in | ||
// all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
// THE SOFTWARE. | ||
|
||
package cassandra | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/gocql/gocql" | ||
|
||
"github.com/uber/cadence/common/service/config" | ||
) | ||
|
||
// NewCassandraCluster creates a cassandra cluster from a given configuration | ||
func NewCassandraCluster(cfg config.Cassandra) *gocql.ClusterConfig { | ||
hosts := parseHosts(cfg.Hosts) | ||
cluster := gocql.NewCluster(hosts...) | ||
cluster.ProtoVersion = 4 | ||
if cfg.Port > 0 { | ||
cluster.Port = cfg.Port | ||
} | ||
if cfg.User != "" && cfg.Password != "" { | ||
cluster.Authenticator = gocql.PasswordAuthenticator{ | ||
Username: cfg.User, | ||
Password: cfg.Password, | ||
} | ||
} | ||
if cfg.Keyspace != "" { | ||
cluster.Keyspace = cfg.Keyspace | ||
} | ||
if cfg.Consistency != "" { | ||
cluster.Consistency = gocql.ParseConsistency(cfg.Consistency) | ||
} | ||
if cfg.Datacenter != "" { | ||
cluster.HostFilter = gocql.DataCentreHostFilter(cfg.Datacenter) | ||
} | ||
if cfg.TLS != nil && cfg.TLS.Enabled { | ||
cluster.SslOpts = &gocql.SslOptions{ | ||
CertPath: cfg.TLS.CertFile, | ||
KeyPath: cfg.TLS.KeyFile, | ||
CaPath: cfg.TLS.CaFile, | ||
EnableHostVerification: cfg.TLS.EnableHostVerification, | ||
} | ||
} | ||
if cfg.MaxConns > 0 { | ||
cluster.NumConns = cfg.MaxConns | ||
} | ||
|
||
cluster.PoolConfig.HostSelectionPolicy = gocql.TokenAwareHostPolicy(gocql.RoundRobinHostPolicy()) | ||
|
||
return cluster | ||
} | ||
|
||
func parseHosts(input string) []string { | ||
var hosts = make([]string, 0) | ||
for _, h := range strings.Split(input, ",") { | ||
if host := strings.TrimSpace(h); len(host) > 0 { | ||
hosts = append(hosts, host) | ||
} | ||
} | ||
return hosts | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.