Skip to content

Commit 34819fe

Browse files
committed
webhook: new flag to configure the webhook server's minimum TLS version
1 parent d1b8fbb commit 34819fe

File tree

3 files changed

+28
-7
lines changed

3 files changed

+28
-7
lines changed

docs/deploy/configurations.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ Currently, you can set only 1 namespace to watch in this flag. See [this Kuberne
106106
|webhook-cert-dir | string | /tmp/k8s-webhook-server/serving-certs | The directory that contains the server key and certificate |
107107
|webhook-cert-file | string | tls.crt | The server certificate name |
108108
|webhook-key-file | string | tls.key | The server key name |
109+
|webhook-tls-min-version | string | 1.3 | The minimum TLS version acceptable by the webhook server |
109110

110111

111112
### disable-ingress-class-annotation

main.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,11 @@ func main() {
9191
setupLog.Error(err, "unable to start manager")
9292
os.Exit(1)
9393
}
94-
config.ConfigureWebhookServer(controllerCFG.RuntimeConfig, mgr)
94+
err = config.ConfigureWebhookServer(controllerCFG.RuntimeConfig, mgr)
95+
if err != nil {
96+
setupLog.Error(err, "unable to configure webhook server")
97+
os.Exit(1)
98+
}
9599
clientSet, err := kubernetes.NewForConfig(mgr.GetConfig())
96100
if err != nil {
97101
setupLog.Error(err, "unable to obtain clientSet")

pkg/config/runtime_config.go

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config
22

33
import (
4+
"fmt"
45
"time"
56

67
"github.com/spf13/pflag"
@@ -26,6 +27,7 @@ const (
2627
flagWebhookCertDir = "webhook-cert-dir"
2728
flagWebhookCertName = "webhook-cert-file"
2829
flagWebhookKeyName = "webhook-key-file"
30+
flagWebhookTLSMinVersion = "webhook-tls-min-version"
2931

3032
defaultKubeconfig = ""
3133
defaultLeaderElectionID = "aws-load-balancer-controller-leader"
@@ -40,10 +42,18 @@ const (
4042
defaultQPS = 1e6
4143
// High enough Burst to fit all expected use cases. Burst=0 is not set here, because
4244
// client code is overriding it.
43-
defaultBurst = 1e6
44-
defaultWebhookCertDir = ""
45-
defaultWebhookCertName = ""
46-
defaultWebhookKeyName = ""
45+
defaultBurst = 1e6
46+
defaultWebhookCertDir = ""
47+
defaultWebhookCertName = ""
48+
defaultWebhookKeyName = ""
49+
defaultWebhookTLSMinVersion = "1.3"
50+
)
51+
52+
var (
53+
supportedTLSVersions = map[string]struct{}{
54+
"1.2": {},
55+
"1.3": {},
56+
}
4757
)
4858

4959
// RuntimeConfig stores the configuration for the controller-runtime
@@ -61,6 +71,7 @@ type RuntimeConfig struct {
6171
WebhookCertDir string
6272
WebhookCertName string
6373
WebhookKeyName string
74+
WebhookTLSMinVersion string
6475
}
6576

6677
// BindFlags binds the command line flags to the fields in the config object
@@ -87,6 +98,7 @@ func (c *RuntimeConfig) BindFlags(fs *pflag.FlagSet) {
8798
fs.StringVar(&c.WebhookCertDir, flagWebhookCertDir, defaultWebhookCertDir, "WebhookCertDir is the directory that contains the webhook server key and certificate.")
8899
fs.StringVar(&c.WebhookCertName, flagWebhookCertName, defaultWebhookCertName, "WebhookCertName is the webhook server certificate name.")
89100
fs.StringVar(&c.WebhookKeyName, flagWebhookKeyName, defaultWebhookKeyName, "WebhookKeyName is the webhook server key name.")
101+
fs.StringVar(&c.WebhookTLSMinVersion, flagWebhookTLSMinVersion, defaultWebhookTLSMinVersion, "Minimum TLS version acceptable by the webhook server.")
90102

91103
}
92104

@@ -128,8 +140,12 @@ func BuildRuntimeOptions(rtCfg RuntimeConfig, scheme *runtime.Scheme) ctrl.Optio
128140
}
129141

130142
// ConfigureWebhookServer set up the server cert for the webhook server.
131-
func ConfigureWebhookServer(rtCfg RuntimeConfig, mgr ctrl.Manager) {
143+
func ConfigureWebhookServer(rtCfg RuntimeConfig, mgr ctrl.Manager) error {
132144
mgr.GetWebhookServer().CertName = rtCfg.WebhookCertName
133145
mgr.GetWebhookServer().KeyName = rtCfg.WebhookKeyName
134-
mgr.GetWebhookServer().TLSMinVersion = "1.3"
146+
if _, found := supportedTLSVersions[rtCfg.WebhookTLSMinVersion]; !found {
147+
return fmt.Errorf("unsupported tls version %q", rtCfg.WebhookTLSMinVersion)
148+
}
149+
mgr.GetWebhookServer().TLSMinVersion = rtCfg.WebhookTLSMinVersion
150+
return nil
135151
}

0 commit comments

Comments
 (0)