Skip to content

Commit 6f13ba0

Browse files
authored
Merge pull request kubernetes#129872 from seans3/websocket-https-proxy
WebSocket HTTPS Proxy support
2 parents b0d6079 + f73945a commit 6f13ba0

File tree

39 files changed

+491
-804
lines changed

39 files changed

+491
-804
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ require (
159159
github.com/google/btree v1.1.3 // indirect
160160
github.com/google/pprof v0.0.0-20241029153458-d1b30febd7db // indirect
161161
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
162-
github.com/gorilla/websocket v1.5.3 // indirect
162+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
163163
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
164164
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
165165
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,8 +302,8 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
302302
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
303303
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
304304
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
305-
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
306-
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
305+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 h1:JeSE6pjso5THxAzdVpqr6/geYxZytqFMBCOtn/ujyeo=
306+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
307307
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 h1:+ngKgrYPPJrOjhax5N+uePQ0Fh1Z7PheYoUI/0nzkPA=
308308
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
309309
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 h1:+9834+KizmvFV7pXQGSXQTsaWhq2GjuNUt0aUU0YBYw=

staging/src/k8s.io/apiextensions-apiserver/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ require (
6262
github.com/golang-jwt/jwt/v4 v4.5.1 // indirect
6363
github.com/golang/protobuf v1.5.4 // indirect
6464
github.com/google/btree v1.1.3 // indirect
65-
github.com/gorilla/websocket v1.5.3 // indirect
65+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
6666
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
6767
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0 // indirect
6868
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect

staging/src/k8s.io/apiextensions-apiserver/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/apiserver/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ require (
1919
github.com/google/gnostic-models v0.6.9
2020
github.com/google/go-cmp v0.7.0
2121
github.com/google/uuid v1.6.0
22-
github.com/gorilla/websocket v1.5.3
22+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
2323
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
2424
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
2525
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f

staging/src/k8s.io/apiserver/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/cli-runtime/go.sum

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/client-go/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ require (
1212
github.com/google/gnostic-models v0.6.9
1313
github.com/google/go-cmp v0.7.0
1414
github.com/google/uuid v1.6.0
15-
github.com/gorilla/websocket v1.5.3
15+
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674
1616
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79
1717
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822
1818
github.com/peterbourgon/diskv v2.0.1+incompatible

staging/src/k8s.io/client-go/go.sum

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

staging/src/k8s.io/client-go/tools/remotecommand/fallback_test.go

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ KR8NJEkK99Vh/tew6jAMll70xFrE7aF8VLXJVE7w4sQzuvHxl9Q=
288288
`)
289289

290290
// See (https://github.com/kubernetes/kubernetes/issues/126134).
291-
func TestFallbackClient_WebSocketHTTPSProxyCausesSPDYFallback(t *testing.T) {
291+
func TestFallbackClient_WebSocketHTTPSProxyNoFallback(t *testing.T) {
292292
cert, err := tls.X509KeyPair(localhostCert, localhostKey)
293293
if err != nil {
294294
t.Errorf("https (valid hostname): proxy_test: %v", err)
@@ -309,42 +309,40 @@ func TestFallbackClient_WebSocketHTTPSProxyCausesSPDYFallback(t *testing.T) {
309309
proxyLocation, err := url.Parse(proxyServer.URL)
310310
require.NoError(t, err)
311311

312-
// Create fake SPDY server. Copy received STDIN data back onto STDOUT stream.
313-
spdyServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
314-
var stdin, stdout bytes.Buffer
315-
ctx, err := createHTTPStreams(w, req, &StreamOptions{
316-
Stdin: &stdin,
317-
Stdout: &stdout,
318-
})
312+
// Create fake WebSocket server. Copy received STDIN data back onto STDOUT stream.
313+
websocketServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
314+
conns, err := webSocketServerStreams(req, w, streamOptionsFromRequest(req))
319315
if err != nil {
320316
w.WriteHeader(http.StatusForbidden)
321317
return
322318
}
323-
defer ctx.conn.Close() //nolint:errcheck
324-
_, err = io.Copy(ctx.stdoutStream, ctx.stdinStream)
319+
defer conns.conn.Close() //nolint:errcheck
320+
// Loopback the STDIN stream onto the STDOUT stream.
321+
_, err = io.Copy(conns.stdoutStream, conns.stdinStream)
325322
if err != nil {
326-
t.Fatalf("error copying STDIN to STDOUT: %v", err)
323+
t.Fatalf("websocket copy error: %v", err)
327324
}
328325
}))
329-
defer spdyServer.Close() //nolint:errcheck
326+
defer websocketServer.Close() //nolint:errcheck
330327

331-
backendLocation, err := url.Parse(spdyServer.URL)
328+
// Now create the WebSocket client (executor), and point it to the TLS proxy server.
329+
// The proxy server should open a websocket connection to the fake websocket server.
330+
websocketServer.URL = websocketServer.URL + "?" + "stdin=true" + "&" + "stdout=true"
331+
websocketLocation, err := url.Parse(websocketServer.URL)
332332
require.NoError(t, err)
333-
334333
clientConfig := &rest.Config{
335-
Host: spdyServer.URL,
334+
Host: websocketLocation.Host,
336335
TLSClientConfig: rest.TLSClientConfig{CAData: localhostCert},
337336
Proxy: func(req *http.Request) (*url.URL, error) {
338337
return proxyLocation, nil
339338
},
340339
}
341-
342-
// Websocket with https proxy will fail in dialing (falling back to SPDY).
343-
websocketExecutor, err := NewWebSocketExecutor(clientConfig, "GET", backendLocation.String())
340+
websocketExecutor, err := NewWebSocketExecutor(clientConfig, "GET", websocketServer.URL)
344341
require.NoError(t, err)
345-
spdyExecutor, err := NewSPDYExecutor(clientConfig, "POST", backendLocation)
342+
emptyURL, _ := url.Parse("")
343+
spdyExecutor, err := NewSPDYExecutor(clientConfig, "POST", emptyURL)
346344
require.NoError(t, err)
347-
// Fallback to spdyExecutor with websocket https proxy error; spdyExecutor succeeds against fake spdy server.
345+
// No fallback to spdyExecutor with websocket.
348346
sawHTTPSProxyError := false
349347
exec, err := NewFallbackExecutor(websocketExecutor, spdyExecutor, func(err error) bool {
350348
if httpstream.IsUpgradeFailure(err) {
@@ -396,9 +394,9 @@ func TestFallbackClient_WebSocketHTTPSProxyCausesSPDYFallback(t *testing.T) {
396394
t.Errorf("unexpected data received: %d sent: %d", len(data), len(randomData))
397395
}
398396

399-
// Ensure the https proxy error was observed
400-
if !sawHTTPSProxyError {
401-
t.Errorf("expected to see https proxy error")
397+
// Ensure the https proxy error was *not* observed
398+
if sawHTTPSProxyError {
399+
t.Errorf("expected to *not* see https proxy error")
402400
}
403401
// Ensure the proxy was called once
404402
if e, a := int64(1), proxyCalled.Load(); e != a {

0 commit comments

Comments
 (0)