Skip to content

Cassandra: Fix TLS host verification #2109

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

Merged
merged 4 commits into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
* [BUGFIX] Fixed etcd client keepalive settings. #2278
* [BUGFIX] Fixed bug in updating last element of FIFO cache. #2270
* [BUGFIX] Register the metrics of the WAL. #2295
* [BUGFIX] Cassandra Storage: Fix endpoint TLS host verification. #2109

### config file breaking changes

Expand Down
19 changes: 16 additions & 3 deletions pkg/chunk/cassandra/storage_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cassandra
import (
"bytes"
"context"
"crypto/tls"
"flag"
"fmt"
"io/ioutil"
Expand Down Expand Up @@ -67,6 +68,9 @@ func (cfg *Config) Validate() error {
if cfg.Password.Value != "" && cfg.PasswordFile != "" {
return errors.Errorf("The password and password_file config options are mutually exclusive.")
}
if cfg.SSL && cfg.HostVerification && len(strings.Split(cfg.Addresses, ",")) != 1 {
return errors.Errorf("Host verification is only possible for a single host.")
}
return nil
}

Expand Down Expand Up @@ -117,9 +121,18 @@ func (cfg *Config) setClusterConfig(cluster *gocql.ClusterConfig) error {
cluster.DisableInitialHostLookup = cfg.DisableInitialHostLookup

if cfg.SSL {
cluster.SslOpts = &gocql.SslOptions{
CaPath: cfg.CAPath,
EnableHostVerification: cfg.HostVerification,
if cfg.HostVerification {
cluster.SslOpts = &gocql.SslOptions{
CaPath: cfg.CAPath,
EnableHostVerification: true,
Config: &tls.Config{
ServerName: strings.Split(cfg.Addresses, ",")[0],
},
}
} else {
cluster.SslOpts = &gocql.SslOptions{
EnableHostVerification: false,
}
}
}
if cfg.Auth {
Expand Down