Skip to content

Commit

Permalink
Support other TLS modes than mutual auth in Client (grafana#3156)
Browse files Browse the repository at this point in the history
* Allow to override server name

This allows to override the expected server name during TLS server
validation. This simplifies the TLS setup as a ServerName can be more
predictable than for example IP addresses. Fixes grafana#3063

Improve TLS client test coverage

Add integration tests that spin up a HTTP/GRPC server and verify that
the client options behave in the expected way.

Allow configuration of non-mutual TLS

Explicitly enable TLS in the client with the flag
`-<prefix>.tls-enabled`. This flag is implicitly enabled when any other
TLS flag is set.

This flag will only be respected by the GRPC client, as for the
HTTP client the scheme used in the URL will take precedence.

Signed-off-by: Christian Simon <simon@swine.de>
Signed-off-by: Peter Štibraný <peter.stibrany@grafana.com>

Co-authored-by: Peter Štibraný <peter.stibrany@grafana.com>
Co-authored-by: Christian Simon <simon@swine.de>
  • Loading branch information
simonswine and pstibrany authored Jan 29, 2021
1 parent 9da230c commit f960556
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
16 changes: 12 additions & 4 deletions gcp/bigtable_index_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
f.BoolVar(&cfg.TableCacheEnabled, "bigtable.table-cache.enabled", true, "If enabled, once a tables info is fetched, it is cached.")
f.DurationVar(&cfg.TableCacheExpiration, "bigtable.table-cache.expiration", 30*time.Minute, "Duration to cache tables before checking again.")

// This overrides our default from TLS disabled to TLS enabled
cfg.GRPCClientConfig.TLSEnabled = true
cfg.GRPCClientConfig.RegisterFlagsWithPrefix("bigtable", f)
}

Expand All @@ -73,8 +75,11 @@ type storageClientV1 struct {

// NewStorageClientV1 returns a new v1 StorageClient.
func NewStorageClientV1(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.IndexClient, error) {
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
if err != nil {
return nil, err
}
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
if err != nil {
return nil, err
}
Expand All @@ -97,8 +102,11 @@ func newStorageClientV1(cfg Config, schemaCfg chunk.SchemaConfig, client *bigtab

// NewStorageClientColumnKey returns a new v2 StorageClient.
func NewStorageClientColumnKey(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.IndexClient, error) {
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
if err != nil {
return nil, err
}
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions gcp/bigtable_object_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ type bigtableObjectClient struct {
// NewBigtableObjectClient makes a new chunk.Client that stores chunks in
// Bigtable.
func NewBigtableObjectClient(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.Client, error) {
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
if err != nil {
return nil, err
}
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
if err != nil {
return nil, err
}
Expand Down
7 changes: 5 additions & 2 deletions gcp/table_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ type tableClient struct {

// NewTableClient returns a new TableClient.
func NewTableClient(ctx context.Context, cfg Config) (chunk.TableClient, error) {
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
client, err := bigtable.NewAdminClient(ctx, cfg.Project, cfg.Instance, opts...)
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
if err != nil {
return nil, err
}
client, err := bigtable.NewAdminClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit f960556

Please sign in to comment.