Skip to content

Commit eb6a6f5

Browse files
Support other TLS modes than mutual auth in Client (#3156)
* 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 #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 <[email protected]> Signed-off-by: Peter Štibraný <[email protected]> Co-authored-by: Peter Štibraný <[email protected]> Co-authored-by: Christian Simon <[email protected]>
1 parent d6cb4e6 commit eb6a6f5

27 files changed

+802
-112
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## master / unreleased
44

55
* [CHANGE] Ingester: don't update internal "last updated" timestamp of TSDB if tenant only sends invalid samples. This affects how "idle" time is computed. #3727
6+
* [CHANGE] Require explicit flag `-<prefix>.tls-enabled` to enable TLS in GRPC clients. Previously it was enough to specify a TLS flag to enable TLS validation. #3156
67
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `-<prefix>.s3.sse-encryption`, you should use the following CLI flags that have been added. #3651
78
- `-<prefix>.s3.sse.type`
89
- `-<prefix>.s3.sse.kms-key-id`
@@ -13,6 +14,7 @@
1314
* Prevent compaction loop in TSDB on data gap.
1415
* [ENHANCEMENT] Return server side performance metrics for query-frontend (using Server-timing header). #3685
1516
* [ENHANCEMENT] Runtime Config: Add a `mode` query parameter for the runtime config endpoint. `/runtime_config?mode=diff` now shows the YAML runtime configuration with all values that differ from the defaults. #3700
17+
* [ENHANCEMENT] Add flag `-<prefix>.tls-server-name` to require a specific server name instead of the hostname on the certificate. #3156
1618
* [BUGFIX] HA Tracker: don't track as error in the `cortex_kv_request_duration_seconds` metric a CAS operation intentionally aborted. #3745
1719

1820
## 1.7.0 in progress

docs/blocks-storage/querier.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,10 @@ querier:
168168
[store_gateway_addresses: <string> | default = ""]
169169

170170
store_gateway_client:
171+
# Enable TLS for gRPC client connecting to store-gateway.
172+
# CLI flag: -querier.store-gateway-client.tls-enabled
173+
[tls_enabled: <boolean> | default = false]
174+
171175
# Path to the client certificate file, which will be used for authenticating
172176
# with the server. Also requires the key path to be configured.
173177
# CLI flag: -querier.store-gateway-client.tls-cert-path
@@ -183,6 +187,10 @@ querier:
183187
# CLI flag: -querier.store-gateway-client.tls-ca-path
184188
[tls_ca_path: <string> | default = ""]
185189

190+
# Override the expected name on the server certificate.
191+
# CLI flag: -querier.store-gateway-client.tls-server-name
192+
[tls_server_name: <string> | default = ""]
193+
186194
# Skip validating server certificate.
187195
# CLI flag: -querier.store-gateway-client.tls-insecure-skip-verify
188196
[tls_insecure_skip_verify: <boolean> | default = false]

docs/configuration/config-file-reference.md

Lines changed: 101 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ query_scheduler:
219219
# CLI flag: -query-scheduler.grpc-client-config.backoff-retries
220220
[max_retries: <int> | default = 10]
221221

222+
# Enable TLS in the GRPC client. This flag needs to be enabled when any
223+
# other TLS flag is set. If set to false, insecure connection to gRPC server
224+
# will be used.
225+
# CLI flag: -query-scheduler.grpc-client-config.tls-enabled
226+
[tls_enabled: <boolean> | default = false]
227+
222228
# Path to the client certificate file, which will be used for authenticating
223229
# with the server. Also requires the key path to be configured.
224230
# CLI flag: -query-scheduler.grpc-client-config.tls-cert-path
@@ -234,6 +240,10 @@ query_scheduler:
234240
# CLI flag: -query-scheduler.grpc-client-config.tls-ca-path
235241
[tls_ca_path: <string> | default = ""]
236242

243+
# Override the expected name on the server certificate.
244+
# CLI flag: -query-scheduler.grpc-client-config.tls-server-name
245+
[tls_server_name: <string> | default = ""]
246+
237247
# Skip validating server certificate.
238248
# CLI flag: -query-scheduler.grpc-client-config.tls-insecure-skip-verify
239249
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -826,6 +836,10 @@ The `querier_config` configures the Cortex querier.
826836
[store_gateway_addresses: <string> | default = ""]
827837
828838
store_gateway_client:
839+
# Enable TLS for gRPC client connecting to store-gateway.
840+
# CLI flag: -querier.store-gateway-client.tls-enabled
841+
[tls_enabled: <boolean> | default = false]
842+
829843
# Path to the client certificate file, which will be used for authenticating
830844
# with the server. Also requires the key path to be configured.
831845
# CLI flag: -querier.store-gateway-client.tls-cert-path
@@ -841,6 +855,10 @@ store_gateway_client:
841855
# CLI flag: -querier.store-gateway-client.tls-ca-path
842856
[tls_ca_path: <string> | default = ""]
843857
858+
# Override the expected name on the server certificate.
859+
# CLI flag: -querier.store-gateway-client.tls-server-name
860+
[tls_server_name: <string> | default = ""]
861+
844862
# Skip validating server certificate.
845863
# CLI flag: -querier.store-gateway-client.tls-insecure-skip-verify
846864
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -940,6 +958,12 @@ grpc_client_config:
940958
# CLI flag: -frontend.grpc-client-config.backoff-retries
941959
[max_retries: <int> | default = 10]
942960
961+
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
962+
# TLS flag is set. If set to false, insecure connection to gRPC server will be
963+
# used.
964+
# CLI flag: -frontend.grpc-client-config.tls-enabled
965+
[tls_enabled: <boolean> | default = false]
966+
943967
# Path to the client certificate file, which will be used for authenticating
944968
# with the server. Also requires the key path to be configured.
945969
# CLI flag: -frontend.grpc-client-config.tls-cert-path
@@ -955,6 +979,10 @@ grpc_client_config:
955979
# CLI flag: -frontend.grpc-client-config.tls-ca-path
956980
[tls_ca_path: <string> | default = ""]
957981
982+
# Override the expected name on the server certificate.
983+
# CLI flag: -frontend.grpc-client-config.tls-server-name
984+
[tls_server_name: <string> | default = ""]
985+
958986
# Skip validating server certificate.
959987
# CLI flag: -frontend.grpc-client-config.tls-insecure-skip-verify
960988
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -1100,6 +1128,12 @@ ruler_client:
11001128
# CLI flag: -ruler.client.backoff-retries
11011129
[max_retries: <int> | default = 10]
11021130
1131+
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
1132+
# TLS flag is set. If set to false, insecure connection to gRPC server will be
1133+
# used.
1134+
# CLI flag: -ruler.client.tls-enabled
1135+
[tls_enabled: <boolean> | default = false]
1136+
11031137
# Path to the client certificate file, which will be used for authenticating
11041138
# with the server. Also requires the key path to be configured.
11051139
# CLI flag: -ruler.client.tls-cert-path
@@ -1115,6 +1149,10 @@ ruler_client:
11151149
# CLI flag: -ruler.client.tls-ca-path
11161150
[tls_ca_path: <string> | default = ""]
11171151
1152+
# Override the expected name on the server certificate.
1153+
# CLI flag: -ruler.client.tls-server-name
1154+
[tls_server_name: <string> | default = ""]
1155+
11181156
# Skip validating server certificate.
11191157
# CLI flag: -ruler.client.tls-insecure-skip-verify
11201158
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -2359,6 +2397,35 @@ bigtable:
23592397
# CLI flag: -bigtable.backoff-retries
23602398
[max_retries: <int> | default = 10]
23612399

2400+
# Enable TLS in the GRPC client. This flag needs to be enabled when any
2401+
# other TLS flag is set. If set to false, insecure connection to gRPC server
2402+
# will be used.
2403+
# CLI flag: -bigtable.tls-enabled
2404+
[tls_enabled: <boolean> | default = true]
2405+
2406+
# Path to the client certificate file, which will be used for authenticating
2407+
# with the server. Also requires the key path to be configured.
2408+
# CLI flag: -bigtable.tls-cert-path
2409+
[tls_cert_path: <string> | default = ""]
2410+
2411+
# Path to the key file for the client certificate. Also requires the client
2412+
# certificate to be configured.
2413+
# CLI flag: -bigtable.tls-key-path
2414+
[tls_key_path: <string> | default = ""]
2415+
2416+
# Path to the CA certificates file to validate server certificate against.
2417+
# If not set, the host's root CA certificates are used.
2418+
# CLI flag: -bigtable.tls-ca-path
2419+
[tls_ca_path: <string> | default = ""]
2420+
2421+
# Override the expected name on the server certificate.
2422+
# CLI flag: -bigtable.tls-server-name
2423+
[tls_server_name: <string> | default = ""]
2424+
2425+
# Skip validating server certificate.
2426+
# CLI flag: -bigtable.tls-insecure-skip-verify
2427+
[tls_insecure_skip_verify: <boolean> | default = false]
2428+
23622429
# If enabled, once a tables info is fetched, it is cached.
23632430
# CLI flag: -bigtable.table-cache.enabled
23642431
[table_cache_enabled: <boolean> | default = true]
@@ -2879,6 +2946,12 @@ grpc_client_config:
28792946
# CLI flag: -ingester.client.backoff-retries
28802947
[max_retries: <int> | default = 10]
28812948
2949+
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
2950+
# TLS flag is set. If set to false, insecure connection to gRPC server will be
2951+
# used.
2952+
# CLI flag: -ingester.client.tls-enabled
2953+
[tls_enabled: <boolean> | default = false]
2954+
28822955
# Path to the client certificate file, which will be used for authenticating
28832956
# with the server. Also requires the key path to be configured.
28842957
# CLI flag: -ingester.client.tls-cert-path
@@ -2894,6 +2967,10 @@ grpc_client_config:
28942967
# CLI flag: -ingester.client.tls-ca-path
28952968
[tls_ca_path: <string> | default = ""]
28962969
2970+
# Override the expected name on the server certificate.
2971+
# CLI flag: -ingester.client.tls-server-name
2972+
[tls_server_name: <string> | default = ""]
2973+
28972974
# Skip validating server certificate.
28982975
# CLI flag: -ingester.client.tls-insecure-skip-verify
28992976
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -2976,6 +3053,12 @@ grpc_client_config:
29763053
# CLI flag: -querier.frontend-client.backoff-retries
29773054
[max_retries: <int> | default = 10]
29783055
3056+
# Enable TLS in the GRPC client. This flag needs to be enabled when any other
3057+
# TLS flag is set. If set to false, insecure connection to gRPC server will be
3058+
# used.
3059+
# CLI flag: -querier.frontend-client.tls-enabled
3060+
[tls_enabled: <boolean> | default = false]
3061+
29793062
# Path to the client certificate file, which will be used for authenticating
29803063
# with the server. Also requires the key path to be configured.
29813064
# CLI flag: -querier.frontend-client.tls-cert-path
@@ -2991,6 +3074,10 @@ grpc_client_config:
29913074
# CLI flag: -querier.frontend-client.tls-ca-path
29923075
[tls_ca_path: <string> | default = ""]
29933076
3077+
# Override the expected name on the server certificate.
3078+
# CLI flag: -querier.frontend-client.tls-server-name
3079+
[tls_server_name: <string> | default = ""]
3080+
29943081
# Skip validating server certificate.
29953082
# CLI flag: -querier.frontend-client.tls-insecure-skip-verify
29963083
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -3027,18 +3114,25 @@ The `etcd_config` configures the etcd client. The supported CLI flags `<prefix>`
30273114
# CLI flag: -<prefix>.etcd.tls-enabled
30283115
[tls_enabled: <boolean> | default = false]
30293116
3030-
# The TLS certificate file path.
3117+
# Path to the client certificate file, which will be used for authenticating
3118+
# with the server. Also requires the key path to be configured.
30313119
# CLI flag: -<prefix>.etcd.tls-cert-path
30323120
[tls_cert_path: <string> | default = ""]
30333121
3034-
# The TLS private key file path.
3122+
# Path to the key file for the client certificate. Also requires the client
3123+
# certificate to be configured.
30353124
# CLI flag: -<prefix>.etcd.tls-key-path
30363125
[tls_key_path: <string> | default = ""]
30373126
3038-
# The trusted CA file path.
3127+
# Path to the CA certificates file to validate server certificate against. If
3128+
# not set, the host's root CA certificates are used.
30393129
# CLI flag: -<prefix>.etcd.tls-ca-path
30403130
[tls_ca_path: <string> | default = ""]
30413131
3132+
# Override the expected name on the server certificate.
3133+
# CLI flag: -<prefix>.etcd.tls-server-name
3134+
[tls_server_name: <string> | default = ""]
3135+
30423136
# Skip validating server certificate.
30433137
# CLI flag: -<prefix>.etcd.tls-insecure-skip-verify
30443138
[tls_insecure_skip_verify: <boolean> | default = false]
@@ -3659,6 +3753,10 @@ The `configstore_config` configures the config database storing rules and alerts
36593753
# CLI flag: -<prefix>.configs.tls-ca-path
36603754
[tls_ca_path: <string> | default = ""]
36613755
3756+
# Override the expected name on the server certificate.
3757+
# CLI flag: -<prefix>.configs.tls-server-name
3758+
[tls_server_name: <string> | default = ""]
3759+
36623760
# Skip validating server certificate.
36633761
# CLI flag: -<prefix>.configs.tls-insecure-skip-verify
36643762
[tls_insecure_skip_verify: <boolean> | default = false]

integration/util.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ func getServerTLSFlags() map[string]string {
6363

6464
func getClientTLSFlagsWithPrefix(prefix string) map[string]string {
6565
return map[string]string{
66-
"-" + prefix + ".tls-cert-path": filepath.Join(e2e.ContainerSharedDir, clientCertFile),
67-
"-" + prefix + ".tls-key-path": filepath.Join(e2e.ContainerSharedDir, clientKeyFile),
68-
"-" + prefix + ".tls-ca-path": filepath.Join(e2e.ContainerSharedDir, caCertFile),
69-
70-
// TODO: Remove this in the future to test if TLS verification works,
71-
// this requires a TLSServerName flags to be specified
72-
"-" + prefix + ".tls-insecure-skip-verify": "true",
66+
"-" + prefix + ".tls-cert-path": filepath.Join(e2e.ContainerSharedDir, clientCertFile),
67+
"-" + prefix + ".tls-key-path": filepath.Join(e2e.ContainerSharedDir, clientKeyFile),
68+
"-" + prefix + ".tls-ca-path": filepath.Join(e2e.ContainerSharedDir, caCertFile),
69+
"-" + prefix + ".tls-server-name": "ingester.client",
70+
"-" + prefix + ".tls-enabled": "true",
7371
}
7472
}

pkg/chunk/gcp/bigtable_index_client.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ func (cfg *Config) RegisterFlags(f *flag.FlagSet) {
5151
f.BoolVar(&cfg.TableCacheEnabled, "bigtable.table-cache.enabled", true, "If enabled, once a tables info is fetched, it is cached.")
5252
f.DurationVar(&cfg.TableCacheExpiration, "bigtable.table-cache.expiration", 30*time.Minute, "Duration to cache tables before checking again.")
5353

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

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

7476
// NewStorageClientV1 returns a new v1 StorageClient.
7577
func NewStorageClientV1(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.IndexClient, error) {
76-
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
77-
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
78+
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
79+
if err != nil {
80+
return nil, err
81+
}
82+
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
7883
if err != nil {
7984
return nil, err
8085
}
@@ -97,8 +102,11 @@ func newStorageClientV1(cfg Config, schemaCfg chunk.SchemaConfig, client *bigtab
97102

98103
// NewStorageClientColumnKey returns a new v2 StorageClient.
99104
func NewStorageClientColumnKey(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.IndexClient, error) {
100-
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
101-
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
105+
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
106+
if err != nil {
107+
return nil, err
108+
}
109+
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
102110
if err != nil {
103111
return nil, err
104112
}

pkg/chunk/gcp/bigtable_object_client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ type bigtableObjectClient struct {
2222
// NewBigtableObjectClient makes a new chunk.Client that stores chunks in
2323
// Bigtable.
2424
func NewBigtableObjectClient(ctx context.Context, cfg Config, schemaCfg chunk.SchemaConfig) (chunk.Client, error) {
25-
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
26-
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, opts...)
25+
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
26+
if err != nil {
27+
return nil, err
28+
}
29+
client, err := bigtable.NewClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
2730
if err != nil {
2831
return nil, err
2932
}

pkg/chunk/gcp/table_client.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ type tableClient struct {
2424

2525
// NewTableClient returns a new TableClient.
2626
func NewTableClient(ctx context.Context, cfg Config) (chunk.TableClient, error) {
27-
opts := toOptions(cfg.GRPCClientConfig.DialOption(bigtableInstrumentation()))
28-
client, err := bigtable.NewAdminClient(ctx, cfg.Project, cfg.Instance, opts...)
27+
dialOpts, err := cfg.GRPCClientConfig.DialOption(bigtableInstrumentation())
28+
if err != nil {
29+
return nil, err
30+
}
31+
client, err := bigtable.NewAdminClient(ctx, cfg.Project, cfg.Instance, toOptions(dialOpts)...)
2932
if err != nil {
3033
return nil, err
3134
}

pkg/frontend/v2/frontend.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ import (
2929

3030
// Config for a Frontend.
3131
type Config struct {
32-
SchedulerAddress string `yaml:"scheduler_address"`
33-
DNSLookupPeriod time.Duration `yaml:"scheduler_dns_lookup_period"`
34-
WorkerConcurrency int `yaml:"scheduler_worker_concurrency"`
35-
GRPCClientConfig grpcclient.ConfigWithTLS `yaml:"grpc_client_config"`
32+
SchedulerAddress string `yaml:"scheduler_address"`
33+
DNSLookupPeriod time.Duration `yaml:"scheduler_dns_lookup_period"`
34+
WorkerConcurrency int `yaml:"scheduler_worker_concurrency"`
35+
GRPCClientConfig grpcclient.Config `yaml:"grpc_client_config"`
3636

3737
// Used to find local IP address, that is sent to scheduler and querier-worker.
3838
InfNames []string `yaml:"instance_interface_names"`

pkg/ingester/client/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func (c *closableHealthAndIngesterClient) Close() error {
5555

5656
// Config is the configuration struct for the ingester client
5757
type Config struct {
58-
GRPCClientConfig grpcclient.ConfigWithTLS `yaml:"grpc_client_config"`
58+
GRPCClientConfig grpcclient.Config `yaml:"grpc_client_config"`
5959
}
6060

6161
// RegisterFlags registers configuration settings used by the ingester client config.

pkg/querier/blocks_store_balanced_set.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"github.com/cortexproject/cortex/pkg/ring/client"
1919
"github.com/cortexproject/cortex/pkg/util"
2020
"github.com/cortexproject/cortex/pkg/util/services"
21-
"github.com/cortexproject/cortex/pkg/util/tls"
2221
)
2322

2423
// BlocksStoreSet implementation used when the blocks are not sharded in the store-gateway
@@ -31,15 +30,15 @@ type blocksStoreBalancedSet struct {
3130
dnsProvider *dns.Provider
3231
}
3332

34-
func newBlocksStoreBalancedSet(serviceAddresses []string, tlsCfg tls.ClientConfig, logger log.Logger, reg prometheus.Registerer) *blocksStoreBalancedSet {
33+
func newBlocksStoreBalancedSet(serviceAddresses []string, clientConfig ClientConfig, logger log.Logger, reg prometheus.Registerer) *blocksStoreBalancedSet {
3534
const dnsResolveInterval = 10 * time.Second
3635

3736
dnsProviderReg := extprom.WrapRegistererWithPrefix("cortex_storegateway_client_", reg)
3837

3938
s := &blocksStoreBalancedSet{
4039
serviceAddresses: serviceAddresses,
4140
dnsProvider: dns.NewProvider(logger, dnsProviderReg, dns.GolangResolverType),
42-
clientsPool: newStoreGatewayClientPool(nil, tlsCfg, logger, reg),
41+
clientsPool: newStoreGatewayClientPool(nil, clientConfig, logger, reg),
4342
}
4443

4544
s.Service = services.NewTimerService(dnsResolveInterval, s.starting, s.resolve, nil)

0 commit comments

Comments
 (0)