mirror of https://github.com/knative/pkg.git
				
				
				
			Allow to disable http2 for the webhook (#2877)
This commit is contained in:
		
							parent
							
								
									df28feae6d
								
							
						
					
					
						commit
						0c39ce4b3a
					
				|  | @ -67,6 +67,17 @@ type Options struct { | ||||||
| 	// GracePeriod is how long to wait after failing readiness probes
 | 	// GracePeriod is how long to wait after failing readiness probes
 | ||||||
| 	// before shutting down.
 | 	// before shutting down.
 | ||||||
| 	GracePeriod time.Duration | 	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
 | // Operation is the verb being operated on
 | ||||||
|  | @ -219,11 +230,18 @@ func (wh *Webhook) Run(stop <-chan struct{}) error { | ||||||
| 		QuietPeriod: wh.Options.GracePeriod, | 		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 | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	server := &http.Server{ | 	server := &http.Server{ | ||||||
| 		Handler:           drainer, | 		Handler:           drainer, | ||||||
| 		Addr:              fmt.Sprint(":", wh.Options.Port), | 		Addr:              fmt.Sprint(":", wh.Options.Port), | ||||||
| 		TLSConfig:         wh.tlsConfig, | 		TLSConfig:         wh.tlsConfig, | ||||||
| 		ReadHeaderTimeout: time.Minute, //https://medium.com/a-journey-with-go/go-understand-and-mitigate-slowloris-attack-711c1b1403f6
 | 		ReadHeaderTimeout: time.Minute, //https://medium.com/a-journey-with-go/go-understand-and-mitigate-slowloris-attack-711c1b1403f6
 | ||||||
|  | 		TLSNextProto:      nextProto, | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	eg, ctx := errgroup.WithContext(ctx) | 	eg, ctx := errgroup.WithContext(ctx) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue