Skip to content

Commit d90e7d3

Browse files
*: add CLI arguments to configure TLS ciphers for gRPC servers + remote-write receiver's server (#8730)
* Support ciphers configuration for server TLS Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Add grpc-server-tls-ciphers argument to Thanos components Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Add remote-write.server-tls-ciphers argument to Receive Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Update docs Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Add TestGRPCServerTLSCiphersAndVersions This commit adds an end-to-end test ensuring correct behaviour when a client establishes a TLS connection to a server. Signed-off-by: Simon Pasquier <spasquie@redhat.com> * Update CHANGELOG.md Signed-off-by: Simon Pasquier <spasquie@redhat.com> --------- Signed-off-by: Simon Pasquier <spasquie@redhat.com>
1 parent 519da47 commit d90e7d3

File tree

15 files changed

+268
-13
lines changed

15 files changed

+268
-13
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ It is recommend to upgrade the storage components first (Receive, Store, etc.) a
2222
### Added
2323

2424
- [#8691](https://github.com/thanos-io/thanos/pull/8691): Compactor: remove the directory marker objects for some s3 compatible object stores
25+
- [#8730](https://github.com/thanos-io/thanos/pull/8730): *: add `--grpc-server-tls-ciphers` to configure cipher suites for gRPC servers.
26+
- [#8730](https://github.com/thanos-io/thanos/pull/8730): Receive: add `--remote-write.server-tls-ciphers` to configure cipher suites for the HTTP server.
2527

2628
### Changed
2729

cmd/thanos/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type grpcConfig struct {
3535
tlsSrvKey string
3636
tlsSrvClientCA string
3737
tlsMinVersion string
38+
tlsCiphers []string
3839
gracePeriod time.Duration
3940
maxConnectionAge time.Duration
4041
}
@@ -55,6 +56,9 @@ func (gc *grpcConfig) registerFlag(cmd extkingpin.FlagClause) *grpcConfig {
5556
cmd.Flag("grpc-server-tls-min-version",
5657
"TLS supported minimum version for gRPC server. If no version is specified, it'll default to 1.3. Allowed values: [\"1.0\", \"1.1\", \"1.2\", \"1.3\"]").
5758
Default("1.3").StringVar(&gc.tlsMinVersion)
59+
cmd.Flag("grpc-server-tls-ciphers",
60+
"TLS cipher suites for gRPC server (repeatable). If not specified, the default Go cipher suites are used. See https://pkg.go.dev/crypto/tls#pkg-constants for valid values.").
61+
StringsVar(&gc.tlsCiphers)
5862
cmd.Flag("grpc-server-max-connection-age", "The grpc server max connection age. This controls how often to re-establish connections and redo TLS handshakes.").
5963
Default("60m").DurationVar(&gc.maxConnectionAge)
6064
cmd.Flag("grpc-grace-period",

cmd/thanos/query.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -595,7 +595,7 @@ func runQuery(
595595
}
596596
// Start query (proxy) gRPC StoreAPI.
597597
{
598-
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), grpcServerConfig.tlsSrvCert, grpcServerConfig.tlsSrvKey, grpcServerConfig.tlsSrvClientCA, grpcServerConfig.tlsMinVersion)
598+
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), grpcServerConfig.tlsSrvCert, grpcServerConfig.tlsSrvKey, grpcServerConfig.tlsSrvClientCA, grpcServerConfig.tlsMinVersion, grpcServerConfig.tlsCiphers)
599599
if err != nil {
600600
return errors.Wrap(err, "setup gRPC server")
601601
}

cmd/thanos/receive.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ func runReceive(
153153
}
154154
}
155155

156-
rwTLSConfig, err := tls.NewServerConfig(log.With(logger, "protocol", "HTTP"), conf.rwServerCert, conf.rwServerKey, conf.rwServerClientCA, conf.rwServerTlsMinVersion)
156+
rwTLSConfig, err := tls.NewServerConfig(log.With(logger, "protocol", "HTTP"), conf.rwServerCert, conf.rwServerKey, conf.rwServerClientCA, conf.rwServerTlsMinVersion, conf.rwServerTlsCiphers)
157157
if err != nil {
158158
return err
159159
}
@@ -346,7 +346,7 @@ func runReceive(
346346

347347
level.Debug(logger).Log("msg", "setting up gRPC server")
348348
{
349-
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpcConfig.tlsSrvCert, conf.grpcConfig.tlsSrvKey, conf.grpcConfig.tlsSrvClientCA, conf.grpcConfig.tlsMinVersion)
349+
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpcConfig.tlsSrvCert, conf.grpcConfig.tlsSrvKey, conf.grpcConfig.tlsSrvClientCA, conf.grpcConfig.tlsMinVersion, conf.grpcConfig.tlsCiphers)
350350
if err != nil {
351351
return errors.Wrap(err, "setup gRPC server")
352352
}
@@ -851,6 +851,7 @@ type receiveConfig struct {
851851
rwClientServerName string
852852
rwClientSkipVerify bool
853853
rwServerTlsMinVersion string
854+
rwServerTlsCiphers []string
854855

855856
dataDir string
856857
labelStrs []string
@@ -935,7 +936,9 @@ func (rc *receiveConfig) registerFlag(cmd extkingpin.FlagClause) {
935936

936937
cmd.Flag("remote-write.server-tls-client-ca", "TLS CA to verify clients against. If no client CA is specified, there is no client verification on server side. (tls.NoClientCert)").Default("").StringVar(&rc.rwServerClientCA)
937938

938-
cmd.Flag("remote-write.server-tls-min-version", "TLS version for the gRPC server, leave blank to default to TLS 1.3, allow values: [\"1.0\", \"1.1\", \"1.2\", \"1.3\"]").Default("1.3").StringVar(&rc.rwServerTlsMinVersion)
939+
cmd.Flag("remote-write.server-tls-min-version", "TLS version for the HTTP server, leave blank to default to TLS 1.3, allow values: [\"1.0\", \"1.1\", \"1.2\", \"1.3\"]").Default("1.3").StringVar(&rc.rwServerTlsMinVersion)
940+
941+
cmd.Flag("remote-write.server-tls-ciphers", "TLS cipher suites for the HTTP server (repeatable). If not specified, the default Go cipher suites are used. See https://pkg.go.dev/crypto/tls#pkg-constants for valid values.").StringsVar(&rc.rwServerTlsCiphers)
939942

940943
cmd.Flag("remote-write.client-tls-cert", "TLS Certificates to use to identify this client to the server.").Default("").StringVar(&rc.rwClientCert)
941944

cmd/thanos/rule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,7 @@ func runRule(
735735
)
736736

737737
// Start gRPC server.
738-
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpc.tlsSrvCert, conf.grpc.tlsSrvKey, conf.grpc.tlsSrvClientCA, conf.grpc.tlsMinVersion)
738+
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpc.tlsSrvCert, conf.grpc.tlsSrvKey, conf.grpc.tlsSrvClientCA, conf.grpc.tlsMinVersion, conf.grpc.tlsCiphers)
739739
if err != nil {
740740
return errors.Wrap(err, "setup gRPC server")
741741
}

cmd/thanos/sidecar.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func runSidecar(
317317
}
318318

319319
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"),
320-
conf.grpc.tlsSrvCert, conf.grpc.tlsSrvKey, conf.grpc.tlsSrvClientCA, conf.grpc.tlsMinVersion)
320+
conf.grpc.tlsSrvCert, conf.grpc.tlsSrvKey, conf.grpc.tlsSrvClientCA, conf.grpc.tlsMinVersion, conf.grpc.tlsCiphers)
321321
if err != nil {
322322
return errors.Wrap(err, "setup gRPC server")
323323
}

cmd/thanos/store.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ func runStore(
555555

556556
// Start query (proxy) gRPC StoreAPI.
557557
{
558-
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpcConfig.tlsSrvCert, conf.grpcConfig.tlsSrvKey, conf.grpcConfig.tlsSrvClientCA, conf.grpcConfig.tlsMinVersion)
558+
tlsCfg, err := tls.NewServerConfig(log.With(logger, "protocol", "gRPC"), conf.grpcConfig.tlsSrvCert, conf.grpcConfig.tlsSrvKey, conf.grpcConfig.tlsSrvClientCA, conf.grpcConfig.tlsMinVersion, conf.grpcConfig.tlsCiphers)
559559
if err != nil {
560560
return errors.Wrap(err, "setup gRPC server")
561561
}

docs/components/query.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ Flags:
346346
If no version is specified, it'll default to
347347
1.3. Allowed values: ["1.0", "1.1", "1.2",
348348
"1.3"]
349+
--grpc-server-tls-ciphers=GRPC-SERVER-TLS-CIPHERS ...
350+
TLS cipher suites for gRPC server
351+
(repeatable). If not specified,
352+
the default Go cipher suites are used.
353+
See https://pkg.go.dev/crypto/tls#pkg-constants
354+
for valid values.
349355
--grpc-server-max-connection-age=60m
350356
The grpc server max connection age. This
351357
controls how often to re-establish connections

docs/components/receive.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,6 @@ Please see the metric `thanos_receive_forward_delay_seconds` to see if you need
373373
The following formula is used for calculating quorum:
374374

375375
```go mdox-exec="sed -n '1068,1078p' pkg/receive/handler.go"
376-
// writeQuorum returns minimum number of replicas that has to confirm write success before claiming replication success.
377376
func (h *Handler) writeQuorum() int {
378377
// NOTE(GiedriusS): this is here because otherwise RF=2 doesn't make sense as all writes
379378
// would need to succeed all the time. Another way to think about it is when migrating
@@ -384,6 +383,7 @@ func (h *Handler) writeQuorum() int {
384383
}
385384
return int((h.options.ReplicationFactor / 2) + 1)
386385
}
386+
387387
```
388388

389389
So, if the replication factor is 2 then at least one write must succeed. With RF=3, two writes must succeed, and so on.
@@ -442,6 +442,12 @@ Flags:
442442
If no version is specified, it'll default to
443443
1.3. Allowed values: ["1.0", "1.1", "1.2",
444444
"1.3"]
445+
--grpc-server-tls-ciphers=GRPC-SERVER-TLS-CIPHERS ...
446+
TLS cipher suites for gRPC server
447+
(repeatable). If not specified,
448+
the default Go cipher suites are used.
449+
See https://pkg.go.dev/crypto/tls#pkg-constants
450+
for valid values.
445451
--grpc-server-max-connection-age=60m
446452
The grpc server max connection age. This
447453
controls how often to re-establish connections
@@ -472,9 +478,15 @@ Flags:
472478
client CA is specified, there is no client
473479
verification on server side. (tls.NoClientCert)
474480
--remote-write.server-tls-min-version="1.3"
475-
TLS version for the gRPC server, leave blank
481+
TLS version for the HTTP server, leave blank
476482
to default to TLS 1.3, allow values: ["1.0",
477483
"1.1", "1.2", "1.3"]
484+
--remote-write.server-tls-ciphers=REMOTE-WRITE.SERVER-TLS-CIPHERS ...
485+
TLS cipher suites for the HTTP server
486+
(repeatable). If not specified,
487+
the default Go cipher suites are used.
488+
See https://pkg.go.dev/crypto/tls#pkg-constants
489+
for valid values.
478490
--remote-write.client-tls-cert=""
479491
TLS Certificates to use to identify this client
480492
to the server.

docs/components/rule.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,12 @@ Flags:
316316
If no version is specified, it'll default to
317317
1.3. Allowed values: ["1.0", "1.1", "1.2",
318318
"1.3"]
319+
--grpc-server-tls-ciphers=GRPC-SERVER-TLS-CIPHERS ...
320+
TLS cipher suites for gRPC server
321+
(repeatable). If not specified,
322+
the default Go cipher suites are used.
323+
See https://pkg.go.dev/crypto/tls#pkg-constants
324+
for valid values.
319325
--grpc-server-max-connection-age=60m
320326
The grpc server max connection age. This
321327
controls how often to re-establish connections

0 commit comments

Comments
 (0)