fix(cli/server): do not redirect /healthz (#12080)

This commit is contained in:
Cian Johnston 2024-02-09 13:44:47 +00:00 committed by GitHub
parent 92b2e26a48
commit 2b307c7c4e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 1 deletions

View File

@ -1991,6 +1991,13 @@ func redirectToAccessURL(handler http.Handler, accessURL *url.URL, tunnel bool,
http.Redirect(w, r, accessURL.String(), http.StatusTemporaryRedirect)
}
// Exception: /healthz
// Kubernetes doesn't like it if you redirect your healthcheck or liveness check endpoint.
if r.URL.Path == "/healthz" {
handler.ServeHTTP(w, r)
return
}
// Exception: DERP
// We use this endpoint when creating a DERP-mesh in the enterprise version to directly
// dial other Coderd derpers. Redirecting to the access URL breaks direct dial since the

View File

@ -685,11 +685,17 @@ func TestServer(t *testing.T) {
require.Equal(t, c.expectRedirect, resp.Header.Get("Location"))
}
// We should never readirect /healthz
respHealthz, err := client.Request(ctx, http.MethodGet, "/healthz", nil)
require.NoError(t, err)
defer respHealthz.Body.Close()
require.Equal(t, http.StatusOK, respHealthz.StatusCode, "/healthz should never redirect")
// We should never redirect DERP
respDERP, err := client.Request(ctx, http.MethodGet, "/derp", nil)
require.NoError(t, err)
defer respDERP.Body.Close()
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode)
require.Equal(t, http.StatusUpgradeRequired, respDERP.StatusCode, "/derp should never redirect")
}
// Verify TLS