@@ -249,6 +249,7 @@ func Run(cfg *server.KubeRBACProxyConfig) error {
249249		return  err 
250250	}
251251
252+ 	var  stoppedCh , listenerStoppedCh  <- chan  struct {}
252253	go  func () {
253254		defer  wg .Done ()
254255		defer  cancel ()
@@ -263,11 +264,15 @@ func Run(cfg *server.KubeRBACProxyConfig) error {
263264		<- stoppedCh 
264265	}()
265266
267+ 	cfg .SecureServing .Cert .CurrentCertKeyContent ()
268+ 
266269	if  cfg .KubeRBACProxyInfo .ProxyEndpointsSecureServing  !=  nil  {
267270		// we need a second listener in order to serve proxy-specific endpoints 
268271		// on a different port (--proxy-endpoints-port) 
269272		proxyEndpointsMux  :=  http .NewServeMux ()
270- 		proxyEndpointsMux .HandleFunc ("/healthz" , func (w  http.ResponseWriter , r  * http.Request ) { _ , _  =  w .Write ([]byte ("ok" )) })
273+ 		proxyEndpointsMux .HandleFunc ("/healthz" , func (w  http.ResponseWriter , r  * http.Request ) {
274+ 			proxyHealtzCheck (w , cfg .SecureServing .Listener .Addr ().String (), listenerStoppedCh , stoppedCh )
275+ 		})
271276
272277		if  err  :=  wg .Add (1 ); err  !=  nil  {
273278			return  err 
@@ -354,3 +359,31 @@ func setupAuthorizer(krbInfo *server.KubeRBACProxyInfo, delegatedAuthz *serverco
354359
355360	return  rewritingAuthorizer , nil 
356361}
362+ 
363+ func  proxyHealtzCheck (w  http.ResponseWriter , localProxyAddr  string , listenerStoppedChan , stoppedChan  <- chan  struct {}) {
364+ 	select  {
365+ 	case  <- stoppedChan :
366+ 		http .Error (w , "the proxying port serving logic has stopped" , http .StatusServiceUnavailable )
367+ 		return 
368+ 	case  <- listenerStoppedChan :
369+ 		http .Error (w , "listener stopped" , http .StatusServiceUnavailable )
370+ 		return 
371+ 	default :
372+ 	}
373+ 
374+ 	// we need the tls.Dialer otherwise the server would log EOF for TLS handshakes 
375+ 	// since the connection would be cut before that was ever attempted 
376+ 	dialer  :=  tls.Dialer {NetDialer : & net.Dialer {}, Config : & tls.Config {InsecureSkipVerify : true }}
377+ 	dialCtx , cancel  :=  context .WithTimeout (context .Background (), 5 * time .Second )
378+ 	defer  cancel ()
379+ 
380+ 	// we just knock on the other listener as we don't want to trigger proxying to upstream 
381+ 	conn , err  :=  dialer .DialContext (dialCtx , "tcp" , localProxyAddr )
382+ 	if  err  !=  nil  {
383+ 		http .Error (w , "failed to connect to the proxying listener" , http .StatusInternalServerError )
384+ 		klog .Errorf ("failed to connect to the proxying listener: %v" , err )
385+ 		return 
386+ 	}
387+ 	_  =  conn .Close ()
388+ 	_ , _  =  w .Write ([]byte ("ok" ))
389+ }
0 commit comments