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

Respect client_idle_timeout config in kube proxy forwarder #49121

Merged
merged 1 commit into from
Nov 25, 2024
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
2 changes: 0 additions & 2 deletions lib/kube/proxy/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,6 @@ const (

// DefaultStreamCreationTimeout
DefaultStreamCreationTimeout = 30 * time.Second

IdleTimeout = 15 * time.Minute
)

// These constants are for remote command execution and port forwarding and are
Expand Down
3 changes: 2 additions & 1 deletion lib/kube/proxy/forwarder.go
Original file line number Diff line number Diff line change
Expand Up @@ -1667,6 +1667,7 @@ func (f *Forwarder) exec(authCtx *authContext, w http.ResponseWriter, req *http.
httpResponseWriter: w,
context: ctx,
pingPeriod: f.cfg.ConnPingPeriod,
idleTimeout: sess.clientIdleTimeout,
onResize: func(remotecommand.TerminalSize) {},
}

Expand Down Expand Up @@ -1811,6 +1812,7 @@ func (f *Forwarder) portForward(authCtx *authContext, w http.ResponseWriter, req
onPortForward: onPortForward,
targetDialer: dialer,
pingPeriod: f.cfg.ConnPingPeriod,
idleTimeout: sess.clientIdleTimeout,
}
f.log.Debugf("Starting %v.", request)
err = runPortForwarding(request)
Expand Down Expand Up @@ -2186,7 +2188,6 @@ func (f *Forwarder) getSPDYExecutor(sess *clusterSession, req *http.Request) (re
}

func (f *Forwarder) getPortForwardDialer(sess *clusterSession, req *http.Request) (httpstream.Dialer, error) {

wsDialer, err := f.getWebsocketDialer(sess, req)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
7 changes: 5 additions & 2 deletions lib/kube/proxy/portforward_spdy.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type portForwardRequest struct {
context context.Context
targetDialer httpstream.Dialer
pingPeriod time.Duration
idleTimeout time.Duration
}

func (p portForwardRequest) String() string {
Expand Down Expand Up @@ -102,8 +103,10 @@ func runPortForwardingHTTPStreams(req portForwardRequest) error {
targetConn: targetConn,
}
defer h.Close()
h.Debugf("Setting port forwarding streaming connection idle timeout to %v", IdleTimeout)
conn.SetIdleTimeout(IdleTimeout)

h.Debugf("Setting port forwarding streaming connection idle timeout to %s.", req.idleTimeout)
conn.SetIdleTimeout(req.idleTimeout)

h.run()
return nil
}
Expand Down
9 changes: 6 additions & 3 deletions lib/kube/proxy/portforward_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,8 @@ func runPortForwardingWebSocket(req portForwardRequest) error {
Channels: channels,
},
})
conn.SetIdleTimeout(IdleTimeout)

conn.SetIdleTimeout(req.idleTimeout)

// Upgrade the request and create the virtual streams.
_, streams, err := conn.Open(
Expand Down Expand Up @@ -352,8 +353,10 @@ func runPortForwardingTunneledHTTPStreams(req portForwardRequest) error {
targetConn: targetConn,
}
defer h.Close()
h.Debugf("Setting port forwarding streaming connection idle timeout to %v", IdleTimeout)
spdyConn.SetIdleTimeout(IdleTimeout)

h.Debugf("Setting port forwarding streaming connection idle timeout to %s.", req.idleTimeout)
spdyConn.SetIdleTimeout(req.idleTimeout)

h.run()
return nil
}
3 changes: 2 additions & 1 deletion lib/kube/proxy/remotecommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type remoteCommandRequest struct {
onResize resizeCallback
context context.Context
pingPeriod time.Duration
idleTimeout time.Duration
}

func (req remoteCommandRequest) eventPodMeta(ctx context.Context, creds kubeCreds) apievents.KubernetesPodMetadata {
Expand Down Expand Up @@ -156,7 +157,7 @@ func createSPDYStreams(req remoteCommandRequest) (*remoteCommandProxy, error) {
return nil, trace.ConnectionProblem(trace.BadParameter("missing connection"), "missing connection")
}

conn.SetIdleTimeout(IdleTimeout)
conn.SetIdleTimeout(req.idleTimeout)

var handler protocolHandler
switch protocol {
Expand Down
4 changes: 3 additions & 1 deletion lib/kube/proxy/remotecommand_websocket.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ func createWebSocketStreams(req remoteCommandRequest) (*remoteCommandProxy, erro
Channels: channels,
},
})
conn.SetIdleTimeout(IdleTimeout)

conn.SetIdleTimeout(req.idleTimeout)

negotiatedProtocol, streams, err := conn.Open(
responsewriter.GetOriginal(req.httpResponseWriter),
req.httpRequest,
Expand Down
Loading