Skip to content

Commit f734f69

Browse files
authored
Merge pull request #259 from slintes/disable-http2-0.6
[release-0.6] Disable HTTP/2
2 parents e0b3a2f + 74f8136 commit f734f69

File tree

2 files changed

+50
-26
lines changed

2 files changed

+50
-26
lines changed

api/v1alpha1/nodehealthcheck_webhook.go

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@ package v1alpha1
1818

1919
import (
2020
"fmt"
21-
"os"
22-
"path/filepath"
2321
"reflect"
2422
"time"
2523

@@ -33,10 +31,6 @@ import (
3331
)
3432

3533
const (
36-
WebhookCertDir = "/apiserver.local.config/certificates"
37-
WebhookCertName = "apiserver.crt"
38-
WebhookKeyName = "apiserver.key"
39-
4034
OngoingRemediationError = "prohibited due to running remediation"
4135
minHealthyError = "MinHealthy must not be negative"
4236
invalidSelectorError = "Invalid selector"
@@ -52,25 +46,6 @@ const (
5246
var nodehealthchecklog = logf.Log.WithName("nodehealthcheck-resource")
5347

5448
func (nhc *NodeHealthCheck) SetupWebhookWithManager(mgr ctrl.Manager) error {
55-
56-
// check if OLM injected certs
57-
certs := []string{filepath.Join(WebhookCertDir, WebhookCertName), filepath.Join(WebhookCertDir, WebhookKeyName)}
58-
certsInjected := true
59-
for _, fname := range certs {
60-
if _, err := os.Stat(fname); err != nil {
61-
certsInjected = false
62-
break
63-
}
64-
}
65-
if certsInjected {
66-
server := mgr.GetWebhookServer()
67-
server.CertDir = WebhookCertDir
68-
server.CertName = WebhookCertName
69-
server.KeyName = WebhookKeyName
70-
} else {
71-
nodehealthchecklog.Info("OLM injected certs for webhooks not found")
72-
}
73-
7449
return ctrl.NewWebhookManagedBy(mgr).
7550
For(nhc).
7651
Complete()

main.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ limitations under the License.
1717
package main
1818

1919
import (
20+
"crypto/tls"
2021
"flag"
2122
"fmt"
2223
"os"
24+
"path/filepath"
2325
"runtime"
2426

2527
// +kubebuilder:scaffold:imports
@@ -51,6 +53,12 @@ import (
5153
"github.com/medik8s/node-healthcheck-operator/version"
5254
)
5355

56+
const (
57+
WebhookCertDir = "/apiserver.local.config/certificates"
58+
WebhookCertName = "apiserver.crt"
59+
WebhookKeyName = "apiserver.key"
60+
)
61+
5462
var (
5563
scheme = pkgruntime.NewScheme()
5664
setupLog = ctrl.Log.WithName("setup")
@@ -72,11 +80,13 @@ func main() {
7280
var metricsAddr string
7381
var enableLeaderElection bool
7482
var probeAddr string
83+
var enableHTTP2 bool
7584
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
7685
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
7786
flag.BoolVar(&enableLeaderElection, "leader-elect", true,
7887
"Enable leader election for controller manager. "+
7988
"Enabling this will ensure there is only one active controller manager.")
89+
flag.BoolVar(&enableHTTP2, "enable-http2", false, "If HTTP/2 should be enabled for the metrics and webhook servers.")
8090

8191
opts := zap.Options{
8292
Development: true,
@@ -90,7 +100,9 @@ func main() {
90100
printVersion()
91101

92102
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
93-
Scheme: scheme,
103+
Scheme: scheme,
104+
// HEADS UP: once controller runtime is updated and this changes to metrics.Options{},
105+
// and in case you configure TLS / SecureServing, disable HTTP/2 in it for mitigating related CVEs!
94106
MetricsBindAddress: metricsAddr,
95107
Port: 9443,
96108
HealthProbeBindAddress: probeAddr,
@@ -102,6 +114,8 @@ func main() {
102114
os.Exit(1)
103115
}
104116

117+
configureWebhookServer(mgr, enableHTTP2)
118+
105119
upgradeChecker, err := cluster.NewClusterUpgradeStatusChecker(mgr)
106120
if err != nil {
107121
setupLog.Error(err, "unable initialize cluster upgrade checker")
@@ -194,3 +208,38 @@ func printVersion() {
194208
setupLog.Info(fmt.Sprintf("Git Commit: %s", version.GitCommit))
195209
setupLog.Info(fmt.Sprintf("Build Date: %s", version.BuildDate))
196210
}
211+
212+
func configureWebhookServer(mgr ctrl.Manager, enableHTTP2 bool) {
213+
214+
server := mgr.GetWebhookServer()
215+
216+
// check for OLM injected certs
217+
certs := []string{filepath.Join(WebhookCertDir, WebhookCertName), filepath.Join(WebhookCertDir, WebhookKeyName)}
218+
certsInjected := true
219+
for _, fname := range certs {
220+
if _, err := os.Stat(fname); err != nil {
221+
certsInjected = false
222+
break
223+
}
224+
}
225+
if certsInjected {
226+
server.CertDir = WebhookCertDir
227+
server.CertName = WebhookCertName
228+
server.KeyName = WebhookKeyName
229+
} else {
230+
setupLog.Info("OLM injected certs for webhooks not found")
231+
}
232+
233+
// disable http/2 for mitigating relevant CVEs
234+
if !enableHTTP2 {
235+
server.TLSOpts = append(server.TLSOpts,
236+
func(c *tls.Config) {
237+
c.NextProtos = []string{"http/1.1"}
238+
},
239+
)
240+
setupLog.Info("HTTP/2 for webhooks disabled")
241+
} else {
242+
setupLog.Info("HTTP/2 for webhooks enabled")
243+
}
244+
245+
}

0 commit comments

Comments
 (0)