Skip to content

Commit 5bbdb44

Browse files
committed
feat: add TLS versions configuration
Add configuration options for TLSMinVersion and TLSMaxVersion. This enables setting TLS 1.3 as minimum version for example for both GRPC and Web, or enforcing TLS 1.2 only for easier debugging of secure connections. Signed-off-by: Tuomo Tanskanen <[email protected]>
1 parent 7ca42d7 commit 5bbdb44

File tree

4 files changed

+49
-9
lines changed

4 files changed

+49
-9
lines changed

cmd/dex/config.go

+15-5
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,16 @@ func (c Config) Validate() error {
6464
{c.Web.HTTP == "" && c.Web.HTTPS == "", "must supply a HTTP/HTTPS address to listen on"},
6565
{c.Web.HTTPS != "" && c.Web.TLSCert == "", "no cert specified for HTTPS"},
6666
{c.Web.HTTPS != "" && c.Web.TLSKey == "", "no private key specified for HTTPS"},
67+
{c.Web.TLSMinVersion != "" && c.Web.TLSMinVersion != "1.2" && c.Web.TLSMinVersion != "1.3", "supported TLS versions are: 1.2, 1.3"},
68+
{c.Web.TLSMaxVersion != "" && c.Web.TLSMaxVersion != "1.2" && c.Web.TLSMaxVersion != "1.3", "supported TLS versions are: 1.2, 1.3"},
69+
{c.Web.TLSMaxVersion != "" && c.Web.TLSMinVersion != "" && c.Web.TLSMinVersion > c.Web.TLSMaxVersion, "TLSMinVersion greater than TLSMaxVersion"},
6770
{c.GRPC.TLSCert != "" && c.GRPC.Addr == "", "no address specified for gRPC"},
6871
{c.GRPC.TLSKey != "" && c.GRPC.Addr == "", "no address specified for gRPC"},
6972
{(c.GRPC.TLSCert == "") != (c.GRPC.TLSKey == ""), "must specific both a gRPC TLS cert and key"},
7073
{c.GRPC.TLSCert == "" && c.GRPC.TLSClientCA != "", "cannot specify gRPC TLS client CA without a gRPC TLS cert"},
74+
{c.GRPC.TLSMinVersion != "" && c.GRPC.TLSMinVersion != "1.2" && c.GRPC.TLSMinVersion != "1.3", "supported TLS versions are: 1.2, 1.3"},
75+
{c.GRPC.TLSMaxVersion != "" && c.GRPC.TLSMaxVersion != "1.2" && c.GRPC.TLSMaxVersion != "1.3", "supported TLS versions are: 1.2, 1.3"},
76+
{c.GRPC.TLSMaxVersion != "" && c.GRPC.TLSMinVersion != "" && c.GRPC.TLSMinVersion > c.GRPC.TLSMaxVersion, "TLSMinVersion greater than TLSMaxVersion"},
7177
}
7278

7379
var checkErrors []string
@@ -149,6 +155,8 @@ type Web struct {
149155
HTTPS string `json:"https"`
150156
TLSCert string `json:"tlsCert"`
151157
TLSKey string `json:"tlsKey"`
158+
TLSMinVersion string `json:"tlsMinVersion"`
159+
TLSMaxVersion string `json:"tlsMaxVersion"`
152160
AllowedOrigins []string `json:"allowedOrigins"`
153161
AllowedHeaders []string `json:"allowedHeaders"`
154162
}
@@ -163,11 +171,13 @@ type Telemetry struct {
163171
// GRPC is the config for the gRPC API.
164172
type GRPC struct {
165173
// The port to listen on.
166-
Addr string `json:"addr"`
167-
TLSCert string `json:"tlsCert"`
168-
TLSKey string `json:"tlsKey"`
169-
TLSClientCA string `json:"tlsClientCA"`
170-
Reflection bool `json:"reflection"`
174+
Addr string `json:"addr"`
175+
TLSCert string `json:"tlsCert"`
176+
TLSKey string `json:"tlsKey"`
177+
TLSClientCA string `json:"tlsClientCA"`
178+
TLSMinVersion string `json:"tlsMinVersion"`
179+
TLSMaxVersion string `json:"tlsMaxVersion"`
180+
Reflection bool `json:"reflection"`
171181
}
172182

173183
// Storage holds app's storage configuration.

cmd/dex/config_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ storage:
7171
connMaxLifetime: 30
7272
connectionTimeout: 3
7373
web:
74-
http: 127.0.0.1:5556
74+
https: 127.0.0.1:5556
75+
tlsMinVersion: 1.3
76+
tlsMaxVersion: 1.2
7577
7678
frontend:
7779
dir: ./web
@@ -144,7 +146,9 @@ logger:
144146
},
145147
},
146148
Web: Web{
147-
HTTP: "127.0.0.1:5556",
149+
HTTPS: "127.0.0.1:5556",
150+
TLSMinVersion: "1.3",
151+
TLSMaxVersion: "1.2",
148152
},
149153
Frontend: server.WebConfig{
150154
Dir: "./web",

cmd/dex/serve.go

+26-2
Original file line numberDiff line numberDiff line change
@@ -145,9 +145,23 @@ func runServe(options serveOptions) error {
145145
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
146146
}
147147

148+
allowedTLSVersions := map[string]int{
149+
"1.2": tls.VersionTLS12,
150+
"1.3": tls.VersionTLS13,
151+
}
152+
148153
if c.GRPC.TLSCert != "" {
154+
tlsMinVersion := tls.VersionTLS12
155+
if c.GRPC.TLSMinVersion != "" {
156+
tlsMinVersion = allowedTLSVersions[c.GRPC.TLSMinVersion]
157+
}
158+
tlsMaxVersion := 0 // default for max is whatever Go defaults to
159+
if c.GRPC.TLSMaxVersion != "" {
160+
tlsMaxVersion = allowedTLSVersions[c.GRPC.TLSMaxVersion]
161+
}
149162
baseTLSConfig := &tls.Config{
150-
MinVersion: tls.VersionTLS12,
163+
MinVersion: uint16(tlsMinVersion),
164+
MaxVersion: uint16(tlsMaxVersion),
151165
CipherSuites: allowedTLSCiphers,
152166
PreferServerCipherSuites: true,
153167
}
@@ -422,8 +436,18 @@ func runServe(options serveOptions) error {
422436
return fmt.Errorf("listening (%s) on %s: %v", name, c.Web.HTTPS, err)
423437
}
424438

439+
tlsMinVersion := tls.VersionTLS12
440+
if c.Web.TLSMinVersion != "" {
441+
tlsMinVersion = allowedTLSVersions[c.Web.TLSMinVersion]
442+
}
443+
tlsMaxVersion := 0 // default for max is whatever Go defaults to
444+
if c.Web.TLSMaxVersion != "" {
445+
tlsMaxVersion = allowedTLSVersions[c.Web.TLSMaxVersion]
446+
}
447+
425448
baseTLSConfig := &tls.Config{
426-
MinVersion: tls.VersionTLS12,
449+
MinVersion: uint16(tlsMinVersion),
450+
MaxVersion: uint16(tlsMaxVersion),
427451
CipherSuites: allowedTLSCiphers,
428452
PreferServerCipherSuites: true,
429453
}

config.yaml.dist

+2
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ web:
5555
# https: 127.0.0.1:5554
5656
# tlsCert: /etc/dex/tls.crt
5757
# tlsKey: /etc/dex/tls.key
58+
# tlsMinVersion: 1.2
59+
# tlsMaxVersion: 1.3
5860

5961
# Dex UI configuration
6062
# frontend:

0 commit comments

Comments
 (0)