Skip to content

Commit 2b307c7

Browse files
authored
fix(cli/server): do not redirect /healthz (#12080)
1 parent 92b2e26 commit 2b307c7

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

cli/server.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1991,6 +1991,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
19911991
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
19921992
}
19931993

1994+
// Exception: /healthz
1995+
// Kubernetes doesn't like it if you redirect your healthcheck or liveness check endpoint.
1996+
if r.URL.Path == "/healthz" {
1997+
handler.ServeHTTP(w, r)
1998+
return
1999+
}
2000+
19942001
// Exception: DERP
19952002
// We use this endpoint when creating a DERP-mesh in the enterprise version to directly
19962003
// dial other Coderd derpers. Redirecting to the access URL breaks direct dial since the

cli/server_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,11 +685,17 @@ func TestServer(t *testing.T) {
685685
require.Equal(t, c.expectRedirect, resp.Header.Get("Location"))
686686
}
687687

688+
// We should never readirect /healthz
689+
respHealthz, err := client.Request(ctx, http.MethodGet, "/healthz", nil)
690+
require.NoError(t, err)
691+
defer respHealthz.Body.Close()
692+
require.Equal(t, http.StatusOK, respHealthz.StatusCode, "/healthz should never redirect")
693+
688694
// We should never redirect DERP
689695
respDERP, err := client.Request(ctx, http.MethodGet, "/derp", nil)
690696
require.NoError(t, err)
691697
defer respDERP.Body.Close()
692-
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode)
698+
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode, "/derp should never redirect")
693699
}
694700

695701
// Verify TLS

0 commit comments

Comments
 (0)