Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[release-v1.9] Allow to disable http2 for the webhook #70

Merged
merged 1 commit into from
Oct 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 44 additions & 0 deletions openshift/patches/003-http2-cve.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
diff --git a/vendor/knative.dev/pkg/webhook/webhook.go b/vendor/knative.dev/pkg/webhook/webhook.go
index 435dfe38..00fcd3c4 100644
--- a/vendor/knative.dev/pkg/webhook/webhook.go
+++ b/vendor/knative.dev/pkg/webhook/webhook.go
@@ -63,6 +63,17 @@ type Options struct {
// GracePeriod is how long to wait after failing readiness probes
// before shutting down.
GracePeriod time.Duration
+
+ // EnableHTTP2 enables HTTP2 for webhooks.
+ // Mitigate CVE-2023-44487 by disabling HTTP2 by default until the Go
+ // standard library and golang.org/x/net are fully fixed.
+ // Right now, it is possible for authenticated and unauthenticated users to
+ // hold open HTTP2 connections and consume huge amounts of memory.
+ // See:
+ // * https://github.com/kubernetes/kubernetes/pull/121120
+ // * https://github.com/kubernetes/kubernetes/issues/121197
+ // * https://github.com/golang/go/issues/63417#issuecomment-1758858612
+ EnableHTTP2 bool
}

// Operation is the verb being operated on
@@ -208,11 +219,18 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
QuietPeriod: wh.Options.GracePeriod,
}

+ // If TLSNextProto is not nil, HTTP/2 support is not enabled automatically.
+ nextProto := map[string]func(*http.Server, *tls.Conn, http.Handler){}
+ if wh.Options.EnableHTTP2 {
+ nextProto = nil
+ }
+
//nolint:gosec
server := &http.Server{
- Handler: drainer,
- Addr: fmt.Sprint(":", wh.Options.Port),
- TLSConfig: wh.tlsConfig,
+ Handler: drainer,
+ Addr: fmt.Sprint(":", wh.Options.Port),
+ TLSConfig: wh.tlsConfig,
+ TLSNextProto: nextProto,
}

eg, ctx := errgroup.WithContext(ctx)
24 changes: 21 additions & 3 deletions vendor/knative.dev/pkg/webhook/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ type Options struct {
// GracePeriod is how long to wait after failing readiness probes
// before shutting down.
GracePeriod time.Duration

// EnableHTTP2 enables HTTP2 for webhooks.
// Mitigate CVE-2023-44487 by disabling HTTP2 by default until the Go
// standard library and golang.org/x/net are fully fixed.
// Right now, it is possible for authenticated and unauthenticated users to
// hold open HTTP2 connections and consume huge amounts of memory.
// See:
// * https://github.com/kubernetes/kubernetes/pull/121120
// * https://github.com/kubernetes/kubernetes/issues/121197
// * https://github.com/golang/go/issues/63417#issuecomment-1758858612
EnableHTTP2 bool
}

// Operation is the verb being operated on
Expand Down Expand Up @@ -208,11 +219,18 @@ func (wh *Webhook) Run(stop <-chan struct{}) error {
QuietPeriod: wh.Options.GracePeriod,
}

// If TLSNextProto is not nil, HTTP/2 support is not enabled automatically.
nextProto := map[string]func(*http.Server, *tls.Conn, http.Handler){}
if wh.Options.EnableHTTP2 {
nextProto = nil
}

//nolint:gosec
server := &http.Server{
Handler: drainer,
Addr: fmt.Sprint(":", wh.Options.Port),
TLSConfig: wh.tlsConfig,
Handler: drainer,
Addr: fmt.Sprint(":", wh.Options.Port),
TLSConfig: wh.tlsConfig,
TLSNextProto: nextProto,
}

eg, ctx := errgroup.WithContext(ctx)
Expand Down
Loading