Skip to content

Commit

Permalink
Added flag to disable http/2
Browse files Browse the repository at this point in the history
  • Loading branch information
anshuman-agarwala committed Feb 4, 2025
1 parent ab4d5c8 commit cc6dc28
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package main

import (
"context"
"crypto/tls"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -62,6 +63,7 @@ var (
logOptions = logs.NewOptions()
webhookPort int
webhookCertDir string
disableHTTP2 bool

scheme = runtime.NewScheme()
setupLog = ctrl.Log.WithName("setup")
Expand Down Expand Up @@ -130,6 +132,9 @@ func initFlags(fs *pflag.FlagSet) {
fs.StringVar(&webhookCertDir, "webhook-cert-dir", "/tmp/k8s-webhook-server/serving-certs/",
"The webhook certificate directory, where the server should find the TLS certificate and key.")

fs.BoolVar(&disableHTTP2, "disable-http2", true, "http/2 should be disabled due to its vulnerabilities. More specifically, disabling http/2 will"+
" prevent from being vulnerable to the HTTP/2 Stream Cancellation and Rapid Reset CVEs.")

logsv1.AddFlags(logOptions, fs)
flags.AddManagerOptions(fs, &managerOptions)
}
Expand Down Expand Up @@ -199,6 +204,15 @@ func main() {
}
}

if disableHTTP2 {
metricsOptions.TLSOpts = append(metricsOptions.TLSOpts, func(c *tls.Config) {
setupLog.Info("disabling http/2")
c.NextProtos = []string{"http/1.1"}
})
} else {
setupLog.Info("WARNING: It is not recommended to enable http/2 due to https://github.com/kubernetes/kubernetes/issues/121197")
}

mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
Scheme: scheme,
LeaderElection: enableLeaderElection,
Expand Down

0 comments on commit cc6dc28

Please sign in to comment.